Merge "Reindent UsercreateTemplate and UserloginTemplate"
[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 if ( !defined( 'MEDIAWIKI' ) ) {
25 die( -1 );
26 }
27
28 class UsercreateTemplate extends BaseTemplate {
29
30 /**
31 * Extensions (AntiSpoof and TitleBlacklist) call this in response to
32 * UserCreateForm hook to add checkboxes to the create account form.
33 */
34 function addInputItem( $name, $value, $type, $msg, $helptext = false ) {
35 $this->data['extraInput'][] = array(
36 'name' => $name,
37 'value' => $value,
38 'type' => $type,
39 'msg' => $msg,
40 'helptext' => $helptext,
41 );
42 }
43
44 function execute() {
45 global $wgCookieExpiration;
46 $expirationDays = ceil( $wgCookieExpiration / ( 3600 * 24 ) );
47 ?>
48 <div class="mw-ui-container">
49 <?php if ( $this->haveData( 'languages' ) ) { ?>
50 <div id="languagelinks">
51 <p><?php $this->html( 'languages' ); ?></p>
52 </div>
53 <?php } ?>
54 <div id="userloginForm">
55 <h2 class="createaccount-join">
56 <?php $this->msg( $this->data['loggedin'] ? 'createacct-another-join' : 'createacct-join' ); ?>
57 </h2>
58 <form name="userlogin2" id="userlogin2" class="mw-ui-vform" method="post" action="<?php $this->text( 'action' ); ?>">
59 <section class="mw-form-header">
60 <?php $this->html( 'header' ); /* extensions such as ConfirmEdit add form HTML here */ ?>
61 </section>
62 <?php if ( $this->data['message'] ) { ?>
63 <div class="<?php $this->text( 'messagetype' ); ?>box">
64 <?php if ( $this->data['messagetype'] == 'error' ) { ?>
65 <strong><?php $this->msg( 'createacct-error' ); ?></strong>
66 <br />
67 <?php } ?>
68 <?php $this->html( 'message' ); ?>
69 </div>
70 <?php } ?>
71
72 <div>
73 <label for='wpName2'>
74 <?php $this->msg( 'userlogin-yourname' ); ?>
75
76 <span class="mw-ui-flush-right"><?php echo $this->getMsg( 'createacct-helpusername' )->parse(); ?></span>
77 </label>
78 <?php
79 echo Html::input( 'wpName', $this->data['name'], 'text', array(
80 'class' => 'mw-input loginText',
81 'id' => 'wpName2',
82 'tabindex' => '1',
83 'size' => '20',
84 'required',
85 'placeholder' => $this->getMsg( $this->data['loggedin'] ?
86 'createacct-another-username-ph' : 'userlogin-yourname-ph' )->text(),
87 ) );
88 ?>
89 </div>
90
91 <div>
92 <?php if ( $this->data['createemail'] ) { ?>
93 <label class="mw-ui-checkbox-label">
94 <input name="wpCreateaccountMail" type="checkbox" value="1" id="wpCreateaccountMail" tabindex="2"
95 <?php if ( $this->data['createemailset'] ) {
96 echo 'checked="checked"';
97 } ?>
98 >
99 <?php $this->msg( 'createaccountmail' ); ?>
100 </label>
101 <?php } ?>
102 </div>
103
104 <div class="mw-row-password">
105 <label for='wpPassword2'><?php $this->msg( 'userlogin-yourpassword' ); ?></label>
106 <?php
107 echo Html::input( 'wpPassword', null, 'password', array(
108 'class' => 'mw-input loginPassword',
109 'id' => 'wpPassword2',
110 'tabindex' => '3',
111 'size' => '20',
112 'required',
113 'placeholder' => $this->getMsg( 'createacct-yourpassword-ph' )->text()
114 ) + User::passwordChangeInputAttribs() );
115 ?>
116 </div>
117
118 <?php
119 if ( $this->data['usedomain'] ) {
120 $doms = "";
121 foreach ( $this->data['domainnames'] as $dom ) {
122 $doms .= "<option>" . htmlspecialchars( $dom ) . "</option>";
123 }
124 ?>
125 <div id="mw-user-domain-section">
126 <label for="wpDomain"><?php $this->msg( 'yourdomainname' ); ?></label>
127 <div class="mw-input">
128 <select name="wpDomain" value="<?php $this->text( 'domain' ); ?>" tabindex="4">
129 <?php echo $doms ?>
130 </select>
131 </div>
132 </div>
133 <?php } ?>
134
135 <div class="mw-row-password">
136 <label for='wpRetype'><?php $this->msg( 'createacct-yourpasswordagain' ); ?></label>
137 <?php
138 echo Html::input( 'wpRetype', null, 'password', array(
139 'class' => 'mw-input loginPassword',
140 'id' => 'wpRetype',
141 'tabindex' => '5',
142 'size' => '20',
143 'required',
144 'placeholder' => $this->getMsg( 'createacct-yourpasswordagain-ph' )->text()
145 ) + User::passwordChangeInputAttribs() );
146 ?>
147 </div>
148
149 <div>
150 <?php if ( $this->data['useemail'] ) { ?>
151 <label for='wpEmail'>
152 <?php
153 $this->msg( $this->data['emailrequired'] ?
154 'createacct-emailrequired' :
155 'createacct-emailoptional'
156 );
157 ?>
158 </label>
159 <?php
160 echo Html::input( 'wpEmail', $this->data['email'], 'email', array(
161 'class' => 'mw-input loginText',
162 'id' => 'wpEmail',
163 'tabindex' => '6',
164 'size' => '20',
165 'placeholder' => $this->getMsg( $this->data['loggedin'] ?
166 'createacct-another-email-ph' : 'createacct-email-ph' )->text()
167 ) + ( $this->data['emailrequired'] ? array() : array( 'required' => '' ) ) );
168 ?>
169 <?php } ?>
170 </div>
171
172 <?php if ( $this->data['userealname'] ) { ?>
173 <div>
174 <label for='wpRealName'><?php $this->msg( 'createacct-realname' ); ?></label>
175 <input type='text' class='mw-input loginText' name="wpRealName" id="wpRealName"
176 tabindex="7"
177 value="<?php $this->text( 'realname' ); ?>" size='20' />
178 <div class="prefsectiontip">
179 <?php $this->msgWiki( $this->data['loggedin'] ? 'createacct-another-realname-tip' : 'prefs-help-realname' ); ?>
180 </div>
181 </div>
182 <?php } ?>
183
184 <?php if ( $this->data['usereason'] ) { ?>
185 <div>
186 <label for='wpReason'><?php $this->msg( 'createacct-reason' ); ?></label>
187 <?php echo Html::input( 'wpReason', $this->data['reason'], 'text', array(
188 'class' => 'mw-input loginText',
189 'id' => 'wpReason',
190 'tabindex' => '8',
191 'size' => '20',
192 'placeholder' => $this->getMsg( 'createacct-reason-ph' )->text()
193 ) ); ?>
194 </div>
195 <?php } ?>
196
197 <?php
198 $tabIndex = 9;
199 if ( isset( $this->data['extraInput'] ) && is_array( $this->data['extraInput'] ) ) {
200 foreach ( $this->data['extraInput'] as $inputItem ) { ?>
201 <div>
202 <?php
203 // If it's a checkbox, output the whole thing (assume it has a msg).
204 if ( $inputItem['type'] == 'checkbox' ) {
205 ?>
206 <label class="mw-ui-checkbox-label">
207 <input
208 name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
209 id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
210 type="checkbox" value="1"
211 tabindex="<?php echo $tabIndex++; ?>"
212 <?php if ( !empty( $inputItem['value'] ) ) {
213 echo 'checked="checked"';
214 } ?>
215 >
216 <?php $this->msg( $inputItem['msg'] ); ?>
217 </label>
218 <?php
219 } else {
220 // Not a checkbox.
221 // TODO (bug 31909) support other input types, e.g. select boxes.
222 ?>
223 <?php if ( !empty( $inputItem['msg'] ) ) { ?>
224 <label for="<?php echo htmlspecialchars( $inputItem['name'] ); ?>">
225 <?php $this->msgWiki( $inputItem['msg'] ); ?>
226 </label>
227 <?php } ?>
228 <input
229 type="<?php echo htmlspecialchars( $inputItem['type'] ); ?>"
230 class="mw-input"
231 name="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
232 tabindex="<?php echo $tabIndex++; ?>"
233 value="<?php echo htmlspecialchars( $inputItem['value'] ); ?>"
234 id="<?php echo htmlspecialchars( $inputItem['name'] ); ?>"
235 />
236 <?php } ?>
237 <?php if ( $inputItem['helptext'] !== false ) { ?>
238 <div class="prefsectiontip">
239 <?php $this->msgWiki( $inputItem['helptext'] ); ?>
240 </div>
241 <?php } ?>
242 </div>
243 <?php
244 }
245 }
246
247 // JS attempts to move the image CAPTCHA below this part of the form,
248 // so skip one index.
249 $tabIndex++;
250 ?>
251 <div class="mw-submit">
252 <?php
253 echo Html::input(
254 'wpCreateaccount',
255 $this->getMsg( $this->data['loggedin'] ? 'createacct-another-submit' : 'createacct-submit' ),
256 'submit',
257 array(
258 'class' => "mw-ui-button mw-ui-big mw-ui-block mw-ui-primary",
259 'id' => 'wpCreateaccount',
260 'tabindex' => $tabIndex++
261 )
262 );
263 ?>
264 </div>
265 <?php if ( $this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
266 <?php if ( $this->haveData( 'token' ) ) { ?><input type="hidden" name="wpCreateaccountToken" value="<?php $this->text( 'token' ); ?>" /><?php } ?>
267 </form>
268 </div>
269 <div class="mw-createacct-benefits-container">
270 <h2><?php $this->msg( 'createacct-benefit-heading' ); ?></h2>
271 <div class="mw-createacct-benefits-list">
272 <?php
273 for ( $benefitIdx = 1; $benefitIdx <= $this->data['benefitCount']; $benefitIdx++ ) {
274 // Pass each benefit's head text (by default a number) as a parameter to the body's message for PLURAL handling.
275 $headUnescaped = $this->getMsg( "createacct-benefit-head$benefitIdx" )->text();
276 ?>
277 <div class="mw-number-text <?php $this->msg( "createacct-benefit-icon$benefitIdx" ); ?>">
278 <h3><?php $this->msg( "createacct-benefit-head$benefitIdx" ); ?></h3>
279 <p><?php echo $this->getMsg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped(); ?></p>
280 </div>
281 <?php } ?>
282 </div>
283 </div>
284 </div>
285 <?php
286
287 }
288 }