Index: branches/wikidata/phase3/includes/SpecialNamespaces.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | * Constructor |
11 | 11 | */ |
12 | 12 | function wfSpecialNamespaces() { |
13 | | - global $wgUser, $wgOut, $wgRequest; |
| 13 | + global $wgUser, $wgRequest; |
14 | 14 | |
15 | 15 | $action = $wgRequest->getVal( 'action' ); |
16 | 16 | $f = new NamespaceForm(); |
— | — | @@ -36,15 +36,15 @@ |
37 | 37 | class NamespaceForm { |
38 | 38 | |
39 | 39 | function showForm( $errorHeader='', $errorBody='' ) { |
40 | | - global $wgOut, $wgUser, $wgLang, $wgNamespaces,$wgTitle; |
| 40 | + global $wgOut, $wgUser, $wgNamespaces,$wgTitle; |
41 | 41 | |
42 | | - $wgOut->setPagetitle( wfMsg( "namespaces" ) ); |
| 42 | + $wgOut->setPagetitle( wfMsg( 'namespaces' ) ); |
43 | 43 | |
44 | 44 | /* In case of an error, we generally just show what went wrong |
45 | 45 | and continue displaying the main form */ |
46 | 46 | if ( '' != $errorHeader ) { |
47 | | - $wgOut->setSubtitle( wfMsg( "transactionerror" ) ); |
48 | | - $wgOut->addHTML( "<p class='error'>".htmlspecialchars($errorHeader)."</P>"); |
| 47 | + $wgOut->setSubtitle( wfMsg( 'transactionerror' ) ); |
| 48 | + $wgOut->addHTML( '<p class="error">' . htmlspecialchars($errorHeader) . '</p>'); |
49 | 49 | if($errorBody) { |
50 | 50 | $wgOut->addWikiText($errorBody); |
51 | 51 | } |
— | — | @@ -52,8 +52,8 @@ |
53 | 53 | |
54 | 54 | # Standard token to avoid remote form submission exploits |
55 | 55 | $token = $wgUser->editToken(); |
56 | | - $action = $wgTitle->escapeLocalURL( "action=submit" ); |
57 | | - $talksuffix = wfEscapeJsString(wfMsgForContent("talkpagesuffix")); |
| 56 | + $action = $wgTitle->escapeLocalURL( 'action=submit' ); |
| 57 | + $talksuffix = wfEscapeJsString(wfMsgForContent('talkpagesuffix')); |
58 | 58 | |
59 | 59 | # For the namespace selection box |
60 | 60 | $name_array = Namespace::getFormattedDefaultNamespaces(); |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | # Sort for foreach loops |
65 | 65 | ksort($name_array); |
66 | 66 | |
67 | | - $wgOut->addWikiText( wfMsg( "add_namespaces_header" ) ); |
| 67 | + $wgOut->addWikiText( wfMsg( 'add_namespaces_header' ) ); |
68 | 68 | |
69 | 69 | # Prefill talk namespace field, but only for languages |
70 | 70 | # where it's not disabled |
— | — | @@ -106,40 +106,45 @@ |
107 | 107 | |
108 | 108 | $wgOut->addWikiText( wfMsg( "modify_namespaces_header" ) ); |
109 | 109 | |
110 | | - $namespace_child_of = wfMsg('namespace_child_of'); |
111 | | - $namespace_support_subpages = wfMsg('namespace_support_subpages'); |
112 | | - $namespace_search_by_default = wfMsg('namespace_search_by_default'); |
113 | | - $namespace_hide_in_lists = wfMsg('namespace_hide_in_lists'); |
114 | | - $namespace_default_link_prefix = wfMsg('namespace_default_link_prefix'); |
115 | | - $namespace_system = wfMsg('namespace_system'); |
116 | | - $namespace_properties = wfMsg('namespace_properties'); |
117 | | - $namespace_slot = wfMsg('namespace_slot'); |
118 | | - $namespace_names = wfMsg('namespace_names'); |
119 | | - $namespace_existing_names = wfMsg('namespace_existing_names'); |
120 | | - $namespace_new_names = wfMsg('namespace_new_names'); |
121 | | - $namespace_default_name = wfMsg('namespace_default_name'); |
122 | | - $namespace_delete_name = wfMsg('namespace_delete_name'); |
123 | | - $namespace_save_changes = wfMsg('namespace_save_changes'); |
124 | | - |
| 110 | + // Array of messages to be used |
| 111 | + $nsMessages = array ( |
| 112 | + 'child_of', 'default_link_prefix', 'default_name', 'delete_name', |
| 113 | + 'existing_names', 'hide_in_lists', 'names', 'new_names', |
| 114 | + 'properties', 'save_changes', 'search_by_default', 'slot', |
| 115 | + 'support_subpages', 'system', |
| 116 | + ); |
| 117 | + |
| 118 | + // Build variables using the array. 'child_of' will do: |
| 119 | + // $namespace_child_of = wfMsg('namespace_child_of'); |
| 120 | + foreach( $nsMessages as $nsMessage ) { |
| 121 | + $msgName = 'namespace_' . $nsMessage ; |
| 122 | + $$msgName = wfMsg( $msgName ); |
| 123 | + } |
| 124 | + |
| 125 | + // Initialise the form |
125 | 126 | $htmlform=<<<END |
126 | 127 | <form name="changenamespaces" method="post" action="{$action}"> |
127 | 128 | <input type="hidden" name="nsAction" value="changenamespaces" /> |
128 | 129 | <input type="hidden" name="wpEditToken" value="{$token}" /> |
129 | 130 | END; |
| 131 | + |
| 132 | + // Now we proceed each namespace |
130 | 133 | foreach ($wgNamespaces as $ns) { |
131 | 134 | |
132 | 135 | $index = $ns->getIndex(); |
| 136 | + |
| 137 | + // Make sure the checkboxes remain checked: |
133 | 138 | $subpages = $ns->allowsSubpages() ? ' checked' : ''; |
134 | 139 | $searchdefault = $ns->isSearchedByDefault() ? ' checked' :''; |
135 | 140 | $hidden = $ns->isHidden ? ' checked' : ''; |
| 141 | + |
136 | 142 | $linkprefix = $ns->getTarget(); |
| 143 | + $parentslot = $ns->getParentIndex(); |
137 | 144 | $namespaceselect = ''; |
138 | | - $parentslot = $ns->getParentIndex(); |
139 | 145 | |
140 | 146 | # maybe make HTMLnamespaceselector more flexible and use |
141 | 147 | # it instead here |
142 | | - if(!$ns->isSpecial()) { |
143 | | - |
| 148 | + if( !$ns->isSpecial() ) { |
144 | 149 | foreach ( $name_array as $arr_index => $arr_name ) { |
145 | 150 | if( $arr_index < NS_MAIN && $arr_name!=$noparent ) |
146 | 151 | continue; |
— | — | @@ -151,6 +156,10 @@ |
152 | 157 | } |
153 | 158 | $namespaceselect .= "\n<option value='$arr_index'$selected>$list_option</option>"; |
154 | 159 | } |
| 160 | + |
| 161 | + |
| 162 | + // TODO : fix code below, maybe use HTMLForm ? |
| 163 | + |
155 | 164 | $namespaceselect_html=<<<END |
156 | 165 | <tr valign="top"><td colspan="2"> |
157 | 166 | {$namespace_child_of}<br /> |
— | — | @@ -199,14 +208,14 @@ |
200 | 209 | $special_html=''; |
201 | 210 | |
202 | 211 | } else { |
203 | | - |
204 | | - $namespaceselect_html=''; |
205 | | - $subpages_html=''; |
206 | | - $searchdefault_html=''; |
207 | | - $hide_html=''; |
208 | | - $target_html=''; |
209 | | - $special_namespace=wfMsg('special_namespace'); |
210 | | - $special_html=<<<END |
| 212 | + // For special namespace |
| 213 | + $namespaceselect_html = ''; |
| 214 | + $subpages_html = ''; |
| 215 | + $searchdefault_html = ''; |
| 216 | + $hide_html = ''; |
| 217 | + $target_html = ''; |
| 218 | + $special_namespace = wfMsg('special_namespace'); |
| 219 | + $special_html = <<<END |
211 | 220 | <tr valign="top"><td colspan="2"> |
212 | 221 | <em>{$special_namespace}</em> |
213 | 222 | </td> |
— | — | @@ -214,82 +223,69 @@ |
215 | 224 | END; |
216 | 225 | } |
217 | 226 | |
218 | | - $systemtype=$ns->getSystemType(); |
219 | | - if($ns->getSystemType()) { |
220 | | - $systemtype_html=<<<END |
| 227 | + |
| 228 | + $systemtype = $ns->getSystemType(); |
| 229 | + |
| 230 | + if( $ns->getSystemType() ) { |
| 231 | + // No delete link ? |
| 232 | + $systemtype_html = <<<END |
221 | 233 | <tr valign="top"><td> |
222 | | -<B><font color="red">{$namespace_system}</font></B> |
| 234 | +<b><font color="red">{$namespace_system}</font></b> |
223 | 235 | </td> |
224 | 236 | <td align="right"> |
225 | | -<B>{$systemtype}</B> |
| 237 | +<b>{$systemtype}</b> |
226 | 238 | </td> |
227 | 239 | </tr> |
228 | 240 | END; |
229 | | - $deletenamespace_html=''; |
| 241 | + $deletenamespace_html = ''; |
230 | 242 | } else { |
231 | | - $sk=$wgUser->getSkin(); |
232 | | - $delete_link=$sk->makeKnownLinkObj($wgTitle,wfMsg('delete_namespace'),'action=delete&ns='.$index); |
233 | | - $deletenamespace_html=<<<END |
| 243 | + // Give out a link to delete the namespace |
| 244 | + $sk = $wgUser->getSkin(); |
| 245 | + $delete_link = $sk->makeKnownLinkObj( $wgTitle, wfMsg('delete_namespace'), 'action=delete&ns=' . $index ); |
| 246 | + $deletenamespace_html = <<<END |
234 | 247 | <tr valign="top"><td colspan="2"> |
235 | | -<strong>{$delete_link}</strong> |
| 248 | +<b>{$delete_link}</b> |
236 | 249 | </td> |
237 | 250 | </tr> |
238 | 251 | END; |
239 | 252 | $systemtype_html=''; |
240 | 253 | } |
241 | | - |
242 | 254 | |
| 255 | + |
| 256 | + // Yet another table of tables :p |
| 257 | + |
243 | 258 | $htmlform .= <<<END |
244 | 259 | <table border="0"> |
245 | | -<tr valign="top"> |
246 | | -<td> |
247 | | -<table border="0" style="margin-right:1em;" width="300"> |
248 | | -<tr><th colspan="2"> |
249 | | -{$namespace_properties} |
250 | | -</th> |
251 | | -</tr> |
252 | | -<tr><td> |
253 | | -{$namespace_slot} |
254 | | -</td> |
255 | | -<td align="right">{$index} |
256 | | -</td> |
257 | | -</tr> |
258 | | -{$systemtype_html} |
259 | | -{$special_html} |
260 | | -{$subpages_html} |
261 | | -{$searchdefault_html} |
262 | | -{$hide_html} |
263 | | -{$target_html} |
264 | | -{$namespaceselect_html} |
265 | | -{$deletenamespace_html} |
266 | | -</table> |
267 | | -</td> |
268 | | -<td> |
269 | | -<table border="0"> |
270 | | -<tr> |
271 | | -<th colspan="3"> |
272 | | -{$namespace_names} |
273 | | -</th> |
274 | | -</tr> |
275 | | -<tr> |
276 | | -<th align="left"> |
277 | | -{$namespace_existing_names} |
278 | | -</th> |
279 | | -<th> |
280 | | -{$namespace_default_name} |
281 | | -</th> |
282 | | -<th> |
283 | | -{$namespace_delete_name} |
284 | | -</th> |
285 | | -</tr> |
| 260 | +<tr valign="top"><td> |
| 261 | + <table border="0" style="margin-right:1em;" width="300"> |
| 262 | + <tr><th colspan="2">{$namespace_properties}</th></tr> |
| 263 | + <tr><td>{$namespace_slot}</td><td align="right">{$index}</td></tr> |
| 264 | + {$systemtype_html} |
| 265 | + {$special_html} |
| 266 | + {$subpages_html} |
| 267 | + {$searchdefault_html} |
| 268 | + {$hide_html} |
| 269 | + {$target_html} |
| 270 | + {$namespaceselect_html} |
| 271 | + {$deletenamespace_html} |
| 272 | + </table> |
| 273 | +</td><td> |
| 274 | + <table border="0"> |
| 275 | + <tr><th colspan="3">{$namespace_names}</th></tr> |
| 276 | + <tr> |
| 277 | + <th align="left">{$namespace_existing_names}</th> |
| 278 | + <th>{$namespace_default_name}</th> |
| 279 | + <th>{$namespace_delete_name}</th> |
| 280 | + </tr> |
286 | 281 | END; |
287 | 282 | |
288 | | - foreach ( $ns->names as $nsi=>$nsname ) { |
| 283 | + foreach ( $ns->names as $nsi => $nsname ) { |
289 | 284 | if ( !is_null($ns->getDefaultNameIndex()) && $ns->getDefaultNameIndex() == $nsi ) { |
290 | 285 | $dc=' checked'; |
291 | 286 | } else { |
292 | 287 | $dc=''; |
293 | 288 | } |
| 289 | + |
294 | 290 | $default = "<input type=\"radio\" name=\"ns{$index}Default\" value=\"{$nsi}\"{$dc} />"; |
295 | 291 | if (!is_null($ns->getCanonicalNameIndex()) &&$ns->getCanonicalNameIndex()== $nsi) { |
296 | 292 | $nameinput = $nsname . '<br/><small>'.wfMsg('canonicalname').'</small>'; |
— | — | @@ -298,45 +294,35 @@ |
299 | 295 | $nameinput = "<input name=\"ns{$index}Name{$nsi}\" size=\"20\" value=\"{$nsname}\" />"; |
300 | 296 | $delete = "<input name=\"ns{$index}Delete{$nsi}\" type=\"checkbox\" value=\"1\" />"; |
301 | 297 | } |
302 | | - $htmlform.= |
| 298 | + $htmlform .= |
303 | 299 | <<<END |
304 | | -<tr valign="top"> |
305 | | -<td width="300"> |
306 | | -{$nameinput} |
307 | | -</td> |
308 | | -<td align="center"> |
309 | | -{$default} |
310 | | -</td> |
311 | | -<td align="center"> |
312 | | -{$delete} |
313 | | -</td> |
314 | | -</tr> |
| 300 | + <tr valign="top"> |
| 301 | + <td width="300">{$nameinput}</td> |
| 302 | + <td align="center">{$default}</td> |
| 303 | + <td align="center">{$delete}</td> |
| 304 | + </tr> |
315 | 305 | END; |
316 | | - |
317 | 306 | } |
318 | | - $htmlform.="<tr><th align=\"left\">{$namespace_new_names}</th></tr>"; |
319 | 307 | |
| 308 | + $htmlform .= '<tr><th align="left">' . $namespace_new_names . '</th></tr>' ; |
| 309 | + |
320 | 310 | # 3 blank namespace fields |
321 | | - if(!is_null($ns->names)) { |
322 | | - end($ns->names); |
323 | | - $highestName=key($ns->names)+1; |
| 311 | + // FIXME cant we just count elements ? |
| 312 | + if( !is_null( $ns->names ) ) { |
| 313 | + end( $ns->names ); |
| 314 | + $highestName = key( $ns->names ) + 1; |
324 | 315 | } else { |
325 | | - $highestName=0; |
| 316 | + $highestName = 0; |
326 | 317 | } |
327 | | - for($i=$highestName;$i<$highestName+3;$i++) { |
328 | | - $htmlform.= |
| 318 | + |
| 319 | + for( $i=$highestName; $i<$highestName+3; $i++) { |
| 320 | + $htmlform .= |
329 | 321 | <<<END |
330 | | -<tr valign="top"> |
331 | | -<td width="300"> |
332 | | -<input name="ns{$index}NewName{$i}" size="20" value="" /> |
333 | | -</td> |
334 | | -<td align="center"> |
335 | | -<input type="radio" name="ns{$index}Default" value="{$i}" /> |
336 | | -</td> |
337 | | -<td align="center"> |
338 | | - |
339 | | -</td> |
340 | | -</tr> |
| 322 | + <tr valign="top"> |
| 323 | + <td width="300"><input name="ns{$index}NewName{$i}" size="20" value="" /></td> |
| 324 | + <td align="center"><input type="radio" name="ns{$index}Default" value="{$i}" /></td> |
| 325 | + <td align="center"> </td> |
| 326 | + </tr> |
341 | 327 | END; |
342 | 328 | } |
343 | 329 | $htmlform .= '</table></td></tr>'; |
— | — | @@ -344,144 +330,174 @@ |
345 | 331 | } |
346 | 332 | $htmlform.= |
347 | 333 | <<<END |
348 | | -<tr><td> |
349 | | -<input type="submit" value="{$namespace_save_changes}" /> |
350 | | -</td></tr> |
| 334 | +<tr><td><input type="submit" value="{$namespace_save_changes}" /></td></tr> |
351 | 335 | </table> |
352 | 336 | </form> |
353 | 337 | END; |
354 | 338 | |
355 | | - $wgOut->addHTML($htmlform); |
| 339 | + // Ouput the form |
| 340 | + $wgOut->addHTML( $htmlform ); |
| 341 | + |
356 | 342 | } |
357 | 343 | |
| 344 | + /** |
| 345 | + * @todo Document |
| 346 | + */ |
358 | 347 | function addNamespaces() { |
359 | 348 | |
360 | | - global $wgOut, $wgUser, $wgLang, $wgRequest; |
| 349 | + global $wgOut, $wgUser, $wgRequest; |
361 | 350 | |
362 | 351 | $nsname = $wgRequest->getText('nsName'); |
363 | 352 | $nstalkname = $wgRequest->getText('nsTalkName'); |
364 | 353 | $nscreatetalk = $wgRequest->getBool('nsCreateTalk'); |
365 | 354 | |
366 | 355 | if(empty($nsname)) { |
367 | | - $this->showForm(wfMsg('namespace_name_missing')); |
| 356 | + $this->showForm( wfMsg('namespace_name_missing') ); |
368 | 357 | } |
369 | | - $dbr=&wfGetDB(DB_SLAVE); |
370 | | - $ns=new Namespace(); |
371 | | - $newnameindex=$ns->addName($nsname); |
372 | | - if(is_null($newnameindex)) { |
373 | | - $this->showForm(wfMsg('namespace_error',$nsname), |
374 | | - wfMsg('namespace_name_illegal_characters', NS_CHAR)); |
| 358 | + |
| 359 | + $ns = new Namespace(); |
| 360 | + $newnameindex = $ns->addName($nsname); |
| 361 | + |
| 362 | + if( is_null($newnameindex) ) { |
| 363 | + $this->showForm( |
| 364 | + wfMsg('namespace_error',$nsname), |
| 365 | + wfMsg('namespace_name_illegal_characters', NS_CHAR) |
| 366 | + ); |
375 | 367 | return false; |
376 | 368 | } |
| 369 | + |
377 | 370 | $ns->setDefaultNameIndex($newnameindex); |
378 | 371 | $nrv=$ns->testSave(); |
379 | 372 | /* |
380 | 373 | The only errors which can occur here should be |
381 | 374 | name-related. |
382 | 375 | */ |
383 | | - if($nrv[NS_RESULT]==NS_NAME_ISSUES) { |
384 | | - $this->showForm(wfMsg("namespace_error",$nsname),$this->nameIssues($nrv)); |
| 376 | + if( $nrv[NS_RESULT] == NS_NAME_ISSUES ) { |
| 377 | + $this->showForm( |
| 378 | + wfMsg('namespace_error',$nsname), |
| 379 | + $this->nameIssues($nrv) |
| 380 | + ); |
385 | 381 | return false; |
386 | 382 | } |
387 | | - $newnamespaceindex=$nrv[NS_SAVE_ID]; |
388 | | - if($nscreatetalk && !empty($nstalkname)) { |
389 | | - $talkns=new Namespace(); |
390 | | - $talkns->setParentIndex($newnamespaceindex); |
| 383 | + |
| 384 | + $newnamespaceindex = $nrv[NS_SAVE_ID]; |
| 385 | + |
| 386 | + if( $nscreatetalk && !empty($nstalkname) ) { |
| 387 | + |
| 388 | + // Initialize a talk namespace |
| 389 | + $talkns = new Namespace(); |
| 390 | + $talkns->setParentIndex( $newnamespaceindex ); |
391 | 391 | $talkns->setSubpages(); |
392 | | - $newtalknameindex=$talkns->addName($nstalkname); |
393 | | - $talkns->setDefaultNameIndex($newtalknameindex); |
394 | | - $trv=$talkns->testSave(); |
395 | | - if($trv[NS_RESULT]!=NS_CREATED) { |
396 | | - $this->showForm(wfMsg("talk_namespace_error",$nstalkname),$this->nameIssues($trv)); |
| 392 | + $newtalknameindex=$talkns->addName( $nstalkname ); |
| 393 | + $talkns->setDefaultNameIndex( $newtalknameindex ); |
| 394 | + |
| 395 | + // attempt to create it |
| 396 | + $trv = $talkns->testSave(); |
| 397 | + // Did it success ? |
| 398 | + if( $trv[NS_RESULT] != NS_CREATED ) { |
| 399 | + $this->showForm( |
| 400 | + wfMsg('talk_namespace_error',$nstalkname), |
| 401 | + $this->nameIssues($trv) |
| 402 | + ); |
397 | 403 | return false; |
398 | 404 | } |
399 | 405 | } |
400 | 406 | |
401 | | - # Save for real. |
| 407 | + // We now have validated stuff, lets save for real. |
| 408 | + |
| 409 | + // TODO error handling ? |
402 | 410 | $ns->save(); |
403 | | - $complete = wfMsg('namespace_created',$nsname); |
404 | | - if($nscreatetalk) { |
| 411 | + $complete = wfMsg( 'namespace_created', $nsname ); |
| 412 | + |
| 413 | + if( $nscreatetalk ) { |
| 414 | + // TODO error handling ? |
405 | 415 | $talkns->save(); |
406 | 416 | $complete .= ' '.wfMsg('talk_namespace_created'); |
407 | 417 | } |
| 418 | + |
| 419 | + // Report success to user |
408 | 420 | $wgOut->addWikiText($complete); |
409 | 421 | $this->showForm(); |
410 | 422 | } |
411 | 423 | |
412 | | - |
| 424 | + /** |
| 425 | + * @todo Document |
| 426 | + */ |
413 | 427 | function changeNamespaces() { |
414 | 428 | |
415 | 429 | global $wgOut, $wgNamespaces, $wgRequest; |
416 | 430 | |
417 | | - $newns=array(); |
418 | | - foreach($wgNamespaces as $ns) { |
419 | | - $nsindex=$ns->getIndex(); |
420 | | - $newns[$nsindex]=new Namespace(); |
| 431 | + $newns = array(); |
| 432 | + foreach( $wgNamespaces as $ns ) { |
| 433 | + $nsindex = $ns->getIndex(); |
| 434 | + $newns[$nsindex] = new Namespace(); |
421 | 435 | $newns[$nsindex]->setIndex($nsindex); |
422 | 436 | $newns[$nsindex]->setSystemType($ns->getSystemType()); |
423 | 437 | |
424 | 438 | if(!$ns->isSpecial()) { |
425 | | - $subvar="ns{$nsindex}Subpages"; |
426 | | - $searchvar="ns{$nsindex}Search"; |
427 | | - $hiddenvar="ns{$nsindex}Hidden"; |
428 | | - $prefixvar="ns{$nsindex}Linkprefix"; |
429 | | - $parentvar="ns{$nsindex}Parent"; |
430 | | - $subpages=$wgRequest->getBool($subvar); |
431 | | - $searchdefault=$wgRequest->getBool($searchvar); |
432 | | - $hidden=$wgRequest->getBool($hiddenvar); |
433 | | - $prefix=$wgRequest->getText($prefixvar); |
434 | | - $parent=$wgRequest->getIntOrNull($parentvar); |
| 439 | + // Some variables names |
| 440 | + $subvar = "ns{$nsindex}Subpages"; |
| 441 | + $searchvar = "ns{$nsindex}Search"; |
| 442 | + $hiddenvar = "ns{$nsindex}Hidden"; |
| 443 | + $prefixvar = "ns{$nsindex}Linkprefix"; |
| 444 | + $parentvar = "ns{$nsindex}Parent"; |
| 445 | + |
| 446 | + // Get data submitted by user |
| 447 | + $subpages = $wgRequest->getBool($subvar); |
| 448 | + $searchdefault = $wgRequest->getBool($searchvar); |
| 449 | + $hidden = $wgRequest->getBool($hiddenvar); |
| 450 | + $prefix = $wgRequest->getText($prefixvar); |
| 451 | + $parent = $wgRequest->getIntOrNull($parentvar); |
| 452 | + |
| 453 | + // Initialise our new namespace |
435 | 454 | $newns[$nsindex]->setSubpages($subpages); |
436 | 455 | $newns[$nsindex]->setSearchedByDefault($searchdefault); |
437 | 456 | $newns[$nsindex]->setHidden($hidden); |
438 | 457 | $newns[$nsindex]->setTarget($prefix); |
| 458 | + |
439 | 459 | if(array_key_exists($parent,$wgNamespaces)) { |
440 | 460 | $newns[$nsindex]->setParentIndex($parent); |
441 | 461 | } |
442 | 462 | } |
443 | 463 | |
444 | | - $newns[$nsindex]->names=$ns->names; |
| 464 | + // Inherit namespace names |
| 465 | + $newns[$nsindex]->names = $ns->names; |
445 | 466 | |
446 | | - # This can never be changed by the user. |
| 467 | + // This can never be changed by the user. |
447 | 468 | $newns[$nsindex]->setCanonicalNameIndex($ns->getCanonicalNameIndex()); |
448 | 469 | |
449 | | - # New names, appended to end |
| 470 | + // New names, appended to end |
450 | 471 | for($i=1;$i<=3;$i++) { |
451 | | - $nvar="ns{$nsindex}NewName{$i}"; |
452 | | - if($nname=$wgRequest->getText($nvar)) { |
| 472 | + $nvar = "ns{$nsindex}NewName{$i}"; |
| 473 | + if( $nname = $wgRequest->getText($nvar) ) { |
453 | 474 | $newns[$nsindex]->addName($nname); |
454 | 475 | } |
455 | 476 | } |
456 | 477 | |
457 | 478 | # Changes and deletions. Do them last since they can |
458 | 479 | # affect index slots of existing names. |
459 | | - foreach($ns->names as $nameindex=>$name) { |
| 480 | + foreach( $ns->names as $nameindex=>$name ) { |
460 | 481 | $var="ns{$nsindex}Name{$nameindex}"; |
461 | 482 | if($req=$wgRequest->getText($var)) { |
462 | 483 | #wfDebug("Name var $var contains $req\n"); |
463 | 484 | |
464 | 485 | # Alter name if necessary. |
465 | | - if($req!=$name) { |
466 | | - |
467 | | - # The last parameter means |
468 | | - # that we do not check if the |
469 | | - # name is valid - this |
470 | | - # is done later for all names. |
471 | | - $newns[$nsindex]->setName( |
472 | | - $name,$req,false |
473 | | - ); |
| 486 | + if($req != $name) { |
| 487 | + # The last parameter means that we do not check if the |
| 488 | + # name is valid - this is done later for all names. |
| 489 | + $newns[$nsindex]->setName($name, $req, false); |
474 | 490 | |
475 | 491 | #wfDebug("Setting name $nameindex of namespace $nsindex to $req. Old name is $name.\n"); |
476 | 492 | } |
477 | 493 | } |
478 | | - $delvar="ns{$nsindex}Delete{$nameindex}"; |
479 | | - if($wgRequest->getInt($delvar)) { |
| 494 | + $delvar = "ns{$nsindex}Delete{$nameindex}"; |
| 495 | + if( $wgRequest->getInt($delvar) ) { |
480 | 496 | #wfDebug("$delvar should be deleted.\n"); |
481 | 497 | $newns[$nsindex]->removeNameByIndex($nameindex); |
482 | 498 | } |
483 | 499 | } |
484 | 500 | |
485 | | - $dvar="ns{$nsindex}Default"; |
| 501 | + $dvar = "ns{$nsindex}Default"; |
486 | 502 | |
487 | 503 | # Did the user select a default name? |
488 | 504 | $dindex = $wgRequest->getIntOrNull($dvar); |
— | — | @@ -492,28 +508,35 @@ |
493 | 509 | } |
494 | 510 | |
495 | 511 | # Does the name exist and is it non-empty? |
496 | | - if(!is_null($dindex) && array_key_exists($dindex, $newns[$nsindex]->names) && !empty($newns[$nsindex]->names[$dindex]) ) { |
| 512 | + if( |
| 513 | + !is_null($dindex) |
| 514 | + && array_key_exists($dindex, $newns[$nsindex]->names) |
| 515 | + && !empty($newns[$nsindex]->names[$dindex]) |
| 516 | + ) { |
497 | 517 | # Use this default name. |
498 | 518 | $newns[$nsindex]->setDefaultNameIndex($dindex); |
499 | 519 | #wfDebug("Setting index for $nsindex to $dindex!\n"); |
500 | 520 | } else { |
501 | | - # We have lost our default name, perhaps |
502 | | - # it was deleted. Get a new one if |
503 | | - # possible. |
| 521 | + # We have lost our default name, perhaps it was deleted. |
| 522 | + # Get a new one if possible. |
504 | 523 | $newns[$nsindex]->setDefaultNameIndex($newns[$nsindex]->getNewDefaultNameIndex()); |
505 | | - |
506 | 524 | } |
507 | 525 | } |
508 | 526 | |
509 | 527 | foreach($newns as $nns) { |
510 | | - $nrv=$nns->testSave(); |
511 | | - if($nrv[NS_RESULT]==NS_NAME_ISSUES) { |
512 | | - $this->showForm(wfMsg("namespace_error",$nns->getDefaultName()),$this->nameIssues($nrv)); |
| 528 | + $nrv = $nns->testSave(); |
| 529 | + if( $nrv[NS_RESULT] == NS_NAME_ISSUES ) { |
| 530 | + $this->showForm( |
| 531 | + wfMsg( |
| 532 | + 'namespace_error', |
| 533 | + $nns->getDefaultName()), |
| 534 | + $this->nameIssues($nrv) |
| 535 | + ); |
513 | 536 | return false; |
514 | 537 | } |
515 | 538 | $nns->save(); |
516 | 539 | } |
517 | | - |
| 540 | + |
518 | 541 | # IMPORTANT: The namespace name indexes are unpredictable when |
519 | 542 | # serialized, so we have to reload the definitions from the |
520 | 543 | # database at this point; otherwise, there could be index |
— | — | @@ -521,21 +544,26 @@ |
522 | 545 | Namespace::load(); |
523 | 546 | |
524 | 547 | # Return to the namespace manager with the changes made. |
525 | | - $wgOut->addWikiText(wfMsg("namespace_changes_saved")); |
| 548 | + $wgOut->addWikiText( wfMsg('namespace_changes_saved') ); |
526 | 549 | $this->showForm(); |
| 550 | + |
527 | 551 | return true; |
528 | 552 | } |
529 | | - |
530 | | - function nameIssues($result) { |
531 | | - |
532 | | - $htmltable=' |
533 | | - <table border="0" width="100%" cellspacing="5" cellpadding="5" rules="all"> |
534 | | - <tr> |
535 | | - <th colspan="2">'.wfMsg('namespace_name_issues').'</th> |
536 | | - </tr><tr> |
537 | | - <th>'.wfMsg('namespace_name_header').'</th> |
538 | | - <th>'.wfMsg('namespace_issue_header').'</th> |
539 | | - </tr>'; |
| 553 | + |
| 554 | + /** |
| 555 | + * @parameter array $result |
| 556 | + * @return string A HTML table with namespaces issues |
| 557 | + */ |
| 558 | + function nameIssues( $result ) { |
| 559 | + |
| 560 | + # Initialize table with heading |
| 561 | + $htmltable= |
| 562 | + '<table border="0" width="100%" cellspacing="5" cellpadding="5" rules="all">' |
| 563 | + . '<tr><th colspan="2">' . wfMsg('namespace_name_issues') . '</th></tr>' |
| 564 | + . '<tr><th>' . wfMsg('namespace_name_header') . '</th>' |
| 565 | + . '<th>'.wfMsg('namespace_issue_header').'</th></tr>' |
| 566 | + . "\n"; |
| 567 | + |
540 | 568 | foreach($result[NS_ILLEGAL_NAMES] as $illegalName) { |
541 | 569 | $htmltable.= |
542 | 570 | '<tr><td>' |
— | — | @@ -576,11 +604,15 @@ |
577 | 605 | .wfMsg('namespace_name_linked'). |
578 | 606 | '</td></tr>'; |
579 | 607 | } |
580 | | - |
581 | | - $htmltable.='</table>'; |
| 608 | + |
| 609 | + # Close table |
| 610 | + $htmltable .= '</table>'."\n"; |
582 | 611 | return $htmltable; |
583 | 612 | } |
584 | | - |
| 613 | + |
| 614 | + /** |
| 615 | + * delete the namespace |
| 616 | + */ |
585 | 617 | function deleteNamespace() { |
586 | 618 | |
587 | 619 | global $wgOut,$wgRequest,$wgNamespaces; |
— | — | @@ -589,21 +621,21 @@ |
590 | 622 | |
591 | 623 | /* There should be no delete links for namespaces which cannot |
592 | 624 | be deleted, but let's catch two possible problems just in case. */ |
593 | | - if(!array_key_exists($nsid,$wgNamespaces)) { |
594 | | - $this->showForm( wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_missing',$nsid) ); |
| 625 | + if(!array_key_exists( $nsid, $wgNamespaces) ) { |
| 626 | + $this->showForm( wfMsg('namespace_not_deletable') , wfMsg('namespace_not_deletable_missing', $nsid) ); |
595 | 627 | return false; |
596 | | - } elseif($wgNamespaces[$nsid]->isSystemNamespace()) { |
597 | | - $this->showForm( wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_system',$nsid) ); |
| 628 | + } elseif( $wgNamespaces[$nsid]->isSystemNamespace() ) { |
| 629 | + $this->showForm( wfMsg('namespace_not_deletable') , wfMsg('namespace_not_deletable_system', $nsid) ); |
598 | 630 | return false; |
599 | 631 | } |
600 | 632 | |
601 | | - $nsdelete = clone($wgNamespaces[$nsid]); |
602 | | - $nsdeletename = $nsdelete->getDefaultName(); |
| 633 | + $nsdelete = clone( $wgNamespaces[$nsid] ); |
| 634 | + $nsdeletename = $nsdelete->getDefaultName(); |
603 | 635 | $drv = $nsdelete->deleteNamespace(); |
604 | 636 | |
605 | 637 | if( empty($nsdeletename) ) { |
606 | 638 | # At least show the index |
607 | | - $nsdeletename=$nsid; |
| 639 | + $nsdeletename = $nsid; |
608 | 640 | } |
609 | 641 | |
610 | 642 | if( $drv[NS_RESULT] == NS_DELETED ) { |