SamanthaNguyen has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/357303 )
Change subject: v3.5.0 - Delete backward-compatibility files, require 1.25+ ...................................................................... v3.5.0 - Delete backward-compatibility files, require 1.25+ Change-Id: I8a1f9d65c1725911508012bb20cc4393f4e244b2 --- A CSS.class.php D CSS.i18n.php D CSS.php A extension.json 4 files changed, 119 insertions(+), 143 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CSS refs/changes/03/357303/1 diff --git a/CSS.class.php b/CSS.class.php new file mode 100644 index 0000000..ead74b7 --- /dev/null +++ b/CSS.class.php @@ -0,0 +1,87 @@ +<?php +/** + * CSS extension - A parser-function for adding CSS to articles via file, + * article or inline rules. + * + * See http://www.mediawiki.org/wiki/Extension:CSS for installation and usage + * details. + * + * @file + * @ingroup Extensions + * @author Aran Dunkley [http://www.organicdesign.co.nz/nad User:Nad] + * @author Rusty Burchfield + * @copyright © 2007-2010 Aran Dunkley + * @copyright © 2011 Rusty Burchfield + * @licence GNU General Public Licence 2.0 or later + */ + +class CSS { + /** + * @param Parser $parser + * @param string $css + * @return string + * @throws MWException + */ + function wfCSSRender( &$parser, $css ) { + global $wgCSSPath, $wgStylePath, $wgCSSIdentifier; + + $css = trim( $css ); + $title = Title::newFromText( $css ); + $rawProtection = "$wgCSSIdentifier=1"; + $headItem = '<!-- Begin Extension:CSS -->'; + + if ( is_object( $title ) && $title->exists() ) { + # Article actually in the db + $params = "action=raw&ctype=text/css&$rawProtection"; + $url = $title->getLocalURL( $params ); + $headItem .= Html::linkedStyle( $url ); + } elseif ( $css[0] == '/' ) { + # Regular file + $base = $wgCSSPath === false ? $wgStylePath : $wgCSSPath; + $url = wfAppendQuery( $base . $css, $rawProtection ); + + # Verify the expanded URL is still using the base URL + if ( strpos( wfExpandUrl( $url ), wfExpandUrl( $base ) ) === 0 ) { + $headItem .= Html::linkedStyle( $url ); + } else { + $headItem .= '<!-- Invalid/malicious path -->'; + } + } else { + # sanitized user CSS + $css = Sanitizer::checkCss( $css ); + + # Encode data URI and append link tag + $dataPrefix = 'data:text/css;charset=UTF-8;base64,'; + $url = $dataPrefix . base64_encode( $css ); + + $headItem .= Html::linkedStyle( $url ); + } + + $headItem .= '<!-- End Extension:CSS -->'; + $parser->getOutput()->addHeadItem( $headItem ); + return ''; + } + + /** + * @param Parser $parser + * @return bool true + */ + public static function onParserFirstCallInit( $parser ) { + $parser->setFunctionHook( 'css', 'wfCSSRender' ); + return true; + } + + /** + * @param RawPage $rawPage + * @param string $text + * @return bool true + */ + public static function onRawPageViewBeforeOutput( &$rawPage, &$text ) { + global $wgCSSIdentifier; + + if ( $rawPage->getRequest()->getBool( $wgCSSIdentifier ) ) { + $text = Sanitizer::checkCss( $text ); + } + return true; + } +} diff --git a/CSS.i18n.php b/CSS.i18n.php deleted file mode 100644 index 57cd273..0000000 --- a/CSS.i18n.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** - * This is a backwards-compatibility shim, generated by: - * https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php - * - * Beginning with MediaWiki 1.23, translation strings are stored in json files, - * and the EXTENSION.i18n.php file only exists to provide compatibility with - * older releases of MediaWiki. For more information about this migration, see: - * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format - * - * This shim maintains compatibility back to MediaWiki 1.17. - */ -$messages = array(); -if ( !function_exists( 'wfJsonI18nShim1fc70790a07163f4' ) ) { - function wfJsonI18nShim1fc70790a07163f4( $cache, $code, &$cachedData ) { - $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] ); - foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; - if ( is_readable( $fileName ) ) { - $data = FormatJson::decode( file_get_contents( $fileName ), true ); - foreach ( array_keys( $data ) as $key ) { - if ( $key === '' || $key[0] === '@' ) { - unset( $data[$key] ); - } - } - $cachedData['messages'] = array_merge( $data, $cachedData['messages'] ); - } - - $cachedData['deps'][] = new FileDependency( $fileName ); - } - return true; - } - - $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShim1fc70790a07163f4'; -} diff --git a/CSS.php b/CSS.php deleted file mode 100644 index 42b43dc..0000000 --- a/CSS.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php -/** - * CSS extension - A parser-function for adding CSS to articles via file, - * article or inline rules. - * - * See http://www.mediawiki.org/wiki/Extension:CSS for installation and usage - * details. - * - * @file - * @ingroup Extensions - * @author Aran Dunkley [http://www.organicdesign.co.nz/nad User:Nad] - * @author Rusty Burchfield - * @copyright © 2007-2010 Aran Dunkley - * @copyright © 2011 Rusty Burchfield - * @licence GNU General Public Licence 2.0 or later - */ - -if ( !defined( 'MEDIAWIKI' ) ) { - die( 'Not an entry point.' ); -} - -$wgCSSPath = false; -$wgCSSIdentifier = 'css-extension'; - -$wgHooks['ParserFirstCallInit'][] = 'wfCSSParserFirstCallInit'; -$wgHooks['RawPageViewBeforeOutput'][] = 'wfCSSRawPageViewBeforeOutput'; - -$wgExtensionCredits['parserhook'][] = array( - 'path' => __FILE__, - 'name' => 'CSS', - 'author' => array ( 'Aran Dunkley', 'Rusty Burchfield' ), - 'descriptionmsg' => 'css-desc', - 'url' => 'https://www.mediawiki.org/wiki/Extension:CSS', - 'version' => '3.4.0', -); - -$wgMessagesDirs['CSS'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['CSS'] = dirname( __FILE__ ) . '/' . 'CSS.i18n.php'; -$wgExtensionMessagesFiles['CSSMagic'] = dirname( __FILE__ ) . '/' . 'CSS.i18n.magic.php'; - -/** - * @param Parser $parser - * @param string $css - * @return string - * @throws MWException - */ -function wfCSSRender( &$parser, $css ) { - global $wgCSSPath, $wgStylePath, $wgCSSIdentifier; - - $css = trim( $css ); - $title = Title::newFromText( $css ); - $rawProtection = "$wgCSSIdentifier=1"; - $headItem = '<!-- Begin Extension:CSS -->'; - - if ( is_object( $title ) && $title->exists() ) { - # Article actually in the db - $params = "action=raw&ctype=text/css&$rawProtection"; - $url = $title->getLocalURL( $params ); - $headItem .= Html::linkedStyle( $url ); - } elseif ( $css[0] == '/' ) { - # Regular file - $base = $wgCSSPath === false ? $wgStylePath : $wgCSSPath; - $url = wfAppendQuery( $base . $css, $rawProtection ); - - # Verify the expanded URL is still using the base URL - if ( strpos( wfExpandUrl( $url ), wfExpandUrl( $base ) ) === 0 ) { - $headItem .= Html::linkedStyle( $url ); - } else { - $headItem .= '<!-- Invalid/malicious path -->'; - } - } else { - # sanitized user CSS - $css = Sanitizer::checkCss( $css ); - - # Encode data URI and append link tag - $dataPrefix = 'data:text/css;charset=UTF-8;base64,'; - $url = $dataPrefix . base64_encode( $css ); - - $headItem .= Html::linkedStyle( $url ); - } - - $headItem .= '<!-- End Extension:CSS -->'; - $parser->getOutput()->addHeadItem( $headItem ); - return ''; -} - -/** - * @param Parser $parser - * @return bool - */ -function wfCSSParserFirstCallInit( $parser ) { - $parser->setFunctionHook( 'css', 'wfCSSRender' ); - return true; -} - -/** - * @param RawPage $rawPage - * @param string $text - * @return bool - */ -function wfCSSRawPageViewBeforeOutput( &$rawPage, &$text ) { - global $wgCSSIdentifier; - - if ( $rawPage->getRequest()->getBool( $wgCSSIdentifier ) ) { - $text = Sanitizer::checkCss( $text ); - } - return true; -} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..f08c10b --- /dev/null +++ b/extension.json @@ -0,0 +1,32 @@ +{ + "name": "CSS", + "version": "3.5.0", + "author": [ + "Aran Dunkley", + "Rusty Burchfield" + ], + "url": "https://www.mediawiki.org/wiki/Extension:CSS", + "descriptionmsg": "css-desc", + "license-name": "GPL-2.0+", + "type": "parserhook", + "ExtensionMessagesFiles": { + "CSSMagic": "CSS.i18n.magic.php" + }, + "MessageDirs": { + "CSS": [ + "i18n" + ] + }, + "AutoloadClasses": { + "CSS": "CSS.class.php" + }, + "Hooks": { + "ParserFirstCallInit": "CSS::onParserFirstCallInit", + "RawPageViewBeforeOutput": "CSS::onRawPageViewBeforeOutput" + }, + "config": { + "CSSPath": false, + "CSSIdentifier": "css-extension" + }, + "manifest_version": 1 +} -- To view, visit https://gerrit.wikimedia.org/r/357303 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8a1f9d65c1725911508012bb20cc4393f4e244b2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CSS Gerrit-Branch: master Gerrit-Owner: SamanthaNguyen <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
