*/
protected $mLinkRenderer;
+ /** @var MagicWordFactory */
+ private $magicWordFactory;
+
/**
* @param array $conf
+ * @param MagicWordFactory|null $magicWordFactory
*/
- public function __construct( $conf = [] ) {
+ public function __construct( $conf = [], MagicWordFactory $magicWordFactory = null ) {
$this->mConf = $conf;
$this->mUrlProtocols = wfUrlProtocols();
$this->mExtLinkBracketedRegex = '/\[(((?i)' . $this->mUrlProtocols . ')' .
$this->mPreprocessorClass = Preprocessor_Hash::class;
}
wfDebug( __CLASS__ . ": using preprocessor: {$this->mPreprocessorClass}\n" );
+
+ $this->magicWordFactory = $magicWordFactory;
+ if ( !$magicWordFactory ) {
+ $this->magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
+ }
}
/**
* @param ParserOptions $options
* @param bool $linestart
* @param bool $clearState
- * @param int $revid Number to pass in {{REVISIONID}}
+ * @param int|null $revid Number to pass in {{REVISIONID}}
* @return ParserOutput A ParserOutput
*/
public function parse(
|| isset( $this->mDoubleUnderscores['notitleconvert'] )
|| $this->mOutput->getDisplayTitle() !== false )
) {
- $convruletitle = $this->getConverterLanguage()->getConvRuleTitle();
+ $convruletitle = $this->getTargetLanguage()->getConvRuleTitle();
if ( $convruletitle ) {
$this->mOutput->setTitleText( $convruletitle );
} else {
- $titleText = $this->getConverterLanguage()->convertTitle( $title );
+ $titleText = $this->getTargetLanguage()->convertTitle( $title );
$this->mOutput->setTitleText( $titleText );
}
}
* Also removes comments.
* Do not call this function recursively.
* @param string $text
- * @param Title $title
+ * @param Title|null $title
* @param ParserOptions $options
* @param int|null $revid
* @param bool|PPFrame $frame
/**
* Accessor/mutator for the Title object
*
- * @param Title $x Title object or null to just get the current one
+ * @param Title|null $x Title object or null to just get the current one
* @return Title
*/
public function Title( $x = null ) {
/**
* Accessor/mutator for the ParserOptions object
*
- * @param ParserOptions $x New value or null to just get the current one
+ * @param ParserOptions|null $x New value or null to just get the current one
* @return ParserOptions Current ParserOptions object
*/
public function Options( $x = null ) {
/**
* Get the language object for language conversion
+ * @deprecated since 1.32, just use getTargetLanguage()
* @return Language|null
*/
public function getConverterLanguage() {
return $this->mLinkRenderer;
}
+ /**
+ * Get the MagicWordFactory that this Parser is using
+ *
+ * @since 1.32
+ * @return MagicWordFactory
+ */
+ public function getMagicWordFactory() {
+ return $this->magicWordFactory;
+ }
+
/**
* Replaces all occurrences of HTML-style comments and the given tags
* in the text with a random marker and returns the next text. The output
}
# Clean up special characters, only run once, next-to-last before doBlockLevels
- $fixtags = [
- # French spaces, last one Guillemet-left
- # only if there is something before the space
- '/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 ',
- # french spaces, Guillemet-right
- '/(\\302\\253) /' => '\\1 ',
- '/ (!\s*important)/' => ' \\1', # Beware of CSS magic word !important, T13874.
- ];
- $text = preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text );
+ $text = Sanitizer::armorFrenchSpaces( $text );
$text = $this->doBlockLevels( $text, $linestart );
# The position of the convert() call should not be changed. it
# assumes that the links are all replaced and the only thing left
# is the <nowiki> mark.
- $text = $this->getConverterLanguage()->convert( $text );
+ $text = $this->getTargetLanguage()->convert( $text );
}
}
if ( $text === false ) {
# Not an image, make a link
$text = Linker::makeExternalLink( $url,
- $this->getConverterLanguage()->markNoConversion( $url, true ),
+ $this->getTargetLanguage()->getConverter()->markNoConversion( $url ),
true, 'free',
$this->getExternalLinkAttribs( $url ), $this->mTitle );
# Register it in the output object...
list( $dtrail, $trail ) = Linker::splitTrail( $trail );
}
- $text = $this->getConverterLanguage()->markNoConversion( $text );
+ // Excluding protocol-relative URLs may avoid many false positives.
+ if ( preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
+ $text = $this->getTargetLanguage()->getConverter()->markNoConversion( $text );
+ }
$url = Sanitizer::cleanUrl( $url );
* @since 1.21
* @param string|bool $url Optional URL, to extract the domain from for rel =>
* nofollow if appropriate
- * @param Title $title Optional Title, for wgNoFollowNsExceptions lookups
+ * @param Title|null $title Optional Title, for wgNoFollowNsExceptions lookups
* @return string|null Rel attribute for $url
*/
public static function getExternalLinkRel( $url = false, $title = null ) {
}
$sortkey = Sanitizer::decodeCharReferences( $sortkey );
$sortkey = str_replace( "\n", '', $sortkey );
- $sortkey = $this->getConverterLanguage()->convertCategoryKey( $sortkey );
+ $sortkey = $this->getTargetLanguage()->convertCategoryKey( $sortkey );
$this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
continue;
*
* @private
*
- * @param string $index Magic variable identifier as mapped in MagicWord::$mVariableIDs
+ * @param string $index Magic variable identifier as mapped in MagicWordFactory::$mVariableIDs
* @param bool|PPFrame $frame
*
* @throws MWException
* @private
*/
public function initialiseVariables() {
- $variableIDs = MagicWord::getVariableIDs();
- $substIDs = MagicWord::getSubstIDs();
+ $variableIDs = $this->magicWordFactory->getVariableIDs();
+ $substIDs = $this->magicWordFactory->getSubstIDs();
$this->mVariables = new MagicWordArray( $variableIDs );
$this->mSubstWords = new MagicWordArray( $substIDs );
$id = $this->mVariables->matchStartToEnd( $part1 );
if ( $id !== false ) {
$text = $this->getVariableValue( $id, $frame );
- if ( MagicWord::getCacheTTL( $id ) > -1 ) {
- $this->mOutput->updateCacheExpiry( MagicWord::getCacheTTL( $id ) );
+ if ( $this->magicWordFactory->getCacheTTL( $id ) > -1 ) {
+ $this->mOutput->updateCacheExpiry(
+ $this->magicWordFactory->getCacheTTL( $id ) );
}
$found = true;
}
# MSG, MSGNW and RAW
if ( !$found ) {
# Check for MSGNW:
- $mwMsgnw = MagicWord::get( 'msgnw' );
+ $mwMsgnw = $this->magicWordFactory->get( 'msgnw' );
if ( $mwMsgnw->matchStartAndRemove( $part1 ) ) {
$nowiki = true;
} else {
# Remove obsolete MSG:
- $mwMsg = MagicWord::get( 'msg' );
+ $mwMsg = $this->magicWordFactory->get( 'msg' );
$mwMsg->matchStartAndRemove( $part1 );
}
# Check for RAW:
- $mwRaw = MagicWord::get( 'raw' );
+ $mwRaw = $this->magicWordFactory->get( 'raw' );
if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
$forceRawInterwiki = true;
}
if ( $title ) {
$titleText = $title->getPrefixedText();
# Check for language variants if the template is not found
- if ( $this->getConverterLanguage()->hasVariants() && $title->getArticleID() == 0 ) {
- $this->getConverterLanguage()->findVariantLink( $part1, $title, true );
+ if ( $this->getTargetLanguage()->hasVariants() && $title->getArticleID() == 0 ) {
+ $this->getTargetLanguage()->findVariantLink( $part1, $title, true );
}
# Do recursion depth check
$limit = $this->mOptions->getMaxTemplateDepth();
$rev_id = $rev ? $rev->getId() : 0;
# If there is no current revision, there is no page
if ( $id === false && !$rev ) {
- $linkCache = LinkCache::singleton();
+ $linkCache = MediaWikiServices::getInstance()->getLinkCache();
$linkCache->addBadLinkObj( $title );
}
*/
public function doDoubleUnderscore( $text ) {
# The position of __TOC__ needs to be recorded
- $mw = MagicWord::get( 'toc' );
+ $mw = $this->magicWordFactory->get( 'toc' );
if ( $mw->match( $text ) ) {
$this->mShowToc = true;
$this->mForceTocPosition = true;
}
# Now match and remove the rest of them
- $mwa = MagicWord::getDoubleUnderscoreArray();
+ $mwa = $this->magicWordFactory->getDoubleUnderscoreArray();
$this->mDoubleUnderscores = $mwa->matchAndRemove( $text );
if ( isset( $this->mDoubleUnderscores['nogallery'] ) ) {
# Avoid insertion of weird stuff like <math> by expanding the relevant sections
$safeHeadline = $this->mStripState->unstripBoth( $safeHeadline );
+ # Remove any <style> or <script> tags (T198618)
+ $safeHeadline = preg_replace(
+ '#<(style|script)(?: [^>]*[^>/])?>.*?</\1>#is',
+ '',
+ $safeHeadline
+ );
+
# Strip out HTML (first regex removes any tag not allowed)
# Allowed tags are:
# * <sup> and <sub> (T10393)
# @todo FIXME: Regex doesn't respect extension tags or nowiki
# => Move this logic to braceSubstitution()
- $substWord = MagicWord::get( 'subst' );
+ $substWord = $this->magicWordFactory->get( 'subst' );
$substRegex = '/\{\{(?!(?:' . $substWord->getBaseRegex() . '))/x' . $substWord->getRegexCase();
$substText = '{{' . $substWord->getSynonym( 0 );
$this->mFunctionHooks[$id] = [ $callback, $flags ];
# Add to function cache
- $mw = MagicWord::get( $id );
+ $mw = $this->magicWordFactory->get( $id );
if ( !$mw ) {
throw new MWException( __METHOD__ . '() expecting a magic word identifier.' );
}