Index: trunk/extensions/PageCSS/PageCSS.php |
— | — | @@ -10,43 +10,30 @@ |
11 | 11 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | 12 | */ |
13 | 13 | |
14 | | -$wgExtensionFunctions[] = 'wfCssHook'; |
| 14 | +$wgExtensionFunctions[] = array( 'CssHook', 'setup' ); |
15 | 15 | $wgExtensionCredits['parserhook'][] = array( |
16 | 16 | 'name' => 'Page CSS', |
17 | 17 | 'description' => 'A parser hook to add per-page css to pages with the <nowiki><css></nowiki> tag', |
18 | 18 | 'author' => 'Ævar Arnfjörð Bjarmason' |
19 | 19 | ); |
20 | 20 | |
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 { |
30 | 22 | |
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' ) ); |
49 | 26 | } |
| 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 | + } |
50 | 39 | |
51 | | - // Establish a singleton. |
52 | | - new CssHook; |
53 | | -} |
| 40 | +} |
\ No newline at end of file |