$oldTidy = $popts->setTidy( $tidy );
$popts->setInterfaceMessage( (bool)$interface );
- $parserOutput = $wgParser->parse(
+ $parserOutput = $wgParser->getFreshParser()->parse(
$text, $title, $popts,
$linestart, true, $this->mRevisionId
);
}
/**
- * Add a ParserOutput object, but without Html
+ * Add a ParserOutput object, but without Html.
*
+ * @deprecated since 1.24, use addParserOutputMetadata() instead.
* @param ParserOutput $parserOutput
*/
public function addParserOutputNoText( &$parserOutput ) {
+ $this->addParserOutputMetadata( $parserOutput );
+ }
+
+ /**
+ * Add all metadata associated with a ParserOutput object, but without the actual HTML. This
+ * includes categories, language links, ResourceLoader modules, effects of certain magic words,
+ * and so on.
+ *
+ * @since 1.24
+ * @param ParserOutput $parserOutput
+ */
+ public function addParserOutputMetadata( &$parserOutput ) {
$this->mLanguageLinks += $parserOutput->getLanguageLinks();
$this->addCategoryLinks( $parserOutput->getCategories() );
$this->mNewSectionLink = $parserOutput->getNewSection();
}
/**
- * Add a ParserOutput object
+ * Add the HTML and enhancements for it (like ResourceLoader modules) associated with a
+ * ParserOutput object, without any other metadata.
+ *
+ * @since 1.24
+ * @param ParserOutput $parserOutput
+ */
+ public function addParserOutputContent( &$parserOutput ) {
+ $this->addParserOutputText( $parserOutput );
+
+ $this->addModules( $parserOutput->getModules() );
+ $this->addModuleScripts( $parserOutput->getModuleScripts() );
+ $this->addModuleStyles( $parserOutput->getModuleStyles() );
+ $this->addModuleMessages( $parserOutput->getModuleMessages() );
+
+ $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
+ }
+
+ /**
+ * Add the HTML associated with a ParserOutput object, without any metadata.
+ *
+ * @since 1.24
+ * @param ParserOutput $parserOutput
+ */
+ public function addParserOutputText( &$parserOutput ) {
+ $text = $parserOutput->getText();
+ wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
+ $this->addHTML( $text );
+ }
+
+ /**
+ * Add everything from a ParserOutput object.
*
* @param ParserOutput $parserOutput
*/
function addParserOutput( &$parserOutput ) {
- $this->addParserOutputNoText( $parserOutput );
+ $this->addParserOutputMetadata( $parserOutput );
$parserOutput->setTOCEnabled( $this->mEnableTOC );
// Touch section edit links only if not previously disabled
if ( $parserOutput->getEditSectionTokens() ) {
$parserOutput->setEditSectionTokens( $this->mEnableSectionEditLinks );
}
- $text = $parserOutput->getText();
- wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
- $this->addHTML( $text );
+
+ $this->addParserOutputText( $parserOutput );
}
/**
$oldLang = $popts->setTargetLanguage( $language );
}
- $parserOutput = $wgParser->parse(
+ $parserOutput = $wgParser->getFreshParser()->parse(
$text, $this->getTitle(), $popts,
$linestart, true, $this->mRevisionId
);
* @private
*/
function replaceInternalLinks2( &$s ) {
+ global $wgExtraInterlanguageLinkPrefixes;
wfProfileIn( __METHOD__ );
wfProfileIn( __METHOD__ . '-setup' );
if ( $noforce ) {
# Interwikis
wfProfileIn( __METHOD__ . "-interwiki" );
- if ( $iw && $this->mOptions->getInterwikiMagic()
- && $nottalk && Language::fetchLanguageName( $iw, null, 'mw' )
+ if (
+ $iw && $this->mOptions->getInterwikiMagic() && $nottalk && (
+ Language::fetchLanguageName( $iw, null, 'mw' ) ||
+ in_array( $iw, $wgExtraInterlanguageLinkPrefixes )
+ )
) {
- // XXX: the above check prevents links to sites with identifiers that are not language codes
-
# Bug 24502: filter duplicates
if ( !isset( $this->mLangLinkLanguages[$iw] ) ) {
$this->mLangLinkLanguages[$iw] = true;
} else {
$localLinkTitle = Title::newFromText( $linkValue );
if ( $localLinkTitle !== null ) {
- $link = $localLinkTitle->getLocalURL();
+ $link = $localLinkTitle->getLinkURL();
}
}
break;
return $html;
}
+
+ /**
+ * Return this parser if it is not doing anything, otherwise
+ * get a fresh parser. You can use this method by doing
+ * $myParser = $wgParser->getFreshParser(), or more simply
+ * $wgParser->getFreshParser()->parse( ... );
+ * if you're unsure if $wgParser is safe to use.
+ *
+ * @since 1.24
+ * @return Parser A parser object that is not parsing anything
+ */
+ public function getFreshParser() {
+ global $wgParserConf;
+ if ( $this->mInParse ) {
+ return new $wgParserConf['class']( $wgParserConf );
+ } else {
+ return $this;
+ }
+ }
}