diff options
author | Aryeh Gregor <simetrical@users.mediawiki.org> | 2008-05-23 22:00:14 +0000 |
---|---|---|
committer | Aryeh Gregor <simetrical@users.mediawiki.org> | 2008-05-23 22:00:14 +0000 |
commit | 4ed81df65fc4f626d89a705cf40da23dc4eb8eec (patch) | |
tree | c871c38c948924f443af158aba1651c062cee548 | |
parent | 42b14d0442e4ba35c11035e55ab5b0aadf8d5e6a (diff) | |
download | mediawikicore-4ed81df65fc4f626d89a705cf40da23dc4eb8eec.tar.gz mediawikicore-4ed81df65fc4f626d89a705cf40da23dc4eb8eec.zip |
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
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/35258
-rw-r--r-- | includes/Namespace.php | 15 | ||||
-rw-r--r-- | includes/Parser.php | 3 | ||||
-rw-r--r-- | includes/Skin.php | 4 | ||||
-rw-r--r-- | includes/SpecialMovepage.php | 15 | ||||
-rw-r--r-- | includes/Title.php | 37 | ||||
-rw-r--r-- | includes/api/ApiQuerySiteinfo.php | 4 |
6 files changed, 39 insertions, 39 deletions
diff --git a/includes/Namespace.php b/includes/Namespace.php index 6b468c8421a6..7c7b7dedd364 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 27b0177d9ce3..26848e234421 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 a1a3a7d37a54..e2e9a3235a55 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 920711359147..94ab79bdbe67 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 4df4a7bcfd4a..b8cf9bb90ec4 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 510e1a2fa68f..bf1cbe4fbe72 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'] = ''; } |