r22946 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22945‎ | r22946 | r22947 >
Date:10:49, 13 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Use parser output head items, and hence make output cacheable again \o/
Modified paths:
  • /trunk/extensions/PageCSS/PageCSS.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageCSS/PageCSS.php
@@ -10,43 +10,30 @@
1111 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1212 */
1313
14 -$wgExtensionFunctions[] = 'wfCssHook';
 14+$wgExtensionFunctions[] = array( 'CssHook', 'setup' );
1515 $wgExtensionCredits['parserhook'][] = array(
1616 'name' => 'Page CSS',
1717 'description' => 'A parser hook to add per-page css to pages with the <nowiki><css></nowiki> tag',
1818 'author' => 'Ævar Arnfjörð Bjarmason'
1919 );
2020
21 -function wfCssHook() {
22 - wfUsePHP( 5.1 );
23 - wfUseMW( '1.6alpha' );
24 -
25 - class CssHook {
26 - private $mCss;
27 -
28 - public function __construct() {
29 - global $wgParser, $wgHooks;
 21+class CssHook {
3022
31 - $wgParser->setHook( 'css' , array( &$this, 'parseHook' ) );
32 -
33 - $wgHooks['SkinTemplateSetupPageCss'][] = array( &$this, 'hook' );
34 - }
35 -
36 - public function parseHook( $in, array $argv, Parser $parser ) {
37 - global $wgCssHookCss;
38 -
39 - $this->mCss .= trim( Sanitizer::checkCss( $in ) );
40 - $parser->disableCache(); // workaround for now
41 - }
42 -
43 - public function hook( &$css ) {
44 - if ( $this->mCss != '' )
45 - $css = "/*<![CDATA[*/\n" . htmlspecialchars( $this->mCss ) . "\n/*]]>*/";
46 -
47 - return false;
48 - }
 23+ public static function setup() {
 24+ global $wgParser;
 25+ $wgParser->setHook( 'css', array( 'CssHook', 'parse' ) );
4926 }
 27+
 28+ public static function parse( $content, array $args, Parser $parser ) {
 29+ $css = htmlspecialchars( trim( Sanitizer::checkCss( $content ) ) );
 30+ $parser->mOutput->addHeadItem( <<<EOT
 31+<style type="text/css">
 32+/*<![CDATA[*/
 33+{$css}
 34+/*]]>*/
 35+</style>
 36+EOT
 37+ );
 38+ }
5039
51 - // Establish a singleton.
52 - new CssHook;
53 -}
 40+}
\ No newline at end of file

Status & tagging log