Few style tweaks

Parameter documentation type hints

Remove unused RL module

Change-Id: I6e265c97eababa4bbfebb9402141664ad24b4e43
This commit is contained in:
Reedy 2016-10-30 22:53:31 +00:00
parent b5be580f26
commit ca778e2b98
4 changed files with 34 additions and 20 deletions

View file

@ -51,7 +51,10 @@ class CSSParser {
(?# Unicode mask literals )
| .
(?# Any unmatched token is reduced to single characters )
)/xis', $css, $match );
)/xis',
$css,
$match
);
$inWhitespaceRun = false;
foreach ( $match[0] as $token ) {

View file

@ -34,13 +34,15 @@ class CSSRenderer {
case '@media':
if ( $media == '' ) {
$this->add(
$rule['rules'], "@media {$rule['text']}"
$rule['rules'],
"@media {$rule['text']}"
);
}
break;
case '':
$this->byMedia[$media] = array_merge(
$this->byMedia[$media], $rule['rules']
$this->byMedia[$media],
$rule['rules']
);
break;
}

View file

@ -1,4 +1,5 @@
<?php
/**
* TemplateStyles extension hooks
*
@ -9,12 +10,18 @@
class TemplateStylesHooks {
/**
* Register parser hooks
* @param Parser $parser
* @return bool
*/
public static function onParserFirstCallInit( &$parser ) {
$parser->setHook( 'templatestyles', 'TemplateStylesHooks::render' );
return true;
}
/**
* @param string $blob
* @return string
*/
private static function decodeFromBlob( $blob ) {
$tree = gzdecode( $blob );
if ( $tree ) {
@ -23,19 +30,28 @@ class TemplateStylesHooks {
return $tree;
}
/**
* @param string $tree
* @return string
*/
private static function encodeToBlob( $tree ) {
return gzencode( serialize( $tree ) );
}
public static function onOutputPageParserOutput( &$out, $parseroutput ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'templatestyles' );
/**
* @param OutputPage $out
* @param ParserOutput $parserOutput
*/
public static function onOutputPageParserOutput( &$out, $parserOutput ) {
$config = \MediaWiki\MediaWikiServices::getInstance()
->getConfigFactory()
->makeConfig( 'templatestyles' );
$renderer = new CSSRenderer();
$pages = [];
foreach ( self::getConfigArray( $config, 'Namespaces' ) as $ns ) {
if ( array_key_exists( $ns, $parseroutput->getTemplates() ) ) {
foreach ( $parseroutput->getTemplates()[$ns] as $title => $pageid ) {
if ( array_key_exists( $ns, $parserOutput->getTemplates() ) ) {
foreach ( $parserOutput->getTemplates()[$ns] as $title => $pageid ) {
$pages[$pageid] = $title;
}
}
@ -43,7 +59,10 @@ class TemplateStylesHooks {
if ( count( $pages ) ) {
$db = wfGetDB( DB_SLAVE );
$res = $db->select( 'page_props', [ 'pp_page', 'pp_value' ], [
$res = $db->select(
'page_props',
[ 'pp_page', 'pp_value' ],
[
'pp_page' => array_keys( $pages ),
'pp_propname' => 'templatestyles'
],
@ -59,7 +78,7 @@ class TemplateStylesHooks {
}
$selfcss = $parseroutput->getProperty( 'templatestyles' );
$selfcss = $parserOutput->getProperty( 'templatestyles' );
if ( $selfcss ) {
$selfcss = self::decodeFromBlob( $selfcss );
if ( $selfcss ) {

View file

@ -20,16 +20,6 @@
"CSSParser": "CSSParser.php",
"CSSRenderer": "CSSRenderer.php"
},
"ext.templateStyles": {
"scripts": [
],
"styles": [
],
"messages": [
],
"dependencies": [
]
},
"Hooks": {
"ParserFirstCallInit": [
"TemplateStylesHooks::onParserFirstCallInit"