From: Aryeh Gregor Date: Fri, 23 May 2008 22:00:14 +0000 (+0000) Subject: Code simplification (-205 bytes :P): X-Git-Tag: 1.31.0-rc.0~47424 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=4ed81df65fc4f626d89a705cf40da23dc4eb8eec;p=lhc%2Fweb%2Fwiklou.git Code simplification (-205 bytes :P): * Add MWNamespace::hasSubpages() and use that instead of $wgNamespacesWithSubpages everywhere * Put early returns first, and don't else { } the rest of the code --- diff --git a/includes/Namespace.php b/includes/Namespace.php index 6b468c8421..7c7b7dedd3 100644 --- a/includes/Namespace.php +++ b/includes/Namespace.php @@ -146,8 +146,8 @@ class MWNamespace { } /** - * Does this namespace contain content, for the purposes - * of calculating statistics, etc? + * Does this namespace contain content, for the purposes of calculating + * statistics, etc? * * @param $index Int: index to check * @return bool @@ -167,4 +167,15 @@ class MWNamespace { return $index >= NS_MAIN; } + /** + * Does the namespace allow subpages? + * + * @param $index int Index to check + * @return bool + */ + public static function hasSubpages( $index ) { + global $wgNamespacesWithSubpages; + return !empty( $wgNamespacesWithSubpages[$index] ); + } + } diff --git a/includes/Parser.php b/includes/Parser.php index 27b0177d9c..26848e2344 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1865,8 +1865,7 @@ class Parser */ function areSubpagesAllowed() { # Some namespaces don't allow subpages - global $wgNamespacesWithSubpages; - return !empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]); + return MWNamespace::hasSubpages( $this->mTitle->getNamespace() ); } /** diff --git a/includes/Skin.php b/includes/Skin.php index a1a3a7d37a..e2e9a3235a 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -882,8 +882,8 @@ END; if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages))) return $subpages; - global $wgOut, $wgTitle, $wgNamespacesWithSubpages; - if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) { + global $wgOut, $wgTitle; + if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) { $ptext=$wgTitle->getPrefixedText(); if(preg_match('/\//',$ptext)) { $links = explode('/',$ptext); diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 9207113591..94ab79bdbe 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -65,7 +65,7 @@ class MovePageForm { } function showForm( $err, $hookErr = '' ) { - global $wgOut, $wgUser, $wgNamespacesWithSubpages; + global $wgOut, $wgUser; $ot = Title::newFromURL( $this->oldTitle ); if( is_null( $ot ) ) { @@ -237,8 +237,7 @@ class MovePageForm { } function doSubmit() { - global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang, - $wgNamespacesWithSubpages; + global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang; if ( $wgUser->pingLimiter( 'move' ) ) { $wgOut->rateLimited(); @@ -317,9 +316,9 @@ class MovePageForm { # case. $dbr = wfGetDB( DB_SLAVE ); if( $this->moveSubpages && ( - !empty($wgNamespacesWithSubpages[$nt->getNamespace()]) || ( + MWNamespace::hasSubpages( $nt->getNamespace() ) || ( $this->moveTalk && - !empty( $wgNamespacesWithSubpages[$nt->getTalkPage()->getNamespace()] ) + MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) ) ) { $conds = array( @@ -327,15 +326,15 @@ class MovePageForm { .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() ) ); $conds['page_namespace'] = array(); - if( !empty( $wgNamespacesWithSubpages[$nt->getNamespace()] ) ) { + if( MWNamespace::hasSubpages( $nt->getNamespace() ) ) { $conds['page_namespace'] []= $ot->getNamespace(); } - if( $this->moveTalk && !empty( $wgNamespacesWithSubpages[$nt->getTalkPage()->getNamespace()] ) ) { + if( $this->moveTalk && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) { $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace(); } } elseif( $this->moveTalk ) { $conds = array( - 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()), + 'page_namespace' => $ot->getTalkPage()->getNamespace(), 'page_title' => $ot->getDBKey() ); } else { diff --git a/includes/Title.php b/includes/Title.php index 4df4a7bcfd..b8cf9bb90e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -697,16 +697,15 @@ class Title { * @return string Base name */ public function getBaseText() { - global $wgNamespacesWithSubpages; - if( !empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) { - $parts = explode( '/', $this->getText() ); - # Don't discard the real title if there's no subpage involved - if( count( $parts ) > 1 ) - unset( $parts[ count( $parts ) - 1 ] ); - return implode( '/', $parts ); - } else { + if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { return $this->getText(); } + + $parts = explode( '/', $this->getText() ); + # Don't discard the real title if there's no subpage involved + if( count( $parts ) > 1 ) + unset( $parts[ count( $parts ) - 1 ] ); + return implode( '/', $parts ); } /** @@ -714,13 +713,11 @@ class Title { * @return string Subpage name */ public function getSubpageText() { - global $wgNamespacesWithSubpages; - if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) { - $parts = explode( '/', $this->mTextform ); - return( $parts[ count( $parts ) - 1 ] ); - } else { + if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { return( $this->mTextform ); } + $parts = explode( '/', $this->mTextform ); + return( $parts[ count( $parts ) - 1 ] ); } /** @@ -1494,13 +1491,9 @@ class Title { * @return bool */ public function isSubpage() { - global $wgNamespacesWithSubpages; - - if( !empty( $wgNamespacesWithSubpages[ $this->mNamespace ] ) ) { - return strpos( $this->getText(), '/' ) !== false; - } else { - return false; - } + return MWNamespace::hasSubpages( $this->mNamespace ) + ? strpos( $this->getText(), '/' ) !== false; + : false; } /** @@ -1508,9 +1501,7 @@ class Title { * @return bool */ public function hasSubpages() { - global $wgNamespacesWithSubpages; - - if( empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) { + if( !MWNamespace::hasSubpages( $this->mNamespace ) ) { # Duh return false; } diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 510e1a2fa6..bf1cbe4fbe 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -104,7 +104,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { } protected function appendNamespaces($property) { - global $wgContLang, $wgNamespacesWithSubpages; + global $wgContLang; $data = array (); foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) { @@ -112,7 +112,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'id' => $ns ); ApiResult :: setContent($data[$ns], $title); - if(!empty($wgNamespacesWithSubpages[$ns])) + if( MWNamespace::hasSubpages( $ns ) ) $data[$ns]['subpages'] = ''; }