* Add MWNamespace::hasSubpages() and use that instead of $wgNamespacesWithSubpages everywhere
* Put early returns first, and don't else { } the rest of the code
}
/**
- * 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
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] );
+ }
+
}
*/
function areSubpagesAllowed() {
# Some namespaces don't allow subpages
- global $wgNamespacesWithSubpages;
- return !empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]);
+ return MWNamespace::hasSubpages( $this->mTitle->getNamespace() );
}
/**
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);
}
function showForm( $err, $hookErr = '' ) {
- global $wgOut, $wgUser, $wgNamespacesWithSubpages;
+ global $wgOut, $wgUser;
$ot = Title::newFromURL( $this->oldTitle );
if( is_null( $ot ) ) {
}
function doSubmit() {
- global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang,
- $wgNamespacesWithSubpages;
+ global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
if ( $wgUser->pingLimiter( 'move' ) ) {
$wgOut->rateLimited();
# 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(
.' 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 {
* @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 );
}
/**
* @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 ] );
}
/**
* @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;
}
/**
* @return bool
*/
public function hasSubpages() {
- global $wgNamespacesWithSubpages;
-
- if( empty( $wgNamespacesWithSubpages[$this->mNamespace] ) ) {
+ if( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
# Duh
return false;
}
}
protected function appendNamespaces($property) {
- global $wgContLang, $wgNamespacesWithSubpages;
+ global $wgContLang;
$data = array ();
foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
'id' => $ns
);
ApiResult :: setContent($data[$ns], $title);
- if(!empty($wgNamespacesWithSubpages[$ns]))
+ if( MWNamespace::hasSubpages( $ns ) )
$data[$ns]['subpages'] = '';
}