r109582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109581‎ | r109582 | r109583 >
Date:23:16, 19 January 2012
Author:gregchiasson
Status:resolved (Comments)
Tags:
Comment:
AFT5 - Add permissions/roll checks to AFT5 feedback page and API calls. Requirements call for additional permissions on features that don't exist yet, which is why there are more roles than we seem to need.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.i18n.php
@@ -32,6 +32,7 @@
3333 // error messages
3434 'articlefeedbackv5-error' => 'An error has occured. Please try again later.',
3535 'articlefeedbackv5-error-email' => 'That e-mail address is not valid.',
 36+ 'articlefeedbackv5-error-blocked' => 'Blocked users may not submit feedback.',
3637 'articlefeedbackv5-error-validation' => 'Validation error.',
3738 'articlefeedbackv5-error-abuse' => 'Your comment violates the $1. Please revise it.',
3839 'articlefeedbackv5-error-abuse-linktext' => 'feedback abuse policy',
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -33,6 +33,13 @@
3434 global $wgUser, $wgArticleFeedbackv5SMaxage;
3535 $params = $this->extractRequestParams();
3636
 37+ // Blocked users are, well, blocked.
 38+ if( $wgUser->isBlocked() ) {
 39+ $this->getResult()->addValue( null, 'error', 'articlefeedbackv5-error-blocked' );
 40+ return;
 41+ }
 42+
 43+
