r11993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11992‎ | r11993 | r11994 >
Date:20:08, 6 December 2005
Author:hashar
Status:old
Tags:
Comment:
Fix code layout / indentation. Sorry for conflicts.
Modified paths:
  • /branches/wikidata/phase3/includes/SpecialNamespaces.php (modified) (history)

Diff [purge]

Index: branches/wikidata/phase3/includes/SpecialNamespaces.php
@@ -1,35 +1,32 @@
22 <?php
33 /**
4 -*
5 -* @package MediaWiki
6 -* @subpackage SpecialPage
7 -*/
 4+ *
 5+ * @package MediaWiki
 6+ * @subpackage SpecialPage
 7+ */
88
99 /**
10 -* Constructor
11 -*/
12 -function wfSpecialNamespaces()
13 -{
14 -global $wgUser, $wgOut, $wgRequest;
 10+ * Constructor
 11+ */
 12+function wfSpecialNamespaces() {
 13+ global $wgUser, $wgOut, $wgRequest;
1514
16 -$action = $wgRequest->getVal( 'action' );
17 -$f = new NamespaceForm();
 15+ $action = $wgRequest->getVal( 'action' );
 16+ $f = new NamespaceForm();
1817
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();
2529 }
26 -} elseif($action == 'delete') {
27 -
28 - $f->deleteNamespace();
2930 }
30 -else {
31 - $f->showForm();
32 -}
33 -}
3431
3532 /**
3633 *
@@ -38,8 +35,7 @@
3936 */
4037 class NamespaceForm {
4138
42 -function showForm( $errorHeader='', $errorBody='' )
43 -{
 39+function showForm( $errorHeader='', $errorBody='' ) {
4440 global $wgOut, $wgUser, $wgLang, $wgNamespaces,$wgTitle;
4541
4642 $wgOut->setPagetitle( wfMsg( "namespaces" ) );
@@ -56,23 +52,24 @@
5753
5854 # Standard token to avoid remote form submission exploits
5955 $token = $wgUser->editToken();
60 - $action = $wgTitle->escapeLocalURL( "action=submit" );
 56+ $action = $wgTitle->escapeLocalURL( "action=submit" );
6157 $talksuffix = wfEscapeJsString(wfMsgForContent("talkpagesuffix"));
6258
6359 # 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+
6764 # Sort for foreach loops
6865 ksort($name_array);
6966
7067 $wgOut->addWikiText( wfMsg( "add_namespaces_header" ) );
 68+
7169 # Prefill talk namespace field, but only for languages
7270 # where it's not disabled
7371 if($talksuffix != '-') {
7472 $talkpagejs=
7573 ' 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 -
7774 } else {
7875 $talkpagejs='';
7976 }
@@ -109,20 +106,20 @@
110107
111108 $wgOut->addWikiText( wfMsg( "modify_namespaces_header" ) );
112109
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');
127124
128125 $htmlform=<<<END
129126 <form name="changenamespaces" method="post" action="{$action}">
@@ -130,26 +127,25 @@
131128 <input type="hidden" name="wpEditToken" value="{$token}" />
132129 END;
133130 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();
143139
144140 # maybe make HTMLnamespaceselector more flexible and use
145141 # it instead here
146142 if(!$ns->isSpecial()) {
147143
148144 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 )
150146 continue;
151147 $list_option = ($arr_index == NS_MAIN ? wfMsg ( 'blanknamespace' ) : $arr_name);
152148 if(is_null($parentslot)) {
153 - $arr_name==$noparent ? $selected = ' selected ' : $selected='';
 149+ $arr_name == $noparent ? $selected = ' selected ' : $selected='';
154150 } else {
155151 $arr_index == $parentslot ? $selected = ' selected' : $selected='';
156152 }
@@ -216,7 +212,6 @@
217213 </td>
218214 </tr>
219215 END;
220 -
221216 }
222217
223218 $systemtype=$ns->getSystemType();
@@ -289,11 +284,11 @@
290285 </tr>
291286 END;
292287
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';
296291 } else {
297 - $dc="";
 292+ $dc='';
298293 }
299294 $default = "<input type=\"radio\" name=\"ns{$index}Default\" value=\"{$nsi}\"{$dc} />";
300295 if (!is_null($ns->getCanonicalNameIndex()) &&$ns->getCanonicalNameIndex()== $nsi) {
@@ -320,6 +315,7 @@
321316
322317 }
323318 $htmlform.="<tr><th align=\"left\">{$namespace_new_names}</th></tr>";
 319+
324320 # 3 blank namespace fields
325321 if(!is_null($ns->names)) {
326322 end($ns->names);
@@ -359,11 +355,13 @@
360356 }
361357
362358 function addNamespaces() {
 359+
363360 global $wgOut, $wgUser, $wgLang, $wgRequest;
364 - $nsname=$wgRequest->getText('nsName');
365 - $nstalkname=$wgRequest->getText('nsTalkName');
366 - $nscreatetalk=$wgRequest->getBool('nsCreateTalk');
367361
 362+ $nsname = $wgRequest->getText('nsName');
 363+ $nstalkname = $wgRequest->getText('nsTalkName');
 364+ $nscreatetalk = $wgRequest->getBool('nsCreateTalk');
 365+
368366 if(empty($nsname)) {
369367 $this->showForm(wfMsg('namespace_name_missing'));
370368 }
@@ -401,18 +399,20 @@
402400
403401 # Save for real.
404402 $ns->save();
405 - $complete=wfMsg('namespace_created',$nsname);
 403+ $complete = wfMsg('namespace_created',$nsname);
406404 if($nscreatetalk) {
407405 $talkns->save();
408 - $complete.=' '.wfMsg('talk_namespace_created');
 406+ $complete .= ' '.wfMsg('talk_namespace_created');
409407 }
410408 $wgOut->addWikiText($complete);
411409 $this->showForm();
412410 }
413411
 412+
414413 function changeNamespaces() {
415414
416 - global $wgOut, $wgNamespaces, $wgRequest;
 415+ global $wgOut, $wgNamespaces, $wgRequest;
 416+
417417 $newns=array();
418418 foreach($wgNamespaces as $ns) {
419419 $nsindex=$ns->getIndex();
@@ -439,6 +439,7 @@
440440 $newns[$nsindex]->setParentIndex($parent);
441441 }
442442 }
 443+
443444 $newns[$nsindex]->names=$ns->names;
444445
445446 # This can never be changed by the user.
@@ -481,10 +482,15 @@
482483 }
483484
484485 $dvar="ns{$nsindex}Default";
 486+
