Jdlrobson has uploaded a new change for review.

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


Change subject: bug 45452: only show donate image button when token available
......................................................................

bug 45452: only show donate image button when token available

note: this means every page that needs a photo will query the commons
api on initial load

Adds slight delay to appearance of photo upload cta but minimises
errors due to a bad token

Change-Id: Ie0d018de4bb8f86e2dec717a9ed4e1bd5b79119a
---
M javascripts/modules/mf-photo.js
1 file changed, 27 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/80/51080/1

diff --git a/javascripts/modules/mf-photo.js b/javascripts/modules/mf-photo.js
index b66fb1e..f269808 100644
--- a/javascripts/modules/mf-photo.js
+++ b/javascripts/modules/mf-photo.js
@@ -1,7 +1,8 @@
 ( function( M, $ ) {
 
        var View = M.require( 'view' ),
-               Api = M.require( 'api' ).Api,
+               api = M.require( 'api' ),
+               Api = api.Api,
                EventEmitter = M.require( 'eventemitter' ),
                ProgressBar = M.require( 'widgets/progress-bar' ),
                nav = M.require( 'navigation' ),
@@ -422,27 +423,31 @@
                        return;
                }
 
-               photoUploader = new PhotoUploader( {
-                       buttonCaption: mw.msg( 'mobile-frontend-photo-upload' ),
-                       insertInPage: true,
-                       pageTitle: M.getConfig( 'title' ),
-                       funnel: 'article'
-               } ).
-                       insertAfter( $pageHeading ).
-                       on( 'start', function() {
-                               photoUploader.detach();
-                       } ).
-                       on( 'success', function( data ) {
-                               popup.show( mw.msg( 
'mobile-frontend-photo-upload-success-article' ), 'toast' );
-                               new LeadPhoto( {
-                                       url: data.url,
-                                       pageUrl: data.descriptionUrl,
-                                       caption: data.description
-                               } ).insertAfter( $pageHeading ).animate();
-                       } ).
-                       on( 'error cancel', function() {
-                               photoUploader.insertAfter( $pageHeading );
-                       } );
+               api.getToken( 'edit', function( tokenData ) {
+                       if ( tokenData && tokenData.tokens && 
tokenData.tokens.edittoken !== '+\\' ) {
+                               photoUploader = new PhotoUploader( {
+                                       buttonCaption: mw.msg( 
'mobile-frontend-photo-upload' ),
+                                       insertInPage: true,
+                                       pageTitle: M.getConfig( 'title' ),
+                                       funnel: 'article'
+                               } ).
+                                       insertAfter( $pageHeading ).
+                                       on( 'start', function() {
+                                               photoUploader.detach();
+                                       } ).
+                                       on( 'success', function( data ) {
+                                               popup.show( mw.msg( 
'mobile-frontend-photo-upload-success-article' ), 'toast' );
+                                               new LeadPhoto( {
+                                                       url: data.url,
+                                                       pageUrl: 
data.descriptionUrl,
+                                                       caption: 
data.description
+                                               } ).insertAfter( $pageHeading 
).animate();
+                                       } ).
+                                       on( 'error cancel', function() {
+                                               photoUploader.insertAfter( 
$pageHeading );
+                                       } );
+                       }
+               }, endpoint );
        }
 
        if ( isSupported() ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0d018de4bb8f86e2dec717a9ed4e1bd5b79119a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to