Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67867
Change subject: Reduce API errors related to anonymous tokens (hopefully)
......................................................................
Reduce API errors related to anonymous tokens (hopefully)
When wgCentralAuthLoginWiki is enabled ask for centralauth tokens
to avoid not logged in on foreign wiki issues
Change-Id: Iada82266e0108189a727c39dad9e32c6cc1c120c
---
M includes/skins/SkinMinerva.php
M javascripts/common/mf-api.js
M javascripts/modules/mf-photo.js
3 files changed, 27 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/67/67867/1
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 145a623..f226a56 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -88,10 +88,12 @@
*/
public function getSkinConfigVariables() {
global $wgMFLeadPhotoUploadCssSelector,
$wgMFEnableCssAnimations,
+ $wgCentralAuthLoginWiki,
$wgMFAnonymousEditing, $wgMFEnablePhotoUploadCTA,
$wgMFPhotoUploadEndpoint, $wgMFPhotoUploadAppendToDesc;
return array(
+ 'wgCentralAuthLoginWiki' => $wgCentralAuthLoginWiki,
'wgMFAnonymousEditing' => $wgMFAnonymousEditing,
'wgMFEnablePhotoUploadCTA' => $wgMFEnablePhotoUploadCTA,
'wgMFPhotoUploadAppendToDesc' =>
$wgMFPhotoUploadAppendToDesc,
diff --git a/javascripts/common/mf-api.js b/javascripts/common/mf-api.js
index d6958fc..ed7fbfc 100644
--- a/javascripts/common/mf-api.js
+++ b/javascripts/common/mf-api.js
@@ -127,20 +127,22 @@
*
* @param {String} tokenType: Name of the type of token needed e.g.
edit, upload - defaults to edit
* @param {String} endpoint: Optional alternative host to query via CORS
+ * @param {String} caToken: Optional additional centralauth token to be
sent with the request
* @return {jQuery.Deferred} Object returned by $.ajax(), callback will
be passed
* the token string, false if the user is anon or undefined where not
available or a warning is set
*/
- Api.prototype.getToken = function( tokenType, endpoint ) {
- var data, d = $.Deferred();
+ Api.prototype.getToken = function( tokenType, endpoint, caToken ) {
+ var data, d = $.Deferred(), noCache;
tokenType = tokenType || 'edit';
+ noCache = tokenType === 'centralauth' || caToken;
if ( !this.tokenCache[ endpoint ] ) {
this.tokenCache[ endpoint ] = {};
}
if ( !M.isLoggedIn() ) {
return d.reject( 'Token requested when not logged in.'
);
- } else if ( this.tokenCache[ endpoint ].hasOwnProperty(
tokenType ) ) {
+ } else if ( !noCache && this.tokenCache[ endpoint
].hasOwnProperty( tokenType ) ) {
return this.tokenCache[ endpoint ][ tokenType ];
} else {
data = {
@@ -149,6 +151,9 @@
};
if ( endpoint ) {
data.origin = M.getOrigin();
+ if ( caToken ) {
+ data.centralauthtoken = caToken;
+ }
}
this.ajax( data, {
url: endpoint || M.getApiUrl(),
diff --git a/javascripts/modules/mf-photo.js b/javascripts/modules/mf-photo.js
index 7c0b84f..c1e459f 100644
--- a/javascripts/modules/mf-photo.js
+++ b/javascripts/modules/mf-photo.js
@@ -134,6 +134,7 @@
}
PhotoApi = Api.extend( {
+ useCentralAuthToken: mw.config.get( 'wgCentralAuthLoginWiki' ),
updatePage: function( options, callback ) {
var self = this;
self.getToken().done( function( token ) {
@@ -154,7 +155,7 @@
'mobile-frontend-photo-article-edit-comment' :
'mobile-frontend-photo-article-donate-comment';
- function doUpload( token ) {
+ function doUpload( token, caToken ) {
var formData = new FormData(),
ext = options.file.name.slice(
options.file.name.lastIndexOf( '.' ) + 1 );
@@ -165,6 +166,9 @@
// add origin only when doing CORS
if ( endpoint ) {
formData.append( 'origin',
M.getOrigin() );
+ if ( caToken ) {
+ formData.append(
'centralauthtoken', caToken );
+ }
}
formData.append( 'filename', options.fileName );
formData.append( 'comment', mw.msg(
options.editSummaryMessage ) );
@@ -233,11 +237,18 @@
}
} );
}
- self.getToken( 'edit', endpoint ).done( function( token
) {
- doUpload( token );
- } ).fail( function( err ) {
- result.reject( err );
- } );
+ if ( self.useCentralAuthToken && endpoint ) {
+ self.getToken( 'centralauth' ).done( function(
caTokenForEditToken ) {
+ self.getToken( 'edit', endpoint,
caTokenForEditToken ).done( function( token ) {
+ // tokens are only valid for
one go so let's get another one
+ self.getToken( 'centralauth'
).done( function( caTokenForUpload ) {
+ doUpload( token,
caTokenForUpload );
+ } ).fail( $.proxy( result,
'reject' ) );
+ } ).fail( $.proxy( result, 'reject' ) );
+ } );
+ } else {
+ self.getToken( 'edit', endpoint ).done(
$.proxy( doUpload ) ).fail( $.proxy( result, 'reject' ) );
+ }
return result;
}
--
To view, visit https://gerrit.wikimedia.org/r/67867
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iada82266e0108189a727c39dad9e32c6cc1c120c
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