From: Aryeh Gregor Date: Fri, 23 May 2008 17:09:28 +0000 (+0000) Subject: * Don't allow moving with subpages to a namespace that doesn't allow subpages. Such... X-Git-Tag: 1.31.0-rc.0~47435 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=033fd9b7016e1f632215d5f47a4a53ed577f32ff;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 34e314e967..e32b7098d2 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -237,7 +237,8 @@ class MovePageForm { } function doSubmit() { - global $wgOut, $wgUser, $wgRequest; + global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang, + $wgNamespacesWithSubpages; if ( $wgUser->pingLimiter( 'move' ) ) { $wgOut->rateLimited(); @@ -302,7 +303,16 @@ class MovePageForm { if( $ot->isTalkPage() || $nt->isTalkPage() ) { $this->moveTalk = false; } - + + # If the target namespace doesn't allow subpages, moving with subpages + # would mean that you couldn't move them back in one operation, which + # is bad. + # + # FIXME: A specific error message should be given in this case. + if( empty( $wgNamespacesWithSubpages[$nt->getNamespace()] ) ) { + $this->moveSubpages = false; + } + # Next make a list of id's. This might be marginally less efficient # than a more direct method, but this is not a highly performance-cri- # tical code path and readable code is more important here. @@ -321,16 +331,14 @@ class MovePageForm { } else { $conds['page_namespace'] = $ot->getNamespace(); } + } elseif( $this->moveTalk ) { + $conds = array( + 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()), + 'page_title' => $ot->getDBKey() + ); } else { - if( $this->moveTalk ) { - $conds = array( - 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()), - 'page_title' => $ot->getDBKey() - ); - } else { - # Skip the query - $conds = null; - } + # Skip the query + $conds = null; } if( !is_null( $conds ) ) { @@ -342,7 +350,6 @@ class MovePageForm { ); } - global $wgMaximumMovedPages, $wgLang; $extraOutput = array(); $skin = $wgUser->getSkin(); $count = 1; diff --git a/includes/Title.php b/includes/Title.php index 40257a614a..4df4a7bcfd 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -715,7 +715,7 @@ class Title { */ public function getSubpageText() { global $wgNamespacesWithSubpages; - if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) { + if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) { $parts = explode( '/', $this->mTextform ); return( $parts[ count( $parts ) - 1 ] ); } else { @@ -1496,8 +1496,8 @@ class Title { public function isSubpage() { global $wgNamespacesWithSubpages; - if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) { - return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace ] == true ); + if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) { + return strpos( $this->getText(), '/' ) !== false; } else { return false; } @@ -1510,7 +1510,7 @@ class Title { public function hasSubpages() { global $wgNamespacesWithSubpages; - if( !isset( $wgNamespacesWithSubpages[$this->mNamespace] ) ) { + if( empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) { # Duh return false; } diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 9db117b509..510e1a2fa6 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -112,7 +112,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'id' => $ns ); ApiResult :: setContent($data[$ns], $title); - if(@$wgNamespacesWithSubpages[$ns]) + if(!empty($wgNamespacesWithSubpages[$ns])) $data[$ns]['subpages'] = ''; }