84 public function __construct( $langobj, $maincode, $variants = [],
85 $variantfallbacks = [],
$flags = [],
88 $this->mLangObj = $langobj;
89 $this->mMainLanguageCode = $maincode;
90 $this->mVariants = array_diff( $variants, $wgDisabledVariants );
91 $this->mVariantFallbacks = $variantfallbacks;
93 $this->mCacheKey =
wfMemcKey(
'conversiontables', $maincode );
107 $this->mFlags = array_merge( $defaultflags,
$flags );
108 foreach ( $this->mVariants
as $v ) {
109 if ( array_key_exists( $v, $manualLevel ) ) {
110 $this->mManualLevel[$v] = $manualLevel[$v];
112 $this->mManualLevel[$v] =
'bidirectional';
114 $this->mFlags[$v] = $v;
140 if ( isset( $this->mVariantFallbacks[$variant] ) ) {
141 return $this->mVariantFallbacks[$variant];
163 if ( $wgUser->isSafeToLoad() && $wgUser->isLoggedIn() && !
$req ) {
169 if ( $wgDefaultLanguageVariant && !
$req ) {
197 if ( $wgDefaultLanguageVariant && !
$req ) {
213 if ( $variant !== null && in_array( $variant, $this->mVariants ) ) {
227 if ( $this->mURLVariant ) {
232 $ret = $wgRequest->getText(
'variant' );
235 $ret = $wgRequest->getVal(
'uselang' );
260 if ( !$wgUser->isSafeToLoad() ) {
263 if ( $wgUser->isLoggedIn() ) {
264 if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
265 $ret = $wgUser->getOption(
'variant' );
267 $ret = $wgUser->getOption(
'variant-' . $this->mMainLanguageCode );
272 $ret = $wgUser->getOption(
'language' );
287 if ( $this->mHeaderVariant ) {
293 $languages = array_keys( $wgRequest->getAcceptLang() );
298 $fallbackLanguages = [];
301 if ( $this->mHeaderVariant ) {
309 if ( is_string( $fallbacks ) && $fallbacks !== $this->mMainLanguageCode ) {
310 $fallbackLanguages[] = $fallbacks;
311 } elseif ( is_array( $fallbacks ) ) {
313 array_merge( $fallbackLanguages, $fallbacks );
317 if ( !$this->mHeaderVariant ) {
319 $fallback_languages = array_unique( $fallbackLanguages );
320 foreach ( $fallback_languages
as $language ) {
322 if ( $this->mHeaderVariant ) {
364 $htmlfix =
'|<[^>]+$|^[^<>]*>';
367 $codefix =
'<code>.+?<\/code>|';
369 $scriptfix =
'<script.*?>.*?<\/script>|';
371 $prefix =
'<pre.*?>.*?<\/pre>|';
373 $reg =
'/' . $codefix . $scriptfix . $prefix .
374 '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix .
'/s';
380 $text = str_replace(
"\000",
'', $text );
382 $markupMatches = null;
383 $elementMatches = null;
384 while ( $startPos < strlen( $text ) ) {
385 if ( preg_match( $reg, $text, $markupMatches, PREG_OFFSET_CAPTURE, $startPos ) ) {
386 $elementPos = $markupMatches[0][1];
387 $element = $markupMatches[0][0];
389 $elementPos = strlen( $text );
394 $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) .
"\000";
397 $startPos = $elementPos + strlen( $element );
401 && preg_match(
'/^(<[^>\s]*)\s([^>]*)(.*)$/', $element, $elementMatches )
405 foreach ( [
'title',
'alt' ]
as $attrName ) {
406 if ( !isset( $attrs[$attrName] ) ) {
409 $attr = $attrs[$attrName];
411 if ( !strpos( $attr,
'://' ) ) {
416 $attr = preg_replace(
'/<[^>]+>/',
'', $attr );
417 if ( $attr !== $attrs[$attrName] ) {
418 $attrs[$attrName] = $attr;
427 $literalBlob .= $element .
"\000";
431 $translatedBlob = $this->
translate( $sourceBlob, $toVariant );
434 $translatedIter = StringUtils::explode(
"\000", $translatedBlob );
435 $literalIter = StringUtils::explode(
"\000", $literalBlob );
437 while ( $translatedIter->valid() && $literalIter->valid() ) {
438 $output .= $translatedIter->current();
439 $output .= $literalIter->current();
440 $translatedIter->next();
441 $literalIter->next();
459 if ( trim( $text ) ) {
461 $text = $this->mTables[$variant]->replace( $text );
476 foreach ( $this->mVariants
as $variant ) {
493 $newConvRuleTitle = $convRule->getTitle();
494 if ( $newConvRuleTitle ) {
496 $this->mConvRuleTitle = $newConvRuleTitle;
500 $convTable = $convRule->getConvTable();
501 $action = $convRule->getRulesAction();
502 foreach ( $convTable
as $variant => $pair ) {
507 if ( $action ==
'add' ) {
509 foreach ( $pair
as $from => $to ) {
510 $this->mTables[$variant]->setPair(
$from, $to );
512 } elseif ( $action ==
'remove' ) {
513 $this->mTables[$variant]->removeArray( $pair );
527 $index =
$title->getNamespace();
549 if ( $variant === null ) {
554 $key =
wfMemcKey(
'languageconverter',
'namespace-text', $index, $variant );
555 $nsVariantText =
$cache->get( $key );
556 if ( $nsVariantText !==
false ) {
557 return $nsVariantText;
561 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inLanguage( $variant );
562 if ( $nsConvMsg->exists() ) {
563 $nsVariantText = $nsConvMsg->plain();
568 if ( $nsVariantText ===
false ) {
569 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inContentLanguage();
570 if ( $nsConvMsg->exists() ) {
571 $nsVariantText = $this->
translate( $nsConvMsg->plain(), $variant );
575 if ( $nsVariantText ===
false ) {
577 $langObj = $this->mLangObj->factory( $variant );
578 $nsVariantText = $langObj->getFormattedNsText( $index );
581 $cache->set( $key, $nsVariantText, 60 );
583 return $nsVariantText;
602 return $this->
convertTo( $text, $variant );
614 if ( $wgDisableLangConversion ) {
618 $this->mConvRuleTitle =
false;
634 $length = strlen( $text );
635 $shouldConvert = !$this->
guessVariant( $text, $variant );
637 while ( $startPos < $length ) {
638 $pos = strpos( $text,
'-{', $startPos );
640 if ( $pos ===
false ) {
642 $fragment = substr( $text, $startPos );
643 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
649 $fragment = substr( $text, $startPos, $pos - $startPos );
650 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
675 if ( $text[$startPos] !==
'-' || $text[$startPos + 1] !==
'{' ) {
676 throw new MWException( __METHOD__ .
': invalid input string' );
681 $warningDone =
false;
682 $length = strlen( $text );
684 while ( $startPos < $length ) {
686 preg_match(
'/-\{|\}-/', $text, $m, PREG_OFFSET_CAPTURE, $startPos );
697 $inner .= substr( $text, $startPos, $pos - $startPos );
705 if ( $depth >= $this->mMaxDepth ) {
707 if ( !$warningDone ) {
708 $inner .=
'<span class="error">' .
709 wfMessage(
'language-converter-depth-warning' )
710 ->numParams( $this->mMaxDepth )->inContentLanguage()->text() .
724 $rule->parse( $variant );
726 return $rule->getDisplay();
728 throw new MWException( __METHOD__ .
': invalid regex match' );
733 if ( $startPos < $length ) {
734 $inner .= substr( $text, $startPos );
737 return '-{' . $this->
autoConvert( $inner, $variant );
752 # If the article has already existed, there is no need to
753 # check it again, otherwise it may cause a fault.
754 if ( is_object( $nt ) && $nt->exists() ) {
759 $isredir = $wgRequest->getText(
'redirect',
'yes' );
760 $action = $wgRequest->getText(
'action' );
761 if ( $action ==
'edit' && $wgRequest->getBool(
'redlink' ) ) {
764 $linkconvert = $wgRequest->getText(
'linkconvert',
'yes' );
765 $disableLinkConversion = $wgDisableLangConversion
771 if ( $disableLinkConversion ||
772 ( !$ignoreOtherCond &&
775 || $action ==
'submit'
776 || $linkconvert ==
'no' ) ) ) {
780 if ( is_object( $nt ) ) {
781 $ns = $nt->getNamespace();
791 foreach ( $variants
as $v ) {
794 if ( !is_null( $varnt ) ) {
795 $linkBatch->addObj( $varnt );
802 $linkBatch->execute();
805 if ( $varnt->getArticleID() > 0 ) {
821 return '!' . $variant;
846 $name = get_class( $this );
848 throw new MWException(
"Must implement loadDefaultTables() method in class $name" );
859 if ( $this->mTablesLoaded ) {
863 $this->mTablesLoaded =
true;
864 $this->mTables =
false;
868 $this->mTables =
$cache->get( $this->mCacheKey );
871 if ( !$this->mTables || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
877 foreach ( $this->mVariants
as $var ) {
879 $this->mTables[$var]->mergeArray( $cached );
883 $this->mTables[self::CACHE_VERSION_KEY] =
true;
885 $cache->set( $this->mCacheKey, $this->mTables, 43200 );
902 if ( $this->mTables ) {
903 unset( $this->mTables );
906 $this->mTablesLoaded =
false;
932 $key =
'Conversiontable/' .
$code;
934 $key .=
'/' . $subpage;
936 if ( array_key_exists( $key, $parsed ) ) {
940 $parsed[$key] =
true;
942 if ( $subpage ===
'' ) {
951 $txt = $revision->getContent(
Revision::RAW )->getNativeData();
959 # Nothing to parse if there's no text
960 if ( $txt ===
false || $txt === null || $txt ===
'' ) {
966 $linkhead = $this->mLangObj->getNsText(
NS_MEDIAWIKI ) .
968 $subs = StringUtils::explode(
'[[', $txt );
970 foreach ( $subs
as $sub ) {
971 $link = explode(
']]', $sub, 2 );
972 if ( count(
$link ) != 2 ) {
975 $b = explode(
'|',
$link[0], 2 );
976 $b = explode(
'/', trim( $b[0] ), 3 );
977 if ( count( $b ) == 3 ) {
983 if ( $b[0] == $linkhead && $b[1] ==
$code ) {
984 $sublinks[] = $sublink;
989 $blocks = StringUtils::explode(
'-{', $txt );
992 foreach ( $blocks
as $block ) {
998 $mappings = explode(
'}-', $block, 2 )[0];
999 $stripped = str_replace( [
"'",
'"',
'*',
'#' ],
'', $mappings );
1000 $table = StringUtils::explode(
';', $stripped );
1001 foreach ( $table
as $t ) {
1002 $m = explode(
'=>', $t, 3 );
1003 if ( count( $m ) != 2 ) {
1007 $tt = explode(
'//', $m[1], 2 );
1008 $ret[trim( $m[0] )] = trim( $tt[0] );
1014 foreach ( $sublinks
as $link ) {
1020 if ( $this->mUcfirst ) {
1021 foreach (
$ret as $k => $v ) {
1022 $ret[$this->mLangObj->ucfirst( $k )] = $this->mLangObj->ucfirst( $v );
1037 # don't mark if already marked
1038 if ( strpos( $text,
'-{' ) || strpos( $text,
'}-' ) ) {
1042 $ret =
"-{R|$text}-";
1069 if ( $c > 1 &&
$t[0] ==
'Conversiontable' ) {
1082 if ( is_null( $this->mVarSeparatorPattern ) ) {
1095 foreach ( $this->mVariants
as $variant ) {
1097 $pat .= $variant .
'\s*:|';
1099 $pat .=
'[^;]*?=>\s*' . $variant .
'\s*:|';
1102 $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.
getText()
Get the text form (spaces not underscores) of the main part.
convertTo($text, $variant)
Same as convert() except a extra parameter to custom variant.
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.
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.
Represents a title within MediaWiki.
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.
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $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.
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.
static newAccelerator($params=[], $fallback=null)
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.
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned after processing 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"<
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $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...
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
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.
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.
if(is_null($wgLocalTZoffset)) if(!$wgDBerrorLogTZ) $wgRequest
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