Index: branches/wikidata/phase3/includes/SpecialNamespaces.php |
— | — | @@ -1,35 +1,32 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | -* |
5 | | -* @package MediaWiki |
6 | | -* @subpackage SpecialPage |
7 | | -*/ |
| 4 | + * |
| 5 | + * @package MediaWiki |
| 6 | + * @subpackage SpecialPage |
| 7 | + */ |
8 | 8 | |
9 | 9 | /** |
10 | | -* Constructor |
11 | | -*/ |
12 | | -function wfSpecialNamespaces() |
13 | | -{ |
14 | | -global $wgUser, $wgOut, $wgRequest; |
| 10 | + * Constructor |
| 11 | + */ |
| 12 | +function wfSpecialNamespaces() { |
| 13 | + global $wgUser, $wgOut, $wgRequest; |
15 | 14 | |
16 | | -$action = $wgRequest->getVal( 'action' ); |
17 | | -$f = new NamespaceForm(); |
| 15 | + $action = $wgRequest->getVal( 'action' ); |
| 16 | + $f = new NamespaceForm(); |
18 | 17 | |
19 | | -if ( $action == 'submit' && $wgRequest->wasPosted() && |
20 | | - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
21 | | - if($wgRequest->getText('nsAction')=='addnamespaces') { |
22 | | - $f->addNamespaces(); |
23 | | - } elseif($wgRequest->getText('nsAction')=='changenamespaces') { |
24 | | - $f->changeNamespaces(); |
| 18 | + if ( $action == 'submit' && $wgRequest->wasPosted() && |
| 19 | + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 20 | + if($wgRequest->getText('nsAction')=='addnamespaces') { |
| 21 | + $f->addNamespaces(); |
| 22 | + } elseif($wgRequest->getText('nsAction')=='changenamespaces') { |
| 23 | + $f->changeNamespaces(); |
| 24 | + } |
| 25 | + } elseif($action == 'delete') { |
| 26 | + $f->deleteNamespace(); |
| 27 | + } else { |
| 28 | + $f->showForm(); |
25 | 29 | } |
26 | | -} elseif($action == 'delete') { |
27 | | - |
28 | | - $f->deleteNamespace(); |
29 | 30 | } |
30 | | -else { |
31 | | - $f->showForm(); |
32 | | -} |
33 | | -} |
34 | 31 | |
35 | 32 | /** |
36 | 33 | * |
— | — | @@ -38,8 +35,7 @@ |
39 | 36 | */ |
40 | 37 | class NamespaceForm { |
41 | 38 | |
42 | | -function showForm( $errorHeader='', $errorBody='' ) |
43 | | -{ |
| 39 | +function showForm( $errorHeader='', $errorBody='' ) { |
44 | 40 | global $wgOut, $wgUser, $wgLang, $wgNamespaces,$wgTitle; |
45 | 41 | |
46 | 42 | $wgOut->setPagetitle( wfMsg( "namespaces" ) ); |
— | — | @@ -56,23 +52,24 @@ |
57 | 53 | |
58 | 54 | # Standard token to avoid remote form submission exploits |
59 | 55 | $token = $wgUser->editToken(); |
60 | | - $action = $wgTitle->escapeLocalURL( "action=submit" ); |
| 56 | + $action = $wgTitle->escapeLocalURL( "action=submit" ); |
61 | 57 | $talksuffix = wfEscapeJsString(wfMsgForContent("talkpagesuffix")); |
62 | 58 | |
63 | 59 | # For the namespace selection box |
64 | | - $name_array= Namespace::getFormattedDefaultNamespaces(); |
65 | | - $noparent=wfMsg('no_parent_namespace'); |
66 | | - $name_array[key($name_array)-1]=$noparent; |
| 60 | + $name_array = Namespace::getFormattedDefaultNamespaces(); |
| 61 | + $noparent = wfMsg('no_parent_namespace'); |
| 62 | + $name_array[key($name_array)-1] = $noparent; |
| 63 | + |
67 | 64 | # Sort for foreach loops |
68 | 65 | ksort($name_array); |
69 | 66 | |
70 | 67 | $wgOut->addWikiText( wfMsg( "add_namespaces_header" ) ); |
| 68 | + |
71 | 69 | # Prefill talk namespace field, but only for languages |
72 | 70 | # where it's not disabled |
73 | 71 | if($talksuffix != '-') { |
74 | 72 | $talkpagejs= |
75 | 73 | ' onchange="if(!window.document.addnamespaces.nsTalkName.value && window.document.addnamespaces.nsName.value && window.document.addnamespaces.nsCreateTalk.checked) { window.document.addnamespaces.nsTalkName.value=window.document.addnamespaces.nsName.value+\''.$talksuffix.'\'; }"'; |
76 | | - |
77 | 74 | } else { |
78 | 75 | $talkpagejs=''; |
79 | 76 | } |
— | — | @@ -109,20 +106,20 @@ |
110 | 107 | |
111 | 108 | $wgOut->addWikiText( wfMsg( "modify_namespaces_header" ) ); |
112 | 109 | |
113 | | - $namespace_child_of=wfMsg('namespace_child_of'); |
114 | | - $namespace_support_subpages=wfMsg('namespace_support_subpages'); |
115 | | - $namespace_search_by_default=wfMsg('namespace_search_by_default'); |
116 | | - $namespace_hide_in_lists=wfMsg('namespace_hide_in_lists'); |
117 | | - $namespace_default_link_prefix=wfMsg('namespace_default_link_prefix'); |
118 | | - $namespace_system=wfMsg('namespace_system'); |
119 | | - $namespace_properties=wfMsg('namespace_properties'); |
120 | | - $namespace_slot=wfMsg('namespace_slot'); |
121 | | - $namespace_names=wfMsg('namespace_names'); |
122 | | - $namespace_existing_names=wfMsg('namespace_existing_names'); |
123 | | - $namespace_new_names=wfMsg('namespace_new_names'); |
124 | | - $namespace_default_name=wfMsg('namespace_default_name'); |
125 | | - $namespace_delete_name=wfMsg('namespace_delete_name'); |
126 | | - $namespace_save_changes=wfMsg('namespace_save_changes'); |
| 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'); |
127 | 124 | |
128 | 125 | $htmlform=<<<END |
129 | 126 | <form name="changenamespaces" method="post" action="{$action}"> |
— | — | @@ -130,26 +127,25 @@ |
131 | 128 | <input type="hidden" name="wpEditToken" value="{$token}" /> |
132 | 129 | END; |
133 | 130 | foreach ($wgNamespaces as $ns) { |
134 | | - |
135 | | - |
136 | | - $index=$ns->getIndex(); |
137 | | - $subpages=$ns->allowsSubpages() ? ' checked' : ''; |
138 | | - $searchdefault=$ns->isSearchedByDefault() ? ' checked' :''; |
139 | | - $hidden=$ns->isHidden ? ' checked' : ''; |
140 | | - $linkprefix=$ns->getTarget(); |
141 | | - $namespaceselect=''; |
142 | | - $parentslot=$ns->getParentIndex(); |
| 131 | + |
| 132 | + $index = $ns->getIndex(); |
| 133 | + $subpages = $ns->allowsSubpages() ? ' checked' : ''; |
| 134 | + $searchdefault = $ns->isSearchedByDefault() ? ' checked' :''; |
| 135 | + $hidden = $ns->isHidden ? ' checked' : ''; |
| 136 | + $linkprefix = $ns->getTarget(); |
| 137 | + $namespaceselect = ''; |
| 138 | + $parentslot = $ns->getParentIndex(); |
143 | 139 | |
144 | 140 | # maybe make HTMLnamespaceselector more flexible and use |
145 | 141 | # it instead here |
146 | 142 | if(!$ns->isSpecial()) { |
147 | 143 | |
148 | 144 | foreach ( $name_array as $arr_index => $arr_name ) { |
149 | | - if( $arr_index < NS_MAIN && $arr_name!=$noparent) |
| 145 | + if( $arr_index < NS_MAIN && $arr_name!=$noparent ) |
150 | 146 | continue; |
151 | 147 | $list_option = ($arr_index == NS_MAIN ? wfMsg ( 'blanknamespace' ) : $arr_name); |
152 | 148 | if(is_null($parentslot)) { |
153 | | - $arr_name==$noparent ? $selected = ' selected ' : $selected=''; |
| 149 | + $arr_name == $noparent ? $selected = ' selected ' : $selected=''; |
154 | 150 | } else { |
155 | 151 | $arr_index == $parentslot ? $selected = ' selected' : $selected=''; |
156 | 152 | } |
— | — | @@ -216,7 +212,6 @@ |
217 | 213 | </td> |
218 | 214 | </tr> |
219 | 215 | END; |
220 | | - |
221 | 216 | } |
222 | 217 | |
223 | 218 | $systemtype=$ns->getSystemType(); |
— | — | @@ -289,11 +284,11 @@ |
290 | 285 | </tr> |
291 | 286 | END; |
292 | 287 | |
293 | | - foreach ($ns->names as $nsi=>$nsname) { |
294 | | - if (!is_null($ns->getDefaultNameIndex()) && $ns->getDefaultNameIndex() == $nsi) { |
295 | | - $dc=" checked"; |
| 288 | + foreach ( $ns->names as $nsi=>$nsname ) { |
| 289 | + if ( !is_null($ns->getDefaultNameIndex()) && $ns->getDefaultNameIndex() == $nsi ) { |
| 290 | + $dc=' checked'; |
296 | 291 | } else { |
297 | | - $dc=""; |
| 292 | + $dc=''; |
298 | 293 | } |
299 | 294 | $default = "<input type=\"radio\" name=\"ns{$index}Default\" value=\"{$nsi}\"{$dc} />"; |
300 | 295 | if (!is_null($ns->getCanonicalNameIndex()) &&$ns->getCanonicalNameIndex()== $nsi) { |
— | — | @@ -320,6 +315,7 @@ |
321 | 316 | |
322 | 317 | } |
323 | 318 | $htmlform.="<tr><th align=\"left\">{$namespace_new_names}</th></tr>"; |
| 319 | + |
324 | 320 | # 3 blank namespace fields |
325 | 321 | if(!is_null($ns->names)) { |
326 | 322 | end($ns->names); |
— | — | @@ -359,11 +355,13 @@ |
360 | 356 | } |
361 | 357 | |
362 | 358 | function addNamespaces() { |
| 359 | + |
363 | 360 | global $wgOut, $wgUser, $wgLang, $wgRequest; |
364 | | - $nsname=$wgRequest->getText('nsName'); |
365 | | - $nstalkname=$wgRequest->getText('nsTalkName'); |
366 | | - $nscreatetalk=$wgRequest->getBool('nsCreateTalk'); |
367 | 361 | |
| 362 | + $nsname = $wgRequest->getText('nsName'); |
| 363 | + $nstalkname = $wgRequest->getText('nsTalkName'); |
| 364 | + $nscreatetalk = $wgRequest->getBool('nsCreateTalk'); |
| 365 | + |
368 | 366 | if(empty($nsname)) { |
369 | 367 | $this->showForm(wfMsg('namespace_name_missing')); |
370 | 368 | } |
— | — | @@ -401,18 +399,20 @@ |
402 | 400 | |
403 | 401 | # Save for real. |
404 | 402 | $ns->save(); |
405 | | - $complete=wfMsg('namespace_created',$nsname); |
| 403 | + $complete = wfMsg('namespace_created',$nsname); |
406 | 404 | if($nscreatetalk) { |
407 | 405 | $talkns->save(); |
408 | | - $complete.=' '.wfMsg('talk_namespace_created'); |
| 406 | + $complete .= ' '.wfMsg('talk_namespace_created'); |
409 | 407 | } |
410 | 408 | $wgOut->addWikiText($complete); |
411 | 409 | $this->showForm(); |
412 | 410 | } |
413 | 411 | |
| 412 | + |
414 | 413 | function changeNamespaces() { |
415 | 414 | |
416 | | - global $wgOut, $wgNamespaces, $wgRequest; |
| 415 | + global $wgOut, $wgNamespaces, $wgRequest; |
| 416 | + |
417 | 417 | $newns=array(); |
418 | 418 | foreach($wgNamespaces as $ns) { |
419 | 419 | $nsindex=$ns->getIndex(); |
— | — | @@ -439,6 +439,7 @@ |
440 | 440 | $newns[$nsindex]->setParentIndex($parent); |
441 | 441 | } |
442 | 442 | } |
| 443 | + |
443 | 444 | $newns[$nsindex]->names=$ns->names; |
444 | 445 | |
445 | 446 | # This can never be changed by the user. |
— | — | @@ -481,10 +482,15 @@ |
482 | 483 | } |
483 | 484 | |
484 | 485 | $dvar="ns{$nsindex}Default"; |
| 486 | + |
485 | 487 | # Did the user select a default name? |
486 | | - $dindex=$wgRequest->getIntOrNull($dvar); |
| 488 | + $dindex = $wgRequest->getIntOrNull($dvar); |
| 489 | + |
487 | 490 | # If not, get the old one. |
488 | | - if(is_null($dindex)) { $dindex=$ns->getDefaultNameIndex();} |
| 491 | + if(is_null($dindex)) { |
| 492 | + $dindex=$ns->getDefaultNameIndex(); |
| 493 | + } |
| 494 | + |
489 | 495 | # Does the name exist and is it non-empty? |
490 | 496 | if(!is_null($dindex) && array_key_exists($dindex, $newns[$nsindex]->names) && !empty($newns[$nsindex]->names[$dindex]) ) { |
491 | 497 | # Use this default name. |
— | — | @@ -498,6 +504,7 @@ |
499 | 505 | |
500 | 506 | } |
501 | 507 | } |
| 508 | + |
502 | 509 | foreach($newns as $nns) { |
503 | 510 | $nrv=$nns->testSave(); |
504 | 511 | if($nrv[NS_RESULT]==NS_NAME_ISSUES) { |
— | — | @@ -575,37 +582,41 @@ |
576 | 583 | } |
577 | 584 | |
578 | 585 | function deleteNamespace() { |
| 586 | + |
579 | 587 | global $wgOut,$wgRequest,$wgNamespaces; |
580 | | - $nsid=$wgRequest->getInt('ns'); |
| 588 | + |
| 589 | + $nsid = $wgRequest->getInt('ns'); |
| 590 | + |
581 | 591 | /* There should be no delete links for namespaces which cannot |
582 | 592 | be deleted, but let's catch two possible problems just in case. */ |
583 | 593 | if(!array_key_exists($nsid,$wgNamespaces)) { |
584 | | - $this->showForm(wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_missing',$nsid)); |
| 594 | + $this->showForm( wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_missing',$nsid) ); |
585 | 595 | return false; |
586 | 596 | } elseif($wgNamespaces[$nsid]->isSystemNamespace()) { |
587 | | - $this->showForm(wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_system',$nsid)); |
| 597 | + $this->showForm( wfMsg('namespace_not_deletable'),wfMsg('namespace_not_deletable_system',$nsid) ); |
588 | 598 | return false; |
589 | 599 | } |
590 | | - $nsdelete=clone($wgNamespaces[$nsid]); |
591 | | - $nsdeletename=$nsdelete->getDefaultName(); |
592 | | - $drv=$nsdelete->deleteNamespace(); |
593 | | - if(empty($nsdeletename)) { |
| 600 | + |
| 601 | + $nsdelete = clone($wgNamespaces[$nsid]); |
| 602 | + $nsdeletename = $nsdelete->getDefaultName(); |
| 603 | + $drv = $nsdelete->deleteNamespace(); |
| 604 | + |
| 605 | + if( empty($nsdeletename) ) { |
594 | 606 | # At least show the index |
595 | 607 | $nsdeletename=$nsid; |
596 | 608 | } |
597 | | - if($drv[NS_RESULT]==NS_DELETED) { |
598 | | - $wgOut->addWikiText(wfMsg("namespace_deleted",$nsdeletename)); |
| 609 | + |
| 610 | + if( $drv[NS_RESULT] == NS_DELETED ) { |
| 611 | + $wgOut->addWikiText( wfMsg('namespace_deleted',$nsdeletename) ); |
599 | 612 | $this->showForm(); |
600 | 613 | return true; |
601 | | - } elseif($drv[NS_RESULT]==NS_NAME_ISSUES) { |
602 | | - $this->showForm(wfMsg('namespace_delete_error',$nsdeletename),$this->nameIssues($drv)); |
| 614 | + } elseif( $drv[NS_RESULT] == NS_NAME_ISSUES ) { |
| 615 | + $this->showForm( wfMsg('namespace_delete_error',$nsdeletename),$this->nameIssues($drv) ); |
603 | 616 | return false; |
604 | 617 | } else { |
605 | | - $this->showForm(wfMsg('namespace_delete_error')); |
| 618 | + $this->showForm( wfMsg('namespace_delete_error') ); |
606 | 619 | return false; |
607 | 620 | } |
608 | 621 | } |
609 | | - |
610 | 622 | } |
611 | | - |
612 | 623 | ?> |