Reedy has uploaded a new change for review. https://gerrit.wikimedia.org/r/315865
Change subject: Revert "Convert ZeroBanner to extension registration" ...................................................................... Revert "Convert ZeroBanner to extension registration" This reverts commit 661408d9e24bbc3350bb3dcce1f910eda6e45420. Change-Id: I0a5e29a9783b43b6d2eef51f4bc13894ceb579e5 --- M README A ZeroBanner.i18n.php M ZeroBanner.php D extension.json M includes/PageRenderingHooks.php 5 files changed, 238 insertions(+), 230 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroBanner refs/changes/65/315865/1 diff --git a/README b/README index 05a33c0..f4217d2 100644 --- a/README +++ b/README @@ -64,27 +64,6 @@ $ vagrant enable-role zero $ vagrant provision -=== Extension configuration === -All Zero-related wikis, including ZeroPortal, will get this configuration: - -$wgJsonConfigs['JsonZeroConfig'] = array( - 'namespace' => NS_ZERO, - 'nsName' => 'Zero', - 'isLocal' => false, // shared cross-wiki - 'cacheKey' => '1', // update when breaking json config structure - to simplify rollbacks -); - -All wikis except for the portal need further customization. They need to know how to access -remote zero configuration, using the given username and password. -On the other hand, ZeroPortal on the other hand, will specify to use current wiki for storage. -See JsonConfig extension documentation for more info. - -$wgJsonConfigs['JsonZeroConfig']['remote'] = array( - 'url' => 'https://zero.wikimedia.org/w/api.php', - 'username' => ..., - 'password' => ..., -); - == Testing == diff --git a/ZeroBanner.i18n.php b/ZeroBanner.i18n.php new file mode 100644 index 0000000..532393c --- /dev/null +++ b/ZeroBanner.i18n.php @@ -0,0 +1,35 @@ +<?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( 'wfJsonI18nShim625f69e14aead689' ) ) { + function wfJsonI18nShim625f69e14aead689( $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'][] = 'wfJsonI18nShim625f69e14aead689'; +} diff --git a/ZeroBanner.php b/ZeroBanner.php index 3fc6d50..ffdd7dc 100644 --- a/ZeroBanner.php +++ b/ZeroBanner.php @@ -1,18 +1,206 @@ <?php +/** + * Extension ZeroBanner — Zero Banners + * + * @file + * @ingroup Extensions + * @author Patrick Reilly + * @author Yuri Astrakhan + * @copyright © 2011 Patrick Reilly, 2013-2014 Yuri Astrakhan + * @licence GNU General Public Licence 2.0 or later + */ -if ( function_exists( 'wfLoadExtension' ) ) { - wfLoadExtension( 'ZeroBanner' ); - // Keep i18n globals so mergeMessageFileList.php doesn't break - $wgMessagesDirs['ZeroBanner'] = __DIR__ . '/i18n'; - $wgExtensionMessagesFiles['ZeroBanner'] = __DIR__ . '/ZeroBanner.i18n.php'; - $wgExtensionMessagesFiles['ZeroBannerAlias'] = __DIR__ . '/ZeroBanner.alias.php'; - $wgExtensionMessagesFiles['ZeroRatedMobileAccessAlias'] = __DIR__ . '/ZeroBanner.alias.php'; - /* wfWarn( - 'Deprecated PHP entry point used for ZeroBanner extension. ' . - 'Please use wfLoadExtension instead, ' . - 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' - ); */ - return; -} else { - die( 'This version of the ZeroBanner extension requires MediaWiki 1.28+' ); +// Needs to be called within MediaWiki; not standalone +if ( !defined( 'MEDIAWIKI' ) ) { + echo( "This is a MediaWiki extension and cannot run standalone.\n" ); + die( -1 ); } + +// Extension credits that will show up on Special:Version +$wgExtensionCredits['other'][] = array( + 'path' => __FILE__, + 'name' => 'ZeroBanner', + 'version' => '1.0.0', + 'author' => array( 'Patrick Reilly', 'Yuri Astrakhan' ), + 'descriptionmsg' => 'zero-desc', + 'url' => 'https://www.mediawiki.org/wiki/Extension:ZeroBanner', + 'license-name' => 'GPL-2.0+', +); + +$zbDir = __DIR__ . DIRECTORY_SEPARATOR; +$wgMessagesDirs['ZeroBanner'] = $zbDir . 'i18n'; +$wgExtensionMessagesFiles['ZeroBanner'] = $zbDir . 'ZeroBanner.i18n.php'; +$wgExtensionMessagesFiles['ZeroBannerAlias'] = $zbDir . "ZeroBanner.alias.php"; + +$wgSpecialPages['ZeroRatedMobileAccess'] = 'ZeroBanner\ZeroSpecialPage'; +$wgExtensionMessagesFiles['ZeroRatedMobileAccessAlias'] = $zbDir . "ZeroBanner.alias.php"; + +$wgAutoloadClasses['GDText\\Box'] = $zbDir . 'vendor/stil/gd-text/src/Box.php'; +$wgAutoloadClasses['GDText\\Color'] = $zbDir . 'vendor/stil/gd-text/src/Color.php'; + +// autoload extension classes +$zbDir .= 'includes' . DIRECTORY_SEPARATOR; +foreach ( + array( + 'ApiRawJsonPrinter' => 'ApiZeroBanner', + 'ApiZeroBanner', + 'PageRendering', + 'TestHooks', + 'PageRenderingHooks', + 'ZeroConfig', + 'ZeroSpecialPage' + ) as $key => $class ) { + $wgAutoloadClasses['ZeroBanner\\' . ( is_string( $key ) ? $key : $class )] = $zbDir . $class . '.php'; +} +unset( $zbDir ); + +$remoteExtPath = 'ZeroBanner'; + +$wgResourceModules['zerobanner.styles'] = array( + 'position' => 'top', + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => 'mobile', + 'styles' => array( 'modules/banner.css', 'modules/redux.less' ), +); + +// this resource is used by the ZeroPortal to display banners on the desktop site +$wgResourceModules['zerobanner.config.styles'] = array( + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => array( 'desktop', 'mobile' ), + 'styles' => 'modules/banner.css', +); + +$wgResourceModules['zerobanner.interstitial'] = array( + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => array( + 'mobile' + ), + 'dependencies' => array( + 'mobile.overlays', + 'mobile.settings', + ), + 'templates' => array( + 'interstitial.hogan' => 'modules/zerobanner.interstitial/interstitial.hogan', + 'zeroinfo.hogan' => 'modules/zerobanner.interstitial/zeroinfo.hogan' + ), + 'scripts' => array( + 'modules/zerobanner.interstitial/ZeroOverlay.js' + ), + 'styles' => array( + 'modules/zerobanner.interstitial/interstitial.less' + ), +); + +$wgResourceModules['zerobanner'] = array( + 'dependencies' => array( + 'mediawiki.router', + 'mobile.settings', + 'zerobanner.styles' + ), + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => array( + 'mobile' + ), + 'scripts' => array( + 'modules/banner.js', + 'modules/interstitial.js', + ), + 'messages' => array( + 'cancel', + 'zero-charge-auth', + 'zero-file-auth', + 'zero-accept', + 'zero-go-back', + 'zero-dont-ask', + 'zero-interstitial-title', + 'zero-info-title', + 'zero-info-intro', + 'zero-info-buttonText', + 'zero-info-url', + 'zero-info-url-free', + 'zero-info-url-not-free', + 'zero-info-langs', + 'zero-info-proxy', + 'zero-info-geek' + ), +); + +$wgResourceModules['zerobanner.special.scripts'] = array( + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => array( 'mobile' ), + 'scripts' => array( 'modules/forms.js' ), +); + +$wgResourceModules['zerobanner.special.styles'] = array( + 'position' => 'top', + 'localBasePath' => __DIR__, + 'remoteExtPath' => $remoteExtPath, + 'targets' => array( 'mobile' ), + 'styles' => array( 'modules/forms.css' ), +); + +/** @var false|string[] $wgZeroSiteOverride For testing, overrides $wgConf->siteFromDB( $wgDBname ) + * On a test wiki, set it to array( 'wikipedia', 'en' ) or similar. + * ZeroBanner explicitly checks for the site to equal 'wikipedia' before enabling Zero. + */ +$wgZeroSiteOverride = false; + +/** @var string $wgZeroBannerClusterDomain Temporary workaround - until I figure out how to calculate it */ +$wgZeroBannerClusterDomain = 'org'; + +/** @var int $wgZeroBannerImageFontSize size of the font used for the image */ +$wgZeroBannerImageFontSize = 14; + +/** @var int $wgZeroBannerImageWidth size of the image banner width */ +$wgZeroBannerImageWidth = 320; + +/** @var int $wgZeroBannerImageHeight size of the image banner width */ +$wgZeroBannerImageHeight = 28; + +/** @var int $wgZeroBannerErrImageWidth size of the error image width */ +$wgZeroBannerErrImageWidth = 320; + +/** @var int $wgZeroBannerErrImageHeight size of the error image width */ +$wgZeroBannerErrImageHeight = 200; + + +/** @var string|false $wgZeroBannerFont use a specific font for image banners */ +$wgZeroBannerFont = __DIR__ . '/unifont/unifont_csur-7.0.03.ttf'; + +$hook = 'ZeroBanner\\PageRenderingHooks::'; +$wgHooks['BeforePageDisplayMobile'][] = $hook . 'onBeforePageDisplay'; +$wgHooks['GetMobileUrl'][] = $hook . 'onGetMobileUrl'; +$wgHooks['MinervaPreRender'][] = $hook . 'onMinervaPreRender'; +$wgHooks['MobileFrontendBeforeDOM'][] = $hook . 'onMobileFrontendBeforeDOM'; +$wgHooks['MakeGlobalVariablesScript'][] = $hook . 'onMakeGlobalVariablesScript'; +$wgHooks['SpecialMobileEditWatchlist::images'][] = $hook . 'onSpecialMobileEditWatchlist_images'; + +$wgHooks['ResourceLoaderTestModules'][] = 'ZeroBanner\\TestHooks::onResourceLoaderTestModules'; + +$wgAPIModules['zeroconfig'] = 'ZeroBanner\ApiZeroBanner'; + +// Define constants but don't add them to the namespace list - they will be used for external access only +define( 'NS_ZERO', 480 ); +define( 'NS_ZERO_TALK', 481 ); + + +// ZeroPortal will further customize this by adding a 'view' +$wgJsonConfigModels['JsonZeroConfig'] = array( 'class' => 'ZeroBanner\ZeroConfig' ); + +// All wikis except for portal need further customization: +// $wgJsonConfigs['JsonZeroConfig']['remote'] = array( +// 'url' => 'https://zero.wikimedia.org/w/api.php', +// 'username' => ..., +// 'password' => ..., +// ); +$wgJsonConfigs['JsonZeroConfig'] = array( + 'namespace' => NS_ZERO, + 'nsName' => 'Zero', + 'isLocal' => false, // shared cross-wiki + 'cacheKey' => '1', // update when breaking json config structure - to simplify rollbacks +); diff --git a/extension.json b/extension.json deleted file mode 100644 index a50f8ac..0000000 --- a/extension.json +++ /dev/null @@ -1,188 +0,0 @@ -{ - "name": "ZeroBanner", - "version": "1.1.0", - "author": [ - "Patrick Reilly", - "Yuri Astrakhan" - ], - "url": "https://www.mediawiki.org/wiki/Extension:ZeroBanner", - "descriptionmsg": "zero-desc", - "license-name": "GPL-2.0+", - "type": "other", - "callback": "ZeroBanner\\PageRenderingHooks::registerExtension", - "SpecialPages": { - "ZeroRatedMobileAccess": "ZeroBanner\\ZeroSpecialPage" - }, - "APIModules": { - "zeroconfig": "ZeroBanner\\ApiZeroBanner" - }, - "MessagesDirs": { - "ZeroBanner": [ - "i18n" - ] - }, - "ExtensionMessagesFiles": { - "ZeroBannerAlias": "ZeroBanner.alias.php", - "ZeroRatedMobileAccessAlias": "ZeroBanner.alias.php" - }, - "AutoloadClasses": { - "GDText\\Box": "vendor/stil/gd-text/src/Box.php", - "GDText\\Color": "vendor/stil/gd-text/src/Color.php", - "ZeroBanner\\ApiRawJsonPrinter": "includes/ApiZeroBanner.php", - "ZeroBanner\\ApiZeroBanner": "includes/ApiZeroBanner.php", - "ZeroBanner\\PageRendering": "includes/PageRendering.php", - "ZeroBanner\\PageRenderingHooks": "includes/PageRenderingHooks.php", - "ZeroBanner\\TestHooks": "includes/TestHooks.php", - "ZeroBanner\\ZeroConfig": "includes/ZeroConfig.php", - "ZeroBanner\\ZeroSpecialPage": "includes/ZeroSpecialPage.php" - }, - "ResourceModules": { - "zerobanner.styles": { - "position": "top", - "targets": "mobile", - "styles": [ - "banner.css", - "redux.less" - ] - }, - "zerobanner.config.styles": { - "targets": [ - "desktop", - "mobile" - ], - "styles": "banner.css" - }, - "zerobanner.interstitial": { - "targets": [ - "mobile" - ], - "dependencies": [ - "mobile.overlays", - "mobile.settings" - ], - "templates": { - "interstitial.hogan": "zerobanner.interstitial/interstitial.hogan", - "zeroinfo.hogan": "zerobanner.interstitial/zeroinfo.hogan" - }, - "scripts": [ - "zerobanner.interstitial/ZeroOverlay.js" - ], - "styles": [ - "zerobanner.interstitial/interstitial.less" - ] - }, - "zerobanner": { - "dependencies": [ - "mediawiki.router", - "mobile.settings", - "zerobanner.styles" - ], - "targets": [ - "mobile" - ], - "scripts": [ - "banner.js", - "interstitial.js" - ], - "messages": [ - "cancel", - "zero-charge-auth", - "zero-file-auth", - "zero-accept", - "zero-go-back", - "zero-dont-ask", - "zero-interstitial-title", - "zero-info-title", - "zero-info-intro", - "zero-info-buttonText", - "zero-info-url", - "zero-info-url-free", - "zero-info-url-not-free", - "zero-info-langs", - "zero-info-proxy", - "zero-info-geek" - ] - }, - "zerobanner.special.scripts": { - "targets": [ - "mobile" - ], - "scripts": [ - "forms.js" - ] - }, - "zerobanner.special.styles": { - "position": "top", - "targets": [ - "mobile" - ], - "styles": [ - "forms.css" - ] - } - }, - "ResourceFileModulePaths": { - "localBasePath": "modules", - "remoteExtPath": "ZeroBanner/modules" - }, - "Hooks": { - "BeforePageDisplayMobile": "ZeroBanner\\PageRenderingHooks::onBeforePageDisplay", - "GetMobileUrl": "ZeroBanner\\PageRenderingHooks::onGetMobileUrl", - "MinervaPreRender": "ZeroBanner\\PageRenderingHooks::onMinervaPreRender", - "MobileFrontendBeforeDOM": "ZeroBanner\\PageRenderingHooks::onMobileFrontendBeforeDOM", - "MakeGlobalVariablesScript": "ZeroBanner\\PageRenderingHooks::onMakeGlobalVariablesScript", - "SpecialMobileEditWatchlist::images": "ZeroBanner\\PageRenderingHooks::onSpecialMobileEditWatchlist_images", - "ResourceLoaderTestModules": "ZeroBanner\\TestHooks::onResourceLoaderTestModules" - }, - "JsonConfigModels": { - "JsonZeroConfig": { - "class": "ZeroBanner\\ZeroConfig" - } - }, - "JsonConfigs": { - "JsonZeroConfig": { - "namespace": 480, - "nsName": "Zero", - "isLocal": false, - "cacheKey": "1" - } - }, - "config": { - "ZeroSiteOverride": { - "@note": "false|string[] For testing, overrides Conf->siteFromDB( DBname )", - "@note2": "On a test wiki, set it to ['wikipedia','en'] or similar.", - "@note3": "ZeroBanner explicitly checks for the site to equal 'wikipedia' before enabling Zero.", - "value": false - }, - "ZeroBannerClusterDomain": { - "@note": "string Temporary workaround - until I figure out how to calculate it", - "value": "org" - }, - "ZeroBannerImageFontSize": { - "@note": "int size of the font used for the image", - "value": 14 - }, - "ZeroBannerImageWidth": { - "@note": "int size of the image banner width", - "value": 320 - }, - "ZeroBannerImageHeight": { - "@note": "int size of the image banner width", - "value": 28 - }, - "ZeroBannerErrImageWidth": { - "@note": "int size of the error image width", - "value": 320 - }, - "ZeroBannerErrImageHeight": { - "@note": "int size of the error image width", - "value": 200 - }, - "ZeroBannerFont": { - "value": "unifont/unifont_csur-7.0.03.ttf", - "path": true - } - }, - "load_composer_autoloader": true, - "manifest_version": 2 -} diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php index 4f501c3..8135497 100644 --- a/includes/PageRenderingHooks.php +++ b/includes/PageRenderingHooks.php @@ -19,12 +19,6 @@ */ class PageRenderingHooks { - public static function registerExtension() { - // Define constants but don't add them to the namespace list - they will be used for external access only - define( 'NS_ZERO', 480 ); - define( 'NS_ZERO_TALK', 481 ); - } - /** * @param IContextSource $context * @return PageRendering -- To view, visit https://gerrit.wikimedia.org/r/315865 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a5e29a9783b43b6d2eef51f4bc13894ceb579e5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ZeroBanner Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits