89 public function __construct( $langobj, $maincode, $variants = [],
90 $variantfallbacks = [],
$flags = [],
93 $this->mLangObj = $langobj;
94 $this->mMainLanguageCode = $maincode;
96 $this->mVariantFallbacks = $variantfallbacks;
97 $this->mVariantNames = Language::fetchLanguageNames();
98 $this->mCacheKey =
wfMemcKey(
'conversiontables', $maincode );
112 $this->mFlags = array_merge( $defaultflags,
$flags );
113 foreach ( $this->mVariants
as $v ) {
114 if ( array_key_exists( $v, $manualLevel ) ) {
115 $this->mManualLevel[$v] = $manualLevel[$v];
117 $this->mManualLevel[$v] =
'bidirectional';
119 $this->mFlags[$v] = $v;
145 if ( isset( $this->mVariantFallbacks[$variant] ) ) {
146 return $this->mVariantFallbacks[$variant];
168 if ( $wgUser->isSafeToLoad() &&
$wgUser->isLoggedIn() && !
$req ) {
174 if ( $wgDefaultLanguageVariant && !
$req ) {
202 if ( $wgDefaultLanguageVariant && !
$req ) {
218 if ( $variant !==
null && in_array( $variant, $this->mVariants ) ) {
232 if ( $this->mURLVariant ) {
265 if ( !
$wgUser->isSafeToLoad() ) {
269 if ( $this->mMainLanguageCode ==
$wgContLang->getCode() ) {
272 $ret =
$wgUser->getOption(
'variant-' . $this->mMainLanguageCode );
292 if ( $this->mHeaderVariant ) {
303 $fallbackLanguages = [];
306 if ( $this->mHeaderVariant ) {
314 if ( is_string( $fallbacks ) && $fallbacks !== $this->mMainLanguageCode ) {
315 $fallbackLanguages[] = $fallbacks;
316 } elseif ( is_array( $fallbacks ) ) {
318 array_merge( $fallbackLanguages, $fallbacks );
322 if ( !$this->mHeaderVariant ) {
324 $fallback_languages = array_unique( $fallbackLanguages );
325 foreach ( $fallback_languages
as $language ) {
327 if ( $this->mHeaderVariant ) {
365 $marker =
'|' . Parser::MARKER_PREFIX .
'[^\x7f]++\x7f';
368 $htmlfix =
'|<[^>\004]++(?=\004$)|^[^<>]*+>';
375 $codefix =
'<code>[^<]*+(?:(?:(?!<\/code>).)[^<]*+)*+<\/code>|';
377 $scriptfix =
'<script[^>]*+>[^<]*+(?:(?:(?!<\/script>).)[^<]*+)*+<\/script>|';
379 $prefix =
'<pre[^>]*+>[^<]*+(?:(?:(?!<\/pre>).)[^<]*+)*+<\/pre>|';
382 $htmlFullTag =
'<(?:[^>=]*+(?>[^>=]*+=\s*+(?:"[^"]*"|\'[^\']*\'|[^\'">\s]*+))*+[^>=]*+>|.*+)|';
384 $reg =
'/' . $codefix . $scriptfix . $prefix . $htmlFullTag .
385 '&[a-zA-Z#][a-z0-9]++;' . $marker . $htmlfix .
'|\004$/s';
391 $text = str_replace(
"\000",
'', $text );
392 $text = str_replace(
"\004",
'', $text );
394 $markupMatches =
null;
395 $elementMatches =
null;
399 while ( $startPos < strlen( $text ) ) {
400 if ( preg_match( $reg, $text .
"\004", $markupMatches, PREG_OFFSET_CAPTURE, $startPos ) ) {
401 $elementPos = $markupMatches[0][1];
402 $element = $markupMatches[0][0];
403 if ( $element ===
"\004" ) {
405 $elementPos = strlen( $text );
407 } elseif ( substr( $element, -1 ) ===
"\004" ) {
413 $element = substr( $element, 0, -1 );
420 $log = LoggerFactory::getInstance(
'languageconverter' );
421 $log->error(
"Hit pcre.backtrack_limit in " . __METHOD__
422 .
". Disabling language conversion for this page.",
424 "method" => __METHOD__,
425 "variant" => $toVariant,
426 "startOfText" => substr( $text, 0, 500 )
432 $sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) .
"\000";
435 $startPos = $elementPos + strlen( $element );
439 && preg_match(
'/^(<[^>\s]*+)\s([^>]*+)(.*+)$/', $element, $elementMatches )
446 $attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
448 $close = substr( $elementMatches[2], -1 ) ===
'/' ?
' /' :
'';
450 foreach ( [
'title',
'alt' ]
as $attrName ) {
451 if ( !isset( $attrs[$attrName] ) ) {
454 $attr = $attrs[$attrName];
456 if ( !strpos( $attr,
'://' ) ) {
461 $attr = preg_replace(
'/<[^>]+>/',
'', $attr );
462 if ( $attr !== $attrs[$attrName] ) {
463 $attrs[$attrName] = $attr;
468 $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
469 $close . $elementMatches[3];
472 $literalBlob .= $element .
"\000";
476 $translatedBlob = $this->
translate( $sourceBlob, $toVariant );
482 while ( $translatedIter->valid() && $literalIter->valid() ) {
483 $output .= $translatedIter->current();
484 $output .= $literalIter->current();
485 $translatedIter->next();
486 $literalIter->next();
504 if ( trim( $text ) ) {
506 $text = $this->mTables[$variant]->replace( $text );
521 foreach ( $this->mVariants
as $variant ) {
538 $newConvRuleTitle = $convRule->getTitle();
539 if ( $newConvRuleTitle ) {
541 $this->mConvRuleTitle = $newConvRuleTitle;
545 $convTable = $convRule->getConvTable();
546 $action = $convRule->getRulesAction();
547 foreach ( $convTable
as $variant => $pair ) {
552 if ( $action ==
'add' ) {
554 foreach ( $pair
as $from => $to ) {
555 $this->mTables[$variant]->setPair(
$from, $to );
557 } elseif ( $action ==
'remove' ) {
558 $this->mTables[$variant]->removeArray( $pair );
572 $index =
$title->getNamespace();
594 if ( $variant ===
null ) {
598 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
599 $key =
$cache->makeKey(
'languageconverter',
'namespace-text', $index, $variant );
600 $nsVariantText =
$cache->get( $key );
601 if ( $nsVariantText !==
false ) {
602 return $nsVariantText;
606 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inLanguage( $variant );
607 if ( $nsConvMsg->exists() ) {
608 $nsVariantText = $nsConvMsg->plain();
613 if ( $nsVariantText ===
false ) {
614 $nsConvMsg =
wfMessage(
'conversion-ns' . $index )->inContentLanguage();
615 if ( $nsConvMsg->exists() ) {
616 $nsVariantText = $this->
translate( $nsConvMsg->plain(), $variant );
620 if ( $nsVariantText ===
false ) {
622 $langObj = $this->mLangObj->factory( $variant );
623 $nsVariantText = $langObj->getFormattedNsText( $index );
626 $cache->set( $key, $nsVariantText, 60 );
628 return $nsVariantText;
647 return $this->
convertTo( $text, $variant );
663 $this->mConvRuleTitle =
false;
679 $length = strlen( $text );
680 $shouldConvert = !$this->
guessVariant( $text, $variant );
683 $noScript =
'<script.*?>.*?<\/script>(*SKIP)(*FAIL)';
684 $noStyle =
'<style.*?>.*?<\/style>(*SKIP)(*FAIL)';
686 $noHtml =
'<(?:[^>=]*+(?>[^>=]*+=\s*+(?:"[^"]*"|\'[^\']*\'|[^\'">\s]*+))*+[^>=]*+>|.*+)(*SKIP)(*FAIL)';
688 while ( $startPos < $length && $continue ) {
689 $continue = preg_match(
691 "/$noScript|$noStyle|$noHtml|-\{/",
700 $fragment = substr( $text, $startPos );
701 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
709 $fragment = substr( $text, $startPos, $pos - $startPos );
710 $out .= $shouldConvert ? $this->
autoConvert( $fragment, $variant ) : $fragment;
734 if ( $text[$startPos] !==
'-' || $text[$startPos + 1] !==
'{' ) {
735 throw new MWException( __METHOD__ .
': invalid input string' );
740 $warningDone =
false;
741 $length = strlen( $text );
743 while ( $startPos < $length ) {
745 preg_match(
'/-\{|\}-/', $text, $m, PREG_OFFSET_CAPTURE, $startPos );
756 $inner .= substr( $text, $startPos, $pos - $startPos );
764 if ( $depth >= $this->mMaxDepth ) {
766 if ( !$warningDone ) {
767 $inner .=
'<span class="error">' .
768 wfMessage(
'language-converter-depth-warning' )
769 ->numParams( $this->mMaxDepth )->inContentLanguage()->text() .
783 $rule->parse( $variant );
785 return $rule->getDisplay();
787 throw new MWException( __METHOD__ .
': invalid regex match' );
792 if ( $startPos < $length ) {
793 $inner .= substr( $text, $startPos );
796 return '-{' . $this->
autoConvert( $inner, $variant );
811 # If the article has already existed, there is no need to
812 # check it again, otherwise it may cause a fault.
813 if ( is_object( $nt ) && $nt->exists() ) {
818 $isredir =
$wgRequest->getText(
'redirect',
'yes' );
820 if ( $action ==
'edit' &&
$wgRequest->getBool(
'redlink' ) ) {
823 $linkconvert =
$wgRequest->getText(
'linkconvert',
'yes' );
830 if ( $disableLinkConversion ||
831 ( !$ignoreOtherCond &&
834 || $action ==
'submit'
835 || $linkconvert ==
'no' ) ) ) {
839 if ( is_object( $nt ) ) {
840 $ns = $nt->getNamespace();
850 foreach ( $variants
as $v ) {
852 $varnt = Title::newFromText( $v, $ns );
853 if ( !is_null( $varnt ) ) {
854 $linkBatch->addObj( $varnt );
861 $linkBatch->execute();
864 if ( $varnt->getArticleID() > 0 ) {
866 $link = $varnt->getText();
880 return '!' . $variant;
905 $name = get_class( $this );
907 throw new MWException(
"Must implement loadDefaultTables() method in class $name" );
918 if ( $this->mTablesLoaded ) {
922 $this->mTablesLoaded =
true;
923 $this->mTables =
false;
927 $this->mTables =
$cache->get( $this->mCacheKey );
930 if ( !$this->mTables || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) {
936 foreach ( $this->mVariants
as $var ) {
938 $this->mTables[$var]->mergeArray( $cached );
944 $cache->set( $this->mCacheKey, $this->mTables, 43200 );
961 if ( $this->mTables ) {
962 unset( $this->mTables );
965 $this->mTablesLoaded =
false;
991 $key =
'Conversiontable/' .
$code;
993 $key .=
'/' . $subpage;
995 if ( array_key_exists( $key, $parsed ) ) {
999 $parsed[$key] =
true;
1001 if ( $subpage ===
'' ) {
1010 $txt = $revision->getContent(
Revision::RAW )->getNativeData();
1018 # Nothing to parse if there's no text
1019 if ( $txt ===
false || $txt ===
null || $txt ===
'' ) {
1025 $linkhead = $this->mLangObj->getNsText(
NS_MEDIAWIKI ) .
1029 foreach ( $subs
as $sub ) {
1030 $link = explode(
']]', $sub, 2 );
1031 if ( count(
$link ) != 2 ) {
1034 $b = explode(
'|',
$link[0], 2 );
1035 $b = explode(
'/', trim( $b[0] ), 3 );
1036 if ( count( $b ) == 3 ) {
1042 if ( $b[0] == $linkhead && $b[1] ==
$code ) {
1043 $sublinks[] = $sublink;
1051 foreach ( $blocks
as $block ) {
1057 $mappings = explode(
'}-', $block, 2 )[0];
1058 $stripped = str_replace( [
"'",
'"',
'*',
'#' ],
'', $mappings );
1060 foreach ( $table
as $t ) {
1061 $m = explode(
'=>',
$t, 3 );
1062 if ( count( $m ) != 2 ) {
1066 $tt = explode(
'//', $m[1], 2 );
1067 $ret[trim( $m[0] )] = trim( $tt[0] );
1073 foreach ( $sublinks
as $link ) {
1079 if ( $this->mUcfirst ) {
1080 foreach (
$ret as $k => $v ) {
1081 $ret[$this->mLangObj->ucfirst( $k )] = $this->mLangObj->ucfirst( $v );
1096 # don't mark if already marked
1097 if ( strpos( $text,
'-{' ) || strpos( $text,
'}-' ) ) {
1101 $ret =
"-{R|$text}-";
1128 if ( $c > 1 &&
$t[0] ==
'Conversiontable' ) {
1141 if ( is_null( $this->mVarSeparatorPattern ) ) {
1154 foreach ( $this->mVariants
as $variant ) {
1156 $pat .= $variant .
'\s*:|';
1158 $pat .=
'[^;]*?=>\s*' . $variant .
'\s*:|';
1161 $this->mVarSeparatorPattern = $pat;
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgDefaultLanguageVariant
Default variant code, if false, the default will be the language code.
$wgDisableLangConversion
Whether to enable language variant conversion.
$wgDisabledVariants
Disabled variants array of language variant conversion.
$wgLanguageConverterCacheType
The cache type for storing language conversion tables, which are used when parsing certain text and i...
$wgDisableTitleConversion
Whether to enable language variant conversion for links.
wfMemcKey()
Make a cache key for the local wiki.
wfProfileOut( $functionname='missing')
Stop profiling of a function.
wfProfileIn( $functionname)
Begin profiling of a function.
if(! $wgDBerrorLogTZ) $wgRequest
Parser for rules of language conversion , parse rules in -{ }- tag.
Base class for language conversion.
getPreferredVariant()
Get preferred language variant.
convertTitle( $title)
Auto convert a Title object to a readable string in the preferred variant.
validateVariant( $variant=null)
Validate the variant.
getDefaultVariant()
Get default variant.
__construct( $langobj, $maincode, $variants=[], $variantfallbacks=[], $flags=[], $manualLevel=[])
Constructor.
recursiveConvertTopLevel( $text, $variant, $depth=0)
Recursively convert text on the outside.
loadTables( $fromCache=true)
Load conversion tables either from the cache or the disk.
getHeaderVariant()
Determine the language variant from the Accept-Language header.
static array $languagesWithVariants
languages supporting variants
autoConvert( $text, $toVariant=false)
Dictionary-based conversion.
recursiveConvertRule( $text, $variant, &$startPos, $depth=0)
Recursively convert text on the inside.
parseCachedTable( $code, $subpage='', $recursive=true)
Parse the conversion table stored in the cache.
getVarSeparatorPattern()
Get the cached separator pattern for ConverterRule::parseRules()
convertNamespace( $index, $variant=null)
Get the namespace display name in the preferred variant.
string $mCacheKey
Memcached key name.
getExtraHashOptions()
Returns language specific hash options.
getVariantFallbacks( $variant)
In case some variant is not defined in the markup, we need to have some fallback.
updateConversionTable(Title $titleobj)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
markNoConversion( $text, $noParse=false)
Enclose a string with the "no conversion" tag.
applyManualConv( $convRule)
Apply manual conversion rules.
translate( $text, $variant)
Translate a string to a variant.
getVariants()
Get all valid variants.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
convert( $text)
Convert text to different variants of a language.
postLoadTables()
Hook for post processing after conversion tables are loaded.
getURLVariant()
Get the variant specified in the URL.
loadDefaultTables()
Load default conversion tables.
autoConvertToAllVariants( $text)
Call translate() to convert text to all valid variants.
guessVariant( $text, $variant)
Guess if a text is written in a variant.
getUserVariant()
Determine if the user has a variant set.
convertTo( $text, $variant)
Same as convert() except a extra parameter to custom variant.
convertCategoryKey( $key)
Convert the sorting key for category links.
getConvRuleTitle()
Get the title produced by the conversion rule.
reloadTables()
Reload the conversion tables.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
static singleton()
Get the signleton instance of this class.
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 explode( $separator, $subject)
Workalike for explode() with limited memory usage.
Represents a title within MediaWiki.
getNamespace()
Get the namespace index, i.e.
getDBkey()
Get the main part with underscores.
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
when a variable name is used in a it is silently declared as a new local masking the global
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
const CONTENT_MODEL_WIKITEXT
this hook is for auditing only $req
the array() calling protocol came about after MediaWiki 1.4rc1.
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
namespace and then decline to actually register it file or subcat img or subcat $title
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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
it s the revision text itself In either if gzip is the revision text is gzipped $flags
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 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
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Allows to change the fields on the form that will be generated $name
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
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
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
switch( $options['output']) $languages