public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
if ( is_object( $text ) ) {
throw new MWException( '$text must be a string, given an object' );
+ } elseif ( $text === null ) {
+ // Legacy code relies on MalformedTitleException being thrown in this case
+ // (happens when URL with no title in it is parsed). TODO fix
+ throw new MalformedTitleException( 'title-invalid-empty' );
}
$titleCache = self::getTitleCache();
public static function makeName( $ns, $title, $fragment = '', $interwiki = '',
$canonicalNamespace = false
) {
- global $wgContLang;
-
if ( $canonicalNamespace ) {
$namespace = MWNamespace::getCanonicalName( $ns );
} else {
- $namespace = $wgContLang->getNsText( $ns );
+ $namespace = MediaWikiServices::getInstance()->getContentLanguage()->getNsText( $ns );
}
$name = $namespace == '' ? $title : "$namespace:$title";
if ( strval( $interwiki ) != '' ) {
* @return bool
*/
public function isValid() {
- $ns = $this->getNamespace();
-
- if ( !MWNamespace::exists( $ns ) ) {
+ if ( !MWNamespace::exists( $this->mNamespace ) ) {
return false;
}
try {
$parser = MediaWikiServices::getInstance()->getTitleParser();
- $parser->parseTitle( $this->getDBkey(), $ns );
+ $parser->parseTitle( $this->mDbkeyform, $this->mNamespace );
return true;
} catch ( MalformedTitleException $ex ) {
return false;
if ( $this->mTitleValue === null ) {
try {
$this->mTitleValue = new TitleValue(
- $this->getNamespace(),
- $this->getDBkey(),
- $this->getFragment(),
- $this->getInterwiki()
+ $this->mNamespace,
+ $this->mDbkeyform,
+ $this->mFragment,
+ $this->mInterwiki
);
} catch ( InvalidArgumentException $ex ) {
wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
* @return string Namespace text
*/
public function getSubjectNsText() {
- global $wgContLang;
- return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
+ return MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( MWNamespace::getSubject( $this->mNamespace ) );
}
/**
* @return string Namespace text
*/
public function getTalkNsText() {
- global $wgContLang;
- return $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) );
+ return MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( MWNamespace::getTalk( $this->mNamespace ) );
}
/**
* @return bool
*/
public function isWatchable() {
- return !$this->isExternal() && MWNamespace::isWatchable( $this->getNamespace() );
+ return !$this->isExternal() && MWNamespace::isWatchable( $this->mNamespace );
}
/**
* @return bool
*/
public function isSpecialPage() {
- return $this->getNamespace() == NS_SPECIAL;
+ return $this->mNamespace == NS_SPECIAL;
}
/**
*/
public function isSpecial( $name ) {
if ( $this->isSpecialPage() ) {
- list( $thisName, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $this->getDBkey() );
+ list( $thisName, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $this->mDbkeyform );
if ( $name == $thisName ) {
return true;
}
* @since 1.19
*/
public function inNamespace( $ns ) {
- return MWNamespace::equals( $this->getNamespace(), $ns );
+ return MWNamespace::equals( $this->mNamespace, $ns );
}
/**
* @return bool
*/
public function hasSubjectNamespace( $ns ) {
- return MWNamespace::subjectEquals( $this->getNamespace(), $ns );
+ return MWNamespace::subjectEquals( $this->mNamespace, $ns );
}
/**
* @return bool
*/
public function isContentPage() {
- return MWNamespace::isContent( $this->getNamespace() );
+ return MWNamespace::isContent( $this->mNamespace );
}
/**
* @return bool
*/
public function isMovable() {
- if ( !MWNamespace::isMovable( $this->getNamespace() ) || $this->isExternal() ) {
+ if ( !MWNamespace::isMovable( $this->mNamespace ) || $this->isExternal() ) {
// Interwiki title or immovable namespace. Hooks don't get to override here
return false;
}
public function isConversionTable() {
// @todo ConversionTable should become a separate content model.
- return $this->getNamespace() == NS_MEDIAWIKI &&
+ return $this->mNamespace == NS_MEDIAWIKI &&
strpos( $this->getText(), 'Conversiontable/' ) === 0;
}
*/
public function isSiteConfigPage() {
return (
- NS_MEDIAWIKI == $this->mNamespace
- && (
- $this->hasContentModel( CONTENT_MODEL_CSS )
- || $this->hasContentModel( CONTENT_MODEL_JSON )
- || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
- )
+ $this->isSiteCssConfigPage()
+ || $this->isSiteJsonConfigPage()
+ || $this->isSiteJsConfigPage()
);
}
*/
public function isUserConfigPage() {
return (
- NS_USER == $this->mNamespace
- && $this->isSubpage()
- && (
- $this->hasContentModel( CONTENT_MODEL_CSS )
- || $this->hasContentModel( CONTENT_MODEL_JSON )
- || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
- )
+ $this->isUserCssConfigPage()
+ || $this->isUserJsonConfigPage()
+ || $this->isUserJsConfigPage()
);
}
return $this->isUserJsConfigPage();
}
+ /**
+ * Is this a sitewide CSS "config" page?
+ *
+ * @return bool
+ * @since 1.32
+ */
+ public function isSiteCssConfigPage() {
+ return (
+ NS_MEDIAWIKI == $this->mNamespace
+ && (
+ $this->hasContentModel( CONTENT_MODEL_CSS )
+ // paranoia - a MediaWiki: namespace page with mismatching extension and content
+ // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
+ || substr( $this->mDbkeyform, -4 ) === '.css'
+ )
+ );
+ }
+
+ /**
+ * Is this a sitewide JSON "config" page?
+ *
+ * @return bool
+ * @since 1.32
+ */
+ public function isSiteJsonConfigPage() {
+ return (
+ NS_MEDIAWIKI == $this->mNamespace
+ && (
+ $this->hasContentModel( CONTENT_MODEL_JSON )
+ // paranoia - a MediaWiki: namespace page with mismatching extension and content
+ // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
+ || substr( $this->mDbkeyform, -5 ) === '.json'
+ )
+ );
+ }
+
+ /**
+ * Is this a sitewide JS "config" page?
+ *
+ * @return bool
+ * @since 1.31
+ */
+ public function isSiteJsConfigPage() {
+ return (
+ NS_MEDIAWIKI == $this->mNamespace
+ && (
+ $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
+ // paranoia - a MediaWiki: namespace page with mismatching extension and content
+ // model is probably by mistake and might get handled incorrectly (see e.g. T112937)
+ || substr( $this->mDbkeyform, -3 ) === '.js'
+ )
+ );
+ }
+
/**
* Is this a talk page of some sort?
*
* @return bool
*/
public function isTalkPage() {
- return MWNamespace::isTalk( $this->getNamespace() );
+ return MWNamespace::isTalk( $this->mNamespace );
}
/**
* @return Title The object for the talk page
*/
public function getTalkPage() {
- return self::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
+ return self::makeTitle( MWNamespace::getTalk( $this->mNamespace ), $this->mDbkeyform );
}
/**
*/
public function getSubjectPage() {
// Is this the same title?
- $subjectNS = MWNamespace::getSubject( $this->getNamespace() );
- if ( $this->getNamespace() == $subjectNS ) {
+ $subjectNS = MWNamespace::getSubject( $this->mNamespace );
+ if ( $this->mNamespace == $subjectNS ) {
return $this;
}
- return self::makeTitle( $subjectNS, $this->getDBkey() );
+ return self::makeTitle( $subjectNS, $this->mDbkeyform );
}
/**
} elseif ( $this->isExternal()
&& !self::getInterwikiLookup()->fetch( $this->mInterwiki )->isLocal()
) {
- return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->getFragment() );
+ return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
}
- return '#' . Sanitizer::escapeIdForLink( $this->getFragment() );
+ return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
}
/**
*/
public function createFragmentTarget( $fragment ) {
return self::makeTitle(
- $this->getNamespace(),
+ $this->mNamespace,
$this->getText(),
$fragment,
- $this->getInterwiki()
+ $this->mInterwiki
);
}
* @return string The prefixed text
*/
private function prefix( $name ) {
- global $wgContLang;
-
$p = '';
if ( $this->isExternal() ) {
$p = $this->mInterwiki . ':';
if ( $nsText === false ) {
// See T165149. Awkward, but better than erroneously linking to the main namespace.
- $nsText = $wgContLang->getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
+ $nsText = MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( NS_SPECIAL ) . ":Badtitle/NS{$this->mNamespace}";
}
$p .= $nsText . ':';
public function getFullText() {
$text = $this->getPrefixedText();
if ( $this->hasFragment() ) {
- $text .= '#' . $this->getFragment();
+ $text .= '#' . $this->mFragment;
}
return $text;
}
* @since 1.20
*/
public function getRootTitle() {
- return self::makeTitle( $this->getNamespace(), $this->getRootText() );
+ return self::makeTitle( $this->mNamespace, $this->getRootText() );
}
/**
* @since 1.20
*/
public function getBaseTitle() {
- return self::makeTitle( $this->getNamespace(), $this->getBaseText() );
+ return self::makeTitle( $this->mNamespace, $this->getBaseText() );
}
/**
* @since 1.20
*/
public function getSubpage( $text ) {
- return self::makeTitleSafe( $this->getNamespace(), $this->getText() . '/' . $text );
+ return self::makeTitleSafe( $this->mNamespace, $this->getText() . '/' . $text );
}
/**
# Yes! It can in interwiki transclusion. But... it probably shouldn't.
$namespace .= ':';
}
- $url = $interwiki->getURL( $namespace . $this->getDBkey() );
+ $url = $interwiki->getURL( $namespace . $this->mDbkeyform );
$url = wfAppendQuery( $url, $query );
} else {
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
$titleRef = $this;
Hooks::run( 'GetLocalURL::Article', [ &$titleRef, &$url ] );
} else {
- global $wgVariantArticlePath, $wgActionPaths, $wgContLang;
+ global $wgVariantArticlePath, $wgActionPaths;
$url = false;
$matches = [];
if ( $url === false
&& $wgVariantArticlePath
&& preg_match( '/^variant=([^&]*)$/', $query, $matches )
- && $this->getPageLanguage()->equals( $wgContLang )
+ && $this->getPageLanguage()->equals(
+ MediaWikiServices::getInstance()->getContentLanguage() )
&& $this->getPageLanguage()->hasVariants()
) {
$variant = urldecode( $matches[1] );
return $errors;
}
+ /**
+ * Check sitewide CSS/JSON/JS permissions
+ *
+ * @param string $action The action to check
+ * @param User $user User to check
+ * @param array $errors List of current errors
+ * @param string $rigor Same format as Title::getUserPermissionsErrors()
+ * @param bool $short Short circuit on first error
+ *
+ * @return array List of errors
+ */
+ private function checkSiteConfigPermissions( $action, $user, $errors, $rigor, $short ) {
+ if ( $action != 'patrol' ) {
+ $error = null;
+ // Sitewide CSS/JSON/JS changes, like all NS_MEDIAWIKI changes, also require the
+ // editinterface right. That's implemented as a restriction so no check needed here.
+ if ( $this->isSiteCssConfigPage() && !$user->isAllowed( 'editsitecss' ) ) {
+ $error = [ 'sitecssprotected', $action ];
+ } elseif ( $this->isSiteJsonConfigPage() && !$user->isAllowed( 'editsitejson' ) ) {
+ $error = [ 'sitejsonprotected', $action ];
+ } elseif ( $this->isSiteJsConfigPage() && !$user->isAllowed( 'editsitejs' ) ) {
+ $error = [ 'sitejsprotected', $action ];
+ }
+
+ if ( $error ) {
+ if ( $user->isAllowed( 'editinterface' ) ) {
+ // Most users / site admins will probably find out about the new, more restrictive
+ // permissions by failing to edit something. Give them more info.
+ // TODO remove this a few release cycles after 1.32
+ $error = [ 'interfaceadmin-info', wfMessage( $error[0], $error[1] ) ];
+ }
+ $errors[] = $error;
+ }
+ }
+
+ return $errors;
+ }
+
/**
* Check CSS/JSON/JS sub-page permissions
*
// Check for explicit whitelisting with and without underscores
if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) ) {
$whitelisted = true;
- } elseif ( $this->getNamespace() == NS_MAIN ) {
+ } elseif ( $this->mNamespace == NS_MAIN ) {
# Old settings might have the title prefixed with
# a colon for main-namespace pages
if ( in_array( ':' . $name, $wgWhitelistRead ) ) {
}
} elseif ( $this->isSpecialPage() ) {
# If it's a special page, ditch the subpage bit and check again
- $name = $this->getDBkey();
+ $name = $this->mDbkeyform;
list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name );
if ( $name ) {
$pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
'checkReadPermissions',
'checkUserBlock', // for wgBlockDisablesLogin
];
- # Don't call checkSpecialsAndNSPermissions or checkUserConfigPermissions
- # here as it will lead to duplicate error messages. This is okay to do
- # since anywhere that checks for create will also check for edit, and
- # those checks are called for edit.
+ # Don't call checkSpecialsAndNSPermissions, checkSiteConfigPermissions
+ # or checkUserConfigPermissions here as it will lead to duplicate
+ # error messages. This is okay to do since anywhere that checks for
+ # create will also check for edit, and those checks are called for edit.
} elseif ( $action == 'create' ) {
$checks = [
'checkQuickPermissions',
'checkQuickPermissions',
'checkPermissionHooks',
'checkSpecialsAndNSPermissions',
+ 'checkSiteConfigPermissions',
'checkUserConfigPermissions',
'checkPageRestrictions',
'checkCascadingSourcesRestrictions',
$types = self::getFilteredRestrictionTypes( $this->exists() );
- if ( $this->getNamespace() != NS_FILE ) {
+ if ( $this->mNamespace != NS_FILE ) {
# Remove the upload restriction for non-file titles
$types = array_diff( $types, [ 'upload' ] );
}
*/
protected function getTitleProtectionInternal() {
// Can't protect pages in special namespaces
- if ( $this->getNamespace() < 0 ) {
+ if ( $this->mNamespace < 0 ) {
return false;
}
'expiry' => 'pt_expiry',
'permission' => 'pt_create_perm'
] + $commentQuery['fields'],
- [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ],
+ [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
__METHOD__,
[],
$commentQuery['joins']
$dbw->delete(
'protected_titles',
- [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ],
+ [ 'pt_namespace' => $this->mNamespace, 'pt_title' => $this->mDbkeyform ],
__METHOD__
);
$this->mTitleProtection = false;
$dbr = wfGetDB( DB_REPLICA );
- if ( $this->getNamespace() == NS_FILE ) {
+ if ( $this->mNamespace == NS_FILE ) {
$tables = [ 'imagelinks', 'page_restrictions' ];
$where_clauses = [
- 'il_to' => $this->getDBkey(),
+ 'il_to' => $this->mDbkeyform,
'il_from=pr_page',
'pr_cascade' => 1
];
} else {
$tables = [ 'templatelinks', 'page_restrictions' ];
$where_clauses = [
- 'tl_namespace' => $this->getNamespace(),
- 'tl_title' => $this->getDBkey(),
+ 'tl_namespace' => $this->mNamespace,
+ 'tl_title' => $this->mDbkeyform,
'tl_from=pr_page',
'pr_cascade' => 1
];
* doesn't allow subpages
*/
public function getSubpages( $limit = -1 ) {
- if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
+ if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
return [];
}
$dbr = wfGetDB( DB_REPLICA );
- $conds['page_namespace'] = $this->getNamespace();
- $conds[] = 'page_title ' . $dbr->buildLike( $this->getDBkey() . '/', $dbr->anyString() );
+ $conds['page_namespace'] = $this->mNamespace;
+ $conds[] = 'page_title ' . $dbr->buildLike( $this->mDbkeyform . '/', $dbr->anyString() );
$options = [];
if ( $limit > -1 ) {
$options['LIMIT'] = $limit;
* @return int The number of archived revisions
*/
public function isDeleted() {
- if ( $this->getNamespace() < 0 ) {
+ if ( $this->mNamespace < 0 ) {
$n = 0;
} else {
$dbr = wfGetDB( DB_REPLICA );
$n = $dbr->selectField( 'archive', 'COUNT(*)',
- [ 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ],
+ [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
__METHOD__
);
- if ( $this->getNamespace() == NS_FILE ) {
+ if ( $this->mNamespace == NS_FILE ) {
$n += $dbr->selectField( 'filearchive', 'COUNT(*)',
- [ 'fa_name' => $this->getDBkey() ],
+ [ 'fa_name' => $this->mDbkeyform ],
__METHOD__
);
}
* @return bool
*/
public function isDeletedQuick() {
- if ( $this->getNamespace() < 0 ) {
+ if ( $this->mNamespace < 0 ) {
return false;
}
$dbr = wfGetDB( DB_REPLICA );
$deleted = (bool)$dbr->selectField( 'archive', '1',
- [ 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ],
+ [ 'ar_namespace' => $this->mNamespace, 'ar_title' => $this->mDbkeyform ],
__METHOD__
);
- if ( !$deleted && $this->getNamespace() == NS_FILE ) {
+ if ( !$deleted && $this->mNamespace == NS_FILE ) {
$deleted = (bool)$dbr->selectField( 'filearchive', '1',
- [ 'fa_name' => $this->getDBkey() ],
+ [ 'fa_name' => $this->mDbkeyform ],
__METHOD__
);
}
* @return int The ID
*/
public function getArticleID( $flags = 0 ) {
- if ( $this->getNamespace() < 0 ) {
+ if ( $this->mNamespace < 0 ) {
$this->mArticleID = 0;
return $this->mArticleID;
}
* @return string Containing capitalized title
*/
public static function capitalize( $text, $ns = NS_MAIN ) {
- global $wgContLang;
-
if ( MWNamespace::isCapitalized( $ns ) ) {
- return $wgContLang->ucfirst( $text );
+ return MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $text );
} else {
return $text;
}
* @return bool True on success
*/
private function secureAndSplit() {
- # Initialisation
- $this->mInterwiki = '';
- $this->mFragment = '';
- $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
-
- $dbkey = $this->mDbkeyform;
-
// @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
// the parsing code with Title, while avoiding massive refactoring.
// @todo: get rid of secureAndSplit, refactor parsing code.
// splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
$titleCodec = MediaWikiServices::getInstance()->getTitleParser();
// MalformedTitleException can be thrown here
- $parts = $titleCodec->splitTitleString( $dbkey, $this->getDefaultNamespace() );
+ $parts = $titleCodec->splitTitleString( $this->mDbkeyform, $this->mDefaultNamespace );
# Fill fields
$this->setFragment( '#' . $parts['fragment'] );
self::getSelectFields(),
[
"{$prefix}_from=page_id",
- "{$prefix}_namespace" => $this->getNamespace(),
- "{$prefix}_title" => $this->getDBkey() ],
+ "{$prefix}_namespace" => $this->mNamespace,
+ "{$prefix}_title" => $this->mDbkeyform ],
__METHOD__,
$options
);
];
}
// Do the source and target namespaces support subpages?
- if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
+ if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
return [
- [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->getNamespace() ) ],
+ [ 'namespace-nosubpages', MWNamespace::getCanonicalName( $this->mNamespace ) ],
];
}
if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
continue;
}
$newPageName = preg_replace(
- '#^' . preg_quote( $this->getDBkey(), '#' ) . '#',
+ '#^' . preg_quote( $this->mDbkeyform, '#' ) . '#',
StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
$oldSubpage->getDBkey() );
if ( $oldSubpage->isTalkPage() ) {
# Does the article have a history?
$row = $dbw->selectField( [ 'page', 'revision' ],
'rev_id',
- [ 'page_namespace' => $this->getNamespace(),
- 'page_title' => $this->getDBkey(),
+ [ 'page_namespace' => $this->mNamespace,
+ 'page_title' => $this->mDbkeyform,
'page_id=rev_page',
'page_latest != rev_id'
],
* $parent => $currentarticle
*/
public function getParentCategories() {
- global $wgContLang;
-
$data = [];
$titleKey = $this->getArticleID();
);
if ( $res->numRows() > 0 ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
foreach ( $res as $row ) {
- // $data[] = Title::newFromText($wgContLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
- $data[$wgContLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
+ // $data[] = Title::newFromText( $contLang->getNsText ( NS_CATEGORY ).':'.$row->cl_to);
+ $data[$contLang->getNsText( NS_CATEGORY ) . ':' . $row->cl_to] =
+ $this->getFullText();
}
}
return $data;
*/
public function equals( Title $title ) {
// Note: === is necessary for proper matching of number-like titles.
- return $this->getInterwiki() === $title->getInterwiki()
- && $this->getNamespace() == $title->getNamespace()
- && $this->getDBkey() === $title->getDBkey();
+ return $this->mInterwiki === $title->mInterwiki
+ && $this->mNamespace == $title->mNamespace
+ && $this->mDbkeyform === $title->mDbkeyform;
}
/**
* @return bool
*/
public function isSubpageOf( Title $title ) {
- return $this->getInterwiki() === $title->getInterwiki()
- && $this->getNamespace() == $title->getNamespace()
- && strpos( $this->getDBkey(), $title->getDBkey() . '/' ) === 0;
+ return $this->mInterwiki === $title->mInterwiki
+ && $this->mNamespace == $title->mNamespace
+ && strpos( $this->mDbkeyform, $title->mDbkeyform . '/' ) === 0;
}
/**
return (bool)wfFindFile( $this );
case NS_SPECIAL:
// valid special page
- return SpecialPageFactory::exists( $this->getDBkey() );
+ return SpecialPageFactory::exists( $this->mDbkeyform );
case NS_MAIN:
// selflink, possibly with fragment
return $this->mDbkeyform == '';
// message content will be displayed, same for language subpages-
// Use always content language to avoid loading hundreds of languages
// to get the link color.
- global $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
list( $name, ) = MessageCache::singleton()->figureMessage(
- $wgContLang->lcfirst( $this->getText() )
+ $contLang->lcfirst( $this->getText() )
);
- $message = wfMessage( $name )->inLanguage( $wgContLang )->useDatabase( false );
+ $message = wfMessage( $name )->inLanguage( $contLang )->useDatabase( false );
return $message->exists();
}
* @return string|bool
*/
public function getDefaultMessageText() {
- global $wgContLang;
-
- if ( $this->getNamespace() != NS_MEDIAWIKI ) { // Just in case
+ if ( $this->mNamespace != NS_MEDIAWIKI ) { // Just in case
return false;
}
list( $name, $lang ) = MessageCache::singleton()->figureMessage(
- $wgContLang->lcfirst( $this->getText() )
+ MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $this->getText() )
);
$message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
*/
public function touchLinks() {
DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks', 'page-touch' ) );
- if ( $this->getNamespace() == NS_CATEGORY ) {
+ if ( $this->mNamespace == NS_CATEGORY ) {
DeferredUpdates::addUpdate(
new HTMLCacheUpdate( $this, 'categorylinks', 'category-touch' )
);
* @return string XML 'id' name
*/
public function getNamespaceKey( $prepend = 'nstab-' ) {
- global $wgContLang;
// Gets the subject namespace of this title
- $subjectNS = MWNamespace::getSubject( $this->getNamespace() );
+ $subjectNS = MWNamespace::getSubject( $this->mNamespace );
// Prefer canonical namespace name for HTML IDs
$namespaceKey = MWNamespace::getCanonicalName( $subjectNS );
if ( $namespaceKey === false ) {
$namespaceKey = $this->getSubjectNsText();
}
// Makes namespace key lowercase
- $namespaceKey = $wgContLang->lc( $namespaceKey );
+ $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
// Uses main
if ( $namespaceKey == '' ) {
$namespaceKey = 'main';
$dbr = wfGetDB( DB_REPLICA );
$where = [
- 'rd_namespace' => $this->getNamespace(),
- 'rd_title' => $this->getDBkey(),
+ 'rd_namespace' => $this->mNamespace,
+ 'rd_title' => $this->mDbkeyform,
'rd_from = page_id'
];
if ( $this->isExternal() ) {
- $where['rd_interwiki'] = $this->getInterwiki();
+ $where['rd_interwiki'] = $this->mInterwiki;
} else {
$where[] = 'rd_interwiki = ' . $dbr->addQuotes( '' ) . ' OR rd_interwiki IS NULL';
}
/**
* Get the language in which the content of this page is written in
- * wikitext. Defaults to $wgContLang, but in certain cases it can be
+ * wikitext. Defaults to content language, but in certain cases it can be
* e.g. $wgLang (such as special pages, which are in the user language).
*
* @since 1.18
/**
* Get the language in which the content of this page is written when
- * viewed by user. Defaults to $wgContLang, but in certain cases it can be
+ * viewed by user. Defaults to content language, but in certain cases it can be
* e.g. $wgLang (such as special pages, which are in the user language).
*
* @since 1.20
$notices = [];
// Optional notice for the entire namespace
- $editnotice_ns = 'editnotice-' . $this->getNamespace();
+ $editnotice_ns = 'editnotice-' . $this->mNamespace;
$msg = wfMessage( $editnotice_ns );
if ( $msg->exists() ) {
$html = $msg->parseAsBlock();
}
}
- if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
+ if ( MWNamespace::hasSubpages( $this->mNamespace ) ) {
// Optional notice for page itself and any parent page
- $parts = explode( '/', $this->getDBkey() );
+ $parts = explode( '/', $this->mDbkeyform );
$editnotice_base = $editnotice_ns;
while ( count( $parts ) > 0 ) {
$editnotice_base .= '-' . array_shift( $parts );
}
} else {
// Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
- $editnoticeText = $editnotice_ns . '-' . strtr( $this->getDBkey(), '/', '-' );
+ $editnoticeText = $editnotice_ns . '-' . strtr( $this->mDbkeyform, '/', '-' );
$msg = wfMessage( $editnoticeText );
if ( $msg->exists() ) {
$html = $msg->parseAsBlock();