485487 # Did the user select a default name?
486 - $dindex=$wgRequest->getIntOrNull($dvar);
 488+ $dindex = $wgRequest->getIntOrNull($dvar);
 489+
487490 # 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+
489495 # Does the name exist and is it non-empty?
490496 if(!is_null($dindex) && array_key_exists($dindex, $newns[$nsindex]->names) && !empty($newns[$nsindex]->names[$dindex]) ) {
491497 # Use this default name.
@@ -498,6 +504,7 @@
499505
500506 }
501507 }
 508+
502509 foreach($newns as $nns) {
503510 $nrv=$nns->testSave();
504511 if($nrv[NS_RESULT]==NS_NAME_ISSUES) {
@@ -575,37 +582,41 @@
576583 }
577584
578585 function deleteNamespace() {
 586+
579587 global $wgOut,$wgRequest,$wgNamespaces;
580 - $nsid=$wgRequest->getInt('ns');
 588+
 589+ $nsid = $wgRequest->getInt('ns');
 590+
581591 /* There should be no delete links for namespaces which cannot
582592 be deleted, but let's catch two possible problems just in case. */
583593 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) );
585595 return false;
586596 } 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) );
588598 return false;
589599 }
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) ) {
594606 # At least show the index
595607 $nsdeletename=$nsid;
596608 }
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) );
599612 $this->showForm();
600613 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) );
603616 return false;
604617 } else {
605 - $this->showForm(wfMsg('namespace_delete_error'));
 618+ $this->showForm( wfMsg('namespace_delete_error') );
606619 return false;
607620 }
608621 }
609 -
610622 }
611 -
612623 ?>

Status & tagging log