r89982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89981‎ | r89982 | r89983 >
Date:17:42, 13 June 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Check if page is ArticleFeedback-enabled before saving in the API
* (bug )
* Fix TypeErorr exception in 'condition' function (wgRestrictionEdit is only defined on existing pages, checking length requires that it defined, adding fallback to empty array)
* Correct comment in ext.articleFeedback.startup.js namespace check, not main namespace perse, anything allowed by wgArticleFeedbackNamespaces.
* Add 'invalidpage' to getPossibleErrors
Modified paths:
  • /trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -278,7 +278,7 @@
279279 'weight': 2,
280280 'condition': function() {
281281 // An empty restrictions array means anyone can edit
282 - var restrictions = mw.config.get( 'wgRestrictionEdit' );
 282+ var restrictions = mw.config.get( 'wgRestrictionEdit', [] );
283283 if ( restrictions.length ) {
284284 var groups = mw.config.get( 'wgUserGroups' );
285285 // Verify that each restriction exists in the user's groups
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
@@ -3,8 +3,10 @@
44 */
55
66 jQuery( function( $ ) {
 7+ // Load check, is this page ArticleFeedback-enabled ?
 8+ // Keep in sync with ApiArticleFeedback.php
79 if (
8 - // Main namespace articles
 10+ // Only on pages in namespaces where it is enabled
911 $.inArray( mw.config.get( 'wgNamespaceNumber' ), mw.config.get( 'wgArticleFeedbackNamespaces', [] ) ) > -1
1012 // Existing pages
1113 && mw.config.get( 'wgArticleId' ) > 0
Index: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
@@ -5,9 +5,11 @@
66 }
77
88 public function execute() {
9 - global $wgUser, $wgArticleFeedbackRatings, $wgArticleFeedbackSMaxage;
 9+ global $wgUser, $wgArticleFeedbackRatings, $wgArticleFeedbackSMaxage,
 10+ $wgArticleFeedbackNamespaces;
1011 $params = $this->extractRequestParams();
1112
 13+ // Anon token check
1214 if ( $wgUser->isAnon() ) {
1315 if ( !isset( $params['anontoken'] ) ) {
1416 $this->dieUsageMsg( array( 'missingparam', 'anontoken' ) );
@@ -20,6 +22,21 @@
2123 $token = '';
2224 }
2325
 26+ // Load check, is this page ArticleFeedback-enabled ?
 27+ // Keep in sync with ext.articleFeedback.startup.js
 28+ $title = Title::newFromID( $params['pageid'] );
 29+ if (
 30+ // Inexisting page ? (newFromID returns null so we can't use $title->exists)
 31+ is_null( $title )
 32+ // Namespace not a valid ArticleFeedback namespace ?
 33+ || !in_array( $title->getNamespace(), $wgArticleFeedbackNamespaces )
 34+ // Page a redirect ?
 35+ || $title->isRedirect()
 36+ ) {
 37+ // ...then error out
 38+ $this->dieUsage( 'ArticleFeedback is not enabled on this page', 'invalidpage' );
 39+ }
 40+
2441 $dbr = wfGetDB( DB_SLAVE );
2542
2643 // Query the latest ratings by this user for this page,
@@ -424,6 +441,7 @@
425442 return array_merge( parent::getPossibleErrors(), array(
426443 array( 'missingparam', 'anontoken' ),
427444 array( 'code' => 'invalidtoken', 'info' => 'The anontoken is not 32 characters' ),
 445+ array( 'code' => 'invalidpage', 'info' => 'ArticleFeedback is not enabled on this page' ),
428446 ) );
429447 }
430448

Sign-offs

UserFlagDate
He7d3rinspected22:37, 13 June 2011

Comments

#Comment by Krinkle (talk | contribs)   17:43, 13 June 2011

that is, (bug 29165) Don't save ArticleFeedback ratings for pages where it is not enabled *

Status & tagging log