Generic method to add stylesheets and scripts to the header from parser extensions. Using a hook is inefficient since it requires loading the code on a parser cache hit. This feature saves the header text to the parser cache, and writes it to the output with no hook being called. Ugly getScript() hack to make it work with third-party skins.
This commit is contained in:
parent
b2666d2d51
commit
d3e07758d4
2 changed files with 34 additions and 5 deletions
|
|
@ -47,6 +47,7 @@ class OutputPage {
|
||||||
$this->mParserOptions = null;
|
$this->mParserOptions = null;
|
||||||
$this->mSquidMaxage = 0;
|
$this->mSquidMaxage = 0;
|
||||||
$this->mScripts = '';
|
$this->mScripts = '';
|
||||||
|
$this->mHeadItems = array();
|
||||||
$this->mETag = false;
|
$this->mETag = false;
|
||||||
$this->mRevisionId = null;
|
$this->mRevisionId = null;
|
||||||
$this->mNewSectionLink = false;
|
$this->mNewSectionLink = false;
|
||||||
|
|
@ -80,7 +81,18 @@ class OutputPage {
|
||||||
$this->mScripts .= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
|
$this->mScripts .= "<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n$script\n/*]]>*/</script>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getScript() { return $this->mScripts; }
|
function getScript() {
|
||||||
|
return $this->mScripts . $this->getHeadItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHeadItems() {
|
||||||
|
$s = '';
|
||||||
|
foreach ( $this->mHeadItems as $item ) {
|
||||||
|
$s .= $item;
|
||||||
|
}
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function setETag($tag) { $this->mETag = $tag; }
|
function setETag($tag) { $this->mETag = $tag; }
|
||||||
function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
|
function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
|
||||||
|
|
@ -355,6 +367,7 @@ class OutputPage {
|
||||||
$this->mSubtitle .= $parserOutput->mSubtitle ;
|
$this->mSubtitle .= $parserOutput->mSubtitle ;
|
||||||
}
|
}
|
||||||
$this->mNoGallery = $parserOutput->getNoGallery();
|
$this->mNoGallery = $parserOutput->getNoGallery();
|
||||||
|
$this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->mHeadItems );
|
||||||
wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
|
wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1101,6 +1114,7 @@ class OutputPage {
|
||||||
$ret .= $sk->getHeadScripts();
|
$ret .= $sk->getHeadScripts();
|
||||||
$ret .= $this->mScripts;
|
$ret .= $this->mScripts;
|
||||||
$ret .= $sk->getUserStyles();
|
$ret .= $sk->getUserStyles();
|
||||||
|
$ret .= $this->getHeadItems();
|
||||||
|
|
||||||
if ($wgUseTrackbacks && $this->isArticleRelated())
|
if ($wgUseTrackbacks && $this->isArticleRelated())
|
||||||
$ret .= $wgTitle->trackbackRDF();
|
$ret .= $wgTitle->trackbackRDF();
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,11 @@ class ParserOutput
|
||||||
$mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
|
$mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
|
||||||
$mImages, # DB keys of the images used, in the array key only
|
$mImages, # DB keys of the images used, in the array key only
|
||||||
$mExternalLinks, # External link URLs, in the key only
|
$mExternalLinks, # External link URLs, in the key only
|
||||||
$mHTMLtitle, # Display HTML title
|
$mHTMLtitle, # Display HTML title
|
||||||
$mSubtitle, # Additional subtitle
|
$mSubtitle, # Additional subtitle
|
||||||
$mNewSection, # Show a new section link?
|
$mNewSection, # Show a new section link?
|
||||||
$mNoGallery; # No gallery on category page? (__NOGALLERY__)
|
$mNoGallery, # No gallery on category page? (__NOGALLERY__)
|
||||||
|
$mHeadItems; # Items to put in the <head> section
|
||||||
|
|
||||||
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
|
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
|
||||||
$containsOldMagic = false, $titletext = '' )
|
$containsOldMagic = false, $titletext = '' )
|
||||||
|
|
@ -38,6 +39,7 @@ class ParserOutput
|
||||||
$this->mSubtitle = "" ;
|
$this->mSubtitle = "" ;
|
||||||
$this->mNewSection = false;
|
$this->mNewSection = false;
|
||||||
$this->mNoGallery = false;
|
$this->mNoGallery = false;
|
||||||
|
$this->mHeadItems = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getText() { return $this->mText; }
|
function getText() { return $this->mText; }
|
||||||
|
|
@ -112,6 +114,19 @@ class ParserOutput
|
||||||
!isset( $this->mVersion ) ||
|
!isset( $this->mVersion ) ||
|
||||||
version_compare( $this->mVersion, Parser::VERSION, "lt" );
|
version_compare( $this->mVersion, Parser::VERSION, "lt" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add some text to the <head>.
|
||||||
|
* If $tag is set, the section with that tag will only be included once
|
||||||
|
* in a given page.
|
||||||
|
*/
|
||||||
|
function addHeadItem( $section, $tag = false ) {
|
||||||
|
if ( $tag !== false ) {
|
||||||
|
$this->mHeadItems[$tag] = $section;
|
||||||
|
} else {
|
||||||
|
$this->mHeadItems[] = $section;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue