jenkins-bot has submitted this change and it was merged.

Change subject: Unconditionally insert shop link via PHP
......................................................................


Unconditionally insert shop link via PHP

This patch causes the Wikimedia Shop link to be inserted via PHP irrespective
of geolocation. Clickthroughs from countries which the shop does not service
can be handled on the shop's page, instead. The JavaScript link insertion code
is retained as an interim strategy for the 30-day period following deployment
of this change during which cached pages may not contain the shop link.

Rationale:

- Changes to the user interface that cause the page to flicker or reflow after
  page content has already loaded prolong user-perceived latency by postponing
  the time at which the interface is complete.
- The shop link module loads in the top queue, meaning the byte size and
  parsing overhead of its payload block page content.
- GeoIP lookups are performed by adding an HTTP request above the fold, meaning
  it blocks the rendering of content. Fundraising banners are allowed to use it
  as a special case, but other extensions may not, as this complicates the
  process of keeping the loading of GeoIP to a minimum.

Bug: 57939
Change-Id: I92dac7589013636b500d0ec6e22fc5a72e264e84
---
M WikimediaShopLink.hooks.php
M WikimediaShopLink.php
M ext.wikimediaShopLink.core.js
3 files changed, 19 insertions(+), 38 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/WikimediaShopLink.hooks.php b/WikimediaShopLink.hooks.php
index 338d33f..8f04dd5 100644
--- a/WikimediaShopLink.hooks.php
+++ b/WikimediaShopLink.hooks.php
@@ -24,43 +24,31 @@
         * @return bool
         */
        public static function addJsVars( $vars ) {
-               global $wgWikimediaShopEnableLink, $wgWikimediaShopLinkTarget, 
$wgWikimediaShopShowLinkCountries;
+               global $wgWikimediaShopEnableLink, $wgWikimediaShopLinkTarget;
 
                if ( $wgWikimediaShopEnableLink ) {
                        $vars['wmfshopLinkTarget'] = $wgWikimediaShopLinkTarget;
-                       $vars['wmfshopLinkCountries'] = 
$wgWikimediaShopShowLinkCountries;
                }
 
                return true;
        }
 
        /**
-        * onSetup: ExtensionFunctions
+        * SkinBuildSidebar hook handler that adds shop link to sidebar
+        *
+        * @param $skin Skin
+        * @param &$sidebar array
         */
-       public static function geoSetup() {
-               global $wgHooks, $wgCentralNoticeLoader;
+       public static function addSidebarLink( $skin, &$sidebar ) {
+               global $wgWikimediaShopEnableLink, $wgWikimediaShopLinkTarget;
 
-               // CentralNotice already loads geoiplookup
-               if ( !isset( $wgCentralNoticeLoader ) || 
!$wgCentralNoticeLoader ) {
-                       $wgHooks['SkinAfterBottomScripts'][] = 
'WikimediaShopLinkHooks::geoLoader';
+               if ( $wgWikimediaShopEnableLink ) {
+                       $sidebar['navigation'][] = array(
+                               'text'  => $skin->msg( 
'wikimediashoplink-linktext' ),
+                               'href'  => $wgWikimediaShopLinkTarget,
+                               'title' => $skin->msg( 
'wikimediashoplink-link-tooltip' ),
+                               'id'    => 'n-shoplink',
+                       );
                }
-
-               return true;
-
-       }
-
-       /**
-        * onSkinAfterBottomScripts
-        */
-       public static function geoLoader( $skin, &$text ) {
-               $geo = array( 'city' => '', 'country' => '' );
-
-               $text .=
-                       // Geo defaults in case geoiplookup is failing
-                       '<script>Geo = ' . Xml::encodeJsVar( $geo ) . 
';</script>'
-                       // Insert the geoIP lookup
-                       . html::linkedScript( 
'//bits.wikimedia.org/geoiplookup' );
-
-               return true;
        }
 }
diff --git a/WikimediaShopLink.php b/WikimediaShopLink.php
index d4ccbbb..a31535d 100644
--- a/WikimediaShopLink.php
+++ b/WikimediaShopLink.php
@@ -34,7 +34,7 @@
 // Register hooks
 $wgHooks['BeforePageDisplay'][] = 'WikimediaShopLinkHooks::loadLink';
 $wgHooks['ResourceLoaderGetConfigVars'][] = 
'WikimediaShopLinkHooks::addJsVars';
-$wgExtensionFunctions[] = 'WikimediaShopLinkHooks::geoSetup';
+$wgHooks['SkinBuildSidebar'][] = 'WikimediaShopLinkHooks::addSidebarLink';
 
 // Register ResourceLoader modules
 $wgResourceModules[ 'ext.wikimediaShopLink.core' ] = array(
@@ -44,18 +44,13 @@
                'wikimediashoplink-link-tooltip',
        ),
        'dependencies' => 'mediawiki.util',
-       'position' => 'top',
-
        'localBasePath' => $dir,
        'remoteExtPath' => 'WikimediaShopLink',
 );
 
 // On/off switch
 $wgWikimediaShopEnableLink = false;
+$wgExtensionMessagesFiles['WikimediaShopLink'] = $dir . 
'/WikimediaShopLink.i18n.php';
 
 // Set this to the base target of any button
 $wgWikimediaShopLinkTarget = '//shop.wikimedia.org';
-
-// Countries where the link should be shown, based in IP.
-// Format: 2 letter (uppercase) ISO codes.
-$wgWikimediaShopShowLinkCountries = array();
diff --git a/ext.wikimediaShopLink.core.js b/ext.wikimediaShopLink.core.js
index e73c541..6faaed9 100644
--- a/ext.wikimediaShopLink.core.js
+++ b/ext.wikimediaShopLink.core.js
@@ -1,14 +1,12 @@
 jQuery( document ).ready(function ( $ ) {
        'use strict';
 
-       var userCountry = window.Geo && window.Geo.country,
-               shopCountries = mw.config.get( 'wmfshopLinkCountries', [] ),
-               hasNavPortal = $( '#p-navigation' ).length;
+       var linkTarget = mw.config.get( 'wmfshopLinkTarget' );
 
-       if ( hasNavPortal && $.inArray( userCountry, shopCountries ) !== -1 ) {
+       if ( linkTarget !== null && $( '#p-navigation' ).length && !$( 
'#n-shoplink' ).length ) {
                mw.util.addPortletLink(
                        'p-navigation',
-                       mw.config.get( 'wmfshopLinkTarget' ),
+                       linkTarget,
                        mw.msg( 'wikimediashoplink-linktext' ),
                        'n-shoplink',
                        mw.msg( 'wikimediashoplink-link-tooltip' )

-- 
To view, visit https://gerrit.wikimedia.org/r/98885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I92dac7589013636b500d0ec6e22fc5a72e264e84
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikimediaShopLink
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Jalexander <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to