*/
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(
* 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 ) {
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
* @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 ) {
*
* @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;
}
*/
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.' );
}