87 public function __construct( $langobj, $maincode, $variants = [],
88 $variantfallbacks = [],
$flags = [],
91 $this->mLangObj = $langobj;
92 $this->mMainLanguageCode = $maincode;
93 $this->mVariants = array_diff( $variants, $wgDisabledVariants );
94 $this->mVariantFallbacks = $variantfallbacks;
96 $this->mCacheKey =
wfMemcKey(
'conversiontables', $maincode );
110 $this->mFlags = array_merge( $defaultflags,
$flags );
111 foreach ( $this->mVariants
as $v ) {
112 if ( array_key_exists( $v, $manualLevel ) ) {
113 $this->mManualLevel[$v] = $manualLevel[$v];
115 $this->mManualLevel[$v] =
'bidirectional';
117 $this->mFlags[$v] = $v;
143 if ( isset( $this->mVariantFallbacks[$variant] ) ) {
144 return $this->mVariantFallbacks[$variant];
166 if ( $wgUser->isSafeToLoad() && $wgUser->isLoggedIn() && !
$req ) {
172 if ( $wgDefaultLanguageVariant && !
$req ) {
200 if ( $wgDefaultLanguageVariant && !
$req ) {
216 if ( $variant !== null && in_array( $variant, $this->mVariants ) ) {
230 if ( $this->mURLVariant ) {
235 $ret = $wgRequest->getText(
'variant' );
238 $ret = $wgRequest->getVal(
'uselang' );
263 if ( !$wgUser->isSafeToLoad() ) {
266 if ( $wgUser->isLoggedIn() ) {
267 if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
268 $ret = $wgUser->getOption(
'variant' );
270 $ret = $wgUser->getOption(
'variant-' . $this->mMainLanguageCode );
275 $ret = $wgUser->getOption(
'language' );
290 if ( $this->mHeaderVariant ) {
296 $languages = array_keys( $wgRequest->getAcceptLang() );
301 $fallbackLanguages = [];
304 if ( $this->mHeaderVariant ) {
312 if ( is_string( $fallbacks ) && $fallbacks !== $this->mMainLanguageCode ) {
313 $fallbackLanguages[] = $fallbacks;
314 } elseif ( is_array( $fallbacks ) ) {
316 array_merge( $fallbackLanguages, $fallbacks );
320 if ( !$this->mHeaderVariant ) {
322 $fallback_languages = array_unique( $fallbackLanguages );
323 foreach ( $fallback_languages
as $language ) {
325 if ( $this->mHeaderVariant ) {
367 $htmlfix =
'|<[^>]+$|^[^<>]*>';
370 $codefix =
'<code>.+?<\/code>|';
372 $scriptfix =
'<script.*?>.*?<\/script>|';
374 $prefix =
'<pre.*?>.*?<\/pre>|';
376 $reg =
'/' . $codefix . $scriptfix . $prefix .
377 '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix .
'/s';
383 $text = str_replace(
"\000",
'', $text );
385 $markupMatches = null;
386 $elementMatches = null;
387 while ( $startPos < strlen( $text ) ) {
388 if ( preg_match( $reg, $text, $markupMatches, PREG_OFFSET_CAPTURE, $startPos ) ) {
389 $elementPos = $markupMatches[0][1];
390 $element = $markupMatches[0][0];
392 $elementPos = strlen( $text );
397 $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) .
"\000";
400 $startPos = $elementPos + strlen( $element );
404 && preg_match(
'/^(<[^>\s]*)\s([^>]*)(.*)$/', $element, $elementMatches )
408 foreach ( [
'title',
'alt' ]
as $attrName ) {
409 if ( !isset( $attrs[$attrName] ) ) {
412 $attr = $attrs[$attrName];
414 if ( !strpos( $attr,
'://' ) ) {
419 $attr = preg_replace(
'/<[^>]+>/',
'', $attr );
420 if ( $attr !== $attrs[$attrName] ) {
421 $attrs[$attrName] = $attr;
430 $literalBlob .= $element .
"\000";
434 $translatedBlob = $this->
translate( $sourceBlob, $toVariant );
440 while ( $translatedIter->valid() && $literalIter->valid() ) {
441 $output .= $translatedIter->current();
442 $output .= $literalIter->current();
443 $translatedIter->next();
444 $literalIter->next();
462 if ( trim( $text ) ) {
464 $text = $this->mTables[$variant]->replace( $text );
479 foreach ( $this->mVariants
as $variant ) {
496 $newConvRuleTitle = $convRule->getTitle();
497 if ( $newConvRuleTitle ) {
499 $this->mConvRuleTitle = $newConvRuleTitle;
503 $convTable = $convRule->getConvTable();
504 $action = $convRule->getRulesAction();
505 foreach ( $convTable
as $variant => $pair ) {
510 if ( $action ==
'add' ) {
512 foreach ( $pair
as $from => $to ) {
513 $this->mTables[$variant]->setPair(
$from, $to );
515 } elseif ( $action ==
'remove' ) {
516 $this->mTables[$variant]->removeArray( $pair );
530 $index =
$title->getNamespace();
552 if ( $variant === null ) {
556 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
557 $key =
$cache->makeKey(
'languageconverter',
'namespace-text', $index, $variant );
558 $nsVariantText =
$cache->get( $key );
559 if ( $nsVariantText !==
false ) {
560 return $nsVariantText;
564 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inLanguage( $variant );
565 if ( $nsConvMsg->exists() ) {
566 $nsVariantText = $nsConvMsg->plain();
571 if ( $nsVariantText ===
false ) {
572 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inContentLanguage();
573 if ( $nsConvMsg->exists() ) {
574 $nsVariantText = $this->
translate( $nsConvMsg->plain(), $variant );
578 if ( $nsVariantText ===
false ) {
580 $langObj = $this->mLangObj->factory( $variant );
581 $nsVariantText = $langObj->getFormattedNsText( $index );
584 $cache->set( $key, $nsVariantText, 60 );
586 return $nsVariantText;
605 return $this->
convertTo( $text, $variant );
617 if ( $wgDisableLangConversion ) {
621 $this->mConvRuleTitle =
false;
637 $length = strlen( $text );
638 $shouldConvert = !$this->
guessVariant( $text, $variant );
640 while ( $startPos < $length ) {
641 $pos = strpos( $text,
'-{', $startPos );
643 if ( $pos ===
false ) {
645 $fragment = substr( $text, $startPos );
646 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
652 $fragment = substr( $text, $startPos, $pos - $startPos );
653 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
678 if ( $text[$startPos] !==
'-' || $text[$startPos + 1] !==
'{' ) {
679 throw new MWException( __METHOD__ .
': invalid input string' );
684 $warningDone =
false;
685 $length = strlen( $text );
687 while ( $startPos < $length ) {
689 preg_match(
'/-\{|\}-/', $text, $m, PREG_OFFSET_CAPTURE, $startPos );
700 $inner .= substr( $text, $startPos, $pos - $startPos );
708 if ( $depth >= $this->mMaxDepth ) {
710 if ( !$warningDone ) {
711 $inner .=
'<span class="error">' .
712 wfMessage(
'language-converter-depth-warning' )
713 ->numParams( $this->mMaxDepth )->inContentLanguage()->text() .
727 $rule->parse( $variant );
729 return $rule->getDisplay();
731 throw new MWException( __METHOD__ .
': invalid regex match' );
736 if ( $startPos < $length ) {
737 $inner .= substr( $text, $startPos );
740 return '-{' . $this->
autoConvert( $inner, $variant );
755 # If the article has already existed, there is no need to
756 # check it again, otherwise it may cause a fault.
757 if ( is_object( $nt ) && $nt->exists() ) {
762 $isredir = $wgRequest->getText(
'redirect',
'yes' );
763 $action = $wgRequest->getText(
'action' );
764 if ( $action ==
'edit' && $wgRequest->getBool(
'redlink' ) ) {
767 $linkconvert = $wgRequest->getText(
'linkconvert',
'yes' );
768 $disableLinkConversion = $wgDisableLangConversion
774 if ( $disableLinkConversion ||
775 ( !$ignoreOtherCond &&
778 || $action ==
'submit'
779 || $linkconvert ==
'no' ) ) ) {
783 if ( is_object( $nt ) ) {
784 $ns = $nt->getNamespace();
794 foreach ( $variants
as $v ) {
797 if ( !is_null( $varnt ) ) {
798 $linkBatch->addObj( $varnt );
805 $linkBatch->execute();
808 if ( $varnt->getArticleID() > 0 ) {
810 $link = $varnt->getText();
824 return '!' . $variant;
849 $name = get_class( $this );
851 throw new MWException(
"Must implement loadDefaultTables() method in class $name" );
862 if ( $this->mTablesLoaded ) {
866 $this->mTablesLoaded =
true;
867 $this->mTables =
false;
871 $this->mTables =
$cache->get( $this->mCacheKey );
874 if ( !$this->mTables || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
880 foreach ( $this->mVariants
as $var ) {
882 $this->mTables[$var]->mergeArray( $cached );
886 $this->mTables[self::CACHE_VERSION_KEY] =
true;
888 $cache->set( $this->mCacheKey, $this->mTables, 43200 );
905 if ( $this->mTables ) {
906 unset( $this->mTables );
909 $this->mTablesLoaded =
false;
935 $key =
'Conversiontable/' .
$code;
937 $key .=
'/' . $subpage;
939 if ( array_key_exists( $key, $parsed ) ) {
943 $parsed[$key] =
true;
945 if ( $subpage ===
'' ) {
954 $txt = $revision->getContent(
Revision::RAW )->getNativeData();
962 # Nothing to parse if there's no text
963 if ( $txt ===
false || $txt === null || $txt ===
'' ) {
969 $linkhead = $this->mLangObj->getNsText(
NS_MEDIAWIKI ) .
973 foreach ( $subs
as $sub ) {
974 $link = explode(
']]', $sub, 2 );
975 if ( count(
$link ) != 2 ) {
978 $b = explode(
'|',
$link[0], 2 );
979 $b = explode(
'/', trim( $b[0] ), 3 );
980 if ( count( $b ) == 3 ) {
986 if ( $b[0] == $linkhead && $b[1] ==
$code ) {
987 $sublinks[] = $sublink;
995 foreach ( $blocks
as $block ) {
1001 $mappings = explode(
'}-', $block, 2 )[0];
1002 $stripped = str_replace( [
"'",
'"',
'*',
'#' ],
'', $mappings );
1004 foreach ( $table
as $t ) {
1005 $m = explode(
'=>', $t, 3 );
1006 if ( count( $m ) != 2 ) {
1010 $tt = explode(
'//', $m[1], 2 );
1011 $ret[trim( $m[0] )] = trim( $tt[0] );
1017 foreach ( $sublinks
as $link ) {
1023 if ( $this->mUcfirst ) {
1024 foreach (
$ret as $k => $v ) {
1025 $ret[$this->mLangObj->ucfirst( $k )] = $this->mLangObj->ucfirst( $v );
1040 # don't mark if already marked
1041 if ( strpos( $text,
'-{' ) || strpos( $text,
'}-' ) ) {
1045 $ret =
"-{R|$text}-";
1072 if ( $c > 1 &&
$t[0] ==
'Conversiontable' ) {
1085 if ( is_null( $this->mVarSeparatorPattern ) ) {
1098 foreach ( $this->mVariants
as $variant ) {
1100 $pat .= $variant .
'\s*:|';
1102 $pat .=
'[^;]*?=>\s*' . $variant .
'\s*:|';
1105 $this->mVarSeparatorPattern = $pat;
convertCategoryKey($key)
Convert the sorting key for category links.
updateConversionTable(Title $titleobj)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
static decodeTagAttributes($text)
Return an associative array of attribute names and values from a partial tag string.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
const CONTENT_MODEL_WIKITEXT
__construct($langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[])
Constructor.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
convertTo($text, $variant)
Same as convert() except a extra parameter to custom variant.
if(!$wgDBerrorLogTZ) $wgRequest
getVarSeparatorPattern()
Get the cached separator pattern for ConverterRule::parseRules()
static getInstance($id)
Get a cached instance of the specified type of cache object.
wfProfileIn($functionname)
Begin profiling of a function.
recursiveConvertTopLevel($text, $variant, $depth=0)
Recursively convert text on the outside.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Base class for language conversion.
getExtraHashOptions()
Returns language specific hash options.
markNoConversion($text, $noParse=false)
Enclose a string with the "no conversion" tag.
parseCachedTable($code, $subpage= '', $recursive=true)
Parse the conversion table stored in the cache.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
loadTables($fromCache=true)
Load conversion tables either from the cache or the disk.
when a variable name is used in a it is silently declared as a new local masking the global
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target...
static fetchLanguageNames($inLanguage=null, $include= 'mw')
Get an array of language names, indexed by code.
postLoadTables()
Hook for post processing after conversion tables are loaded.
wfProfileOut($functionname= 'missing')
Stop profiling of a function.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Class representing a list of titles The execute() method checks them all for existence and adds them ...
getVariantFallbacks($variant)
In case some variant is not defined in the markup, we need to have some fallback. ...
getDBkey()
Get the main part with underscores.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
switch($options['output']) $languages
getURLVariant()
Get the variant specified in the URL.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
recursiveConvertRule($text, $variant, &$startPos, $depth=0)
Recursively convert text on the inside.
reloadTables()
Reload the conversion tables.
Parser for rules of language conversion , parse rules in -{ }- tag.
getUserVariant()
Determine if the user has a variant set.
translate($text, $variant)
Translate a string to a variant.
$wgLanguageConverterCacheType
The cache type for storing language conversion tables, which are used when parsing certain text and i...
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
namespace and then decline to actually register it file or subcat img or subcat $title
$wgDisabledVariants
Disabled variants array of language variant conversion.
getVariants()
Get all valid variants.
getNamespace()
Get the namespace index, i.e.
static expandAttributes(array $attribs)
Given an associative array of element attributes, generate a string to stick after the element name i...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
$wgDisableLangConversion
Whether to enable language variant conversion.
$wgDefaultLanguageVariant
Default variant code, if false, the default will be the language code.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
this hook is for auditing only $req
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
getHeaderVariant()
Determine the language variant from the Accept-Language header.
guessVariant($text, $variant)
Guess if a text is written in a variant.
string $mCacheKey
Memcached key name.
getDefaultVariant()
Get default variant.
applyManualConv($convRule)
Apply manual conversion rules.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
autoConvert($text, $toVariant=false)
Dictionary-based conversion.
getConvRuleTitle()
Get the title produced by the conversion rule.
convert($text)
Convert text to different variants of a language.
wfMemcKey()
Make a cache key for the local wiki.
static explode($separator, $subject)
Workalike for explode() with limited memory usage.
validateVariant($variant=null)
Validate the variant.
convertNamespace($index, $variant=null)
Get the namespace display name in the preferred variant.
static array $languagesWithVariants
languages supporting variants
getPreferredVariant()
Get preferred language variant.
autoConvertToAllVariants($text)
Call translate() to convert text to all valid variants.
loadDefaultTables()
Load default conversion tables.
static singleton()
Get the signleton instance of this class.
convertTitle($title)
Auto convert a Title object to a readable string in the preferred variant.
Allows to change the fields on the form that will be generated $name