http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89982
Revision: 89982
Author: krinkle
Date: 2011-06-13 17:42:40 +0000 (Mon, 13 Jun 2011)
Log Message:
-----------
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
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
Modified: trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php
===================================================================
--- trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php 2011-06-13
17:27:29 UTC (rev 89981)
+++ trunk/extensions/ArticleFeedback/api/ApiArticleFeedback.php 2011-06-13
17:42:40 UTC (rev 89982)
@@ -5,9 +5,11 @@
}
public function execute() {
- global $wgUser, $wgArticleFeedbackRatings,
$wgArticleFeedbackSMaxage;
+ global $wgUser, $wgArticleFeedbackRatings,
$wgArticleFeedbackSMaxage,
+ $wgArticleFeedbackNamespaces;
$params = $this->extractRequestParams();
+ // Anon token check
if ( $wgUser->isAnon() ) {
if ( !isset( $params['anontoken'] ) ) {
$this->dieUsageMsg( array( 'missingparam',
'anontoken' ) );
@@ -20,6 +22,21 @@
$token = '';
}
+ // Load check, is this page ArticleFeedback-enabled ?
+ // Keep in sync with ext.articleFeedback.startup.js
+ $title = Title::newFromID( $params['pageid'] );
+ if (
+ // Inexisting page ? (newFromID returns null so we
can't use $title->exists)
+ is_null( $title )
+ // Namespace not a valid ArticleFeedback namespace ?
+ || !in_array( $title->getNamespace(),
$wgArticleFeedbackNamespaces )
+ // Page a redirect ?
+ || $title->isRedirect()
+ ) {
+ // ...then error out
+ $this->dieUsage( 'ArticleFeedback is not
enabled on this page', 'invalidpage' );
+ }
+
$dbr = wfGetDB( DB_SLAVE );
// Query the latest ratings by this user for this page,
@@ -424,6 +441,7 @@
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'anontoken' ),
array( 'code' => 'invalidtoken', 'info' => 'The
anontoken is not 32 characters' ),
+ array( 'code' => 'invalidpage', 'info' =>
'ArticleFeedback is not enabled on this page' ),
) );
}
Modified:
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
===================================================================
---
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
2011-06-13 17:27:29 UTC (rev 89981)
+++
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
2011-06-13 17:42:40 UTC (rev 89982)
@@ -278,7 +278,7 @@
'weight': 2,
'condition': function() {
// An empty restrictions array means anyone can
edit
- var restrictions = mw.config.get(
'wgRestrictionEdit' );
+ var restrictions = mw.config.get(
'wgRestrictionEdit', [] );
if ( restrictions.length ) {
var groups = mw.config.get(
'wgUserGroups' );
// Verify that each restriction exists
in the user's groups
Modified:
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
===================================================================
---
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
2011-06-13 17:27:29 UTC (rev 89981)
+++
trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
2011-06-13 17:42:40 UTC (rev 89982)
@@ -3,8 +3,10 @@
*/
jQuery( function( $ ) {
+ // Load check, is this page ArticleFeedback-enabled ?
+ // Keep in sync with ApiArticleFeedback.php
if (
- // Main namespace articles
+ // Only on pages in namespaces where it is enabled
$.inArray( mw.config.get( 'wgNamespaceNumber' ), mw.config.get(
'wgArticleFeedbackNamespaces', [] ) ) > -1
// Existing pages
&& mw.config.get( 'wgArticleId' ) > 0
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs