Florianschmidtwelzow has uploaded a new change for review.
https://gerrit.wikimedia.org/r/178793
Change subject: Use user rights to check, if the user can edit page
......................................................................
Use user rights to check, if the user can edit page
wgRestrictionLevels, returned by the mobileview api module, is an array of
user rights, the user needs to edit the requested page. It's false to check
these rights against the groups, the current user belongs to, so use the
effective user rights to check, if the user is allowed to edit the page or not.
Bug: T74877
Change-Id: I1ab70ac0f61238c39a43e6db63c75df9b5465819
---
M javascripts/Page.js
M javascripts/user.js
M tests/qunit/test_Page.js
3 files changed, 7 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/93/178793/1
diff --git a/javascripts/Page.js b/javascripts/Page.js
index 2a0e841..ee756d9 100644
--- a/javascripts/Page.js
+++ b/javascripts/Page.js
@@ -86,10 +86,10 @@
var editProtection = this.options.protection.edit,
resp = $.Deferred();
- user.getGroups().done( function ( groups ) {
+ user.getRights().done( function ( rights ) {
var editable = false;
- $.each( groups, function ( i, group ) {
- if ( $.inArray( group, editProtection )
> -1 ) {
+ $.each( rights, function ( i, right ) {
+ if ( $.inArray( right, editProtection )
> -1 ) {
editable = true;
return false;
}
diff --git a/javascripts/user.js b/javascripts/user.js
index a2d2299..f65bb90 100644
--- a/javascripts/user.js
+++ b/javascripts/user.js
@@ -13,6 +13,8 @@
isAnon: mw.user.isAnon,
/* @see mediaWiki.user */
getName: mw.user.getName,
+ /* @see mediaWiki.user */
+ getRights: mw.user.getRights,
/**
* Find current users edit count
* @method
@@ -21,15 +23,6 @@
getEditCount: function () {
return mw.config.get( 'wgUserEditCount' );
},
- /**
- * FIXME: Not sure why mw.user is asynchronous when the
information is available
- * For reasons I do not understand getGroups in core causes an
unnecessary ajax request
- * The information this returns is identical to the content of
the config variable.
- * To avoid an unnecessary ajax request on every page view
simply use config variable.
- */
- getGroups: function () {
- return $.Deferred().resolve( mw.config.get(
'wgUserGroups' ) );
- }
};
M.define( 'user', user );
diff --git a/tests/qunit/test_Page.js b/tests/qunit/test_Page.js
index 783a336..fbc4aa1 100644
--- a/tests/qunit/test_Page.js
+++ b/tests/qunit/test_Page.js
@@ -31,12 +31,12 @@
QUnit.expect( 4 );
var p, p2, user, user2;
user = {
- getGroups: function() {
+ getRights: function() {
return $.Deferred().resolve( ['*'] );
}
};
user2 = {
- getGroups: function() {
+ getRights: function() {
return $.Deferred().resolve( [ '*', 'user',
'autoconfirmed', 'sysop' ] );
}
};
--
To view, visit https://gerrit.wikimedia.org/r/178793
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ab70ac0f61238c39a43e6db63c75df9b5465819
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits