Brought to you by vim macros.
Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
* @return string
*/
function getSubcategorySortChar( $title, $sortkey ) {
- global $wgContLang;
-
if ( $title->getPrefixedText() == $sortkey ) {
$word = $title->getDBkey();
} else {
$firstChar = $this->collation->getFirstLetter( $word );
- return $wgContLang->convert( $firstChar );
+ return MediaWikiServices::getInstance()->getContentLanguage()->convert( $firstChar );
}
/**
* @param bool $isRedirect
*/
function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
- global $wgContLang;
if ( $this->showGallery ) {
$flip = $this->flip['file'];
if ( $flip ) {
} else {
$this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
- $this->imgsNoGallery_start_char[] = $wgContLang->convert(
- $this->collation->getFirstLetter( $sortkey ) );
+ $this->imgsNoGallery_start_char[] = MediaWikiServices::getInstance()->
+ getContentLanguage()->convert( $this->collation->getFirstLetter( $sortkey ) );
}
}
* @param bool $isRedirect
*/
function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
- global $wgContLang;
-
$this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
- $this->articles_start_char[] = $wgContLang->convert(
- $this->collation->getFirstLetter( $sortkey ) );
+ $this->articles_start_char[] = MediaWikiServices::getInstance()->
+ getContentLanguage()->convert( $this->collation->getFirstLetter( $sortkey ) );
}
function finaliseCategoryState() {
/**
* @param Language $lang Language to use for comment truncation. Defaults
- * to $wgContLang.
+ * to content language.
* @param int $migrationStage One of the MIGRATION_* constants
*/
public function __construct( Language $lang, $migrationStage ) {
* @return CommentStore
*/
public static function newKey( $key ) {
- global $wgCommentTableSchemaMigrationStage, $wgContLang;
+ global $wgCommentTableSchemaMigrationStage;
// TODO uncomment once not used in extensions
// wfDeprecated( __METHOD__, '1.31' );
- $store = new CommentStore( $wgContLang, $wgCommentTableSchemaMigrationStage );
+ $store = new CommentStore( MediaWikiServices::getInstance()->getContentLanguage(),
+ $wgCommentTableSchemaMigrationStage );
$store->key = $key;
return $store;
}
*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* CommentStoreComment represents a comment stored by CommentStore. The fields
* @return CommentStoreComment
*/
public static function newUnsavedComment( $comment, array $data = null ) {
- global $wgContLang;
-
if ( $comment instanceof CommentStoreComment ) {
return $comment;
}
if ( $comment instanceof Message ) {
$message = clone $comment;
- $text = $message->inLanguage( $wgContLang ) // Avoid $wgForceUIMsgAsContentMsg
+ // Avoid $wgForceUIMsgAsContentMsg
+ $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
->setInterfaceMessageFlag( true )
->text();
return new CommentStoreComment( null, $text, $message, $data );
* @since 1.21
*/
protected function getContentObject( $def_content = null ) {
- global $wgContLang;
-
$content = false;
$user = $this->context->getUser();
if ( $undoMsg === null ) {
$oldContent = $this->page->getContent( Revision::RAW );
- $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
+ $popts = ParserOptions::newFromUserAndLang(
+ $user, MediaWikiServices::getInstance()->getContentLanguage() );
$newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
if ( $newContent->getModel() !== $oldContent->getModel() ) {
// The undo may change content
* save and then make a comparison.
*/
public function showDiff() {
- global $wgContLang;
-
$oldtitlemsg = 'currentrev';
# if message does not exist, show diff against the preloaded default
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) {
Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] );
$user = $this->context->getUser();
- $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
+ $popts = ParserOptions::newFromUserAndLang( $user,
+ MediaWikiServices::getInstance()->getContentLanguage() );
$newContent = $newContent->preSaveTransform( $this->mTitle, $user, $popts );
}
* @return string
*/
public static function getEditToolbar( $title = null ) {
- global $wgContLang, $wgOut;
- global $wgEnableUploads, $wgForeignFileRepos;
+ global $wgOut, $wgEnableUploads, $wgForeignFileRepos;
$imagesAvailable = $wgEnableUploads || count( $wgForeignFileRepos );
$showSignature = true;
$showSignature = MWNamespace::wantSignatures( $title->getNamespace() );
}
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+
/**
* $toolarray is an array of arrays each of which includes the
* opening tag, the closing tag, optionally a sample text that is
],
$imagesAvailable ? [
'id' => 'mw-editbutton-image',
- 'open' => '[[' . $wgContLang->getNsText( NS_FILE ) . ':',
+ 'open' => '[[' . $contLang->getNsText( NS_FILE ) . ':',
'close' => ']]',
'sample' => wfMessage( 'image_sample' )->text(),
'tip' => wfMessage( 'image_tip' )->text(),
] : false,
$imagesAvailable ? [
'id' => 'mw-editbutton-media',
- 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA ) . ':',
+ 'open' => '[[' . $contLang->getNsText( NS_MEDIA ) . ':',
'close' => ']]',
'sample' => wfMessage( 'media_sample' )->text(),
'tip' => wfMessage( 'media_tip' )->text(),
return $langcode;
}
- global $wgContLang, $wgLanguageCode;
+ global $wgLanguageCode;
if ( $langcode === true || $langcode === $wgLanguageCode ) {
# $langcode is the language code of the wikis content language object.
# or it is a boolean and value is true
- return $wgContLang;
+ return MediaWikiServices::getInstance()->getContentLanguage();
}
global $wgLang;
# $langcode is a string, but not a valid language code; use content language.
wfDebug( "Invalid language code passed to wfGetLangObj, falling back to content language.\n" );
- return $wgContLang;
+ return MediaWikiServices::getInstance()->getContentLanguage();
}
/**
*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* This class is a collection of static functions that serve two purposes:
* @return array
*/
public static function namespaceSelectorOptions( array $params = [] ) {
- global $wgContLang;
-
$options = [];
if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
$options[$params['all']] = wfMessage( 'namespacesall' )->text();
}
// Add all namespaces as options (in the content language)
- $options += $wgContLang->getFormattedNamespaces();
+ $options +=
+ MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces();
$optionsOut = [];
// Filter out namespaces below 0 and massage labels
// main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
$nsName = wfMessage( 'blanknamespace' )->text();
} elseif ( is_int( $nsId ) ) {
- $nsName = $wgContLang->convertNamespace( $nsId );
+ $nsName = MediaWikiServices::getInstance()->getContentLanguage()->
+ convertNamespace( $nsId );
}
$optionsOut[$nsId] = $nsName;
}
* @return string
*/
public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
- global $wgContLang;
-
// First we check whether the namespace exists or not.
if ( MWNamespace::exists( $namespace ) ) {
if ( $namespace == NS_MAIN ) {
$name = $context->msg( 'blanknamespace' )->text();
} else {
- $name = $wgContLang->getFormattedNsText( $namespace );
+ $name = MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( $namespace );
}
return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
} else {
([^[]*) # 3. link trail (the text up until the next link)
/x',
function ( $match ) use ( $title, $local, $wikiId ) {
- global $wgContLang;
-
$medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
- $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
+ $medians .= preg_quote(
+ MediaWikiServices::getInstance()->getContentLanguage()->getNsText( NS_MEDIA ),
+ '/'
+ ) . '):';
$comment = $match[0];
$match[1] = substr( $match[1], 1 );
}
if ( $match[1] !== false && $match[1] !== '' ) {
- if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
+ if ( preg_match(
+ MediaWikiServices::getInstance()->getContentLanguage()->linkTrail(),
+ $match[3],
+ $submatch
+ ) ) {
$trail = $submatch[1];
} else {
$trail = "";
* @return array
*/
static function splitTrail( $trail ) {
- global $wgContLang;
- $regex = $wgContLang->linkTrail();
+ $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail();
$inside = '';
if ( $trail !== '' ) {
$m = [];
* @return string Wikitext
*/
public static function getGrantsWikiText( $grantsFilter, $lang = null ) {
- global $wgContLang;
-
if ( is_string( $lang ) ) {
$lang = Language::factory( $lang );
} elseif ( $lang === null ) {
- $lang = $wgContLang;
+ $lang = MediaWikiServices::getInstance()->getContentLanguage();
}
$s = '';
* @return Title Title object to be $wgTitle
*/
private function parseTitle() {
- global $wgContLang;
-
$request = $this->context->getRequest();
$curid = $request->getInt( 'curid' );
$title = $request->getVal( 'title' );
if ( !is_null( $ret ) && $ret->getNamespace() == NS_MEDIA ) {
$ret = Title::makeTitle( NS_FILE, $ret->getDBkey() );
}
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
// Check variant links so that interwiki links don't have to worry
// about the possible different language variants
- if ( $wgContLang->hasVariants()
- && !is_null( $ret ) && $ret->getArticleID() == 0
+ if (
+ $contLang->hasVariants() && !is_null( $ret ) && $ret->getArticleID() == 0
) {
- $wgContLang->findVariantLink( $title, $ret );
+ $contLang->findVariantLink( $title, $ret );
}
}
* @file
* @author Niklas Laxström
*/
+use MediaWiki\MediaWikiServices;
/**
* The Message class provides methods which fulfil two basic services:
* @since 1.26
*/
public function getTitle() {
- global $wgContLang, $wgForceUIMsgAsContentMsg;
+ global $wgForceUIMsgAsContentMsg;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$title = $this->key;
if (
- !$this->language->equals( $wgContLang )
+ !$this->language->equals( $contLang )
&& in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
) {
$code = $this->language->getCode();
$title .= '/' . $code;
}
- return Title::makeTitle( NS_MEDIAWIKI, $wgContLang->ucfirst( strtr( $title, ' ', '_' ) ) );
+ return Title::makeTitle(
+ NS_MEDIAWIKI, $contLang->ucfirst( strtr( $title, ' ', '_' ) ) );
}
/**
return $this;
}
- global $wgContLang;
- $this->inLanguage( $wgContLang );
+ $this->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
return $this;
}
* @param array $categories Mapping category name => sort key
*/
public function addCategoryLinks( array $categories ) {
- global $wgContLang;
-
if ( !$categories ) {
return;
}
'OutputPageMakeCategoryLinks',
[ &$outputPage, $categories, &$this->mCategoryLinks ] )
) {
- $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+ $services = MediaWikiServices::getInstance();
+ $linkRenderer = $services->getLinkRenderer();
foreach ( $categories as $category => $type ) {
// array keys will cast numeric category names to ints, so cast back to string
$category = (string)$category;
if ( !$title ) {
continue;
}
- $wgContLang->findVariantLink( $category, $title, true );
+ $services->getContentLanguage()->findVariantLink( $category, $title, true );
if ( $category != $origcategory && array_key_exists( $category, $categories ) ) {
continue;
}
- $text = $wgContLang->convertHtml( $title->getText() );
+ $text = $services->getContentLanguage()->convertHtml( $title->getText() );
$this->mCategories[$type][] = $title->getText();
$this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
}
*
* @param string $text
* @param bool $linestart Is this the start of a line?
- * @param bool $interface Use interface language ($wgLang instead of
- * $wgContLang) while parsing language sensitive magic words like GRAMMAR and PLURAL.
- * This also disables LanguageConverter.
+ * @param bool $interface Use interface language (instead of content language) while parsing
+ * language sensitive magic words like GRAMMAR and PLURAL. This also disables
+ * LanguageConverter.
* @param Language|null $language Target language object, will override $interface
* @throws MWException
* @return string HTML
*
* @param string $text
* @param bool $linestart Is this the start of a line?
- * @param bool $interface Use interface language ($wgLang instead of
- * $wgContLang) while parsing language sensitive magic
- * words like GRAMMAR and PLURAL
+ * @param bool $interface Use interface language (instead of content language) while parsing
+ * language sensitive magic words like GRAMMAR and PLURAL
* @return string HTML
*/
public function parseInline( $text, $linestart = true, $interface = false ) {
* @throws MWException
*/
public function output( $return = false ) {
- global $wgContLang;
-
if ( $this->mDoNothing ) {
return $return ? '' : null;
}
ob_start();
$response->header( 'Content-type: ' . $config->get( 'MimeType' ) . '; charset=UTF-8' );
- $response->header( 'Content-language: ' . $wgContLang->getHtmlCode() );
+ $response->header( 'Content-language: ' .
+ MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
if ( !$this->mArticleBodyOnly ) {
$sk = $this->getSkin();
* @return string The doctype, opening "<html>", and head element.
*/
public function headElement( Skin $sk, $includeStyle = true ) {
- global $wgContLang;
-
$userdir = $this->getLanguage()->getDir();
- $sitedir = $wgContLang->getDir();
+ $sitedir = MediaWikiServices::getInstance()->getContentLanguage()->getDir();
$pieces = [];
$pieces[] = Html::htmlHeader( Sanitizer::mergeAttributes(
* @return array
*/
public function getJSVars() {
- global $wgContLang;
-
$curRevisionId = 0;
$articleId = 0;
$canonicalSpecialPageName = false; # T23115
$vars['wgUserNewMsgRevisionId'] = $user->getNewMessageRevisionId();
}
- if ( $wgContLang->hasVariants() ) {
- $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( $contLang->hasVariants() ) {
+ $vars['wgUserVariant'] = $contLang->getPreferredVariant();
}
// Same test as SkinTemplate
$vars['wgIsProbablyEditable'] = $title->quickUserCan( 'edit', $user )
* @return DefaultPreferencesFactory
*/
protected static function getDefaultPreferencesFactory() {
- global $wgContLang;
$authManager = AuthManager::singleton();
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
$config = MediaWikiServices::getInstance()->getMainConfig();
$preferencesFactory = new DefaultPreferencesFactory(
- $config, $wgContLang, $authManager, $linkRenderer
+ $config, MediaWikiServices::getInstance()->getContentLanguage(), $authManager,
+ $linkRenderer
);
return $preferencesFactory;
}
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Handles searching prefixes of titles and finding any page
* names that match. Used largely by the OpenSearch implementation.
// if the content language has variants, try to retrieve fallback results
$fallbackLimit = $limit - count( $searches );
if ( $fallbackLimit > 0 ) {
- global $wgContLang;
-
- $fallbackSearches = $wgContLang->autoConvertToAllVariants( $search );
+ $fallbackSearches = MediaWikiServices::getInstance()->getContentLanguage()->
+ autoConvertToAllVariants( $search );
$fallbackSearches = array_diff( array_unique( $fallbackSearches ), [ $search ] );
foreach ( $fallbackSearches as $fbs ) {
* @return array
*/
protected function specialSearch( $search, $limit, $offset ) {
- global $wgContLang;
-
$searchParts = explode( '/', $search, 2 );
$searchKey = $searchParts[0];
$subpageSearch = $searchParts[1] ?? null;
}
# normalize searchKey, so aliases with spaces can be found - T27675
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$searchKey = str_replace( ' ', '_', $searchKey );
- $searchKey = $wgContLang->caseFold( $searchKey );
+ $searchKey = $contLang->caseFold( $searchKey );
// Unlike SpecialPage itself, we want the canonical forms of both
// canonical and alias title forms...
$keys = [];
foreach ( SpecialPageFactory::getNames() as $page ) {
- $keys[$wgContLang->caseFold( $page )] = [ 'page' => $page, 'rank' => 0 ];
+ $keys[$contLang->caseFold( $page )] = [ 'page' => $page, 'rank' => 0 ];
}
- foreach ( $wgContLang->getSpecialPageAliases() as $page => $aliases ) {
+ foreach ( $contLang->getSpecialPageAliases() as $page => $aliases ) {
if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# T22885
continue;
}
foreach ( $aliases as $key => $alias ) {
- $keys[$wgContLang->caseFold( $alias )] = [ 'page' => $alias, 'rank' => $key ];
+ $keys[$contLang->caseFold( $alias )] = [ 'page' => $alias, 'rank' => $key ];
}
}
ksort( $keys );
* @return array (default: contains only NS_MAIN)
*/
protected function validateNamespaces( $namespaces ) {
- global $wgContLang;
-
- // We will look at each given namespace against wgContLang namespaces
- $validNamespaces = $wgContLang->getNamespaces();
+ // We will look at each given namespace against content language namespaces
+ $validNamespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
if ( is_array( $namespaces ) && count( $namespaces ) > 0 ) {
$valid = [];
foreach ( $namespaces as $ns ) {
/**
* @var Language
*/
- private $contentLanguage;
+ private $contLang;
/**
* @var LoggerInterface
* @param ParserCache $parserCache
* @param JobQueueGroup $jobQueueGroup
* @param MessageCache $messageCache
- * @param Language $contentLanguage
+ * @param Language $contLang
* @param LoggerInterface|null $saveParseLogger
*/
public function __construct(
ParserCache $parserCache,
JobQueueGroup $jobQueueGroup,
MessageCache $messageCache,
- Language $contentLanguage,
+ Language $contLang,
LoggerInterface $saveParseLogger = null
) {
$this->wikiPage = $wikiPage;
$this->revisionStore = $revisionStore;
$this->jobQueueGroup = $jobQueueGroup;
$this->messageCache = $messageCache;
- $this->contentLanguage = $contentLanguage;
+ $this->contLang = $contLang;
// XXX: replace all wfDebug calls with a Logger. Do we nede more than one logger here?
$this->saveParseLogger = $saveParseLogger ?: new NullLogger();
$this->canonicalParserOutput = $output;
}
- $userPopts = ParserOptions::newFromUserAndLang( $user, $this->contentLanguage );
+ $userPopts = ParserOptions::newFromUserAndLang( $user, $this->contLang );
Hooks::run( 'ArticlePrepareTextForEdit', [ $wikiPage, $userPopts ] );
$this->user = $user;
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 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 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 . ':';
$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 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;
}
* $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;
// 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
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 );
* @return string XML 'id' name
*/
public function getNamespaceKey( $prepend = 'nstab-' ) {
- global $wgContLang;
// Gets the subject namespace of this title
$subjectNS = MWNamespace::getSubject( $this->getNamespace() );
// Prefer canonical namespace name for HTML IDs
$namespaceKey = $this->getSubjectNsText();
}
// Makes namespace key lowercase
- $namespaceKey = $wgContLang->lc( $namespaceKey );
+ $namespaceKey = MediaWikiServices::getInstance()->getContentLanguage()->lc( $namespaceKey );
// Uses main
if ( $namespaceKey == '' ) {
$namespaceKey = 'main';
/**
* 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
$router->add( $wgActionPaths, [ 'action' => '$key' ] );
}
- global $wgVariantArticlePath, $wgContLang;
+ global $wgVariantArticlePath;
if ( $wgVariantArticlePath ) {
$router->add( $wgVariantArticlePath,
[ 'variant' => '$2' ],
- [ '$2' => $wgContLang->getVariants() ]
+ [ '$2' => MediaWikiServices::getInstance()->getContentLanguage()->
+ getVariants() ]
);
}
/**
* Check for title, action, and/or variant data in the URL
* and interpolate it into the GET variables.
- * This should only be run after $wgContLang is available,
+ * This should only be run after the content language is available,
* as we may need the list of language variants to determine
* available variant URLs.
*/
$data[$key] = $this->normalizeUnicode( $val );
}
} else {
- global $wgContLang;
- $data = isset( $wgContLang ) ?
- $wgContLang->normalize( $data ) :
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $data = $contLang ? $contLang->normalize( $data ) :
UtfNormal\Validator::cleanUp( $data );
}
return $data;
# Work around PHP *feature* to avoid *bugs* elsewhere.
$name = strtr( $name, '.', '_' );
if ( isset( $arr[$name] ) ) {
- global $wgContLang;
$data = $arr[$name];
if ( isset( $_GET[$name] ) && !is_array( $data ) ) {
# Check for alternate/legacy character encoding.
- if ( isset( $wgContLang ) ) {
- $data = $wgContLang->checkTitleEncoding( $data );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( $contLang ) {
+ $data = $contLang->checkTitleEncoding( $data );
}
}
$data = $this->normalizeUnicode( $data );
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Object to access the $_FILES array
*
return null;
}
- global $wgContLang;
$name = $this->fileInfo['name'];
# Safari sends filenames in HTML-encoded Unicode form D...
# Horrid and evil! Let's try to make some kind of sense of it.
$name = Sanitizer::decodeCharReferences( $name );
- $name = $wgContLang->normalize( $name );
+ $name = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $name );
wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
return $name;
}
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Module of static functions for generating XML
*/
}
/**
- * Format an XML element as with self::element(), but run text through the
- * $wgContLang->normalize() validator first to ensure that no invalid UTF-8
- * is passed.
+ * Format an XML element as with self::element(), but run text through the content language's
+ * normalize() validator first to ensure that no invalid UTF-8 is passed.
*
* @param string $element
* @param array $attribs Name=>value pairs. Values will be escaped.
* @return string
*/
public static function elementClean( $element, $attribs = [], $contents = '' ) {
- global $wgContLang;
if ( $attribs ) {
$attribs = array_map( [ 'UtfNormal\Validator', 'cleanUp' ], $attribs );
}
if ( $contents ) {
- $contents = $wgContLang->normalize( $contents );
+ $contents =
+ MediaWikiServices::getInstance()->getContentLanguage()->normalize( $contents );
}
return self::element( $element, $attribs, $contents );
}
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @defgroup Actions Action done on pages
*/
* @since 1.25
*/
public function addHelpLink( $to, $overrideBaseUrl = false ) {
- global $wgContLang;
- $msg = wfMessage( $wgContLang->lc(
+ $msg = wfMessage( MediaWikiServices::getInstance()->getContentLanguage()->lc(
self::getActionName( $this->getContext() )
) . '-helppage' );
$rev->getComment()
);
if ( $rev->getComment() == '' ) {
- global $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$title = $this->msg( 'history-feed-item-nocomment',
$rev->getUserText(),
- $wgContLang->timeanddate( $rev->getTimestamp() ),
- $wgContLang->date( $rev->getTimestamp() ),
- $wgContLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text();
+ $contLang->timeanddate( $rev->getTimestamp() ),
+ $contLang->date( $rev->getTimestamp() ),
+ $contLang->time( $rev->getTimestamp() )
+ )->inContentLanguage()->text();
} else {
$title = $rev->getUserText() .
$this->msg( 'colon-separator' )->inContentLanguage()->text() .
* @return array
*/
protected function pageInfo() {
- global $wgContLang;
-
$services = MediaWikiServices::getInstance();
$user = $this->getUser();
$wordIDs = $magicWords->names;
// Array of IDs => localized magic words
- $localizedWords = $wgContLang->getMagicWords();
+ $localizedWords = $services->getContentLanguage()->getMagicWords();
$listItems = [];
foreach ( $pageProperties as $property => $value ) {
* @author Rob Church <robchur@gmail.com>
*/
+use MediaWiki\MediaWikiServices;
+
/**
* File reversion user interface
*
}
protected function getFormFields() {
- global $wgContLang;
-
$timestamp = $this->oldFile->getTimestamp();
$user = $this->getUser();
$userTime = $lang->userTime( $timestamp, $user );
$siteTs = MWTimestamp::getLocalInstance( $timestamp );
$ts = $siteTs->format( 'YmdHis' );
- $siteDate = $wgContLang->date( $ts, false, false );
- $siteTime = $wgContLang->time( $ts, false, false );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $siteDate = $contLang->date( $ts, false, false );
+ $siteTime = $contLang->time( $ts, false, false );
$tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
return [
// Preserve U+001F for self::parseMultiValue(), or error out if that won't be called
if ( isset( $value ) && substr( $rawValue, 0, 1 ) === "\x1f" ) {
if ( $multi ) {
- // This loses the potential $wgContLang->checkTitleEncoding() transformation
- // done by WebRequest for $_GET. Let's call that a feature.
+ // This loses the potential checkTitleEncoding() transformation done by
+ // WebRequest for $_GET. Let's call that a feature.
$value = implode( "\x1f", $request->normalizeUnicode( explode( "\x1f", $rawValue ) ) );
} else {
$this->dieWithError( 'apierror-badvalue-notmultivalue', 'badvalue_notmultivalue' );
* @param array $options Formatting options (described above)
*/
public static function getHelp( IContextSource $context, $modules, array $options ) {
- global $wgContLang;
-
if ( !is_array( $modules ) ) {
$modules = [ $modules ];
}
}
$out->setPageTitle( $context->msg( 'api-help-title' ) );
- $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ $services = MediaWikiServices::getInstance();
+ $cache = $services->getMainWANObjectCache();
$cacheKey = null;
if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
- $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
+ $options['recursivesubmodules'] &&
+ $context->getLanguage()->equals( $services->getContentLanguage() )
) {
$cacheHelpTimeout = $context->getConfig()->get( 'APICacheHelpTimeout' );
if ( $cacheHelpTimeout > 0 ) {
// for uselang=user (see T85635).
} else {
if ( $uselang === 'content' ) {
- global $wgContLang;
- $uselang = $wgContLang->getCode();
+ $uselang = MediaWikiServices::getInstance()->getContentLanguage()->getCode();
}
$code = RequestContext::sanitizeLangCode( $uselang );
$this->getContext()->setLanguage( $code );
if ( $errorLangCode === 'uselang' ) {
$errorLang = $this->getLanguage();
} elseif ( $errorLangCode === 'content' ) {
- global $wgContLang;
- $errorLang = $wgContLang;
+ $errorLang = MediaWikiServices::getInstance()->getContentLanguage();
} else {
$errorLangCode = RequestContext::sanitizeLangCode( $errorLangCode );
$errorLang = Language::factory( $errorLangCode );
* @since 1.21
*/
public function getNormalizedTitlesAsResult( $result = null ) {
- global $wgContLang;
-
$values = [];
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
foreach ( $this->getNormalizedTitles() as $rawTitleStr => $titleStr ) {
- $encode = ( $wgContLang->normalize( $rawTitleStr ) !== $rawTitleStr );
+ $encode = $contLang->normalize( $rawTitleStr ) !== $rawTitleStr;
$values[] = [
'fromencoded' => $encode,
'from' => $encode ? rawurlencode( $rawTitleStr ) : $rawTitleStr,
$this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
} else {
// Variants checking
- global $wgContLang;
- if ( $this->mConvertTitles &&
- $wgContLang->hasVariants() &&
- !$titleObj->exists()
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if (
+ $this->mConvertTitles && $contLang->hasVariants() && !$titleObj->exists()
) {
// Language::findVariantLink will modify titleText and titleObj into
// the canonical variant if possible
$titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText();
- $wgContLang->findVariantLink( $titleText, $titleObj );
+ $contLang->findVariantLink( $titleText, $titleObj );
$titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
}
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A query action to return messages from site message cache
*
// Whether we have any sort of message customisation filtering
$customiseFilterEnabled = $params['customised'] !== 'all';
if ( $customiseFilterEnabled ) {
- global $wgContLang;
-
$customisedMessages = AllMessagesTablePager::getCustomisedStatuses(
array_map(
[ $langObj, 'ucfirst' ],
$messages_target
),
$langObj->getCode(),
- !$langObj->equals( $wgContLang )
+ !$langObj->equals( MediaWikiServices::getInstance()->getContentLanguage() )
);
$customised = $params['customised'] === 'modified';
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A query action to get image information and upload history.
*
* @return array Result array
*/
public static function getInfo( $file, $prop, $result, $thumbParams = null, $opts = false ) {
- global $wgContLang;
-
$anyHidden = false;
if ( !$opts || is_string( $opts ) ) {
$opts = [
'version' => $opts ?: 'latest',
- 'language' => $wgContLang,
+ 'language' => MediaWikiServices::getInstance()->getContentLanguage(),
'multilang' => false,
'extmetadatafilter' => [],
'revdelUser' => null,
}
public function getAllowedParams() {
- global $wgContLang;
-
return [
'prop' => [
ApiBase::PARAM_ISMULTI => true,
],
'extmetadatalanguage' => [
ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_DFLT => $wgContLang->getCode(),
+ ApiBase::PARAM_DFLT =>
+ MediaWikiServices::getInstance()->getContentLanguage()->getCode(),
],
'extmetadatamultilang' => [
ApiBase::PARAM_TYPE => 'boolean',
}
private function getAllVariants( $text, $ns = NS_MAIN ) {
- global $wgContLang;
$result = [];
- foreach ( $wgContLang->getVariants() as $variant ) {
- $convertTitle = $wgContLang->autoConvert( $text, $variant );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ foreach ( $contLang->getVariants() as $variant ) {
+ $convertTitle = $contLang->autoConvert( $text, $variant );
if ( $ns !== NS_MAIN ) {
- $convertNs = $wgContLang->convertNamespace( $ns, $variant );
+ $convertNs = $contLang->convertNamespace( $ns, $variant );
$convertTitle = $convertNs . ':' . $convertTitle;
}
$result[$variant] = $convertTitle;
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A query module to list all langlinks (links to corresponding foreign language pages).
*
}
public function getAllowedParams() {
- global $wgContLang;
return [
'prop' => [
ApiBase::PARAM_ISMULTI => true,
'descending'
]
],
- 'inlanguagecode' => $wgContLang->getCode(),
+ 'inlanguagecode' => MediaWikiServices::getInstance()->getContentLanguage()->getCode(),
'limit' => [
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Query module to perform full text search within wiki titles and content
*
* @return void
*/
private function run( $resultPageSet = null ) {
- global $wgContLang;
$params = $this->extractRequestParams();
// Extract parameters
}
// Add the search results to the result
- $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
+ $terms = MediaWikiServices::getInstance()->getContentLanguage()->
+ convertForSearchResult( $matches->termMatches() );
$titles = [];
$count = 0;
$limit = $params['limit'];
}
protected function appendGeneralInfo( $property ) {
- global $wgContLang;
-
$config = $this->getConfig();
$data = [];
$data['langconversion'] = !$config->get( 'DisableLangConversion' );
$data['titleconversion'] = !$config->get( 'DisableTitleConversion' );
- if ( $wgContLang->linkPrefixExtension() ) {
- $linkPrefixCharset = $wgContLang->linkPrefixCharset();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( $contLang->linkPrefixExtension() ) {
+ $linkPrefixCharset = $contLang->linkPrefixCharset();
$data['linkprefixcharset'] = $linkPrefixCharset;
// For backwards compatibility
$data['linkprefix'] = "/^((?>.*[^$linkPrefixCharset]|))(.+)$/sDu";
$data['linkprefix'] = '';
}
- $linktrail = $wgContLang->linkTrail();
+ $linktrail = $contLang->linkTrail();
$data['linktrail'] = $linktrail ?: '';
$data['legaltitlechars'] = Title::legalChars();
$data['lang'] = $config->get( 'LanguageCode' );
$fallbacks = [];
- foreach ( $wgContLang->getFallbackLanguages() as $code ) {
+ foreach ( $contLang->getFallbackLanguages() as $code ) {
$fallbacks[] = [ 'code' => $code ];
}
$data['fallback'] = $fallbacks;
ApiResult::setIndexedTagName( $data['fallback'], 'lang' );
- if ( $wgContLang->hasVariants() ) {
+ if ( $contLang->hasVariants() ) {
$variants = [];
- foreach ( $wgContLang->getVariants() as $code ) {
+ foreach ( $contLang->getVariants() as $code ) {
$variants[] = [
'code' => $code,
- 'name' => $wgContLang->getVariantname( $code ),
+ 'name' => $contLang->getVariantname( $code ),
];
}
$data['variants'] = $variants;
ApiResult::setIndexedTagName( $data['variants'], 'lang' );
}
- $data['rtl'] = $wgContLang->isRTL();
- $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
+ $data['rtl'] = $contLang->isRTL();
+ $data['fallback8bitEncoding'] = $contLang->fallback8bitEncoding();
$data['readonly'] = wfReadOnly();
if ( $data['readonly'] ) {
}
protected function appendNamespaces( $property ) {
- global $wgContLang;
$data = [
ApiResult::META_TYPE => 'assoc',
];
- foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
+ foreach (
+ MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
+ as $ns => $title
+ ) {
$data[$ns] = [
'id' => intval( $ns ),
'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
}
protected function appendNamespaceAliases( $property ) {
- global $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$aliases = array_merge( $this->getConfig()->get( 'NamespaceAliases' ),
- $wgContLang->getNamespaceAliases() );
- $namespaces = $wgContLang->getNamespaces();
+ $contLang->getNamespaceAliases() );
+ $namespaces = $contLang->getNamespaces();
$data = [];
foreach ( $aliases as $title => $ns ) {
if ( $namespaces[$ns] == $title ) {
}
protected function appendSpecialPageAliases( $property ) {
- global $wgContLang;
$data = [];
- $aliases = $wgContLang->getSpecialPageAliases();
+ $aliases = MediaWikiServices::getInstance()->getContentLanguage()->getSpecialPageAliases();
foreach ( SpecialPageFactory::getNames() as $specialpage ) {
if ( isset( $aliases[$specialpage] ) ) {
$arr = [ 'realname' => $specialpage, 'aliases' => $aliases[$specialpage] ];
}
protected function appendMagicWords( $property ) {
- global $wgContLang;
$data = [];
- foreach ( $wgContLang->getMagicWords() as $magicword => $aliases ) {
+ foreach (
+ MediaWikiServices::getInstance()->getContentLanguage()->getMagicWords()
+ as $magicword => $aliases
+ ) {
$caseSensitive = array_shift( $aliases );
$arr = [ 'name' => $magicword, 'aliases' => $aliases ];
$arr['case-sensitive'] = (bool)$caseSensitive;
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* This class represents the result of the API operations.
* It simply wraps a nested array structure, adding some functions to simplify
* @return array|mixed|string
*/
private static function validateValue( $value ) {
- global $wgContLang;
-
if ( is_object( $value ) ) {
// Note we use is_callable() here instead of instanceof because
// ApiSerializable is an informal protocol (see docs there for details).
} elseif ( is_float( $value ) && !is_finite( $value ) ) {
throw new InvalidArgumentException( 'Cannot add non-finite floats to ApiResult' );
} elseif ( is_string( $value ) ) {
- $value = $wgContLang->normalize( $value );
+ $value = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $value );
} elseif ( $value !== null && !is_scalar( $value ) ) {
$type = gettype( $value );
if ( is_resource( $value ) ) {
* @param bool $useContextLang Use 'uselang' to set the user's language
*/
private function setDefaultUserOptions( User $user, $useContextLang ) {
- global $wgContLang;
-
$user->setToken();
- $lang = $useContextLang ? \RequestContext::getMain()->getLanguage() : $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+
+ $lang = $useContextLang ? \RequestContext::getMain()->getLanguage() : $contLang;
$user->setOption( 'language', $lang->getPreferredVariant() );
- if ( $wgContLang->hasVariants() ) {
- $user->setOption( 'variant', $wgContLang->getPreferredVariant() );
+ if ( $contLang->hasVariants() ) {
+ $user->setOption( 'variant', $contLang->getPreferredVariant() );
}
}
* @return bool
*/
public static function useFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
- global $wgContLang;
$config = MediaWikiServices::getInstance()->getMainConfig();
if ( !$config->get( 'UseFileCache' ) && $mode !== self::MODE_REBUILD ) {
$ulang = $context->getLanguage();
// Check that there are no other sources of variation
- if ( $user->getId() || !$ulang->equals( $wgContLang ) ) {
+ if ( $user->getId() ||
+ !$ulang->equals( MediaWikiServices::getInstance()->getContentLanguage() ) ) {
return false;
}
* @return void
*/
public function loadFromFileCache( IContextSource $context, $mode = self::MODE_NORMAL ) {
- global $wgContLang;
$config = MediaWikiServices::getInstance()->getMainConfig();
wfDebug( __METHOD__ . "()\n" );
$context->getOutput()->sendCacheControl();
header( "Content-Type: {$config->get( 'MimeType' )}; charset=UTF-8" );
- header( "Content-Language: {$wgContLang->getHtmlCode()}" );
+ header( 'Content-Language: ' .
+ MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
if ( $this->useGzip() ) {
if ( wfClientAcceptsGzip() ) {
header( 'Content-Encoding: gzip' );
return false;
}
- global $wgContLang;
- if ( !$wgContLang->needsGenderDistinction() ) {
+ if ( !MediaWikiServices::getInstance()->getContentLanguage()->needsGenderDistinction() ) {
return false;
}
protected $clusterCache;
/** @var BagOStuff */
protected $srvCache;
+ /** @var Language */
+ protected $contLang;
/**
* Singleton instance
? MediaWikiServices::getInstance()->getLocalServerObjectCache()
: new EmptyBagOStuff(),
$wgUseDatabaseMessages,
- $wgMsgCacheExpiry
+ $wgMsgCacheExpiry,
+ MediaWikiServices::getInstance()->getContentLanguage()
);
}
* @return string Normalized message key
*/
public static function normalizeKey( $key ) {
- global $wgContLang;
-
$lckey = strtr( $key, ' ', '_' );
if ( ord( $lckey ) < 128 ) {
$lckey[0] = strtolower( $lckey[0] );
} else {
- $lckey = $wgContLang->lcfirst( $lckey );
+ $lckey = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $lckey );
}
return $lckey;
* @param BagOStuff $serverCache
* @param bool $useDB Whether to look for message overrides (e.g. MediaWiki: pages)
* @param int $expiry Lifetime for cache. @see $mExpiry.
+ * @param Language|null $contLang Content language of site
*/
public function __construct(
WANObjectCache $wanCache,
BagOStuff $clusterCache,
BagOStuff $serverCache,
$useDB,
- $expiry
+ $expiry,
+ Language $contLang = null
) {
$this->wanCache = $wanCache;
$this->clusterCache = $clusterCache;
$this->mDisable = !$useDB;
$this->mExpiry = $expiry;
+ $this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
}
/**
// (b) Update the shared caches in a deferred update with a fresh DB snapshot
DeferredUpdates::addCallableUpdate(
function () use ( $title, $msg, $code ) {
- global $wgContLang, $wgMaxMsgCacheEntrySize;
+ global $wgMaxMsgCacheEntrySize;
// Allow one caller at a time to avoid race conditions
$scopedLock = $this->getReentrantScopedLock(
$this->clusterCache->makeKey( 'messages', $code )
// Purge the message in the message blob store
$resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
$blobStore = $resourceloader->getMessageBlobStore();
- $blobStore->updateMessage( $wgContLang->lcfirst( $msg ) );
+ $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
Hooks::run( 'MessageCacheReplace', [ $title, $text ] );
},
* @return string|bool The message, or false if not found
*/
protected function getMessageFromFallbackChain( $lang, $lckey, $useDB ) {
- global $wgContLang;
-
$alreadyTried = [];
// First try the requested language.
}
// Now try checking the site language.
- $message = $this->getMessageForLang( $wgContLang, $lckey, $useDB, $alreadyTried );
+ $message = $this->getMessageForLang( $this->contLang, $lckey, $useDB, $alreadyTried );
return $message;
}
* @return string|bool The message, or false if not found
*/
private function getMessageForLang( $lang, $lckey, $useDB, &$alreadyTried ) {
- global $wgContLang;
-
$langcode = $lang->getCode();
// Try checking the database for the requested language
if ( $useDB ) {
- $uckey = $wgContLang->ucfirst( $lckey );
+ $uckey = $this->contLang->ucfirst( $lckey );
if ( !isset( $alreadyTried[$langcode] ) ) {
$message = $this->getMsgFromNamespace(
* @return array Array of message keys (strings)
*/
public function getAllMessageKeys( $code ) {
- global $wgContLang;
-
$this->load( $code );
if ( !$this->cache->has( $code ) ) {
// Apparently load() failed
$cache = array_diff( $cache, [ '!NONEXISTENT' ] );
// Keys may appear with a capital first letter. lcfirst them.
- return array_map( [ $wgContLang, 'lcfirst' ], array_keys( $cache ) );
+ return array_map( [ $this->contLang, 'lcfirst' ], array_keys( $cache ) );
}
/**
* @since 1.29
*/
public function updateMessageOverride( Title $title, Content $content = null ) {
- global $wgContLang;
-
$msgText = $this->getMessageTextFromContent( $content );
if ( $msgText === null ) {
$msgText = false; // treat as not existing
$this->replace( $title->getDBkey(), $msgText );
- if ( $wgContLang->hasVariants() ) {
- $wgContLang->updateConversionTable( $title );
+ if ( $this->contLang->hasVariants() ) {
+ $this->contLang->updateConversionTable( $title );
}
}
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @since 1.16.3
* @author Tim Starling
* @return Collation
*/
public static function factory( $collationName ) {
- global $wgContLang;
-
switch ( $collationName ) {
case 'uppercase':
return new UppercaseCollation;
case 'numeric':
- return new NumericUppercaseCollation( $wgContLang );
+ return new NumericUppercaseCollation(
+ MediaWikiServices::getInstance()->getContentLanguage() );
case 'identity':
return new IdentityCollation;
case 'uca-default':
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Collation class that's essentially a no-op.
*
}
public function getFirstLetter( $string ) {
- global $wgContLang;
// Copied from UppercaseCollation.
// I'm kind of unclear on when this could happen...
if ( $string[0] == "\0" ) {
$string = substr( $string, 1 );
}
- return $wgContLang->firstChar( $string );
+ return MediaWikiServices::getInstance()->getContentLanguage()->firstChar( $string );
}
}
class NumericUppercaseCollation extends UppercaseCollation {
/**
- * @var $digitTransformLang Language How to convert digits (usually $wgContLang)
+ * @var $digitTransformLang Language How to convert digits (usually the content language)
*/
private $digitTransformLang;
* @param Language $lang How to convert digits.
* For example, if given language "my" than ၇ is treated like 7.
*
- * It is expected that usually this is given $wgContLang.
+ * It is expected that usually this is given the content language.
*/
public function __construct( Language $lang ) {
$this->digitTransformLang = $lang;
<?php
+use MediaWiki\MediaWikiServices;
use MediaWiki\Search\ParserOutputSearchDataExtractor;
/**
/**
* Get the language in which the content of the given page is written.
*
- * This default implementation just returns $wgContLang (except for pages
+ * This default implementation just returns the content language (except for pages
* in the MediaWiki namespace)
*
* Note that the pages language is not cacheable, since it may in some
* @return Language The page's language
*/
public function getPageLanguage( Title $title, Content $content = null ) {
- global $wgContLang, $wgLang;
- $pageLang = $wgContLang;
+ global $wgLang;
+ $pageLang = MediaWikiServices::getInstance()->getContentLanguage();
if ( $title->getNamespace() == NS_MEDIAWIKI ) {
// Parse mediawiki messages with correct target language
* @author Daniel Kinzler
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Content object implementation for representing flat text.
*
}
public function getTextForSummary( $maxlength = 250 ) {
- global $wgContLang;
-
$text = $this->getNativeData();
- $truncatedtext = $wgContLang->truncateForDatabase(
- preg_replace( "/[\n\r]/", ' ', $text ),
- max( 0, $maxlength ) );
+ $truncatedtext = MediaWikiServices::getInstance()->getContentLanguage()->
+ truncateForDatabase( preg_replace( "/[\n\r]/", ' ', $text ), max( 0, $maxlength ) );
return $truncatedtext;
}
*
* @param Content $that The other content object to compare this content object to.
* @param Language|null $lang The language object to use for text segmentation.
- * If not given, $wgContentLang is used.
+ * If not given, the content language is used.
*
* @return Diff A diff representing the changes that would have to be
* made to this content object to make it equal to $that.
*/
public function diff( Content $that, Language $lang = null ) {
- global $wgContLang;
-
$this->checkModelID( $that->getModel() );
// @todo could implement this in DifferenceEngine and just delegate here?
if ( !$lang ) {
- $lang = $wgContLang;
+ $lang = MediaWikiServices::getInstance()->getContentLanguage();
}
$otext = $this->getNativeData();
} elseif ( $this->lang === null ) {
$this->recursion = true;
- global $wgContLang;
-
try {
$request = $this->getRequest();
$user = $this->getUser();
Hooks::run( 'UserGetLanguageObject', [ $user, &$code, $this ] );
if ( $code === $this->getConfig()->get( 'LanguageCode' ) ) {
- $this->lang = $wgContLang;
+ $this->lang = MediaWikiServices::getInstance()->getContentLanguage();
} else {
$obj = Language::factory( $code );
$this->lang = $obj;
* @ingroup Database
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\Blob;
use Wikimedia\Rdbms\ResultWrapper;
* @throws DBUnexpectedError
*/
private function insertOneRow( $table, $row, $fname ) {
- global $wgContLang;
-
$table = $this->tableName( $table );
// "INSERT INTO tables (a, b, c)"
$sql = "INSERT INTO " . $table . " (" . implode( ',', array_keys( $row ) ) . ')';
$val = $this->getInfinity();
}
- $val = ( $wgContLang != null ) ? $wgContLang->checkTitleEncoding( $val ) : $val;
+ $val = MediaWikiServices::getInstance()->getContentLanguage()->
+ checkTitleEncoding( $val );
if ( oci_bind_by_name( $stmt, ":$col", $val, -1, SQLT_CHR ) === false ) {
$e = oci_error( $stmt );
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
}
function addQuotes( $s ) {
- global $wgContLang;
- if ( isset( $wgContLang->mLoaded ) && $wgContLang->mLoaded ) {
- $s = $wgContLang->checkTitleEncoding( $s );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( isset( $contLang->mLoaded ) && $contLang->mLoaded ) {
+ $s = $contLang->checkTitleEncoding( $s );
}
return "'" . $this->strencode( $s ) . "'";
}
private function wrapFieldForWhere( $table, &$col, &$val ) {
- global $wgContLang;
-
$col_info = $this->fieldInfoMulti( $table, $col );
$col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
if ( $col_type == 'CLOB' ) {
$col = 'TO_CHAR(' . $col . ')';
- $val = $wgContLang->checkTitleEncoding( $val );
+ $val =
+ MediaWikiServices::getInstance()->getContentLanguage()->checkTitleEncoding( $val );
} elseif ( $col_type == 'VARCHAR2' ) {
- $val = $wgContLang->checkTitleEncoding( $val );
+ $val =
+ MediaWikiServices::getInstance()->getContentLanguage()->checkTitleEncoding( $val );
}
}
* @throws DBUnexpectedError
*/
function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
- global $wgContLang;
-
$table = $this->tableName( $table );
$opts = $this->makeUpdateOptions( $options );
$sql = "UPDATE $opts $table SET ";
$val = '31-12-2030 12:00:00.000000';
}
- $val = ( $wgContLang != null ) ? $wgContLang->checkTitleEncoding( $val ) : $val;
+ $val = MediaWikiServices::getInstance()->getContentLanguage()->
+ checkTitleEncoding( $val );
if ( oci_bind_by_name( $stmt, ":$col", $val ) === false ) {
$e = oci_error( $stmt );
$this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ );
* @return array
*/
private function getCategoryInsertions( $existing = [] ) {
- global $wgContLang, $wgCategoryCollation;
+ global $wgCategoryCollation;
$diffs = array_diff_assoc( $this->mCategories, $existing );
$arr = [];
foreach ( $diffs as $name => $prefix ) {
$nt = Title::makeTitleSafe( NS_CATEGORY, $name );
- $wgContLang->findVariantLink( $name, $nt, true );
+ MediaWikiServices::getInstance()->getContentLanguage()->
+ findVariantLink( $name, $nt, true );
$type = MWNamespace::getCategoryLinkType( $this->mTitle->getNamespace() );
* @return string
*/
public function updateText( $text, SearchEngine $se = null ) {
- global $wgContLang;
-
# Language-specific strip/conversion
- $text = $wgContLang->normalizeForSearch( $text );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch( $text );
$se = $se ?: MediaWikiServices::getInstance()->newSearchEngine();
$lc = $se->legalSearchChars() . '&#;';
+ # Strip HTML markup
$text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
- ' ', $wgContLang->lc( " " . $text . " " ) ); # Strip HTML markup
+ ' ', MediaWikiServices::getInstance()->getContentLanguage()->lc( " " . $text . " " ) );
$text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
"\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
* @return string A stripped-down title string ready for the search index
*/
private function getNormalizedTitle( SearchEngine $search ) {
- global $wgContLang;
-
$ns = $this->title->getNamespace();
$title = $this->title->getText();
$lc = $search->legalSearchChars() . '&#;';
- $t = $wgContLang->normalizeForSearch( $title );
+ $t = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch( $title );
$t = preg_replace( "/[^{$lc}]+/", ' ', $t );
- $t = $wgContLang->lc( $t );
+ $t = MediaWikiServices::getInstance()->getContentLanguage()->lc( $t );
# Handle 's, s'
$t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
* @return bool|string
*/
protected function textDiff( $otext, $ntext ) {
- global $wgContLang;
-
$otext = str_replace( "\r\n", "\n", $otext );
$ntext = str_replace( "\r\n", "\n", $ntext );
}
# Native PHP diff
- $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) );
- $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $ota = explode( "\n", $contLang->segmentForDiff( $otext ) );
+ $nta = explode( "\n", $contLang->segmentForDiff( $ntext ) );
$diffs = new Diff( $ota, $nta );
$formatter = new TableDiffFormatter();
- $difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) );
+ $difftext = $contLang->unsegmentForDiff( $formatter->format( $diffs ) );
$difftext .= $this->debug( 'native PHP' );
return $difftext;
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* @ingroup Dump
*/
* @return string
*/
function openStream() {
- global $wgContLang;
$ver = WikiExporter::schemaVersion();
return Xml::element( 'mediawiki', [
'xmlns' => "http://www.mediawiki.org/xml/export-$ver/",
*/
'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
"http://www.mediawiki.org/xml/export-$ver.xsd",
- 'version' => $ver,
- 'xml:lang' => $wgContLang->getHtmlCode() ],
+ 'version' => $ver,
+ 'xml:lang' => MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() ],
null ) .
"\n" .
$this->siteInfo();
* @return string
*/
function namespaces() {
- global $wgContLang;
$spaces = "<namespaces>\n";
- foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
+ foreach (
+ MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces()
+ as $ns => $title
+ ) {
$spaces .= ' ' .
Xml::element( 'namespace',
[
return $title->getPrefixedText();
}
- global $wgContLang;
- $prefix = $wgContLang->getFormattedNsText( $title->getNamespace() );
+ $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( $title->getNamespace() );
// @todo Emit some kind of warning to the user if $title->getNamespace() !==
// NS_MAIN and $prefix === '' (viz. pages in an unregistered namespace)
* @details
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Base code for file repositories.
*
* @return string
*/
public function getNameFromTitle( Title $title ) {
- global $wgContLang;
if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
$name = $title->getUserCaseDBKey();
if ( $this->initialCapital ) {
- $name = $wgContLang->ucfirst( $name );
+ $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
}
} else {
$name = $title->getDBkey();
$applyMatchingFiles = function ( ResultWrapper $res, &$searchSet, &$finalFiles )
use ( $fileMatchesSearch, $flags )
{
- global $wgContLang;
$info = $this->getInfo();
foreach ( $res as $row ) {
$file = $this->newFileFromRow( $row );
$dbKeysLook = [ strtr( $file->getName(), ' ', '_' ) ];
if ( !empty( $info['initialCapital'] ) ) {
// Search keys for "hi.png" and "Hi.png" should use the "Hi.png file"
- $dbKeysLook[] = $wgContLang->lcfirst( $file->getName() );
+ $dbKeysLook[] = MediaWikiServices::getInstance()->getContentLanguage()->
+ lcfirst( $file->getName() );
}
foreach ( $dbKeysLook as $dbKey ) {
if ( isset( $searchSet[$dbKey] )
}
function purgeDescriptionPage() {
- global $wgContLang;
-
- $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() );
+ $url = $this->repo->getDescriptionRenderUrl(
+ $this->getName(), MediaWikiServices::getInstance()->getContentLanguage()->getCode() );
$key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5( $url ) );
MediaWikiServices::getInstance()->getMainWANObjectCache()->delete( $key );
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Image gallery
*
* @throws MWException
*/
static function factory( $mode = false, IContextSource $context = null ) {
- global $wgContLang;
self::loadModes();
if ( !$context ) {
$context = RequestContext::getMainAndWarn( __METHOD__ );
$mode = $galleryOptions['mode'];
}
- $mode = $wgContLang->lc( $mode );
+ $mode = MediaWikiServices::getInstance()->getContentLanguage()->lc( $mode );
if ( isset( self::$modeMapping[$mode] ) ) {
$class = self::$modeMapping[$mode];
}
// @todo Code is incomplete.
- // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) .
- // ":{$ut}" );
+ // $linkTarget = Title::newFromText( MediaWikiServices::getInstance()->
+ // getContentLanguage()->getNsText( MWNamespace::getUser() ) . ":{$ut}" );
// $ul = Linker::link( $linkTarget, $ut );
$meta = [];
<?php
+use MediaWiki\MediaWikiServices;
use MediaWiki\Widget\TitleInputWidget;
/**
$title = Title::newFromTextThrow( $value );
} else {
// Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions
- global $wgContLang;
- $namespaceName = $wgContLang->getNsText( $this->mParams['namespace'] );
+ $namespaceName = MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( $this->mParams['namespace'] );
$title = Title::newFromTextThrow( $namespaceName . ':' . $value );
}
} catch ( MalformedTitleException $e ) {
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* XML file reader for the page data importer.
*
$status->fatal( 'import-rootpage-invalid' );
} else {
if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
- global $wgContLang;
-
$displayNSText = $title->getNamespace() == NS_MAIN
? wfMessage( 'blanknamespace' )->text()
- : $wgContLang->getNsText( $title->getNamespace() );
+ : MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( $title->getNamespace() );
$status->fatal( 'import-rootpage-nosubpage', $displayNSText );
} else {
// set namespace to 'all', so the namespace check in processTitle() can pass
* @ingroup Deployment
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Class for the core installer command line interface.
*
if ( isset( $option['lang'] ) ) {
global $wgLang, $wgLanguageCode;
$this->setVar( '_UserLang', $option['lang'] );
- $wgContLang = Language::factory( $option['lang'] );
- $wgLang = Language::factory( $option['lang'] );
$wgLanguageCode = $option['lang'];
+ $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $wgLang = Language::factory( $option['lang'] );
RequestContext::getMain()->setLanguage( $wgLang );
}
'Converting links and brokenlinks tables to pagelinks'
);
- global $wgContLang;
- foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
+ foreach (
+ MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces() as $ns => $name
+ ) {
if ( $ns == 0 ) {
continue;
}
* @ingroup Deployment
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Class for the core installer web interface.
*
if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
$wgLanguageCode = $this->getAcceptLanguage();
- $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
+ $wgLang = Language::factory( $wgLanguageCode );
RequestContext::getMain()->setLanguage( $wgLang );
$this->setVar( 'wgLanguageCode', $wgLanguageCode );
$this->setVar( '_UserLang', $wgLanguageCode );
} else {
$wgLanguageCode = $this->getVar( 'wgLanguageCode' );
- $wgContLang = Language::factory( $wgLanguageCode );
}
+ $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
}
/**
* @ingroup Deployment
*/
+use MediaWiki\MediaWikiServices;
+
class WebInstallerName extends WebInstallerPage {
/**
}
// Make sure it won't conflict with any existing namespaces
- global $wgContLang;
- $nsIndex = $wgContLang->getNsIndex( $name );
+ $nsIndex = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $name );
if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
$this->parent->showError( 'config-ns-conflict', $name );
$retVal = false;
/**
* @var Language
*/
- private $contentLanguage;
+ private $contLang;
/**
* @var WANObjectCache
private $thisSite = null;
/**
- * @param Language $contentLanguage Language object used to convert prefixes to lower case
+ * @param Language $contLang Language object used to convert prefixes to lower case
* @param WANObjectCache $objectCache Cache for interwiki info retrieved from the database
* @param int $objectCacheExpiry Expiry time for $objectCache, in seconds
* @param bool|array|string $cdbData The path of a CDB file, or
* @param string $fallbackSite The code to assume for the local site,
*/
function __construct(
- Language $contentLanguage,
+ Language $contLang,
WANObjectCache $objectCache,
$objectCacheExpiry,
$cdbData,
) {
$this->localCache = new MapCacheLRU( 100 );
- $this->contentLanguage = $contentLanguage;
+ $this->contLang = $contLang;
$this->objectCache = $objectCache;
$this->objectCacheExpiry = $objectCacheExpiry;
$this->cdbData = $cdbData;
return null;
}
- $prefix = $this->contentLanguage->lc( $prefix );
+ $prefix = $this->contLang->lc( $prefix );
if ( $this->localCache->has( $prefix ) ) {
return $this->localCache->get( $prefix );
}
* @return string Text
*/
public function getIRCActionText() {
- global $wgContLang;
-
$this->plaintext = true;
$this->irctext = true;
// Text of title the action is aimed at.
$target = $entry->getTarget()->getPrefixedText();
$text = null;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
switch ( $entry->getType() ) {
case 'move':
switch ( $entry->getSubtype() ) {
$rawDuration = $parameters['5::duration'];
$rawFlags = $parameters['6::flags'];
}
- $duration = $wgContLang->translateBlockExpiry(
+ $duration = $contLang->translateBlockExpiry(
$rawDuration,
null,
wfTimestamp( TS_UNIX, $entry->getTimestamp() )
);
- $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $wgContLang );
+ $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $contLang );
$text = wfMessage( 'blocklogentry' )
->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
break;
->rawParams( $target )->inContentLanguage()->escaped();
break;
case 'reblock':
- $duration = $wgContLang->translateBlockExpiry(
+ $duration = $contLang->translateBlockExpiry(
$parameters['5::duration'],
null,
wfTimestamp( TS_UNIX, $entry->getTimestamp() )
);
- $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang );
+ $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'],
+ $contLang );
$text = wfMessage( 'reblock-logentry' )
->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped();
break;
public static function actionText( $type, $action, $title = null, $skin = null,
$params = [], $filterWikilinks = false
) {
- global $wgLang, $wgContLang, $wgLogActions;
+ global $wgLang, $wgLogActions;
if ( is_null( $skin ) ) {
- $langObj = $wgContLang;
+ $langObj = MediaWikiServices::getInstance()->getContentLanguage();
$langObjOrNull = null;
} else {
$langObj = $wgLang;
* @since 1.26
*/
+use MediaWiki\MediaWikiServices;
+
/**
* This class formats protect log entries.
*
}
public function formatParametersForApi() {
- global $wgContLang;
-
$ret = parent::formatParametersForApi();
if ( isset( $ret['details'] ) && is_array( $ret['details'] ) ) {
foreach ( $ret['details'] as &$detail ) {
if ( isset( $detail['expiry'] ) ) {
- $detail['expiry'] = $wgContLang->formatExpiry( $detail['expiry'], TS_ISO_8601, 'infinite' );
+ $detail['expiry'] = MediaWikiServices::getInstance()->getContentLanguage()->
+ formatExpiry( $detail['expiry'], TS_ISO_8601, 'infinite' );
}
}
}
* @since 1.22
*/
+use MediaWiki\MediaWikiServices;
+
/**
* This class formats rights log entries.
*
*/
class RightsLogFormatter extends LogFormatter {
protected function makePageLink( Title $title = null, $parameters = [], $html = null ) {
- global $wgContLang, $wgUserrightsInterwikiDelimiter;
+ global $wgUserrightsInterwikiDelimiter;
if ( !$this->plaintext ) {
- $text = $wgContLang->ucfirst( $title->getDBkey() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->
+ ucfirst( $title->getDBkey() );
$parts = explode( $wgUserrightsInterwikiDelimiter, $text, 2 );
if ( count( $parts ) === 2 ) {
* @private
*/
function sendPersonalised( $watchingUser, $source ) {
- global $wgContLang, $wgEnotifUseRealName;
+ global $wgEnotifUseRealName;
// From the PHP manual:
// Note: The to parameter cannot be an address in the form of
// "Something <someone@example.com>". The mail command will not parse
# $PAGEEDITDATE is the time and date of the page change
# expressed in terms of individual local time of the notification
# recipient, i.e. watching user
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$body = str_replace(
[ '$WATCHINGUSERNAME',
'$PAGEEDITDATE',
'$PAGEEDITTIME' ],
[ $wgEnotifUseRealName && $watchingUser->getRealName() !== ''
? $watchingUser->getRealName() : $watchingUser->getName(),
- $wgContLang->userDate( $this->timestamp, $watchingUser ),
- $wgContLang->userTime( $this->timestamp, $watchingUser ) ],
+ $contLang->userDate( $this->timestamp, $watchingUser ),
+ $contLang->userTime( $this->timestamp, $watchingUser ) ],
$this->body );
$headers = [];
* @return Status|null
*/
function sendImpersonal( $addresses ) {
- global $wgContLang;
-
if ( empty( $addresses ) ) {
return null;
}
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$body = str_replace(
[ '$WATCHINGUSERNAME',
'$PAGEEDITDATE',
'$PAGEEDITTIME' ],
[ wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
- $wgContLang->date( $this->timestamp, false, false ),
- $wgContLang->time( $this->timestamp, false, false ) ],
+ $contLang->date( $this->timestamp, false, false ),
+ $contLang->time( $this->timestamp, false, false ) ],
$this->body );
return UserMailer::send( $addresses, $this->from, $this->subject, $body, [
public static function flattenArrayContentLang( $vals, $type = 'ul',
$noHtml = false, $context = false
) {
- global $wgContLang;
$obj = new FormatMetadata;
if ( $context ) {
$obj->setContext( $context );
}
$context = new DerivativeContext( $obj->getContext() );
- $context->setLanguage( $wgContLang );
+ $context->setLanguage( MediaWikiServices::getInstance()->getContentLanguage() );
$obj->setContext( $context );
return $obj->flattenArrayReal( $vals, $type, $noHtml );
*/
switch ( $type ) {
case 'lang':
- // Display default, followed by ContLang,
+ // Display default, followed by ContentLanguage,
// followed by the rest in no particular
// order.
* @return string The text content of "exif-$tag-$val" message in lower case
*/
private function exifMsg( $tag, $val, $arg = null, $arg2 = null ) {
- global $wgContLang;
-
if ( $val === '' ) {
$val = 'value';
}
- return $this->msg( $wgContLang->lc( "exif-$tag-$val" ), $arg, $arg2 )->text();
+ return $this->msg(
+ MediaWikiServices::getInstance()->getContentLanguage()->lc( "exif-$tag-$val" ),
+ $arg,
+ $arg2
+ )->text();
}
/**
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Builds the image revision log shown on image pages
*
* @return string
*/
public function imageHistoryLine( $iscur, $file ) {
- global $wgContLang;
-
$user = $this->getUser();
$lang = $this->getLanguage();
$timestamp = wfTimestamp( TS_MW, $file->getTimestamp() );
$row .= '<td><span class="history-deleted">' .
$this->msg( 'rev-deleted-comment' )->escaped() . '</span></td>';
} else {
- $row .= '<td dir="' . $wgContLang->getDir() . '">' .
- Linker::formatComment( $description, $this->title ) . '</td>';
+ $row .=
+ '<td dir="' . MediaWikiServices::getInstance()->getContentLanguage()->getDir() .
+ '">' . Linker::formatComment( $description, $this->title ) . '</td>';
}
$rowClass = null;
* @return DerivedPageDataUpdater
*/
private function newDerivedDataUpdater() {
- global $wgContLang, $wgRCWatchCategoryMembership, $wgArticleCountMethod;
+ global $wgRCWatchCategoryMembership, $wgArticleCountMethod;
$derivedDataUpdater = new DerivedPageDataUpdater(
$this, // NOTE: eventually, PageUpdater should not know about WikiPage
$this->getParserCache(),
JobQueueGroup::singleton(),
MessageCache::singleton(),
- $wgContLang,
+ MediaWikiServices::getInstance()->getContentLanguage(),
LoggerFactory::getInstance( 'SaveParse' )
);
* @return string
*/
protected function formatExpiry( $expiry ) {
- global $wgContLang;
-
if ( $expiry != 'infinity' ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
return wfMessage(
'protect-expiring',
- $wgContLang->timeanddate( $expiry, false, false ),
- $wgContLang->date( $expiry, false, false ),
- $wgContLang->time( $expiry, false, false )
+ $contLang->timeanddate( $expiry, false, false ),
+ $contLang->date( $expiry, false, false ),
+ $contLang->time( $expiry, false, false )
)->inContentLanguage()->text();
} else {
return wfMessage( 'protect-expiry-indefinite' )
* @return string
*/
public function protectDescriptionLog( array $limit, array $expiry ) {
- global $wgContLang;
-
$protectDescriptionLog = '';
foreach ( array_filter( $limit ) as $action => $restrictions ) {
$expiryText = $this->formatExpiry( $expiry[$action] );
- $protectDescriptionLog .= $wgContLang->getDirMark() .
+ $protectDescriptionLog .=
+ MediaWikiServices::getInstance()->getContentLanguage()->getDirMark() .
"[$action=$restrictions] ($expiryText)";
}
public function commitRollback( $fromP, $summary, $bot,
&$resultDetails, User $guser, $tags = null
) {
- global $wgUseRCPatrol, $wgContLang;
+ global $wgUseRCPatrol;
$dbw = wfGetDB( DB_MASTER );
$targetEditorForPublic = $target->getUser( RevisionRecord::FOR_PUBLIC );
// Allow the custom summary to use the same args as the default message
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$args = [
$targetEditorForPublic ? $targetEditorForPublic->getName() : null,
$currentEditorForPublic ? $currentEditorForPublic->getName() : null,
$s->rev_id,
- $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
+ $contLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
$current->getId(),
- $wgContLang->timeanddate( $current->getTimestamp() )
+ $contLang->timeanddate( $current->getTimestamp() )
];
if ( $summary instanceof Message ) {
$summary = $summary->params( $args )->inContentLanguage()->text();
* @ingroup Parser
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Date formatter, recognises dates in plain text and formats them according to user preferences.
* @todo preferences, OutputPage
* @return DateFormatter
*/
public static function getInstance( Language $lang = null ) {
- global $wgContLang, $wgMainCacheType;
+ global $wgMainCacheType;
- $lang = $lang ?: $wgContLang;
+ $lang = $lang ?: MediaWikiServices::getInstance()->getContentLanguage();
$cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
static $dateFormatter = false;
# to other users, and potentially even used inside links and such,
# it needs to be consistent for all visitors.
$this->mRevisionTimestamp = $this->contLang->userAdjust( $timestamp, '' );
-
}
return $this->mRevisionTimestamp;
}
* @return ParserOptions
*/
public static function newFromAnon() {
- global $wgContLang;
- return new ParserOptions( new User, $wgContLang );
+ return new ParserOptions( new User,
+ MediaWikiServices::getInstance()->getContentLanguage() );
}
/**
* @param IContextSource|string|User|null $context
* - If an IContextSource, the options are initialized based on the source's User and Language.
* - If the string 'canonical', the options are initialized with an anonymous user and
- * $wgContLang.
+ * the content language.
* - If a User or null, the options are initialized for that User (or $wgUser if null).
* 'userlang' is taken from the $userLang parameter, defaulting to $wgLang if that is null.
* @param Language|StubObject|null $userLang (see above)
$wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
$wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
$wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion,
- $wgEnableMagicLinks, $wgContLang;
+ $wgEnableMagicLinks;
if ( self::$defaults === null ) {
// *UPDATE* ParserOptions::matches() if any of this changes as needed
'numberheadings' => User::getDefaultOption( 'numberheadings' ),
'thumbsize' => User::getDefaultOption( 'thumbsize' ),
'stubthreshold' => 0,
- 'userlang' => $wgContLang,
+ 'userlang' => MediaWikiServices::getInstance()->getContentLanguage(),
];
}
if ( !is_null( $title ) ) {
$confstr .= $title->getPageLanguage()->getExtraHashOptions();
} else {
- global $wgContLang;
- $confstr .= $wgContLang->getExtraHashOptions();
+ $confstr .=
+ MediaWikiServices::getInstance()->getContentLanguage()->getExtraHashOptions();
}
$confstr .= $wgRenderHashAppend;
* @ingroup Parser
*/
+use MediaWiki\MediaWikiServices;
+
/**
* HTML sanitizer for MediaWiki
* @ingroup Parser
* @return string Still normalized, without entities
*/
public static function decodeCharReferencesAndNormalize( $text ) {
- global $wgContLang;
$text = preg_replace_callback(
self::CHAR_REFS_REGEX,
[ self::class, 'decodeCharReferencesCallback' ],
);
if ( $count ) {
- return $wgContLang->normalize( $text );
+ return MediaWikiServices::getInstance()->getContentLanguage()->normalize( $text );
} else {
return $text;
}
*/
use Cdb\Reader as CdbReader;
+use MediaWiki\MediaWikiServices;
/**
* Functions to check passwords against a policy requirement
* @return Status error if username and password match, and policy is true
*/
public static function checkPasswordCannotMatchUsername( $policyVal, User $user, $password ) {
- global $wgContLang;
$status = Status::newGood();
$username = $user->getName();
- if ( $policyVal && $wgContLang->lc( $password ) === $wgContLang->lc( $username ) ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if (
+ $policyVal && $contLang->lc( $password ) === $contLang->lc( $username )
+ ) {
$status->error( 'password-name-match' );
}
return $status;
/** @var Config */
protected $config;
- /** @var Language The wiki's content language, equivalent to $wgContLang. */
+ /** @var Language The wiki's content language. */
protected $contLang;
/** @var AuthManager */
* @return bool
*/
public function getFlip( $context ) {
- global $wgContLang;
-
- return $wgContLang->getDir() !== $context->getDirection();
+ return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
+ $context->getDirection();
}
/**
* @author Roan Kattouw
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Module for ResourceLoader initialization.
*
return $this->configVars[$hash];
}
- global $wgContLang;
$conf = $this->getConfig();
// We can't use Title::newMainPage() if 'mainpage' is in
* - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces.
* - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive.
*/
- $namespaceIds = $wgContLang->getNamespaceIds();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $namespaceIds = $contLang->getNamespaceIds();
$caseSensitiveNamespaces = [];
foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) {
- $namespaceIds[$wgContLang->lc( $name )] = $index;
+ $namespaceIds[$contLang->lc( $name )] = $index;
if ( !MWNamespace::isCapitalized( $index ) ) {
$caseSensitiveNamespaces[] = $index;
}
'wgServer' => $conf->get( 'Server' ),
'wgServerName' => $conf->get( 'ServerName' ),
'wgUserLanguage' => $context->getLanguage(),
- 'wgContentLanguage' => $wgContLang->getCode(),
+ 'wgContentLanguage' => $contLang->getCode(),
'wgTranslateNumerals' => $conf->get( 'TranslateNumerals' ),
'wgVersion' => $conf->get( 'Version' ),
'wgEnableAPI' => true, // Deprecated since MW 1.32
'wgEnableWriteAPI' => true, // Deprecated since MW 1.32
'wgMainPageTitle' => $mainPage->getPrefixedText(),
- 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
+ 'wgFormattedNamespaces' => $contLang->getFormattedNamespaces(),
'wgNamespaceIds' => $namespaceIds,
'wgContentNamespaces' => MWNamespace::getContentNamespaces(),
'wgSiteName' => $conf->get( 'Sitename' ),
* @return string
*/
public function normalizeText( $string ) {
- global $wgContLang;
-
// Some languages such as Chinese require word segmentation
- return $wgContLang->segmentByWord( $string );
+ return MediaWikiServices::getInstance()->getContentLanguage()->segmentByWord( $string );
}
/**
* @return SearchNearMatcher
*/
public function getNearMatcher( Config $config ) {
- global $wgContLang;
- return new SearchNearMatcher( $config, $wgContLang );
+ return new SearchNearMatcher( $config,
+ MediaWikiServices::getInstance()->getContentLanguage() );
}
/**
$withAllKeyword = true,
$withPrefixSearchExtractNamespaceHook = false
) {
- global $wgContLang;
-
$parsed = $query;
if ( strpos( $query, ':' ) === false ) { // nothing to do
return false;
if ( !$allQuery && strpos( $query, ':' ) !== false ) {
$prefix = str_replace( ' ', '_', substr( $query, 0, strpos( $query, ':' ) ) );
- $index = $wgContLang->getNsIndex( $prefix );
+ $index = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $prefix );
if ( $index !== false ) {
$extractedNamespace = [ $index ];
$parsed = substr( $query, strlen( $prefix ) + 1 );
$results = $this->completionSearchBackendOverfetch( $search );
$fallbackLimit = 1 + $this->limit - $results->getSize();
if ( $fallbackLimit > 0 ) {
- global $wgContLang;
-
- $fallbackSearches = $wgContLang->autoConvertToAllVariants( $search );
+ $fallbackSearches = MediaWikiServices::getInstance()->getContentLanguage()->
+ autoConvertToAllVariants( $search );
$fallbackSearches = array_diff( array_unique( $fallbackSearches ), [ $search ] );
foreach ( $fallbackSearches as $fbs ) {
* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Highlight bits of wikitext
*
* @return string
*/
public function highlightText( $text, $terms, $contextlines, $contextchars ) {
- global $wgContLang, $wgSearchHighlightBoundaries;
+ global $wgSearchHighlightBoundaries;
if ( $text == '' ) {
return '';
if ( $key == 2 ) {
// see if this is an image link
$ns = substr( $val[0], 2, -1 );
- if ( $wgContLang->getNsIndex( $ns ) != NS_FILE ) {
+ if (
+ MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsIndex( $ns ) != NS_FILE
+ ) {
break;
}
* @return string
*/
function caseCallback( $matches ) {
- global $wgContLang;
if ( strlen( $matches[0] ) > 1 ) {
- return '[' . $wgContLang->lc( $matches[0] ) . $wgContLang->uc( $matches[0] ) . ']';
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ return '[' . $contLang->lc( $matches[0] ) .
+ $contLang->uc( $matches[0] ) . ']';
} else {
return $matches[0];
}
if ( $colon === false ) {
return $matches[2]; // replace with caption
}
- global $wgContLang;
$ns = substr( $matches[1], 0, $colon );
- $index = $wgContLang->getNsIndex( $ns );
+ $index = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $ns );
if ( $index !== false && ( $index == NS_FILE || $index == NS_CATEGORY ) ) {
return $matches[0]; // return the whole thing
} else {
* @return string
*/
public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
- global $wgContLang;
-
$lines = explode( "\n", $text );
$terms = implode( '|', $terms );
$lineno = 0;
$extract = "";
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
foreach ( $lines as $line ) {
if ( 0 == $contextlines ) {
break;
}
--$contextlines;
// truncate function changes ... to relevant i18n message.
- $pre = $wgContLang->truncateForVisual( $m[1], - $contextchars, '...', false );
+ $pre = $contLang->truncateForVisual( $m[1], - $contextchars, '...', false );
if ( count( $m ) < 3 ) {
$post = '';
} else {
- $post = $wgContLang->truncateForVisual( $m[3], $contextchars, '...', false );
+ $post = $contLang->truncateForVisual( $m[3], $contextchars, '...', false );
}
$found = $m[2];
* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
/**
* @return string
*/
private function parseQuery( $filteredText, $fulltext ) {
- global $wgContLang;
$lc = $this->legalSearchChars( self::CHARS_NO_SYNTAX );
$this->searchTerms = [];
if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
$filteredText, $m, PREG_SET_ORDER ) ) {
foreach ( $m as $terms ) {
- $q[] = $terms[1] . $wgContLang->normalizeForSearch( $terms[2] );
+ $q[] = $terms[1] . MediaWikiServices::getInstance()->getContentLanguage()->
+ normalizeForSearch( $terms[2] );
if ( !empty( $terms[3] ) ) {
$regexp = preg_quote( $terms[3], '/' );
* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Search engine hook for MySQL 4+
* @ingroup Search
* @return array
*/
private function parseQuery( $filteredText, $fulltext ) {
- global $wgContLang;
-
$lc = $this->legalSearchChars( self::CHARS_NO_SYNTAX ); // Minus syntax chars (" and *)
$searchon = '';
$this->searchTerms = [];
// Some languages such as Serbian store the input form in the search index,
// so we may need to search for matches in multiple writing system variants.
- $convertedVariants = $wgContLang->autoConvertToAllVariants( $term );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $convertedVariants = $contLang->autoConvertToAllVariants( $term );
if ( is_array( $convertedVariants ) ) {
$variants = array_unique( array_values( $convertedVariants ) );
} else {
// around problems with minimum lengths and encoding in MySQL's
// fulltext engine.
// For Chinese this also inserts spaces between adjacent Han characters.
- $strippedVariants = array_map(
- [ $wgContLang, 'normalizeForSearch' ],
- $variants );
+ $strippedVariants = array_map( [ $contLang, 'normalizeForSearch' ], $variants );
// Some languages such as Chinese force all variants to a canonical
// form when stripping to the low-level search index, so to be sure
}
private function regexTerm( $string, $wildcard ) {
- global $wgContLang;
-
$regex = preg_quote( $string, '/' );
- if ( $wgContLang->hasWordBreaks() ) {
+ if ( MediaWikiServices::getInstance()->getContentLanguage()->hasWordBreaks() ) {
if ( $wildcard ) {
// Don't cut off the final bit!
$regex = "\b$regex";
* @return mixed|string
*/
function normalizeText( $string ) {
- global $wgContLang;
-
$out = parent::normalizeText( $string );
// MySQL fulltext index doesn't grok utf-8, so we
$out = preg_replace_callback(
"/([\\xc0-\\xff][\\x80-\\xbf]*)/",
[ $this, 'stripForSearchCallback' ],
- $wgContLang->lc( $out ) );
+ MediaWikiServices::getInstance()->getContentLanguage()->lc( $out ) );
// And to add insult to injury, the default indexing
// ignores short words... Pad them so we can pass them
* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Search engine hook base class for Oracle (ConText).
* @ingroup Search
* @return string
*/
private function parseQuery( $filteredText, $fulltext ) {
- global $wgContLang;
$lc = $this->legalSearchChars( self::CHARS_NO_SYNTAX );
$this->searchTerms = [];
foreach ( $m as $terms ) {
// Search terms in all variant forms, only
// apply on wiki with LanguageConverter
- $temp_terms = $wgContLang->autoConvertToAllVariants( $terms[2] );
+ $temp_terms = MediaWikiServices::getInstance()->getContentLanguage()->
+ autoConvertToAllVariants( $terms[2] );
if ( is_array( $temp_terms ) ) {
$temp_terms = array_unique( array_values( $temp_terms ) );
foreach ( $temp_terms as $t ) {
}
private function escapeTerm( $t ) {
- global $wgContLang;
- $t = $wgContLang->normalizeForSearch( $t );
+ $t = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch( $t );
$t = isset( $this->reservedWords[strtoupper( $t )] ) ? '{' . $t . '}' : $t;
$t = preg_replace( '/^"(.*)"$/', '($1)', $t );
$t = preg_replace( '/([-&|])/', '\\\\$1', $t );
* @ingroup Search
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Search engine hook for SQLite
* @ingroup Search
* @return string
*/
private function parseQuery( $filteredText, $fulltext ) {
- global $wgContLang;
$lc = $this->legalSearchChars( self::CHARS_NO_SYNTAX ); // Minus syntax chars (" and *)
$searchon = '';
$this->searchTerms = [];
// Some languages such as Serbian store the input form in the search index,
// so we may need to search for matches in multiple writing system variants.
- $convertedVariants = $wgContLang->autoConvertToAllVariants( $term );
+ $convertedVariants = MediaWikiServices::getInstance()->getContentLanguage()->
+ autoConvertToAllVariants( $term );
if ( is_array( $convertedVariants ) ) {
$variants = array_unique( array_values( $convertedVariants ) );
} else {
// fulltext engine.
// For Chinese this also inserts spaces between adjacent Han characters.
$strippedVariants = array_map(
- [ $wgContLang, 'normalizeForSearch' ],
+ [ MediaWikiServices::getInstance()->getContentLanguage(),
+ 'normalizeForSearch' ],
$variants );
// Some languages such as Chinese force all variants to a canonical
}
private function regexTerm( $string, $wildcard ) {
- global $wgContLang;
-
$regex = preg_quote( $string, '/' );
- if ( $wgContLang->hasWordBreaks() ) {
+ if ( MediaWikiServices::getInstance()->getContentLanguage()->hasWordBreaks() ) {
if ( $wildcard ) {
// Don't cut off the final bit!
$regex = "\b$regex";
}
protected function searchInternal( $term, $fulltext ) {
- global $wgContLang;
-
if ( !$this->fulltextSearchSupported() ) {
return null;
}
- $filteredTerm = $this->filter( $wgContLang->lc( $term ) );
+ $filteredTerm =
+ $this->filter( MediaWikiServices::getInstance()->getContentLanguage()->lc( $term ) );
$resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) );
$total = null;
* should fall back to the next notice in its sequence
*/
private function getCachedNotice( $name ) {
- global $wgRenderHashAppend, $wgContLang;
+ global $wgRenderHashAppend;
$needParse = false;
}
);
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
return Html::rawElement(
'div',
[
'id' => 'localNotice',
- 'lang' => $wgContLang->getHtmlCode(),
- 'dir' => $wgContLang->getDir()
+ 'lang' => $contLang->getHtmlCode(),
+ 'dir' => $contLang->getDir()
],
$parsed
);
* @return QuickTemplate The template to be executed by outputPage
*/
protected function prepareQuickTemplate() {
- global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
+ global $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
$wgSitename, $wgLogo, $wgMaxCredits,
$wgShowCreditsIfMax, $wgArticlePath,
$wgScriptPath, $wgServer;
// heading for the page title. Defaults to empty string.
$tpl->set( 'prebodyhtml', '' );
- if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if (
+ $userLangCode !== $contLang->getHtmlCode() ||
+ $userLangDir !== $contLang->getDir()
+ ) {
$escUserlang = htmlspecialchars( $userLangCode );
$escUserdir = htmlspecialchars( $userLangDir );
// Attributes must be in double quotes because htmlspecialchars() doesn't
if ( $msg->exists() ) {
$text = $msg->text();
} else {
- global $wgContLang;
- $text = $wgContLang->getConverter()->convertNamespace(
- MWNamespace::getSubject( $title->getNamespace() ) );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->getConverter()->
+ convertNamespace( MWNamespace::getSubject( $title->getNamespace() ) );
}
// Avoid PHP 7.1 warning of passing $this by reference
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\IDatabase;
* @return string
*/
public function formatResult( $skin, $row ) {
- global $wgContLang;
-
$title = Title::makeTitleSafe( $row->namespace, $row->title );
if ( $title instanceof Title ) {
- $text = $wgContLang->convert( $title->getPrefixedText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->
+ convert( $title->getPrefixedText() );
return $this->getLinkRenderer()->makeLink( $title, $text );
} else {
return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\DBError;
* @param int $offset Paging offset
*/
protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
- global $wgContLang;
-
if ( $num > 0 ) {
$html = [];
if ( !$this->listoutput ) {
}
$html = $this->listoutput
- ? $wgContLang->listToText( $html )
+ ? MediaWikiServices::getInstance()->getContentLanguage()->listToText( $html )
: implode( '', $html );
$out->addHTML( $html );
* @param string $summaryMessageKey Message key of the summary
*/
function outputHeader( $summaryMessageKey = '' ) {
- global $wgContLang;
-
if ( $summaryMessageKey == '' ) {
- $msg = $wgContLang->lc( $this->getName() ) . '-summary';
+ $msg = MediaWikiServices::getInstance()->getContentLanguage()->lc( $this->getName() ) .
+ '-summary';
} else {
$msg = $summaryMessageKey;
}
return;
}
- global $wgContLang;
- $msg = $this->msg( $wgContLang->lc( $this->getName() ) . '-helppage' );
+ $msg = $this->msg(
+ MediaWikiServices::getInstance()->getContentLanguage()->lc( $this->getName() ) .
+ '-helppage' );
if ( !$msg->isDisabled() ) {
$helpUrl = Skin::makeUrl( $msg->plain() );
* @defgroup SpecialPage SpecialPage
*/
use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\MediaWikiServices;
use Wikimedia\ObjectFactory;
/**
* @return array
*/
private static function getAliasList() {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
if ( is_null( self::$aliases ) ) {
- global $wgContLang;
- $aliases = $wgContLang->getSpecialPageAliases();
+ $aliases = $contLang->getSpecialPageAliases();
$pageList = self::getPageList();
self::$aliases = [];
// Force every canonical name to be an alias for itself.
foreach ( $pageList as $name => $stuff ) {
- $caseFoldedAlias = $wgContLang->caseFold( $name );
+ $caseFoldedAlias = $contLang->caseFold( $name );
self::$aliases[$caseFoldedAlias] = $name;
$keepAlias[$caseFoldedAlias] = 'canonical';
}
foreach ( $aliases as $realName => $aliasList ) {
$aliasList = array_values( $aliasList );
foreach ( $aliasList as $i => $alias ) {
- $caseFoldedAlias = $wgContLang->caseFold( $alias );
+ $caseFoldedAlias = $contLang->caseFold( $alias );
if ( isset( self::$aliases[$caseFoldedAlias] ) &&
$realName === self::$aliases[$caseFoldedAlias]
* @return array Array( String, String|null ), or array( null, null ) if the page is invalid
*/
public static function resolveAlias( $alias ) {
- global $wgContLang;
$bits = explode( '/', $alias, 2 );
- $caseFoldedAlias = $wgContLang->caseFold( $bits[0] );
+ $caseFoldedAlias = MediaWikiServices::getInstance()->getContentLanguage()->
+ caseFold( $bits[0] );
$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
$aliases = self::getAliasList();
if ( isset( $aliases[$caseFoldedAlias] ) ) {
* @return string
*/
public static function getLocalNameFor( $name, $subpage = false ) {
- global $wgContLang;
- $aliases = $wgContLang->getSpecialPageAliases();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $aliases = $contLang->getSpecialPageAliases();
$aliasList = self::getAliasList();
// Find the first alias that maps back to $name
if ( isset( $aliases[$name] ) ) {
$found = false;
foreach ( $aliases[$name] as $alias ) {
- $caseFoldedAlias = $wgContLang->caseFold( $alias );
+ $caseFoldedAlias = $contLang->caseFold( $alias );
$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
if ( isset( $aliasList[$caseFoldedAlias] ) &&
$aliasList[$caseFoldedAlias] === $name
$name = "$name/$subpage";
}
- return $wgContLang->ucfirst( $name );
+ return $contLang->ucfirst( $name );
}
/**
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Implements Special:Ancientpages
*
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$d = $this->getLanguage()->userTimeAndDate( $result->value, $this->getUser() );
$title = Title::makeTitle( $result->namespace, $result->title );
$linkRenderer = $this->getLinkRenderer();
$link = $linkRenderer->makeKnownLink(
$title,
- $wgContLang->convert( $title->getPrefixedText() )
+ MediaWikiServices::getInstance()->getContentLanguage()->
+ convert( $title->getPrefixedText() )
);
return $this->getLanguage()->specialList( $link, htmlspecialchars( $d ) );
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Special page outputs information on sourcing a book with a particular ISBN
* The parser creates links to this page when dealing with ISBNs in wikitext
private function showList( $isbn ) {
$out = $this->getOutput();
- global $wgContLang;
-
$isbn = self::cleanIsbn( $isbn );
# Hook to allow extensions to insert additional HTML,
# e.g. for API-interacting plugins and so on
# Fall back to the defaults given in the language file
$out->addWikiMsg( 'booksources-text' );
$out->addHTML( '<ul>' );
- $items = $wgContLang->getBookstoreList();
+ $items = MediaWikiServices::getInstance()->getContentLanguage()->getBookstoreList();
foreach ( $items as $label => $url ) {
$out->addHTML( $this->makeListItem( $isbn, $label, $url ) );
}
* @return HTMLForm
*/
protected function getNormalForm() {
- global $wgContLang;
-
$fields = [];
$count = 0;
$nsText = ( $ns == NS_MAIN )
? $this->msg( 'blanknamespace' )->escaped()
- : htmlspecialchars( $wgContLang->getFormattedNsText( $ns ) );
+ : htmlspecialchars( MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( $ns ) );
$this->toc .= Linker::tocLine( "editwatchlist-{$data['section']}", $nsText,
$this->getLanguage()->formatNum( ++$tocLength ), 1 ) . Linker::tocLineEnd();
}
* @return array
*/
private function getPagesFromCategory( $title ) {
- global $wgContLang;
-
$maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
$name = $title->getDBkey();
foreach ( $res as $row ) {
$n = $row->page_title;
if ( $row->page_namespace ) {
- $ns = $wgContLang->getNsText( $row->page_namespace );
+ $ns = MediaWikiServices::getInstance()->getContentLanguage()->getNsText(
+ $row->page_namespace );
$n = $ns . ':' . $n;
}
* @return array
*/
private function getPagesFromNamespace( $nsindex ) {
- global $wgContLang;
-
$maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
$dbr = wfGetDB( DB_REPLICA );
$n = $row->page_title;
if ( $row->page_namespace ) {
- $ns = $wgContLang->getNsText( $row->page_namespace );
+ $ns = MediaWikiServices::getInstance()->getContentLanguage()->getNsText(
+ $row->page_namespace );
$n = $ns . ':' . $n;
}
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Special page for listing the articles with the fewest revisions.
*
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$nt = Title::makeTitleSafe( $result->namespace, $result->title );
if ( !$nt ) {
return Html::element(
);
}
$linkRenderer = $this->getLinkRenderer();
- $text = $wgContLang->convert( $nt->getPrefixedText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->
+ convert( $nt->getPrefixedText() );
$plink = $linkRenderer->makeLink( $nt, $text );
$nl = $this->msg( 'nrevisions' )->numParams( $result->value )->text();
* @return string HTML
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$linkRenderer = $this->getLinkRenderer();
$nt = $result->getTitle();
- $text = $wgContLang->convert( $nt->getText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->convert( $nt->getText() );
$plink = $linkRenderer->makeLink(
$nt,
$text
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* This special page lists all defined user groups and the associated rights.
* See also @ref $wgGroupPermissions.
}
private function outputNamespaceProtectionInfo() {
- global $wgContLang;
$out = $this->getOutput();
$namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
if ( $namespace == NS_MAIN ) {
$namespaceText = $this->msg( 'blanknamespace' )->text();
} else {
- $namespaceText = $wgContLang->convertNamespace( $namespace );
+ $namespaceText = MediaWikiServices::getInstance()->getContentLanguage()->
+ convertNamespace( $namespace );
}
$out->addHTML(
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A form to make the database readonly (eg for maintenance purposes).
*
}
public function onSubmit( array $data ) {
- global $wgContLang;
-
if ( !$data['Confirm'] ) {
return Status::newFatal( 'locknoconfirm' );
}
}
fwrite( $fp, $data['Reason'] );
$timestamp = wfTimestampNow();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
fwrite( $fp, "\n<p>" . $this->msg( 'lockedbyandtime',
$this->getUser()->getName(),
- $wgContLang->date( $timestamp, false, false ),
- $wgContLang->time( $timestamp, false, false )
+ $contLang->date( $timestamp, false, false ),
+ $contLang->time( $timestamp, false, false )
)->inContentLanguage()->text() . "</p>\n" );
fclose( $fp );
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Searches the database for files of the requested MIME type, comparing this with the
* 'img_major_mime' and 'img_minor_mime' fields in the image table.
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$linkRenderer = $this->getLinkRenderer();
$nt = Title::makeTitle( $result->namespace, $result->title );
- $text = $wgContLang->convert( $nt->getText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->convert( $nt->getText() );
$plink = $linkRenderer->makeLink(
Title::newFromText( $nt->getPrefixedText() ),
$text
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\IDatabase;
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
if ( !$nt ) {
return Html::element(
);
}
- $text = $wgContLang->convert( $nt->getText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->convert( $nt->getText() );
$plink = $this->getLinkRenderer()->makeLink( $nt, $text );
$nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
class SpecialNewFiles extends IncludableSpecialPage {
/** @var FormOptions */
protected $opts;
* Send the text to be displayed above the options
*/
function setTopText() {
- global $wgContLang;
-
$message = $this->msg( 'newimagestext' )->inContentLanguage();
if ( !$message->isDisabled() ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$this->getOutput()->addWikiText(
Html::rawElement( 'p',
- [ 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ],
+ [
+ 'lang' => $contLang->getHtmlCode(),
+ 'dir' => $contLang->getDir()
+ ],
"\n" . $message->plain() . "\n"
),
/* $lineStart */ false,
* @param string $par Becomes "FOO" when called like Special:Prefixindex/FOO (default null)
*/
function execute( $par ) {
- global $wgContLang;
-
$this->setHeaders();
$this->outputHeader();
$this->hideRedirects = $request->getBool( 'hideredirects', $this->hideRedirects );
$this->stripPrefix = $request->getBool( 'stripprefix', $this->stripPrefix );
- $namespaces = $wgContLang->getNamespaces();
+ $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
$out->setPageTitle(
( $namespace > 0 && array_key_exists( $namespace, $namespaces ) )
? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
* @param string|null $from List all pages from this name (default false)
*/
protected function showPrefixChunk( $namespace, $prefix, $from = null ) {
- global $wgContLang;
-
if ( $from === null ) {
$from = $prefix;
}
$fromList = $this->getNamespaceKeyAndText( $namespace, $from );
$prefixList = $this->getNamespaceKeyAndText( $namespace, $prefix );
- $namespaces = $wgContLang->getNamespaces();
+ $namespaces = MediaWikiServices::getInstance()->getContentLanguage()->getNamespaces();
$res = null;
$n = 0;
$nextRow = null;
* @author Rob Church <robchur@gmail.com>, Ilmari Karonen
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Special page to direct the user to a random page
*
}
public function execute( $par ) {
- global $wgContLang;
-
if ( is_string( $par ) ) {
// Testing for stringiness since we want to catch
// the empty string to mean main namespace only.
- $this->setNamespace( $wgContLang->getNsIndex( $par ) );
+ $this->setNamespace(
+ MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $par ) );
}
$title = $this->getRandomTitle();
* @return string
*/
private function getNsList() {
- global $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$nsNames = [];
foreach ( $this->namespaces as $n ) {
if ( $n === NS_MAIN ) {
$nsNames[] = $this->msg( 'blanknamespace' )->plain();
} else {
- $nsNames[] = $wgContLang->getNsText( $n );
+ $nsNames[] = $contLang->getNsText( $n );
}
}
- return $wgContLang->commaList( $nsNames );
+ return $contLang->commaList( $nsNames );
}
/**
* @param FormOptions $opts Unused
*/
function setTopText( FormOptions $opts ) {
- global $wgContLang;
-
$message = $this->msg( 'recentchangestext' )->inContentLanguage();
if ( !$message->isDisabled() ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
// Parse the message in this weird ugly way to preserve the ability to include interlanguage
// links in it (T172461). In the future when T66969 is resolved, perhaps we can just use
// $message->parse() instead. This code is copied from Message::parseText().
// Message class sets the interface flag to false when parsing in a language different than
// user language, and this is wiki content language
/*interface*/false,
- $wgContLang
+ $contLang
);
$content = $parserOutput->getText( [
'enableSectionEditLinks' => false,
$this->getOutput()->addParserOutputMetadata( $parserOutput );
$langAttributes = [
- 'lang' => $wgContLang->getHtmlCode(),
- 'dir' => $wgContLang->getDir(),
+ 'lang' => $contLang->getHtmlCode(),
+ 'dir' => $contLang->getDir(),
];
$topLinksAttributes = [ 'class' => 'mw-recentchanges-toplinks' ];
* @param string $term
*/
public function showResults( $term ) {
- global $wgContLang;
-
if ( $this->searchEngineType !== null ) {
$this->setExtraParam( 'srbackend', $this->searchEngineType );
}
$this->searchConfig,
$this->getSearchProfiles()
);
- $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
+ $filePrefix = MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( NS_FILE ) . ':';
if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
// Empty query -- straight view of search form
if ( !Hooks::run( 'SpecialSearchResultsPrepend', [ $this, $out, $term ] ) ) {
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IResultWrapper;
use Wikimedia\Rdbms\IDatabase;
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$nt = Title::makeTitleSafe( $result->namespace, $result->title );
if ( !$nt ) {
return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
}
- $text = $wgContLang->convert( $nt->getPrefixedText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->
+ convert( $nt->getPrefixedText() );
$linkRenderer = $this->getLinkRenderer();
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A querypage to list the most wanted categories - implements Special:Wantedcategories
*
* @return string
*/
function formatResult( $skin, $result ) {
- global $wgContLang;
-
$nt = Title::makeTitle( $result->namespace, $result->title );
- $text = $wgContLang->convert( $nt->getText() );
+ $text = MediaWikiServices::getInstance()->getContentLanguage()->convert( $nt->getText() );
if ( !$this->isCached() ) {
// We can assume the freshest data
* @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A License class for use on Special:Upload
*/
* @return string
*/
protected static function getMessageFromParams( $params ) {
- global $wgContLang;
-
if ( !empty( $params['licenses'] ) ) {
return $params['licenses'];
}
// Also see https://phabricator.wikimedia.org/T3495
$defaultMsg = wfMessage( 'licenses' )->inContentLanguage();
if ( !$defaultMsg->exists() || $defaultMsg->plain() === '-' ) {
- $defaultMsg = wfMessage( 'licenses' )->inLanguage( $wgContLang );
+ $defaultMsg = wfMessage( 'licenses' )->inLanguage(
+ MediaWikiServices::getInstance()->getContentLanguage() );
}
return $defaultMsg->plain();
$file = null;
}
if ( $file ) {
- global $wgContLang;
-
$mto = $file->transform( [ 'width' => 120 ] );
if ( $mto ) {
$this->addHeaderText(
- '<div class="thumb t' . $wgContLang->alignEnd() . '">' .
+ '<div class="thumb t' .
+ MediaWikiServices::getInstance()->getContentLanguage()->alignEnd() . '">' .
Html::element( 'img', [
'src' => $mto->getUrl(),
'class' => 'thumbimage',
* @ingroup Pager
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\FakeResultWrapper;
/**
*
* @ingroup Pager
*/
-use MediaWiki\MediaWikiServices;
-
class AllMessagesTablePager extends TablePager {
protected $filter, $prefix, $langcode, $displayPrefix;
$this->mDefaultDirection = IndexPager::DIR_DESCENDING;
$this->mLimitsShown = [ 20, 50, 100, 250, 500, 5000 ];
- global $wgContLang;
-
$this->talk = $this->msg( 'talkpagelinktext' )->escaped();
- $this->lang = $langObj ?: $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $this->lang = $langObj ?: $contLang;
$this->langcode = $this->lang->getCode();
- $this->foreign = !$this->lang->equals( $wgContLang );
+ $this->foreign = !$this->lang->equals( $contLang );
$request = $this->getRequest();
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A parser that translates page titles on a foreign wiki into ForeignTitle
* objects, with no knowledge of the namespace setup on the foreign site.
public function createForeignTitle( $title, $ns = null ) {
$pieces = explode( ':', $title, 2 );
- global $wgContLang;
-
/**
* Can we assume that the part of the page title before the colon is a
* namespace name?
* ID, we fall back to using the local wiki's namespace names to resolve
* this -- better than nothing, and mimics the old crappy behavior
*/
- $isNamespacePartValid = is_null( $ns ) ?
- ( $wgContLang->getNsIndex( $pieces[0] ) !== false ) :
- $ns != 0;
+ $isNamespacePartValid = is_null( $ns )
+ ? MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $pieces[0] ) !==
+ false
+ : $ns != 0;
if ( count( $pieces ) === 2 && $isNamespacePartValid ) {
list( $namespaceName, $pageName ) = $pieces;
* @file
*/
+use MediaWiki\MediaWikiServices;
+
/**
* A class to convert page titles on a foreign wiki (ForeignTitle objects) into
* page titles on the local wiki (Title objects), using a default namespace
* @return Title|null
*/
public function createTitleFromForeignTitle( ForeignTitle $foreignTitle ) {
- global $wgContLang;
-
if ( $foreignTitle->isNamespaceIdKnown() ) {
$foreignNs = $foreignTitle->getNamespaceId();
// Do we have a local namespace by the same name as the foreign
// namespace?
- $targetNs = $wgContLang->getNsIndex( $foreignTitle->getNamespaceName() );
+ $targetNs = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex(
+ $foreignTitle->getNamespaceName() );
if ( $targetNs !== false ) {
return Title::makeTitleSafe( $targetNs, $foreignTitle->getText() );
}
* @return bool
*/
public static function isValidUserName( $name ) {
- global $wgContLang, $wgMaxNameChars;
+ global $wgMaxNameChars;
if ( $name == ''
|| self::isIP( $name )
|| strpos( $name, '/' ) !== false
|| strlen( $name ) > $wgMaxNameChars
- || $name != $wgContLang->ucfirst( $name )
+ || $name != MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name )
) {
return false;
}
*/
public static function getCanonicalName( $name, $validate = 'valid' ) {
// Force usernames to capital
- global $wgContLang;
- $name = $wgContLang->ucfirst( $name );
+ $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
# Reject names containing '#'; these will be cleaned up
# with title normalisation, but then it's too late to
* @return array Array of String options
*/
public static function getDefaultOptions() {
- global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
+ global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgDefaultSkin;
static $defOpt = null;
static $defOptLang = null;
- if ( $defOpt !== null && $defOptLang === $wgContLang->getCode() ) {
- // $wgContLang does not change (and should not change) mid-request,
- // but the unit tests change it anyway, and expect this method to
- // return values relevant to the current $wgContLang.
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( $defOpt !== null && $defOptLang === $contLang->getCode() ) {
+ // The content language does not change (and should not change) mid-request, but the
+ // unit tests change it anyway, and expect this method to return values relevant to the
+ // current content language.
return $defOpt;
}
$defOpt = $wgDefaultUserOptions;
// Default language setting
- $defOptLang = $wgContLang->getCode();
+ $defOptLang = $contLang->getCode();
$defOpt['language'] = $defOptLang;
foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
- $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode;
+ if ( $langCode === $contLang->getCode() ) {
+ $defOpt['variant'] = $langCode;
+ } else {
+ $defOpt["variant-$langCode"] = $langCode;
+ }
}
// NOTE: don't use SearchEngineConfig::getSearchableNamespaces here,
* @param array|null $data Rows for the current user out of the user_properties table
*/
protected function loadOptions( $data = null ) {
- global $wgContLang;
-
$this->load();
if ( $this->mOptionsLoaded ) {
// There's no need to do it for logged-in users: they can set preferences,
// and handling of page content is done by $pageLang->getPreferredVariant() and such,
// so don't override user's choice (especially when the user chooses site default).
- $variant = $wgContLang->getDefaultVariant();
+ $variant = MediaWikiServices::getInstance()->getContentLanguage()->getDefaultVariant();
$this->mOptions['variant'] = $variant;
$this->mOptions['language'] = $variant;
$this->mOptionsLoaded = true;
namespace MediaWiki\Widget\Search;
+use MediaWiki\MediaWikiServices;
use Message;
use SearchResultSet;
use SpecialSearch;
SearchResultSet $titleResultSet = null,
SearchResultSet $textResultSet = null
) {
- global $wgContLang;
-
$hasTitle = $titleResultSet ? $titleResultSet->numRows() > 0 : false;
$hasText = $textResultSet ? $textResultSet->numRows() > 0 : false;
$hasSecondary = $textResultSet
// Convert the whole thing to desired language variant
// TODO: Move this up to Special:Search?
- return $wgContLang->convert( $out );
+ return MediaWikiServices::getInstance()->getContentLanguage()->convert( $out );
}
/**
* @return string HTML
*/
protected function renderResultSet( SearchResultSet $resultSet, $offset ) {
- global $wgContLang;
-
- $terms = $wgContLang->convertForSearchResult( $resultSet->termMatches() );
+ $terms = MediaWikiServices::getInstance()->getContentLanguage()->
+ convertForSearchResult( $resultSet->termMatches() );
$hits = [];
foreach ( $resultSet as $result ) {
use Hooks;
use Html;
+use MediaWiki\MediaWikiServices;
use MediaWiki\Widget\SearchInputWidget;
use MWNamespace;
use SearchEngineConfig;
* @return bool
*/
protected function startsWithImage( $term ) {
- global $wgContLang;
-
$parts = explode( ':', $term );
return count( $parts ) > 1
- ? $wgContLang->getNsIndex( $parts[0] ) === NS_FILE
+ ? MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $parts[0] ) ===
+ NS_FILE
: false;
}
* @return string HTML
*/
protected function powerSearchBox( $term, array $opts ) {
- global $wgContLang;
-
$rows = [];
$activeNamespaces = $this->specialSearch->getNamespaces();
foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) {
$rows[$subject] = "";
}
- $name = $wgContLang->getConverter()->convertNamespace( $namespace );
+ $name = MediaWikiServices::getInstance()->getContentLanguage()->getConverter()->
+ convertNamespace( $namespace );
if ( $name === '' ) {
$name = $this->specialSearch->msg( 'blanknamespace' )->text();
}
* Get a namespace value by key
*
* <code>
- * $mw_ns = $wgContLang->getNsText( NS_MEDIAWIKI );
+ * $mw_ns = $lang->getNsText( NS_MEDIAWIKI );
* echo $mw_ns; // prints 'MediaWiki'
* </code>
*
* producing output.
*
* <code>
- * $mw_ns = $wgContLang->getFormattedNsText( NS_MEDIAWIKI_TALK );
+ * $mw_ns = $lang->getFormattedNsText( NS_MEDIAWIKI_TALK );
* echo $mw_ns; // prints 'MediaWiki talk'
* </code>
*
* @return mixed Variant if one found, null otherwise
*/
protected function getUserVariant() {
- global $wgUser, $wgContLang;
+ global $wgUser;
// memoizing this function wreaks havoc on parserTest.php
/*
return false;
}
if ( $wgUser->isLoggedIn() ) {
- if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
+ if (
+ $this->mMainLanguageCode ==
+ MediaWikiServices::getInstance()->getContentLanguage()->getCode()
+ ) {
$ret = $wgUser->getOption( 'variant' );
} else {
$ret = $wgUser->getOption( 'variant-' . $this->mMainLanguageCode );
<?php
+use MediaWiki\MediaWikiServices;
+
require __DIR__ . '/../Maintenance.php';
class BenchmarkTidy extends Maintenance {
}
private function benchmark( $driver, $html ) {
- global $wgContLang;
-
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$times = [];
$innerCount = 10;
$outerCount = 10;
$t = microtime( true );
for ( $i = 0; $i < $innerCount; $i++ ) {
$driver->tidy( $html );
- print $wgContLang->formatSize( memory_get_usage( true ) ) . "\n";
+ print $contLang->formatSize( memory_get_usage( true ) ) . "\n";
}
$t = ( ( microtime( true ) - $t ) / $innerCount ) * 1000;
$times[] = $t;
print "Median: $median ms\n";
print "Mean: $mean ms\n";
print "Maximum: $max ms\n";
- print "Memory usage: " .
- $wgContLang->formatSize( memory_get_usage( true ) ) . "\n";
+ print "Memory usage: " . $contLang->formatSize( memory_get_usage( true ) ) . "\n";
print "Peak memory usage: " .
- $wgContLang->formatSize( memory_get_peak_usage( true ) ) . "\n";
+ $contLang->formatSize( memory_get_peak_usage( true ) ) . "\n";
}
}
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/cleanupTable.inc';
/**
}
protected function processRowToUppercase( $row ) {
- global $wgContLang;
-
$current = Title::makeTitle( $row->page_namespace, $row->page_title );
$display = $current->getPrefixedText();
$lower = $row->page_title;
- $upper = $wgContLang->ucfirst( $row->page_title );
+ $upper = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $row->page_title );
if ( $upper == $lower ) {
$this->output( "\"$display\" already uppercase.\n" );
}
protected function processRowToLowercase( $row ) {
- global $wgContLang;
-
$current = Title::makeTitle( $row->page_namespace, $row->page_title );
$display = $current->getPrefixedText();
$upper = $row->page_title;
- $lower = $wgContLang->lcfirst( $row->page_title );
+ $lower = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $row->page_title );
if ( $upper == $lower ) {
$this->output( "\"$display\" already lowercase.\n" );
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/cleanupTable.inc';
/**
}
protected function processRow( $row ) {
- global $wgContLang;
-
$source = $row->img_name;
if ( $source == '' ) {
// Ye olde empty rows. Just kill them.
// We also have some HTML entities there
$cleaned = Sanitizer::decodeCharReferences( $cleaned );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+
// Some are old latin-1
- $cleaned = $wgContLang->checkTitleEncoding( $cleaned );
+ $cleaned = $contLang->checkTitleEncoding( $cleaned );
// Many of remainder look like non-normalized unicode
- $cleaned = $wgContLang->normalize( $cleaned );
+ $cleaned = $contLang->normalize( $cleaned );
$title = Title::makeTitleSafe( NS_FILE, $cleaned );
* @param object $row
*/
protected function processRow( $row ) {
- global $wgContLang;
$display = Title::makeName( $row->page_namespace, $row->page_title );
- $verified = $wgContLang->normalize( $display );
+ $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
$title = Title::newFromText( $verified );
if ( !is_null( $title )
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/cleanupTable.inc';
/**
}
protected function processRow( $row ) {
- global $wgContLang;
$current = Title::makeTitle( $row->wl_namespace, $row->wl_title );
$display = $current->getPrefixedText();
- $verified = $wgContLang->normalize( $display );
+ $verified = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $display );
$title = Title::newFromText( $verified );
if ( $row->wl_user == 0 || is_null( $title ) || !$title->equals( $current ) ) {
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
return;
}
- global $wgContLang;
-
# counters etc
$numBadLinks = $curRowsRead = 0;
foreach ( $res as $row ) {
$title = $row->cur_title;
if ( $row->cur_namespace ) {
- $title = $wgContLang->getNsText( $row->cur_namespace ) . ":$title";
+ $title = MediaWikiServices::getInstance()->getContentLanguage()->
+ getNsText( $row->cur_namespace ) . ":$title";
}
$ids[$title] = $row->cur_id;
$curRowsRead++;
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
* @param array &$messageInfo
*/
protected function fetchMessageInfo( $langCode, array &$messageInfo ) {
- global $wgContLang;
-
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
if ( $langCode ) {
$this->output( "\n... fetching message info for language: $langCode" );
- $nonContLang = true;
+ $nonContentLanguage = true;
} else {
$this->output( "\n... fetching message info for content language" );
- $langCode = $wgContLang->getCode();
- $nonContLang = false;
+ $langCode = $contLang->getCode();
+ $nonContentLanguage = false;
}
/* Based on SpecialAllmessages::reallyDoQuery #filter=modified */
$l10nCache = Language::getLocalisationCache();
$messageNames = $l10nCache->getSubitemList( 'en', 'messages' );
// Normalise message names for NS_MEDIAWIKI page_title
- $messageNames = array_map( [ $wgContLang, 'ucfirst' ], $messageNames );
+ $messageNames = array_map( [ $contLang, 'ucfirst' ], $messageNames );
$statuses = AllMessagesTablePager::getCustomisedStatuses(
- $messageNames, $langCode, $nonContLang );
+ $messageNames, $langCode, $nonContentLanguage );
// getCustomisedStatuses is stripping the sub page from the page titles, add it back
- $titleSuffix = $nonContLang ? "/$langCode" : '';
+ $titleSuffix = $nonContentLanguage ? "/$langCode" : '';
foreach ( $messageNames as $key ) {
$customised = isset( $statuses['pages'][$key] );
* @throws MWException
*/
private function getTextDb( $id ) {
- global $wgContLang;
if ( !isset( $this->db ) ) {
throw new MWException( __METHOD__ . "No database available" );
}
return false;
}
$stripped = str_replace( "\r", "", $text );
- $normalized = $wgContLang->normalize( $stripped );
+ $normalized = MediaWikiServices::getInstance()->getContentLanguage()->
+ normalize( $stripped );
return $normalized;
}
}
private function getTextSpawnedOnce( $id ) {
- global $wgContLang;
-
$ok = fwrite( $this->spawnWrite, "$id\n" );
// $this->progress( ">> $id" );
if ( !$ok ) {
// Do normalization in the dump thread...
$stripped = str_replace( "\r", "", $text );
- $normalized = $wgContLang->normalize( $stripped );
+ $normalized = MediaWikiServices::getInstance()->getContentLanguage()->
+ normalize( $stripped );
return $normalized;
}
* @see http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
* Main loop
*/
public function main() {
- global $wgContLang;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
fwrite( $this->findex, $this->openIndex() );
$length = $this->limit[0];
$i = $smcount = 0;
- $fns = $wgContLang->getFormattedNsText( $namespace );
+ $fns = $contLang->getFormattedNsText( $namespace );
$this->output( "$namespace ($fns)\n" );
$skippedRedirects = 0; // Number of redirects skipped for that namespace
foreach ( $res as $row ) {
$length += strlen( $entry );
$this->write( $this->file, $entry );
// generate pages for language variants
- if ( $wgContLang->hasVariants() ) {
- $variants = $wgContLang->getVariants();
+ if ( $contLang->hasVariants() ) {
+ $variants = $contLang->getVariants();
foreach ( $variants as $vCode ) {
- if ( $vCode == $wgContLang->getCode() ) {
+ if ( $vCode == $contLang->getCode() ) {
continue; // we don't want default variant
}
$entry = $this->fileEntry(
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/Maintenance.php';
/**
}
private function getNsIndex( $namespace ) {
- global $wgContLang;
- $result = $wgContLang->getNsIndex( $namespace );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $result = $contLang->getNsIndex( $namespace );
if ( $result !== false ) {
return $result;
}
$ns = intval( $namespace );
- if ( strval( $ns ) === $namespace && $wgContLang->getNsText( $ns ) !== false ) {
+ if ( strval( $ns ) === $namespace && $contLang->getNsText( $ns ) !== false ) {
return $ns;
}
$this->fatalError( "Unknown namespace text / index specified: $namespace" );
*
* @file
* @ingroup MaintenanceLanguage
- * @todo Make this more useful, right now just dumps $wgContLang
+ * @todo Make this more useful, right now just dumps content language
*/
require_once __DIR__ . '/../Maintenance.php';
* @return bool
*/
private function checkAll( $options ) {
- global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks;
+ global $wgNamespaceAliases, $wgCapitalLinks;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
$spaces = [];
// List interwikis first, so they'll be overridden
// by any conflicting local namespaces.
foreach ( $this->getInterwikiList() as $prefix ) {
- $name = $wgContLang->ucfirst( $prefix );
+ $name = $contLang->ucfirst( $prefix );
$spaces[$name] = 0;
}
$spaces[$name] = $ns;
}
}
- foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
+ foreach ( $contLang->getNamespaces() as $ns => $name ) {
if ( $name !== '' ) {
$spaces[$name] = $ns;
}
foreach ( $wgNamespaceAliases as $name => $ns ) {
$spaces[$name] = $ns;
}
- foreach ( $wgContLang->getNamespaceAliases() as $name => $ns ) {
+ foreach ( $contLang->getNamespaceAliases() as $name => $ns ) {
$spaces[$name] = $ns;
}
// since we're doing case-sensitive searches in the db.
foreach ( $spaces as $name => $ns ) {
$moreNames = [];
- $moreNames[] = $wgContLang->uc( $name );
- $moreNames[] = $wgContLang->ucfirst( $wgContLang->lc( $name ) );
- $moreNames[] = $wgContLang->ucwords( $name );
- $moreNames[] = $wgContLang->ucwords( $wgContLang->lc( $name ) );
- $moreNames[] = $wgContLang->ucwordbreaks( $name );
- $moreNames[] = $wgContLang->ucwordbreaks( $wgContLang->lc( $name ) );
+ $moreNames[] = $contLang->uc( $name );
+ $moreNames[] = $contLang->ucfirst( $contLang->lc( $name ) );
+ $moreNames[] = $contLang->ucwords( $name );
+ $moreNames[] = $contLang->ucwords( $contLang->lc( $name ) );
+ $moreNames[] = $contLang->ucwordbreaks( $name );
+ $moreNames[] = $contLang->ucwordbreaks( $contLang->lc( $name ) );
if ( !$wgCapitalLinks ) {
foreach ( $moreNames as $altName ) {
- $moreNames[] = $wgContLang->lcfirst( $altName );
+ $moreNames[] = $contLang->lcfirst( $altName );
}
- $moreNames[] = $wgContLang->lcfirst( $name );
+ $moreNames[] = $contLang->lcfirst( $name );
}
foreach ( array_unique( $moreNames ) as $altName ) {
if ( $altName !== $name ) {
require_once __DIR__ . '/Maintenance.php';
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IMaintainableDatabase;
/**
);
$orphans = $result->numRows();
if ( $orphans > 0 ) {
- global $wgContLang;
-
$this->output( "$orphans orphan revisions...\n" );
$this->output( sprintf(
"%10s %10s %14s %20s %s\n",
foreach ( $result as $row ) {
$comment = $commentStore->getComment( 'rev_comment', $row )->text;
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
if ( $comment !== '' ) {
- $comment = '(' . $wgContLang->truncateForVisual( $comment, 40 ) . ')';
+ $comment = '(' . $contLang->truncateForVisual( $comment, 40 ) . ')';
}
- $rev_user_text = $wgContLang->truncateForVisual( $row->rev_user_text, 20 );
+ $rev_user_text = $contLang->truncateForVisual( $row->rev_user_text, 20 );
# pad $rev_user_text to 20 characters. Note that this may
# yield poor results if $rev_user_text contains combining
# or half-width characters. Alas.
* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
$optionsWithoutArgs = [ 'verbose' ];
require_once __DIR__ . '/commandLine.inc';
// This resolves a few differences between the old preprocessor and the
// XML-based one, which doesn't like illegals and converts line endings.
// It's done by the MW UI, so it's a reasonably legitimate thing to do.
- global $wgContLang;
- $s = $wgContLang->normalize( $s );
+ $s = MediaWikiServices::getInstance()->getContentLanguage()->normalize( $s );
return $s;
}
require_once __DIR__ . '/Maintenance.php';
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IMaintainableDatabase;
/**
}
function addMissingImage( $filename, $fullpath ) {
- global $wgContLang;
-
$timestamp = $this->dbw->timestamp( $this->getRepo()->getFileTimestamp( $fullpath ) );
- $altname = $wgContLang->checkTitleEncoding( $filename );
+ $altname = MediaWikiServices::getInstance()->getContentLanguage()->
+ checkTitleEncoding( $filename );
if ( $altname != $filename ) {
if ( $this->dryrun ) {
$filename = $altname;
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Base class that store and restore the Language objects
*/
abstract class MediaWikiLangTestCase extends MediaWikiTestCase {
protected function setUp() {
- global $wgLanguageCode, $wgContLang;
+ global $wgLanguageCode;
- if ( $wgLanguageCode != $wgContLang->getCode() ) {
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ if ( $wgLanguageCode != $contLang->getCode() ) {
throw new MWException( "Error in MediaWikiLangTestCase::setUp(): " .
- "\$wgLanguageCode ('$wgLanguageCode') is different from " .
- "\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" );
+ "\$wgLanguageCode ('$wgLanguageCode') is different from content language code (" .
+ $contLang->getCode() . ")" );
}
parent::setUp();
<?php
+use MediaWiki\MediaWikiServices;
use Wikimedia\ScopedCallback;
use Wikimedia\TestingAccessWrapper;
* @return CommentStore
*/
protected function makeStore( $stage ) {
- global $wgContLang;
- $store = new CommentStore( $wgContLang, $stage );
+ $store = new CommentStore( MediaWikiServices::getInstance()->getContentLanguage(), $stage );
return $store;
}
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group Editing
*
protected function setUp() {
parent::setUp();
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $this->setContentLang( $contLang );
+
$this->setMwGlobals( [
'wgExtraNamespaces' => [
12312 => 'Dummy',
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Test class for Export methods.
*
* @covers WikiExporter::pageByTitle
*/
public function testPageByTitle() {
- global $wgContLang;
$pageTitle = 'UTPage';
$exporter = new WikiExporter(
}
}
- $actualNamespaces = (array)$wgContLang->getNamespaces();
+ $actualNamespaces = (array)MediaWikiServices::getInstance()->getContentLanguage()->
+ getNamespaces();
$actualNamespaces = array_values( $actualNamespaces );
$this->assertEquals( $actualNamespaces, $xmlNamespaces );
* @covers \MediaWiki\Storage\DerivedPageDataUpdater::getCanonicalParserOptions()
*/
public function testGetCanonicalParserOptions() {
- global $wgContLang;
-
$user = $this->getTestUser()->getUser();
$page = $this->getPage( __METHOD__ );
$updater->prepareContent( $user, $update, false );
$options1 = $updater->getCanonicalParserOptions();
- $this->assertSame( $wgContLang, $options1->getUserLangObj() );
+ $this->assertSame( MediaWikiServices::getInstance()->getContentLanguage(),
+ $options1->getUserLangObj() );
$speculativeId = call_user_func( $options1->getSpeculativeRevIdCallback(), $page->getTitle() );
$this->assertSame( $parentRev->getId() + 1, $speculativeId );
<?php
+use MediaWiki\MediaWikiServices;
+
class TimeAdjustTest extends MediaWikiLangTestCase {
protected function setUp() {
parent::setUp();
* @covers Language::userAdjust
*/
public function testUserAdjust( $date, $localTZoffset, $expected ) {
- global $wgContLang;
-
$this->setMwGlobals( 'wgLocalTZoffset', $localTZoffset );
$this->assertEquals(
$expected,
- strval( $wgContLang->userAdjust( $date, '' ) ),
+ strval( MediaWikiServices::getInstance()->getContentLanguage()->
+ userAdjust( $date, '' ) ),
"User adjust {$date} by {$localTZoffset} minutes should give {$expected}"
);
}
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group Database
*
* @covers Title::checkQuickPermissions
*/
public function testQuickPermissions() {
- global $wgContLang;
- $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
+ $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( NS_PROJECT );
$this->setUser( 'anon' );
$this->setTitle( NS_TALK );
* @covers Title::checkPageRestrictions
*/
public function testPageRestrictions() {
- global $wgContLang;
-
- $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
+ $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
+ getFormattedNsText( NS_PROJECT );
$this->setTitle( NS_MAIN );
$this->title->mRestrictionsLoaded = true;
# Format:
# - expected
# - Title name
- # - wgContLang (expected in most case)
+ # - content language (expected in most cases)
# - wgLang (on some specific pages)
# - wgDefaultLanguageVariant
# - Optional message
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group Database
* @group Cache
protected function setUp() {
parent::setUp();
$this->configureLanguages();
+ MessageCache::destroyInstance();
MessageCache::singleton()->enable();
}
* @param string|null $content Content of the created page, or null for a generic string
*/
protected function makePage( $title, $lang, $content = null ) {
- global $wgContLang;
-
if ( $content === null ) {
$content = $lang;
}
- if ( $lang !== $wgContLang->getCode() ) {
+ if ( $lang !== MediaWikiServices::getInstance()->getContentLanguage()->getCode() ) {
$title = "$title/$lang";
}
}
public function testReplaceMsg() {
- global $wgContLang;
-
$messageCache = MessageCache::singleton();
$message = 'go';
- $uckey = $wgContLang->ucfirst( $message );
+ $uckey = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $message );
$oldText = $messageCache->get( $message ); // "Ausführen"
$dbw = wfGetDB( DB_MASTER );
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group ContentHandler
* @group Database
* @covers TextContent::preSaveTransform
*/
public function testPreSaveTransform( $text, $expected ) {
- global $wgContLang;
-
- $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
+ $options = ParserOptions::newFromUserAndLang( $this->context->getUser(),
+ MediaWikiServices::getInstance()->getContentLanguage() );
$content = $this->newContent( $text );
$content = $content->preSaveTransform(
* @covers TextContent::preloadTransform
*/
public function testPreloadTransform( $text, $expected ) {
- global $wgContLang;
- $options = ParserOptions::newFromUserAndLang( $this->context->getUser(), $wgContLang );
+ $options = ParserOptions::newFromUserAndLang( $this->context->getUser(),
+ MediaWikiServices::getInstance()->getContentLanguage() );
$content = $this->newContent( $text );
$content = $content->preloadTransform( $this->context->getTitle(), $options );
* @covers WikitextContentHandler::makeRedirectContent
*/
public function testMakeRedirectContent( $title, $expected ) {
- global $wgContLang;
- $wgContLang->resetNamespaces();
+ MediaWikiServices::getInstance()->getContentLanguage()->resetNamespaces();
MediaWikiServices::getInstance()->resetServiceForTesting( 'MagicWordFactory' );
public function testNewCanonical() {
$wgUser = $this->getMutableTestUser()->getUser();
$wgLang = Language::factory( 'fr' );
- $wgContLang = Language::factory( 'qqx' );
+ $contLang = Language::factory( 'qqx' );
- $this->setContentLang( $wgContLang );
+ $this->setContentLang( $contLang );
$this->setMwGlobals( [
'wgUser' => $wgUser,
'wgLang' => $wgLang,
$this->assertSame( $user, $popt->getUser() );
$this->assertSame( $lang, $popt->getUserLangObj() );
- // Passing 'canonical' uses an anon and $wgContLang, and ignores
- // any passed $userLang
+ // Passing 'canonical' uses an anon and $contLang, and ignores any passed $userLang
$popt = ParserOptions::newCanonical( 'canonical' );
$this->assertTrue( $popt->getUser()->isAnon() );
- $this->assertSame( $wgContLang, $popt->getUserLangObj() );
+ $this->assertSame( $contLang, $popt->getUserLangObj() );
$popt = ParserOptions::newCanonical( 'canonical', $lang2 );
- $this->assertSame( $wgContLang, $popt->getUserLangObj() );
+ $this->assertSame( $contLang, $popt->getUserLangObj() );
// Passing an IContextSource uses the user and lang from it, and ignores
// any passed $userLang
<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* Basic tests for Parser::getPreloadText
* @author Antoine Musso
private $title;
protected function setUp() {
- global $wgContLang;
-
parent::setUp();
- $this->testParserOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+ $this->testParserOptions = ParserOptions::newFromUserAndLang( new User,
+ MediaWikiServices::getInstance()->getContentLanguage() );
$this->testParser = new Parser();
$this->testParser->Options( $this->testParserOptions );
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @covers Preprocessor
*
];
protected function setUp() {
- global $wgContLang;
parent::setUp();
- $this->mOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+ $this->mOptions = ParserOptions::newFromUserAndLang( new User,
+ MediaWikiServices::getInstance()->getContentLanguage() );
$this->mPreprocessors = [];
foreach ( self::$classNames as $className ) {
}
private function getParserOptions() {
- global $wgContLang;
- $popt = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+ $popt = ParserOptions::newFromUserAndLang( new User,
+ MediaWikiServices::getInstance()->getContentLanguage() );
return $popt;
}
<?php
+
+use MediaWiki\MediaWikiServices;
use Wikimedia\ScopedCallback;
/**
public function testConflictResolution(
$test, $aliasesList, $alias, $expectedName, $expectedAlias, $expectWarnings
) {
- global $wgContLang;
- $lang = clone $wgContLang;
+ $lang = clone MediaWikiServices::getInstance()->getContentLanguage();
$lang->mExtendedSpecialPageAliases = $aliasesList;
$this->setContentLang( $lang );
$this->setMwGlobals( 'wgSpecialPages',
* @covers LanguageConverter::getUserVariant
*/
public function testGetPreferredVariantUserOptionForForeignLanguage() {
- global $wgContLang, $wgUser;
+ global $wgUser;
- $wgContLang = Language::factory( 'en' );
+ $this->setContentLang( 'en' );
$wgUser = new User;
$wgUser->load(); // from 'defaults'
$wgUser->mId = 1;
* @covers LanguageConverter::getURLVariant
*/
public function testGetPreferredVariantHeaderUserVsUrl() {
- global $wgContLang, $wgRequest, $wgUser;
+ global $wgRequest, $wgUser;
- $wgContLang = Language::factory( 'tg-latn' );
+ $this->setContentLang( 'tg-latn' );
$wgRequest->setVal( 'variant', 'tg' );
$wgUser = User::newFromId( "admin" );
$wgUser->setId( 1 );
* @covers LanguageConverter::getURLVariant
*/
public function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
- global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
+ global $wgDefaultLanguageVariant, $wgRequest;
- $wgContLang = Language::factory( 'tg-latn' );
+ $this->setContentLang( 'tg-latn' );
$wgDefaultLanguageVariant = 'tg';
$wgRequest->setVal( 'variant', null );
$this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
namespace MediaWiki\Tests\Maintenance;
+use MediaWiki\MediaWikiServices;
use DumpBackup;
use ManualLogEntry;
use Title;
}
function testPlain() {
- global $wgContLang;
-
// Preparing the dump
$fname = $this->getNewTempFile();
$this->assertLogItem( $this->logId1, "BackupDumperLogUserA",
$this->userId1, null, "type", "subtype", "PageA" );
- $this->assertNotNull( $wgContLang, "Content language object validation" );
- $namespace = $wgContLang->getNsText( NS_TALK );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $this->assertNotNull( $contLang, "Content language object validation" );
+ $namespace = $contLang->getNsText( NS_TALK );
$this->assertInternalType( 'string', $namespace );
$this->assertGreaterThan( 0, strlen( $namespace ) );
$this->assertLogItem( $this->logId2, "BackupDumperLogUserB",
}
function testXmlDumpsBackupUseCaseLogging() {
- global $wgContLang;
-
$this->checkHasGzip();
// Preparing the dump
$this->assertLogItem( $this->logId1, "BackupDumperLogUserA",
$this->userId1, null, "type", "subtype", "PageA" );
- $this->assertNotNull( $wgContLang, "Content language object validation" );
- $namespace = $wgContLang->getNsText( NS_TALK );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+ $this->assertNotNull( $contLang, "Content language object validation" );
+ $namespace = $contLang->getNsText( NS_TALK );
$this->assertInternalType( 'string', $namespace );
$this->assertGreaterThan( 0, strlen( $namespace ) );
$this->assertLogItem( $this->logId2, "BackupDumperLogUserB",