Dr0ptp4kt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/83133


Change subject: Better prevent chargeable resources from being inadvertently 
accessed.
......................................................................

Better prevent chargeable resources from being inadvertently accessed.

* Currently, login is the mechanism raising prompts.
* Change variable reassign of isMdot while testing to simulate zeroDot behavior.
* In production, isMdot and isZerot will be based on the regexes.

Change-Id: Icd8c9140e3a22de60e148670f7bbc67a356950d8
---
M ZeroRatedMobileAccess.php
M includes/PageRenderingHooks.php
A modules/interstitial.js
A modules/redux.css
A modules/redux.js
A templates/interstitial.html
6 files changed, 199 insertions(+), 6 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/33/83133/1

diff --git a/ZeroRatedMobileAccess.php b/ZeroRatedMobileAccess.php
index 8917917..b2f545c 100644
--- a/ZeroRatedMobileAccess.php
+++ b/ZeroRatedMobileAccess.php
@@ -59,15 +59,28 @@
        'localBasePath' => $localBasePath,
        'remoteExtPath' => $remoteExtPath,
        'targets' => array( 'mobile' ),
-       'styles' => array( 'modules/banner.css' ),
+       'styles' => array( 'modules/banner.css', 'modules/redux.css' ),
+);
+
+$wgResourceModules['mobile.zero.templates'] = array(
+       'localBasePath' => $localBasePath,
+       'localTemplateBasePath' => $localBasePath . '/templates',
+       'templates' => array( 'interstitial' ),
+       'class' => 'MFResourceLoaderModule',
 );
 
 $wgResourceModules['mobile.zero.scripts'] = array(
-       'dependencies' => array( 'mobile.startup' ),
+       'dependencies' => array( 'mobile.stable', 'mobile.zero.styles', 
'mobile.zero.templates' ),
        'localBasePath' => $localBasePath,
        'remoteExtPath' => $remoteExtPath,
        'targets' => array( 'mobile' ),
-       'scripts' => array( 'modules/banner.js' ),
+       'scripts' => array( 'modules/banner.js', 'modules/interstitial.js', 
'modules/redux.js' ),
+       'messages' => array(
+               'zero-rated-mobile-access-charge-auth',
+               'zero-rated-mobile-access-banner-text-data-charges-yes',
+               'zero-rated-mobile-access-banner-text-data-charges-no',
+               'zero-rated-mobile-access-go-back'
+       )
 );
 
 $wgResourceModules['zero.config'] = array(
diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 0accecd..02b273c 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -167,15 +167,18 @@
                                if ( strpos( $referer, 'zero.wikipedia.org' ) 
!== false ) {
                                        $warn .= ' && zero referer';
                                }
+                               $out->addModuleStyles( 'mobile.zero.styles' );
+                               $out->addModules( 'mobile.zero.scripts' );
                        }
                        if ( $warn !== '' ) {
                                self::logDebug( '!config' . $warn );
                        }
+               } else {
+                       $out->addModuleStyles( 'mobile.zero.styles' );
+                       $out->addModules( 'mobile.zero.scripts' );
                }
 
-               // @FIXME: Should not be added for non-zero sites
-               $out->addModuleStyles( 'mobile.zero.styles' );
-               $out->addModules( 'mobile.zero.scripts' );
+
 
                $isFilePage = $out->getTitle()->inNamespace( NS_FILE );
                $showBanner = $config !== null || $wgRequest->getFuzzyBool( 
'renderZeroRatedBanner' );
diff --git a/modules/interstitial.js b/modules/interstitial.js
new file mode 100644
index 0000000..3160648
--- /dev/null
+++ b/modules/interstitial.js
@@ -0,0 +1,32 @@
+( function( M, $ ) {
+    var zZeroRe = /Special:ZeroRatedMobileAccess(.+)$/;
+    var zFromRe = /[&?]from=([^&]+)/;
+    var zToRe = /[&?]to=([^&]+)/;
+    var Overlay = M.require('Overlay');
+
+    $( document ).ready( function() {
+        $( "a" ).on( "click", function( ev ) {
+            var zT = $( ev.delegateTarget );
+            var zDest = zT.prop( "href" );
+            var zMatch = zToRe.exec( zDest );
+            var zRegexesPassed = zDest && zZeroRe.test( zDest ) && 
zFromRe.test( zDest ) && zMatch !== null;
+
+            if ( zRegexesPassed ) {
+                ev.preventDefault();
+                var ZeroOverlay = Overlay.extend({
+                    template: M.template.get( 'interstitial' ),
+                    defaults: {
+                        warning: mw.msg( 
'zero-rated-mobile-access-charge-auth' ),
+                        yes: mw.msg( 
'zero-rated-mobile-access-banner-text-data-charges-yes' ),
+                        no: mw.msg( 
'zero-rated-mobile-access-banner-text-data-charges-no' ),
+                        goback:  mw.msg( 'zero-rated-mobile-access-go-back' )
+                    }
+                });
+
+                return new ZeroOverlay({
+                    url: zMatch[1]
+                }).show();
+            }
+        });
+    });
+} ( mw.mobileFrontend, jQuery ) );
\ No newline at end of file
diff --git a/modules/redux.css b/modules/redux.css
new file mode 100644
index 0000000..f8f6e26
--- /dev/null
+++ b/modules/redux.css
@@ -0,0 +1,4 @@
+#page-actions  { display:none; }
+#mw-mf-last-modified { display:none } /* until mobile optimized */
+.icon-watchlist, .icon-settings, .icon-loginout, .icon-nearby { display:none; }
+.mw-mf-settings > ul:nth-child(2) > li:nth-child(2), .mw-mf-settings > 
ul:nth-child(2) > li:nth-child(4) { display:none }
\ No newline at end of file
diff --git a/modules/redux.js b/modules/redux.js
new file mode 100644
index 0000000..6696e11
--- /dev/null
+++ b/modules/redux.js
@@ -0,0 +1,132 @@
+( function( M, $ ) {
+
+    var isMdot = document.location.hostname.toLowerCase().search( 
/\.m\.wikipedia\.org$/ ) !== -1,
+        isZeroDot = document.location.hostname.toLowerCase().search( 
/\.zero\.wikipedia\.org$/ ) !== -1,
+        Overlay = M.require( 'Overlay' ),
+        intercept = function ( ev, url ) {
+
+            ev.preventDefault();
+            var dest = url ? url : ev.delegateTarget.href,
+                ZeroOverlay = Overlay.extend( {
+                template: M.template.get( 'interstitial' ),
+                defaults: {
+                    warning: mw.msg( 'zero-rated-mobile-access-charge-auth' ), 
/* TODO: new 24-hr warning */
+                    yes: mw.msg( 
'zero-rated-mobile-access-banner-text-data-charges-yes' ),
+                    no: mw.msg( 
'zero-rated-mobile-access-banner-text-data-charges-no' ),
+                    goback:  mw.msg( 'zero-rated-mobile-access-go-back' )
+                }
+            } );
+
+            return new ZeroOverlay( {
+                url: dest
+            } ).show();
+        };
+
+    isMdot = true; /* will remove once ready to host */
+    isZeroDot = !isMdot; /* will remove once ready to host */
+
+    $( document ).ready( function() {
+        var here = mw.config.get( 'wgPageName' ),
+            pageProbablyEditable = mw.config.get( 'wgIsProbablyEditable' ),
+            allowedEditGroups = mw.config.get( 'wgRestrictionEdit' ),
+            userGroups = mw.config.get( 'wgUserGroups' ),
+            userProbablyHasEdit = allowedEditGroups !== null && ( 
allowedEditGroups.length === 0 || allowedEditGroups.filter(
+                function ( g ) {
+                    return userGroups.indexOf( g ) !== -1;
+                }
+            ).length > 0 ),
+            pageEditableByUser = pageProbablyEditable && userProbablyHasEdit,
+            photo = M.require( 'modules/uploads/_leadphoto' ),
+            photoNeeded = photo.needsPhoto( $( '#content' ) );
+
+
+        if ( isMdot ) {
+            if ( !M.isLoggedIn() && pageProbablyEditable && photoNeeded ) {
+                $( '#ca-upload' ).unbind();
+                $( '#ca-upload' ).on( 'click', function ( ev ) {
+                    var params = {
+                            returnto: here,
+                            returntoquery: 'article_action=addphoto'
+                        },
+                        login = M.pageApi.getPageUrl( 'Special:UserLogin', 
params );
+                    intercept( ev, login );
+                } );
+            } else if ( !M.isLoggedIn() && ( !pageProbablyEditable || 
!photoNeeded ) ) {
+                $( '#ca-upload' ).hide();
+            } else if ( M.isLoggedIn && ( !pageEditableByUser || !photoNeeded 
) ) {
+                $( '#ca-upload' ).hide();
+            } /* user logged in, page editable by user, photo needed: behave 
normally */
+
+            $( '.icon-settings' ).show();
+            /* TODO: once 30-day toggle available, enable on zeroDot, too */
+
+        /* be SURE this is Zero, and take corrective action when it's the case 
*/
+        } else if ( isZeroDot ) {
+            $( '.icon-uploads' ).hide();
+            $( '#ca-upload' ).hide();
+        }
+
+        if ( !M.isLoggedIn() && pageProbablyEditable ) {
+            $( '#ca-edit' ).unbind();
+            $( '#ca-edit' ).on( 'click', function ( ev ) {
+                var params = {
+                        returnto: here,
+                        returntoquery: 'article_action=edit'
+                    },
+                    login = M.pageApi.getPageUrl( 'Special:UserLogin', params 
);
+                intercept( ev, login );
+            } );
+
+
+            $( '.edit-page' ).unbind();
+            $( '.edit-page' ).on( 'click', function( ev ) {
+                var sect = $( this ).parent().attr( 'id' ),
+                    params = {
+                        returnto: here + '#' + sect
+                    },
+                    login = M.pageApi.getPageUrl( 'Special:UserLogin', params 
);
+                intercept( ev, login );
+            } );
+
+
+        } else if ( !M.isLoggedIn() && !pageProbablyEditable ) {
+            $( '#ca-edit').hide();
+        } else if ( M.isLoggedIn() && !pageEditableByUser ) {
+            $( '#ca-edit').hide();
+        } /* user logged in, page editable by user: behave normally */
+
+
+
+        if ( !M.isLoggedIn() ) {
+
+            $( '.icon-watchlist a' ).on( 'click', intercept);
+
+            $( '.icon-uploads a' ).on( 'click', intercept );
+
+            /* $( '.icon-settings a' ).on( 'click', intercept ); */
+            /* TODO: HTTPS toggle pref, Beta and Experimental support (see 
suppression in CSS and below) */
+
+            $( '.icon-loginout a' ).on( 'click', intercept );
+
+
+            $( '#ca-watch a' ).unbind();
+            $( '#ca-watch' ).on( 'click', function ( ev ) {
+                var params = {
+                        returnto: here,
+                        returntoquery: 'article_action=watch'
+                    },
+                    login = M.pageApi.getPageUrl( 'Special:UserLogin', params 
);
+                intercept( ev, login );
+            } );
+        }
+
+        $( '.icon-watchlist' ).show();
+        $( '.icon-loginout' ).show();
+        $( '#page-actions' ).show();
+
+        $( '.mw-mf-settings-description' ).hide();
+        /* CSS not working for .mw-mf-settings-description b/c of page 
lifecycle I think */
+
+        /* currently safe: #ca-talk (text), #li-coordinates (text),  */
+    });
+} ( mw.mobileFrontend, jQuery ) );
\ No newline at end of file
diff --git a/templates/interstitial.html b/templates/interstitial.html
new file mode 100644
index 0000000..4cf94f6
--- /dev/null
+++ b/templates/interstitial.html
@@ -0,0 +1,9 @@
+<div class="header mw-mf-banner mw-mf-banner-undismissable">
+{{warning}}
+</div>
+<div class="button-bar button-bar-centered buttonBar">
+    <a href="{{url}}" class="button">{{yes}}</a>
+    <button class="cancel inline">{{no}}</button>
+</div>
+
+<div><button class="cancel inline">&lt;&lt; {{goback}}</button></div>
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd8c9140e3a22de60e148670f7bbc67a356950d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Dr0ptp4kt <[email protected]>

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

Reply via email to