Merge "Warn on account creation when username is adjusted"
[lhc/web/wiklou.git] / includes / templates / Usercreate.php
1 <?php
2 /**
3 * Html form for account creation (since 1.22 with VForm appearance).
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Templates
22 */
23
24 class UsercreateTemplate extends BaseTemplate {
25
26 /**
27 * Extensions (AntiSpoof and TitleBlacklist) call this in response to
28 * UserCreateForm hook to add checkboxes to the create account form.
29 */
30 function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
31 $this->data['extraInput'][] = array(
32 'name' => $name,
33 'value' => $value,
34 'type' => $type,
35 'msg' => $msg,
36 'helptext' => $helptext,
37 );
38 }
39
40 function execute() {
41 global $wgCookieExpiration;
42 $expirationDays = ceil( $wgCookieExpiration / ( 3600 * 24 ) );
43 ?>
44 <div class="mw-ui-container">
45 <?php if ( $this->haveData( 'languages' ) ) { ?>
46 <div id="languagelinks">
47 <p><?php $this->html( 'languages' ); ?></p>
48 </div>
49 <?php }
50 if ( !wfMessage( 'signupstart' )->isDisabled() ) { ?>
51 <div id="signupstart"><?php $this->msgWiki( 'signupstart' ); ?></div>
52 <?php } ?>
53 <div id="userloginForm">
54 <h2 class="createaccount-join">
55 <?php $this->msg( $this->data['loggedin'] ? 'createacct-another-join' : 'createacct-join' ); ?>
56 </h2>
57 <form name="userlogin2" id="userlogin2" class="mw-ui-vform" method="post" action="<?php $this->text( 'action' ); ?>">
58 <section class="mw-form-header">
59 <?php $this->html( 'header' ); /* extensions such as ConfirmEdit add form HTML here */ ?>
60 </section>
61 <!-- This element is used by the mediawiki.special.userlogin.signup.js module. -->
62 <div
63 id="mw-createacct-status-area"
64 <?php if ( $this->data['message'] ) { ?>
65 class="<?php echo $this->data['messagetype']; ?>box"
66 <?php } else { ?>
67 style="display: none;"
68 <?php } ?>
69 >
70 <?php if ( $this->data['message'] ) { ?>
71 <?php if ( $this->data['messagetype'] == 'error' ) { ?>
72 <strong><?php $this->msg( 'createacct-error' ); ?></strong>
73 <br />
74 <?php } ?>
75 <?php $this->html( 'message' ); ?>
76 <?php } ?>
77 </div>
78
79 <div>
80 <label for='wpName2'>
81 <?php $this->msg( 'userlogin-yourname' ); ?>
82
83 <span class="mw-ui-flush-right"><?php echo $this->getMsg( 'createacct-helpusername' )->parse(); ?></span>
84 </label>
85 <?php
86 echo Html::input( 'wpName', $this->data['name'], 'text', array(
87 'class' => 'mw-input loginText',
88 'id' => 'wpName2',
89 'tabindex' => '1',
90 'size' => '20',
91 'required',
92 'placeholder' => $this->getMsg( $this->data['loggedin'] ?
93 'createacct-another-username-ph' : 'userlogin-yourname-ph' )->text(),
94 ) );
95 ?>
96 </div>
97
98 <div>
99 <?php if ( $this->data['createemail'] ) { ?>
100 <label class="mw-ui-checkbox-label">
101 <input name="wpCreateaccountMail" type="checkbox" value="1" id="wpCreateaccountMail" tabindex="2"
102 <?php if ( $this->data['createemailset'] ) {
103 echo 'checked="checked"';
104 } ?>
105 >
106 <?php $this->msg( 'createaccountmail' ); ?>
107 </label>
108 <?php } ?>
109 </div>
110
111 <div class="mw-row-password">
112 <label for='wpPassword2'><?php $this->msg( 'userlogin-yourpassword' ); ?></label>
113 <?php
114 echo Html::input( 'wpPassword', null, 'password', array(
115 'class' => 'mw-input loginPassword',
116 'id' => 'wpPassword2',
117 'tabindex' => '3',
118 'size' => '20',
119 'required',
120 'placeholder' => $this->getMsg( 'createacct-yourpassword-ph' )->text()
121 ) + User::passwordChangeInputAttribs() );
122 ?>
123 </div>
124
125 <?php
126 if ( $this->data['usedomain'] ) {
127 $select = new XmlSelect( 'wpDomain', false, $this->data['domain'] );
128 $select->setAttribute( 'tabindex', 4 );
129 foreach ( $this->data['domainnames'] as $dom ) {
130 $select->addOption( $dom );
131 }
132 ?>
133 <div id="mw-user-domain-section">
134 <label for="wpDomain"><?php $this->msg( 'yourdomainname' ); ?></label>
135 <div class="mw-input">
136 <?php echo $select->getHTML(); ?>
137 </div>
138 </div>
139 <?php } ?>
140
141 <div class="mw-row-password">
142 <label for='wpRetype'><?php $this->msg( 'createacct-yourpasswordagain' ); ?></label>
143 <?php
144 echo Html::input( 'wpRetype', null, 'password', array(
145 'class' => 'mw-input loginPassword',
146 'id' => 'wpRetype',
147 'tabindex' => '5',
148 'size' => '20',
149 'required',
150 'placeholder' => $this->getMsg( 'createacct-yourpasswordagain-ph' )->text()
151 ) + User::passwordChangeInputAttribs() );
152 ?>
153 </div>
154
155 <div>
156 <?php if ( $this->data['useemail'] ) { ?>
157 <label for='wpEmail'>
158 <?php
159 $this->msg( $this->data['emailrequired'] ?
160 'createacct-emailrequired' :
161 'createacct-emailoptional'
162 );
163 ?>
164 </label>
165 <?php
166 echo Html::input( 'wpEmail', $this->data['email'], 'email', array(
167 'class' => 'mw-input loginText',
168 'id' => 'wpEmail',
169 'tabindex' => '6',
170 'size' => '20',
171 'required' => $this->data['emailrequired'],
172 'placeholder' => $this->getMsg( $this->data['loggedin'] ?
173 'createacct-another-email-ph' : 'createacct-email-ph' )->text()
174 ) );
175 ?>
176 <?php } ?>
177 </div>
178
179 <?php if ( $this->data['userealname'] ) { ?>
180 <div>
181 <label for='wpRealName'><?php $this->msg( 'createacct-realname' ); ?></label>
182 <input type='text' class='mw-input loginText' name="wpRealName" id="wpRealName"
183 tabindex="7"
184 value="<?php $this->text( 'realname' ); ?>" size='20' />
185 <div class="prefsectiontip">
186 <?php $this->msgWiki( $this->data['loggedin'] ? 'createacct-another-realname-tip' : 'prefs-help-realname' ); ?>
187 </div>
188 </div>
189 <?php } ?>
190
191 <?php if ( $this->data['usereason'] ) { ?>
192 <div>
193 <label for='wpReason'><?php $this->msg( 'createacct-reason' ); ?></label>
194 <?php echo Html::input( 'wpReason', $this->data['reason'], 'text', array(
195 'class' => 'mw-input loginText',
196 'id' => 'wpReason',
197 'tabindex' => '8',
198 'size' => '20',
199 'placeholder' => $this->getMsg( 'createacct-reason-ph' )->text()
200 ) ); ?>
201 </div>
202 <?php } ?>
203
204 <?php
205 $tabIndex = 9;
206 if ( isset( $this->data['extraInput'] ) && is_array( $this->data['extraInput'] ) ) {
207 foreach ( $this->data['extraInput'] as $inputItem ) { ?>
208 <div>
209 <?php
210 // If it's a checkbox, output the whole thing (assume it has a msg).
211 if ( $inputItem['type'] == 'checkbox' ) {
212 ?>
213 <label class="mw-ui-checkbox-label">
214 <input
215 name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
216 id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
217 type="checkbox" value="1"
218 tabindex="<?php echo $tabIndex++; ?>"
219 <?php if ( !empty( $inputItem['value'] ) ) {
220 echo 'checked="checked"';
221 } ?>
222 >
223 <?php $this->msg( $inputItem['msg'] ); ?>
224 </label>
225 <?php
226 } else {
227 // Not a checkbox.
228 // TODO (bug 31909) support other input types, e.g. select boxes.
229 ?>
230 <?php if ( !empty( $inputItem['msg'] ) ) { ?>
231 <label for="<?php echo htmlspecialchars( $inputItem['name'] ); ?>">
232 <?php $this->msgWiki( $inputItem['msg'] ); ?>
233 </label>
234 <?php } ?>
235 <input
236 type="<?php echo htmlspecialchars( $inputItem['type'] ); ?>"
237 class="mw-input"
238 name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
239 tabindex="<?php echo $tabIndex++; ?>"
240 value="<?php echo htmlspecialchars( $inputItem['value'] ); ?>"
241 id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
242 />
243 <?php } ?>
244 <?php if ( $inputItem['helptext'] !== false ) { ?>
245 <div class="prefsectiontip">
246 <?php $this->msgWiki( $inputItem['helptext'] ); ?>
247 </div>
248 <?php } ?>
249 </div>
250 <?php
251 }
252 }
253
254 // JS attempts to move the image CAPTCHA below this part of the form,
255 // so skip one index.
256 $tabIndex++;
257 ?>
258 <div class="mw-submit">
259 <?php
260 echo Html::input(
261 'wpCreateaccount',
262 $this->getMsg( $this->data['loggedin'] ? 'createacct-another-submit' : 'createacct-submit' ),
263 'submit',
264 array(
265 'class' => "mw-ui-button mw-ui-big mw-ui-block mw-ui-constructive",
266 'id' => 'wpCreateaccount',
267 'tabindex' => $tabIndex++
268 )
269 );
270 ?>
271 </div>
272 <?php if ( $this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
273 <?php if ( $this->haveData( 'token' ) ) { ?><input type="hidden" name="wpCreateaccountToken" value="<?php $this->text( 'token' ); ?>" /><?php } ?>
274 </form>
275 <?php if ( !wfMessage( 'signupend' )->isDisabled() ) { ?>
276 <div id="signupend"><?php $this->html( 'signupend' ); ?></div>
277 <?php } ?>
278 </div>
279 <div class="mw-createacct-benefits-container">
280 <h2><?php $this->msg( 'createacct-benefit-heading' ); ?></h2>
281 <div class="mw-createacct-benefits-list">
282 <?php
283 for ( $benefitIdx = 1; $benefitIdx <= $this->data['benefitCount']; $benefitIdx++ ) {
284 // Pass each benefit's head text (by default a number) as a parameter to the body's message for PLURAL handling.
285 $headUnescaped = $this->getMsg( "createacct-benefit-head$benefitIdx" )->text();
286 ?>
287 <div class="mw-number-text <?php $this->msg( "createacct-benefit-icon$benefitIdx" ); ?>">
288 <h3><?php $this->msg( "createacct-benefit-head$benefitIdx" ); ?></h3>
289 <p><?php echo $this->getMsg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped(); ?></p>
290 </div>
291 <?php } ?>
292 </div>
293 </div>
294 </div>
295 <?php
296
297 }
298 }