3744 // Anon token check
3845 $token = $this->getAnonToken( $params );
3946
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -14,12 +14,13 @@
1515 * @subpackage Api
1616 */
1717 class ApiViewFeedbackArticleFeedbackv5 extends ApiQueryBase {
18 -
 18+ private $access = array();
1919 /**
2020 * Constructor
2121 */
2222 public function __construct( $query, $moduleName ) {
2323 parent::__construct( $query, $moduleName, 'afvf' );
 24+ $this->access = ApiArticleFeedbackv5Utils::initializeAccess();
2425 }
2526
2627 /**
@@ -185,6 +186,16 @@
186187
187188 private function getFilterCriteria( $filter, $filterValue = null ) {
188189 $where = array();
 190+
 191+ // Permissions check
 192+ if(
 193+ ( $filter == 'invisible' && !$this->access[ 'rollbackers' ] )
 194+ || ( $filter == 'deleted' && !$this->access[ 'oversight' ] )
 195+
 196+ ) {
 197+ $filter = null;
 198+ }
 199+
189200 switch( $filter ) {
190201 case 'all':
191202 $where = array();
@@ -217,10 +228,10 @@
218229 default: $content .= $this->renderNoBucket( $record ); break;
219230 }
220231 # TODO: check roles to determine what to show here (and cache somewhere so we don't keep looking them up).
221 - $can_flag = 1;
222 - $can_upvote = 1;
223 - $can_hide = 1;
224 - $can_delete = 1;
 232+ $can_flag = !$this->access[ 'blocked' ];
 233+ $can_vote = !$this->access[ 'blocked' ];
 234+ $can_hide = $this->access[ 'rollbackers' ];
 235+ $can_delete = $this->access[ 'oversight' ];
225236 $id = $record[0]->af_id;
226237
227238 # $header_links = Html::openElement( 'p', array( 'class' => 'articleFeedbackv5-comment-head' ) )
@@ -251,7 +262,7 @@
252263
253264 $footer_links = Html::openElement( 'p', array( 'class' => 'articleFeedbackv5-comment-foot' ) );
254265
255 - if( $can_upvote ) {
 266+ if( $can_vote ) {
256267 $footer_links .= Html::element( 'span', array(
257268 'class' => 'articleFeedbackv5-helpful-caption'
258269 ), wfMessage( 'articlefeedbackv5-form-helpful-label', ( $record[0]->af_helpful_count + $record[0]->af_unhelpful_count ) ) )
@@ -286,6 +297,7 @@
287298 . Html::openElement( 'ul', array(
288299 'id' => 'articleFeedbackv5-feedback-tools-list-'.$id
289300 ) )
 301+ # TODO: unhide hidden posts
290302 . ( $can_hide ? Html::rawElement( 'li', array(), Html::element( 'a', array(
291303 'id' => "articleFeedbackv5-hide-link-$id",
292304 'class' => 'articleFeedbackv5-hide-link'
@@ -294,6 +306,8 @@
295307 'id' => "articleFeedbackv5-abuse-link-$id",
296308 'class' => 'articleFeedbackv5-abuse-link'
297309 ), wfMessage( 'articlefeedbackv5-form-abuse', $record[0]->af_abuse_count )->text() ) ) : '' )
 310+ # TODO: nonoversight can mark for oversight, oversight can
 311+ # either delete or un-delete, based on deletion status
298312 . ( $can_delete ? Html::rawElement( 'li', array(), Html::element( 'a', array(
299313 'id' => "articleFeedbackv5-delete-link-$id",
300314 'class' => 'articleFeedbackv5-delete-link'
@@ -490,5 +504,4 @@
491505 public function getVersion() {
492506 return __CLASS__ . ': $Id: ApiViewRatingsArticleFeedbackv5.php 103439 2011-11-17 03:19:01Z rsterbin $';
493507 }
494 -
495508 }
Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5Utils.php
@@ -190,5 +190,18 @@
191191
192192 $dbw->commit();
193193 }
 194+
 195+ public function initializeAccess() {
 196+ global $wgUser;
 197+ return array(
 198+ 'blocked' => $wgUser->isBlocked(),
 199+ 'anon' => $wgUser->isAnon(),
 200+ 'registered' => !$wgUser->isAnon() && !$wgUser->isBlocked(),
 201+ 'autoconfirmed' => in_array('autoconfirmed', $wgUser->getEffectiveGroups()),
 202+ 'rollbackers' => in_array('rollbacker', $wgUser->getEffectiveGroups()),
 203+ 'admins' => in_array('sysop', $wgUser->getEffectiveGroups()),
 204+ 'oversight' => in_array('oversight', $wgUser->getEffectiveGroups())
 205+ );
 206+ }
194207 }
195208
Index: trunk/extensions/ArticleFeedbackv5/SpecialArticleFeedbackv5.php
@@ -15,18 +15,31 @@
1616 * @subpackage Special
1717 */
1818 class SpecialArticleFeedbackv5 extends SpecialPage {
 19+ private $access;
1920 private $filters = array(
2021 'visible',
21 - 'invisible',
2222 'all',
2323 'comment'
2424 );
 25+ private $sorts = array(
 26+ 'newest',
 27+ 'oldest',
 28+ 'helpful'
 29+ );
2530
2631 /**
2732 * Constructor
2833 */
2934 public function __construct() {
3035 parent::__construct( 'ArticleFeedbackv5' );
 36+ $this->access = ApiArticleFeedbackv5Utils::initializeAccess();
 37+
 38+ if( $this->access[ 'rollbackers' ] ) {
 39+ $filter[] = 'invisible';
 40+ }
 41+ if( $this->access[ 'oversight' ] ) {
 42+ $filter[] = 'deleted';
 43+ }
3144 }
3245
3346 /**
@@ -121,8 +134,7 @@
122135 $out->addModules( 'jquery.articleFeedbackv5.special' );
123136
124137 $sortLabels = array();
125 - $sortOpts = array( 'newest', 'oldest', 'helpful' );
126 - foreach ( $sortOpts as $sort ) {
 138+ foreach ( $this->sorts as $sort ) {
127139 $sortLabels[] = Html::element(
128140 'a',
129141 array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r109624AFT5 - followup to r109582, replace spaces with tabs.gregchiasson16:09, 20 January 2012

Comments

#Comment by Santhosh.thottingal (talk | contribs)   09:27, 20 January 2012

please add message documentation for articlefeedbackv5-error-blocked in $messages['qqq']

#Comment by Johnduhart (talk | contribs)   14:41, 20 January 2012

Mixes spaces and tabs.

#Comment by Gregchiasson (talk | contribs)   22:27, 24 January 2012

Spaces and tabs were fixed in r109624, and the articlefeedbackv5-error-blocked documentation was added in r109620 (which, admittedly, I forgot to tag as a followup to this).

#Comment by Catrope (talk | contribs)   05:59, 31 January 2012
+                        'autoconfirmed' => in_array('autoconfirmed', $wgUser->getEffectiveGroups()),
+                        'rollbackers'   => in_array('rollbacker', $wgUser->getEffectiveGroups()),
+                        'admins'        => in_array('sysop', $wgUser->getEffectiveGroups()),
+                        'oversight'     => in_array('oversight', $wgUser->getEffectiveGroups())

Please don't hardcode group names like this, use rights instead, like this:

// Check if the user has a given right
if ( $wgUser->isAllowed( 'articlefeedbackv5-viewdeletedfeedback' ) ) { ... }

// Add this to ArticleFeedbackv5.php to add the right
$wgAvailableRights[] = 'articlefeedbackv5-viewdeletedfeedback';

// Add an i18n message describing the right in ArticleFeedbackv5.i18n.php
'right-articlefeedbackv5-viewdeletedfeedback' => 'View deleted ArticleFeedback comments',

// To assign the right to a group, put this in LocalSettings.php:
$wgGroupPermissions['sysop']['articlefeedbackv5-viewdeletedfeedback'] = true;

OK otherwise.

#Comment by Catrope (talk | contribs)   06:56, 31 January 2012

Groups/rights stuff fixed in r109931.

Status & tagging log