r35235 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35234‎ | r35235 | r35236 >
Date:17:09, 23 May 2008
Author:simetrical
Status:old
Tags:
Comment:
* Don't allow moving with subpages to a namespace that doesn't allow subpages. Such a move is only questionably reasonable, and even if reasonable it's not possible to revert it.
* Use a consistent test for whether a namespace permits subpages: empty(), not isset or boolean test with errors suppressed or a combination of those. The isset test alone (used in isSubpage()) is particularly broken because it returns true if the namespace is explicitly set to *not* allow namespaces, and only returns false if the entry is unset.
* Reshuffle some global declarations, simplify a conditional block
Modified paths:
  • /trunk/phase3/includes/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialMovepage.php
@@ -237,7 +237,8 @@
238238 }
239239
240240 function doSubmit() {
241 - global $wgOut, $wgUser, $wgRequest;
 241+ global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang,
 242+ $wgNamespacesWithSubpages;
242243
243244 if ( $wgUser->pingLimiter( 'move' ) ) {
244245 $wgOut->rateLimited();
@@ -302,7 +303,16 @@
303304 if( $ot->isTalkPage() || $nt->isTalkPage() ) {
304305 $this->moveTalk = false;
305306 }
306 -
 307+
 308+ # If the target namespace doesn't allow subpages, moving with subpages
 309+ # would mean that you couldn't move them back in one operation, which
 310+ # is bad.
 311+ #
 312+ # FIXME: A specific error message should be given in this case.
 313+ if( empty( $wgNamespacesWithSubpages[$nt->getNamespace()] ) ) {
 314+ $this->moveSubpages = false;
 315+ }
 316+
307317 # Next make a list of id's. This might be marginally less efficient
308318 # than a more direct method, but this is not a highly performance-cri-
309319 # tical code path and readable code is more important here.
@@ -321,16 +331,14 @@
322332 } else {
323333 $conds['page_namespace'] = $ot->getNamespace();
324334 }
 335+ } elseif( $this->moveTalk ) {
 336+ $conds = array(
 337+ 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()),
 338+ 'page_title' => $ot->getDBKey()
 339+ );
325340 } else {
326 - if( $this->moveTalk ) {
327 - $conds = array(
328 - 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()),
329 - 'page_title' => $ot->getDBKey()
330 - );
331 - } else {
332 - # Skip the query
333 - $conds = null;
334 - }
 341+ # Skip the query
 342+ $conds = null;
335343 }
336344
337345 if( !is_null( $conds ) ) {
@@ -342,7 +350,6 @@
343351 );
344352 }
345353
346 - global $wgMaximumMovedPages, $wgLang;
347354 $extraOutput = array();
348355 $skin = $wgUser->getSkin();
349356 $count = 1;
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -112,7 +112,7 @@
113113 'id' => $ns
114114 );
115115 ApiResult :: setContent($data[$ns], $title);
116 - if(@$wgNamespacesWithSubpages[$ns])
 116+ if(!empty($wgNamespacesWithSubpages[$ns]))
117117 $data[$ns]['subpages'] = '';
118118 }
119119
Index: trunk/phase3/includes/Title.php
@@ -715,7 +715,7 @@
716716 */
717717 public function getSubpageText() {
718718 global $wgNamespacesWithSubpages;
719 - if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {
 719+ if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) {
720720 $parts = explode( '/', $this->mTextform );
721721 return( $parts[ count( $parts ) - 1 ] );
722722 } else {
@@ -1496,8 +1496,8 @@
14971497 public function isSubpage() {
14981498 global $wgNamespacesWithSubpages;
14991499
1500 - if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) {
1501 - return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace ] == true );
 1500+ if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) {
 1501+ return strpos( $this->getText(), '/' ) !== false;
15021502 } else {
15031503 return false;
15041504 }
@@ -1510,7 +1510,7 @@
15111511 public function hasSubpages() {
15121512 global $wgNamespacesWithSubpages;
15131513
1514 - if( !isset( $wgNamespacesWithSubpages[$this->mNamespace] ) ) {
 1514+ if( empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) {
15151515 # Duh
15161516 return false;
15171517 }

Status & tagging log