* Don't allow moving with subpages to a namespace that doesn't allow subpages. Such...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 23 May 2008 17:09:28 +0000 (17:09 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 23 May 2008 17:09:28 +0000 (17:09 +0000)
* 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

includes/SpecialMovepage.php
includes/Title.php
includes/api/ApiQuerySiteinfo.php

index 34e314e..e32b709 100644 (file)
@@ -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;
index 40257a6..4df4a7b 100644 (file)
@@ -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;
                }
index 9db117b..510e1a2 100644 (file)
@@ -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'] = '';
                }