/** @var SpecialPageFactory */
private $specialPageFactory;
+ /** @var Config */
+ private $siteConfig;
+
/**
- * @param array $conf See $wgParserConf documentation
+ * @param array $parserConf See $wgParserConf documentation
* @param MagicWordFactory|null $magicWordFactory
* @param Language|null $contLang Content language
* @param ParserFactory|null $factory
* @param string|null $urlProtocols As returned from wfUrlProtocols()
* @param SpecialPageFactory|null $spFactory
+ * @param Config|null $siteConfig
*/
public function __construct(
- array $conf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null,
- ParserFactory $factory = null, $urlProtocols = null, SpecialPageFactory $spFactory = null
+ array $parserConf = [], MagicWordFactory $magicWordFactory = null,
+ Language $contLang = null, ParserFactory $factory = null, $urlProtocols = null,
+ SpecialPageFactory $spFactory = null, Config $siteConfig = null
) {
- $this->mConf = $conf;
+ $this->mConf = $parserConf;
$this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols();
$this->mExtLinkBracketedRegex = '/\[(((?i)' . $this->mUrlProtocols . ')' .
self::EXT_LINK_ADDR .
self::EXT_LINK_URL_CLASS . '*)\p{Zs}*([^\]\\x00-\\x08\\x0a-\\x1F\\x{FFFD}]*?)\]/Su';
- if ( isset( $conf['preprocessorClass'] ) ) {
- $this->mPreprocessorClass = $conf['preprocessorClass'];
+ if ( isset( $parserConf['preprocessorClass'] ) ) {
+ $this->mPreprocessorClass = $parserConf['preprocessorClass'];
} elseif ( wfIsHHVM() ) {
# Under HHVM Preprocessor_Hash is much faster than Preprocessor_DOM
$this->mPreprocessorClass = Preprocessor_Hash::class;
$this->factory = $factory ?? $services->getParserFactory();
$this->specialPageFactory = $spFactory ?? $services->getSpecialPageFactory();
+ $this->siteConfig = $siteConfig ?? MediaWikiServices::getInstance()->getMainConfig();
}
/**
* @return string
*/
protected function makeLimitReport() {
- global $wgShowHostnames;
-
$maxIncludeSize = $this->mOptions->getMaxIncludeSize();
$cpuTime = $this->mOutput->getTimeSinceStart( 'cpu' );
Hooks::run( 'ParserLimitReportPrepare', [ $this, $this->mOutput ] );
$limitReport = "NewPP limit report\n";
- if ( $wgShowHostnames ) {
+ if ( $this->siteConfig->get( 'ShowHostnames' ) ) {
$limitReport .= 'Parsed by ' . wfHostname() . "\n";
}
$limitReport .= 'Cached time: ' . $this->mOutput->getCacheTime() . "\n";
// Since we're not really outputting HTML, decode the entities and
// then re-encode the things that need hiding inside HTML comments.
$limitReport = htmlspecialchars_decode( $limitReport );
- // Run deprecated hook
- Hooks::run( 'ParserLimitReport', [ $this, &$limitReport ], '1.22' );
// Sanitize for comment. Note '‐' in the replacement is U+2010,
// which looks much like the problematic '-'.
$this->mOutput->setLimitReportData( 'limitreport-timingprofile', $profileReport );
// Add other cache related metadata
- if ( $wgShowHostnames ) {
+ if ( $this->siteConfig->get( 'ShowHostnames' ) ) {
$this->mOutput->setLimitReportData( 'cachereport-origin', wfHostname() );
}
$this->mOutput->setLimitReportData( 'cachereport-timestamp',
} else {
# attempt to sanitize at least some nesting problems
# (T4702 and quite a few others)
+ # This code path is buggy and deprecated!
+ wfDeprecated( 'disabling tidy', '1.33' );
$tidyregs = [
# ''Something [http://www.cool.com cool''] -->
# <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a>
* @private
*/
public function replaceInternalLinks2( &$s ) {
- global $wgExtraInterlanguageLinkPrefixes;
-
static $tc = false, $e1, $e1_img;
# the % is needed to support urlencoded titles as well
if ( !$tc ) {
if (
$iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
Language::fetchLanguageName( $iw, null, 'mw' ) ||
- in_array( $iw, $wgExtraInterlanguageLinkPrefixes )
+ in_array( $iw, $this->siteConfig->get( 'ExtraInterlanguageLinkPrefixes' ) )
)
) {
# T26502: filter duplicates
* @return string
*/
public function getVariableValue( $index, $frame = false ) {
- global $wgSitename, $wgServer, $wgServerName;
- global $wgArticlePath, $wgScriptPath, $wgStylePath;
-
if ( is_null( $this->mTitle ) ) {
// If no title set, bad things are going to happen
// later. Title should always be set since this
$value = SpecialVersion::getVersion();
break;
case 'articlepath':
- return $wgArticlePath;
+ return $this->siteConfig->get( 'ArticlePath' );
case 'sitename':
- return $wgSitename;
+ return $this->siteConfig->get( 'Sitename' );
case 'server':
- return $wgServer;
+ return $this->siteConfig->get( 'Server' );
case 'servername':
- return $wgServerName;
+ return $this->siteConfig->get( 'ServerName' );
case 'scriptpath':
- return $wgScriptPath;
+ return $this->siteConfig->get( 'ScriptPath' );
case 'stylepath':
- return $wgStylePath;
+ return $this->siteConfig->get( 'StylePath' );
case 'directionmark':
return $pageLang->getDirMark();
case 'contentlanguage':
- global $wgLanguageCode;
- return $wgLanguageCode;
+ return $this->siteConfig->get( 'LanguageCode' );
case 'pagelanguage':
$value = $pageLang->getCode();
break;
* @return string
*/
public function interwikiTransclude( $title, $action ) {
- global $wgEnableScaryTranscluding, $wgTranscludeCacheExpiry;
-
- if ( !$wgEnableScaryTranscluding ) {
+ if ( !$this->siteConfig->get( 'EnableScaryTranscluding' ) ) {
return wfMessage( 'scarytranscludedisabled' )->inContentLanguage()->text();
}
( $wikiId !== false ) ? $wikiId : 'external',
sha1( $url )
),
- $wgTranscludeCacheExpiry,
+ $this->siteConfig->get( 'TranscludeCacheExpiry' ),
function ( $oldValue, &$ttl ) use ( $url, $fname, $cache ) {
$req = MWHttpRequest::factory( $url, [], $fname );
* @private
*/
public function formatHeadings( $text, $origText, $isMain = true ) {
- global $wgMaxTocLevel;
-
# Inhibit editsection links if requested in the page
if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
$maybeShowEditLink = false;
$headlines = $numMatches !== false ? $matches[3] : [];
+ $maxTocLevel = $this->siteConfig->get( 'MaxTocLevel' );
foreach ( $headlines as $headline ) {
$isTemplate = false;
$titleText = false;
# Increase TOC level
$toclevel++;
$sublevelCount[$toclevel] = 0;
- if ( $toclevel < $wgMaxTocLevel ) {
+ if ( $toclevel < $maxTocLevel ) {
$prevtoclevel = $toclevel;
$toc .= Linker::tocIndent();
$numVisible++;
if ( $i == 0 ) {
$toclevel = 1;
}
- if ( $toclevel < $wgMaxTocLevel ) {
- if ( $prevtoclevel < $wgMaxTocLevel ) {
+ if ( $toclevel < $maxTocLevel ) {
+ if ( $prevtoclevel < $maxTocLevel ) {
# Unindent only if the previous toc level was shown :p
$toc .= Linker::tocUnindent( $prevtoclevel - $toclevel );
$prevtoclevel = $toclevel;
}
} else {
# No change in level, end TOC line
- if ( $toclevel < $wgMaxTocLevel ) {
+ if ( $toclevel < $maxTocLevel ) {
$toc .= Linker::tocLineEnd();
}
}
) . ' ' . $headline;
}
- if ( $enoughToc && ( !isset( $wgMaxTocLevel ) || $toclevel < $wgMaxTocLevel ) ) {
+ if ( $enoughToc && ( !isset( $maxTocLevel ) || $toclevel < $maxTocLevel ) ) {
$toc .= Linker::tocLine( $linkAnchor, $tocline,
$numbering, $toclevel, ( $isTemplate ? false : $sectionIndex ) );
}
}
if ( $enoughToc ) {
- if ( $prevtoclevel > 0 && $prevtoclevel < $wgMaxTocLevel ) {
+ if ( $prevtoclevel > 0 && $prevtoclevel < $maxTocLevel ) {
$toc .= Linker::tocUnindent( $prevtoclevel - 1 );
}
$toc = Linker::tocList( $toc, $this->mOptions->getUserLangObj() );
* @return string
*/
public function getUserSig( &$user, $nickname = false, $fancySig = null ) {
- global $wgMaxSigChars;
-
$username = $user->getName();
# If not given, retrieve from the user object.
$nickname = $nickname == null ? $username : $nickname;
- if ( mb_strlen( $nickname ) > $wgMaxSigChars ) {
+ if ( mb_strlen( $nickname ) > $this->siteConfig->get( 'MaxSigChars' ) ) {
$nickname = $username;
wfDebug( __METHOD__ . ": $username has overlong signature.\n" );
} elseif ( $fancySig !== false ) {
$alt = $this->stripAltText( $match, false );
break;
case 'gallery-internal-link':
- $linkValue = strip_tags( $this->replaceLinkHoldersText( $match ) );
- $chars = self::EXT_LINK_URL_CLASS;
- $addr = self::EXT_LINK_ADDR;
- $prots = $this->mUrlProtocols;
- // check to see if link matches an absolute url, if not then it must be a wiki link.
+ $linkValue = $this->stripAltText( $match, false );
if ( preg_match( '/^-{R|(.*)}-$/', $linkValue ) ) {
// Result of LanguageConverter::markNoConversion
// invoked on an external link.
$linkValue = substr( $linkValue, 4, -2 );
}
- if ( preg_match( "/^($prots)$addr$chars*$/u", $linkValue ) ) {
- $link = $linkValue;
- $this->mOutput->addExternalLink( $link );
- } else {
- $localLinkTitle = Title::newFromText( $linkValue );
- if ( $localLinkTitle !== null ) {
- $this->mOutput->addLink( $localLinkTitle );
- $link = $localLinkTitle->getLinkURL();
- }
+ list( $type, $target ) = $this->parseLinkParameter( $linkValue );
+ if ( $type === 'link-url' ) {
+ $link = $target;
+ $this->mOutput->addExternalLink( $target );
+ } elseif ( $type === 'link-title' ) {
+ $link = $target->getLinkURL();
+ $this->mOutput->addLink( $target );
}
break;
default:
# * bottom
# * text-bottom
+ global $wgMediaInTargetLanguage;
+
# Protect LanguageConverter markup when splitting into parts
$parts = StringUtils::delimiterExplode(
'-{', '}-', '|', $options, true /* allow nesting */
$value = $this->stripAltText( $value, $holders );
break;
case 'link':
- $chars = self::EXT_LINK_URL_CLASS;
- $addr = self::EXT_LINK_ADDR;
- $prots = $this->mUrlProtocols;
- if ( $value === '' ) {
- $paramName = 'no-link';
- $value = true;
+ list( $paramName, $value ) =
+ $this->parseLinkParameter(
+ $this->stripAltText( $value, $holders )
+ );
+ if ( $paramName ) {
$validated = true;
- } elseif ( preg_match( "/^((?i)$prots)/", $value ) ) {
- if ( preg_match( "/^((?i)$prots)$addr$chars*$/u", $value, $m ) ) {
- $paramName = 'link-url';
- $this->mOutput->addExternalLink( $value );
+ if ( $paramName === 'no-link' ) {
+ $value = true;
+ }
+ if ( $paramName === 'link-url' ) {
if ( $this->mOptions->getExternalLinkTarget() ) {
$params[$type]['link-target'] = $this->mOptions->getExternalLinkTarget();
}
- $validated = true;
- }
- } else {
- $linkTitle = Title::newFromText( $value );
- if ( $linkTitle ) {
- $paramName = 'link-title';
- $value = $linkTitle;
- $this->mOutput->addLink( $linkTitle );
- $validated = true;
}
}
break;
# Use the "caption" for the tooltip text
$params['frame']['title'] = $this->stripAltText( $caption, $holders );
}
+ if ( $wgMediaInTargetLanguage ) {
+ $params['handler']['targetlang'] = $this->getTargetLanguage()->getCode();
+ }
Hooks::run( 'ParserMakeImageParams', [ $title, $file, &$params, $this ] );
return $ret;
}
+ /**
+ * Parse the value of 'link' parameter in image syntax (`[[File:Foo.jpg|link=<value>]]`).
+ *
+ * Adds an entry to appropriate link tables.
+ *
+ * @since 1.32
+ * @return array of `[ type, target ]`, where:
+ * - `type` is one of:
+ * - `null`: Given value is not a valid link target, use default
+ * - `'no-link'`: Given value is empty, do not generate a link
+ * - `'link-url'`: Given value is a valid external link
+ * - `'link-title'`: Given value is a valid internal link
+ * - `target` is:
+ * - When `type` is `null` or `'no-link'`: `false`
+ * - When `type` is `'link-url'`: URL string corresponding to given value
+ * - When `type` is `'link-title'`: Title object corresponding to given value
+ */
+ public function parseLinkParameter( $value ) {
+ $chars = self::EXT_LINK_URL_CLASS;
+ $addr = self::EXT_LINK_ADDR;
+ $prots = $this->mUrlProtocols;
+ $type = null;
+ $target = false;
+ if ( $value === '' ) {
+ $type = 'no-link';
+ } elseif ( preg_match( "/^((?i)$prots)/", $value ) ) {
+ if ( preg_match( "/^((?i)$prots)$addr$chars*$/u", $value, $m ) ) {
+ $this->mOutput->addExternalLink( $value );
+ $type = 'link-url';
+ $target = $value;
+ }
+ } else {
+ $linkTitle = Title::newFromText( $value );
+ if ( $linkTitle ) {
+ $this->mOutput->addLink( $linkTitle );
+ $type = 'link-title';
+ $target = $linkTitle;
+ }
+ }
+ return [ $type, $target ];
+ }
+
/**
* @param string $caption
* @param LinkHolderArray|bool $holders
return '#' . Sanitizer::escapeIdForLink( $sectionName );
}
- private static function makeLegacyAnchor( $sectionName ) {
- global $wgFragmentMode;
- if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
+ private function makeLegacyAnchor( $sectionName ) {
+ $fragmentMode = $this->siteConfig->get( 'FragmentMode' );
+ if ( isset( $fragmentMode[1] ) && $fragmentMode[1] === 'legacy' ) {
// ForAttribute() and ForLink() are the same for legacy encoding
$id = Sanitizer::escapeIdForAttribute( $sectionName, Sanitizer::ID_FALLBACK );
} else {
# Strip out wikitext links(they break the anchor)
$text = $this->stripSectionName( $text );
$sectionName = self::getSectionNameFromStrippedText( $text );
- return self::makeLegacyAnchor( $sectionName );
+ return $this->makeLegacyAnchor( $sectionName );
}
/**