jenkins-bot has submitted this change and it was merged. Change subject: Add extension.json, empty PHP entry point, remove i18n shim ......................................................................
Add extension.json, empty PHP entry point, remove i18n shim Bug: T87887 Change-Id: I39b05537ab802c6368174070e6cd0e904772a222 --- A Campaigns.hooks.php D Campaigns.i18n.php M Campaigns.php A extension.json 4 files changed, 133 insertions(+), 175 deletions(-) Approvals: Paladox: Looks good to me, but someone else must approve Siebrand: Looks good to me, but someone else must approve Jforrester: Looks good to me, approved jenkins-bot: Verified diff --git a/Campaigns.hooks.php b/Campaigns.hooks.php new file mode 100644 index 0000000..6c73821 --- /dev/null +++ b/Campaigns.hooks.php @@ -0,0 +1,77 @@ +<?php + +class CampaignsHooks { + public static function onUserCreateForm( &$template ) { + global $wgCookiePrefix; + $maxCampaignLen = 40; + + $skin = $template->getSkin(); + + $request = $skin->getRequest(); + $campaign = $request->getVal( 'campaign', '' ); + if ( $campaign === '' || strlen( $campaign ) > $maxCampaignLen ) { + return true; + } + + // The version of the page for a logged-in user will not be cached and + // served to anonymous users, so it's OK to check on server. + if ( !$skin->getUser()->isAnon() ) { + return true; + }; + + $out = $skin->getOutput(); + $out->addJsConfigVars( 'wgCampaignsCampaign', $campaign ); + $out->addModules( 'ext.campaigns' ); + + return true; + } + + public static function onAddNewAccount( $user, $byEmail ) { + global $wgEventLoggingSchemaRevs, $wgRequest, $wgUser, $wgCookiePrefix; + + $userId = $user->getId(); + $creatorUserId = $wgUser->getId(); + + // MediaWiki allows existing users to create accounts on behalf + // of others. In such cases the ID of the newly-created user and + // the ID of the user making this web request are different. + $isSelfMade = ( $userId && $userId === $creatorUserId ); + + $displayMobile = class_exists( 'MobileContext' ) && + MobileContext::singleton()->shouldDisplayMobileView(); + + $event = array( + 'token' => $wgRequest->getCookie( 'mediaWiki.user.id', '', '' ), + 'userId' => $userId, + 'userName' => $user->getName(), + 'isSelfMade' => $isSelfMade, + 'campaign' => $wgRequest->getCookie( '-campaign', $wgCookiePrefix, '' ), + 'userBuckets' => $wgRequest->getCookie( 'userbuckets', '', '' ), + 'displayMobile' => $displayMobile, + ); + + $returnTo = $wgRequest->getVal( 'returnto' ); + if ( $returnTo !== null ) { + $event[ 'returnTo' ] = $returnTo; + } + + $returnToQuery = $wgRequest->getVal( 'returntoquery' ); + if ( $returnToQuery !== null ) { + $event[ 'returnToQuery' ] = $returnToQuery; + } + + EventLogging::logEvent( 'ServerSideAccountCreation', 5487345, $event ); + return true; + } + + public static function onUserLoginForm( &$template ) { + if ( $template->haveData( 'createOrLoginHref' ) ) { + $url = $template->data[ 'createOrLoginHref' ]; + $url .= strpos( $url, '?' ) ? '&' : '?'; + $url .= 'campaign=loginCTA'; + $template->set( 'createOrLoginHref', $url ); + } + + return true; + } +} \ No newline at end of file diff --git a/Campaigns.i18n.php b/Campaigns.i18n.php deleted file mode 100644 index 0a07fbd..0000000 --- a/Campaigns.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( 'wfJsonI18nShim887ba74db1743220' ) ) { - function wfJsonI18nShim887ba74db1743220( $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'][] = 'wfJsonI18nShim887ba74db1743220'; -} diff --git a/Campaigns.php b/Campaigns.php index 8448b38..209039e 100644 --- a/Campaigns.php +++ b/Campaigns.php @@ -1,141 +1,13 @@ <?php -/** - * Campaigns extension - * - * @ingroup Extensions - * - * @author S Page <sp...@wikimedia.org> - * - * @license GPL v2 or later - */ - -$wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'Campaigns', - 'version' => '0.2.0', - 'url' => 'https://www.mediawiki.org/wiki/Extension:Campaigns', - 'author' => 'S Page', - 'descriptionmsg' => 'campaigns-desc', - 'license-name' => 'GPL-2.0+', -); - - -// Messages -$wgMessagesDirs['Campaigns'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['Campaigns'] = __DIR__ . '/Campaigns.i18n.php'; - - -// Modules - -$wgResourceModules['ext.campaigns'] = array( - 'scripts' => 'ext.campaigns.js', - 'localBasePath' => __DIR__ . '/modules', - 'remoteExtPath' => 'Campaigns/modules', - 'dependencies' => array( - 'jquery.cookie', - ), - 'targets' => array( 'mobile', 'desktop' ), -); - - -// Hooks - -/** - * If there's a ?campaign=someName in the query string and the user is not - * logged in, send JavaScript with the page to process campaign. - * - * Don't set the cookie in PHP because we believe the Squid cache will not - * send the Set-Cookie header along with a cached version of the page. The - * Squid cache fragments on query string, hence the right campaign value and - * JS module will be sent to the client for different ?campaign=foo parameters. - * - * @param &$template template instance for the form - * @return bool True - */ -$wgHooks['UserCreateForm'][] = function( &$template ) { - global $wgCookiePrefix; - $maxCampaignLen = 40; - - $skin = $template->getSkin(); - - $request = $skin->getRequest(); - $campaign = $request->getVal( 'campaign', '' ); - if ( $campaign === '' || strlen( $campaign ) > $maxCampaignLen ) { - return true; - } - - // The version of the page for a logged-in user will not be cached and - // served to anonymous users, so it's OK to check on server. - if ( !$skin->getUser()->isAnon() ) { - return true; - }; - - $out = $skin->getOutput(); - $out->addJsConfigVars( 'wgCampaignsCampaign', $campaign ); - $out->addModules( 'ext.campaigns' ); - - return true; -}; - -/** - * Log account creation. - * @see https://www.mediawiki.org/wiki/Manual:Hooks/AddNewAccount - * - * @param User $user The User object that was created. - * @param boolean $byEmail The form has a [By e-mail] button. - * @return bool True - */ -$wgHooks['AddNewAccount'][] = function( $user, $byEmail ) { - global $wgEventLoggingSchemaRevs, $wgRequest, $wgUser, $wgCookiePrefix; - - $userId = $user->getId(); - $creatorUserId = $wgUser->getId(); - - // MediaWiki allows existing users to create accounts on behalf - // of others. In such cases the ID of the newly-created user and - // the ID of the user making this web request are different. - $isSelfMade = ( $userId && $userId === $creatorUserId ); - - $displayMobile = class_exists( 'MobileContext' ) && - MobileContext::singleton()->shouldDisplayMobileView(); - - $event = array( - 'token' => $wgRequest->getCookie( 'mediaWiki.user.id', '', '' ), - 'userId' => $userId, - 'userName' => $user->getName(), - 'isSelfMade' => $isSelfMade, - 'campaign' => $wgRequest->getCookie( '-campaign', $wgCookiePrefix, '' ), - 'userBuckets' => $wgRequest->getCookie( 'userbuckets', '', '' ), - 'displayMobile' => $displayMobile, - ); - - $returnTo = $wgRequest->getVal( 'returnto' ); - if ( $returnTo !== null ) { - $event[ 'returnTo' ] = $returnTo; - } - - $returnToQuery = $wgRequest->getVal( 'returntoquery' ); - if ( $returnToQuery !== null ) { - $event[ 'returnToQuery' ] = $returnToQuery; - } - - EventLogging::logEvent( 'ServerSideAccountCreation', 5487345, $event ); - return true; -}; - -/** - * Adds campaign param to link on login form. - * - * @param &$template template instance for the form - * @return bool True - */ -$wgHooks['UserLoginForm'][] = function( &$template ) { - if ( $template->haveData( 'createOrLoginHref' ) ) { - $url = $template->data[ 'createOrLoginHref' ]; - $url .= strpos( $url, '?' ) ? '&' : '?'; - $url .= 'campaign=loginCTA'; - $template->set( 'createOrLoginHref', $url ); - } - - return true; -}; +if ( function_exists( 'wfLoadExtension' ) ) { + wfLoadExtension( 'Campaigns' ); + // Keep i18n globals so mergeMessageFileList.php doesn't break + $wgMessagesDirs['Campaigns'] = __DIR__ . '/i18n'; + /* wfWarn( + 'Deprecated PHP entry point used for Campaigns extension. Please use wfLoadExtension instead, ' . + 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' + ); */ + return; +} else { + die( 'This version of the Campaigns extension requires MediaWiki 1.25+' ); +} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..ca47974 --- /dev/null +++ b/extension.json @@ -0,0 +1,44 @@ +{ + "name": "Campaigns", + "version": "0.2.0", + "author": "S Page", + "url": "https://www.mediawiki.org/wiki/Extension:Campaigns", + "descriptionmsg": "campaigns-desc", + "license-name": "GPL-2.0+", + "type": "other", + "Hooks": { + "UserCreateForm": [ + "CampaignsHooks::onUserCreateForm" + ], + "AddNewAccount": [ + "CampaignsHooks::onAddNewAccount" + ], + "UserLoginForm": [ + "CampaignsHooks::onUserLoginForm" + ] + }, + "MessagesDirs": { + "Campaigns": [ + "i18n" + ] + }, + "ResourceModules": { + "ext.campaigns": { + "scripts": "ext.campaigns.js", + "dependencies": [ + "jquery.cookie" + ], + "targets": [ + "mobile", + "desktop" + ] + } + }, + "ResourceFileModulePaths": { + "localBasePath": "modules", + "remoteExtPath": "Campaigns/modules" + }, + "AutoloadClasses": { + "CampaignsHooks": "Campaigns.hooks.php" + } +} -- To view, visit https://gerrit.wikimedia.org/r/194019 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I39b05537ab802c6368174070e6cd0e904772a222 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Campaigns Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: Spage <sp...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits