Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/61797
Change subject: WIP - Quickly enable/disable AFTv5
......................................................................
WIP - Quickly enable/disable AFTv5
@todo:
* Enable/disable ajax links in toolbox, on article page
* Make Special page message pretty
Change-Id: I7029a628ba724ba53f3aaebbf98e3d652c823464
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.i18n.php
M ArticleFeedbackv5.php
M SpecialArticleFeedbackv5.php
A api/ApiSetStatusArticleFeedbackv5.php
M modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
M modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
7 files changed, 311 insertions(+), 11 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5
refs/changes/97/61797/1
diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index 9f2d623..d2ec8a1 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -751,7 +751,7 @@
$requestPermission = $wgRequest->getVal(
'articlefeedbackv5-protection-level' );
$requestExpiry = $wgRequest->getText(
'articlefeedbackv5-protection-expiration' );
$requestExpirySelection = $wgRequest->getVal(
'articlefeedbackv5-protection-expiration-selection' );
-
+/*
// fetch permissions set to edit page ans make sure that AFT
permissions are no tighter than these
$editPermission = $article->getTitle()->getRestrictions( 'edit'
);
if ( !$editPermission ) {
@@ -762,7 +762,7 @@
$errorMsg .= wfMessage(
'articlefeedbackv5-protection-level-error' )->escaped();
return false;
}
-
+*/
if ( $requestExpirySelection == 'existing' ) {
$expirationTime =
ArticleFeedbackv5Permissions::getRestriction( $article->getId() )->pr_expiry;
} else {
diff --git a/ArticleFeedbackv5.i18n.php b/ArticleFeedbackv5.i18n.php
index e63e822..be7df70 100644
--- a/ArticleFeedbackv5.i18n.php
+++ b/ArticleFeedbackv5.i18n.php
@@ -70,6 +70,14 @@
'articlefeedbackv5-protection-permission-member' => 'Enable for
logged-in users only',
'articlefeedbackv5-protection-permission-editor' => 'Enable for
autoconfirmed users only',
'articlefeedbackv5-protection-permission-administrator' => 'Enable for
administrators only',
+ 'articlefeedbackv5-disabled' => "Feedback has been disabled",
+ 'articlefeedbackv5-disabled-admin-admin' => "Feedback has been disabled
for readers and editors. They can't post new feedback on this page.",
+ 'articlefeedbackv5-disabled-admin-editor' => "Feedback has been
disabled for readers. They can't post new feedback on this page.",
+ 'articlefeedbackv5-disabled-editor-admin' => "Feedback has been
disabled by an administrator. Readers can't post new feedback on this page.",
+ 'articlefeedbackv5-disabled-editor-editor' => "Feedback has been
disabled. Readers can't post new feedback on this page.",
+ 'articlefeedbackv5-disabled-reader' => "Feedback has been disabled.
Readers can't post new feedback on this page.",
+ 'articlefeedbackv5-disabled-admin-button-text' => 'Change protection',
+ 'articlefeedbackv5-disabled-editor-button-text' => 'Enable feedback',
/* My Contributions */
'articlefeedbackv5-contribs-entry' => '$1 . . $2 . . [[$3|Feedback:
$4]] $5 $6 $7',
@@ -266,6 +274,8 @@
'articlefeedbackv5-abuse-saved' => 'Flagged as abuse',
'articlefeedbackv5-abuse-saved-tooltip' => 'Remove the flag you set',
'articlefeedbackv5-error-loading-feedback' => 'Error loading feedback',
+ 'articlefeedbackv5-invalid-page-id' => 'Invalid page ID',
+ 'articlefeedbackv5-insufficient-permissions' => 'Insufficient
permission level',
'articlefeedbackv5-invalid-feedback-id' => 'Invalid feedback ID',
'articlefeedbackv5-invalid-log-id' => 'Invalid log ID',
'articlefeedbackv5-invalid-log-update' => 'Log entry could not be
updated',
@@ -799,6 +809,14 @@
'articlefeedbackv5-protection-permission-member' => 'Dropdown menu
option to enable AFT for registered users only',
'articlefeedbackv5-protection-permission-editor' => 'Dropdown menu
option to enable AFT for editors only',
'articlefeedbackv5-protection-permission-administrator' => 'Dropdown
menu option to enable AFT for administrators only',
+ 'articlefeedbackv5-disabled' => 'Title for the message that article
feedback has been disabled for this page',
+ 'articlefeedbackv5-disabled-admin-admin' => 'Message, to an admin, that
has disabled feedback for this page for both editors and readers',
+ 'articlefeedbackv5-disabled-admin-editor' => 'Message, to an admin,
that has disabled feedback for this page for readers',
+ 'articlefeedbackv5-disabled-editor-admin' => "Message, to an editor,
that has disabled feedback for this page for both editors and readers (an
editor can't edit this setting)",
+ 'articlefeedbackv5-disabled-editor-editor' => 'Message, to an editor,
that has disabled feedback for this page for readers',
+ 'articlefeedbackv5-disabled-reader' => "Message, to a reader, that has
disabled feedback for this page (a reader can't edit this setting)",
+ 'articlefeedbackv5-disabled-admin-button-text' => 'Button text for link
to page protection, where admins can enable/disable the article feedback tool',
+ 'articlefeedbackv5-disabled-editor-button-text' => 'Button text for
link that will (re-)enable the article feedback tool at once, for editors',
'articlefeedbackv5-contribs-entry' => 'AFT entry line displayed on My
Contributions. An example of this line could be: 10:59, 30 August 2012 . .
(+55) . . Feedback: Main Page (This is some more feedback, using the AFT
feedback form) . . Status: Helpful and Featured
* $1 - the date with link to feedback permalink - in the example: "10:59, 30
August 2012"
* $2 - the comment character count - in the example: "(+55)"
@@ -1148,7 +1166,9 @@
'articlefeedbackv5-abuse-saved' => 'Message displayed when abuse flag
was saved successfully.',
'articlefeedbackv5-abuse-saved-tooltip' => 'Tooltip shown on the
un-flag as abuse link, to indicate what clicking on it will do (the link text
-- {{msg-mw|articlefeedbackv5-abuse-saved}} -- is used to indicate state).',
'articlefeedbackv5-error-loading-feedback' => 'Message displayed when
there was an error loading feedback - result is a largely-blank page.',
- 'articlefeedbackv5-invalid-feedback-id' => 'Message to be displayed
when, though the api, an invalid feedback id paremeter is given.',
+ 'articlefeedbackv5-invalid-page-id' => 'Message to be displayed when,
via the api, an invalid page id parameter is given',
+ 'articlefeedbackv5-insufficient-permissions' => 'Message to be
displayed when, via the api, something is to be executed that the user does not
have sufficient permissions for',
+ 'articlefeedbackv5-invalid-feedback-id' => 'Message to be displayed
when, via the api, an invalid feedback id parameter is given.',
'articlefeedbackv5-invalid-log-id' => "Message to be displayed when the
id of the action's log entry can't be found'",
'articlefeedbackv5-invalid-log-update' => 'Message to be displayed when
the log entry could not be updated (e.g.: error in adding a note after the
action has been performed already)',
'articlefeedbackv5-invalid-feedback-flag' => 'Message to be displayed
when, though the api, an invalid flag parameter (e.g. oversight, feature,
helpful, ...) is given.',
diff --git a/ArticleFeedbackv5.php b/ArticleFeedbackv5.php
index 79a8737..72f6cb3 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -391,6 +391,7 @@
$wgAutoloadClasses['ApiArticleFeedbackv5'] = __DIR__ .
'/api/ApiArticleFeedbackv5.php';
$wgAutoloadClasses['ApiViewRatingsArticleFeedbackv5'] = __DIR__ .
'/api/ApiViewRatingsArticleFeedbackv5.php';
$wgAutoloadClasses['ApiViewFeedbackArticleFeedbackv5'] = __DIR__ .
'/api/ApiViewFeedbackArticleFeedbackv5.php';
+$wgAutoloadClasses['ApiSetStatusArticleFeedbackv5'] = __DIR__ .
'/api/ApiSetStatusArticleFeedbackv5.php';
$wgAutoloadClasses['ApiAddFlagNoteArticleFeedbackv5'] = __DIR__ .
'/api/ApiAddFlagNoteArticleFeedbackv5.php';
$wgAutoloadClasses['ApiFlagFeedbackArticleFeedbackv5'] = __DIR__ .
'/api/ApiFlagFeedbackArticleFeedbackv5.php';
$wgAutoloadClasses['ApiViewActivityArticleFeedbackv5'] = __DIR__ .
'/api/ApiViewActivityArticleFeedbackv5.php';
@@ -431,6 +432,7 @@
// API Registration
$wgAPIListModules['articlefeedbackv5-view-feedback'] =
'ApiViewFeedbackArticleFeedbackv5';
$wgAPIListModules['articlefeedbackv5-view-activity'] =
'ApiViewActivityArticleFeedbackv5';
+$wgAPIModules['articlefeedbackv5-set-status'] =
'ApiSetStatusArticleFeedbackv5';
$wgAPIModules['articlefeedbackv5-add-flag-note'] =
'ApiAddFlagNoteArticleFeedbackv5';
$wgAPIModules['articlefeedbackv5-flag-feedback'] =
'ApiFlagFeedbackArticleFeedbackv5';
$wgAPIModules['articlefeedbackv5'] = 'ApiArticleFeedbackv5';
@@ -710,6 +712,9 @@
'articlefeedbackv5-invalid-feedback-flag',
'articlefeedbackv5-invalid-feedback-state',
'articlefeedbackv5-feedback-reloaded-after-error',
+ 'articlefeedbackv5-error-unknown',
+ 'articlefeedbackv5-invalid-page-id',
+ 'articlefeedbackv5-insufficient-permissions',
'articlefeedbackv5-comment-more',
'articlefeedbackv5-comment-less',
diff --git a/SpecialArticleFeedbackv5.php b/SpecialArticleFeedbackv5.php
index eb13f8a..e2db08c 100644
--- a/SpecialArticleFeedbackv5.php
+++ b/SpecialArticleFeedbackv5.php
@@ -201,7 +201,9 @@
Html::rawElement(
'div',
array( 'id' => 'articleFeedbackv5-special-wrap'
),
- $this->buildHeaderLinks() .
$this->buildContent( $renderer, $records )
+ $this->buildStatusBox() .
+ $this->buildHeaderLinks() .
+ $this->buildContent( $renderer, $records )
)
);
@@ -285,12 +287,12 @@
$this->title,
$this->msg(
'articlefeedbackv5-go-to-article' )->escaped()
) .
- ' | ' .
- Linker::link(
- $this->title->getTalkPage(),
- $this->msg(
'articlefeedbackv5-discussion-page' )->escaped()
- ) .
- ' | ';
+ ' | ' .
+ Linker::link(
+ $this->title->getTalkPage(),
+ $this->msg(
'articlefeedbackv5-discussion-page' )->escaped()
+ ) .
+ ' | ';
}
// build header for list-views
@@ -437,6 +439,77 @@
}
/**
+ * If AFTv5 is disabled for a certain page, show a notice and link
+ * to re-enable (if possible)
+ *
+ * @return string
+ */
+ protected function buildStatusBox() {
+ if ( !$this->pageId ) {
+ return '';
+ }
+
+ $restriction = ArticleFeedbackv5Permissions::getRestriction(
$this->pageId )->pr_level;
+
+ // not restricted
+ if ( $restriction == 'aft-reader' ) {
+ return '';
+ }
+
+ $link = '';
+
+ // admins can change settings at page protection
+ if ( $this->getUser()->isAllowed( 'aft-administrator' ) ) {
+ $title = Title::newFromID( $this->pageId );
+ $link = Linker::linkKnown(
+ $title,
+ $this->msg(
'articlefeedbackv5-disabled-admin-button-text' )->escaped(),
+ array(),
+ array( 'action' => 'protect' )
+ );
+
+ // admin-only setting
+ if ( $restriction === 'aft-administrator' ) {
+ $message =
'articlefeedbackv5-disabled-admin-admin';
+
+ // admin+editors setting
+ } else {
+ $message =
'articlefeedbackv5-disabled-admin-editor';
+ }
+
+ // editors can change settings unless restriction is
admin-specific
+ } elseif ( $this->getUser()->isAllowed( 'aft-editor' ) ) {
+ // admin-only setting
+ if ( $restriction === 'aft-administrator' ) {
+ $message =
'articlefeedbackv5-disabled-editor-admin';
+
+ // admin+editors setting
+ } else {
+ // link will trigger API call in JS
+ $link = Html::rawElement(
+ 'a',
+ array( 'href' => '#', 'id' =>
'articlefeedbackv5-enable' ),
+ $this->msg(
'articlefeedbackv5-disabled-editor-button-text' )->escaped()
+ );
+
+ $message =
'articlefeedbackv5-disabled-editor-editor';
+ }
+
+ // reader can't change settings
+ } else {
+ $message = 'articlefeedbackv5-disabled-reader';
+ }
+
+ return Html::rawElement(
+ 'div',
+ array( 'id' => 'articlefeedbackv5-disabled' ),
+ $this->msg( 'articlefeedbackv5-disabled' )->escaped() .
+ $this->msg( $message )->escaped() .
+ $link
+ );
+ }
+
+ /**
* @param ArticleFeedbackv5Render $renderer the renderer
* @param DataModelList $record the fetched records
* @return string
diff --git a/api/ApiSetStatusArticleFeedbackv5.php
b/api/ApiSetStatusArticleFeedbackv5.php
new file mode 100644
index 0000000..8712bb4
--- /dev/null
+++ b/api/ApiSetStatusArticleFeedbackv5.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * ApiSetStatusArticleFeedbackv5 class
+ *
+ * @package ArticleFeedback
+ * @subpackage Api
+ * @author Matthias Mullie <[email protected]>
+ */
+
+/**
+ * This class allows one to quickly enable/disable the AFTv5 form for a
certain page.
+ *
+ * @package ArticleFeedback
+ * @subpackage Api
+ */
+class ApiSetStatusArticleFeedbackv5 extends ApiBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, '' );
+ }
+
+ public function execute() {
+ wfProfileIn( __METHOD__ );
+
+ global $wgUser;
+
+ $params = $this->extractRequestParams();
+ $results = array();
+
+ // check if page exists
+ if ( Title::newFromID( $params['pageid'] ) === null ) {
+ $results['result'] = 'Error';
+ $results['reason'] =
'articlefeedbackv5-invalid-page-id';
+
+ // check if current user has editor permission
+ } elseif ( !$wgUser->isAllowed( 'aft-editor' ) ) {
+ $results['result'] = 'Error';
+ $results['reason'] =
'articlefeedbackv5-insufficient-permissions';
+
+ // check if existing page restriction is not too tight (set
tight by administrator, should not be overridden)
+ } elseif ( ArticleFeedbackv5Permissions::getRestriction(
$params['pageid'] )->pr_level === 'aft-administrator' ) {
+ $results['result'] = 'Error';
+ $results['reason'] =
'articlefeedbackv5-insufficient-permissions';
+
+ } else {
+ // enable: allow for all (= allow reader and up);
+ // disable: disable for editor and below (= allow
aft-administrator and up)
+ $restriction = $params['enable'] ? 'aft-reader' :
'aft-editor';
+
+ $success = ArticleFeedbackv5Permissions::setRestriction(
+ $params['pageid'],
+ $restriction,
+ wfGetDB( DB_SLAVE )->getInfinity()
+ );
+
+ if ( !$success ) {
+ $results['result'] = 'Error';
+ $results['reason'] =
'articlefeedbackv5-error-unknown';
+ } else {
+ $results['result'] = 'Success';
+ $results['reason'] = null;
+ }
+ }
+
+ $this->getResult()->addValue(
+ null,
+ $this->getModuleName(),
+ $results
+ );
+
+ wfProfileOut( __METHOD__ );
+ }
+
+ /**
+ * Gets the allowed parameters
+ *
+ * @return array the params info, indexed by allowed key
+ */
+ public function getAllowedParams() {
+ return array(
+ 'pageid' => array(
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_ISMULTI => false,
+ ApiBase::PARAM_TYPE => 'integer'
+ ),
+ 'enable' => array(
+ ApiBase::PARAM_TYPE => array( 0, 1 ),
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ );
+ }
+
+ /**
+ * Gets the parameter descriptions
+ *
+ * @return array the descriptions, indexed by allowed key
+ */
+ public function getParamDescription() {
+ return array(
+ 'pageid' => 'PageID to enable/disable AFTv5 for',
+ 'enable' => '1 to enable, 0 to disable AFTv5',
+ );
+ }
+
+ /**
+ * Gets the api descriptions
+ *
+ * @return array the description as the first element in an array
+ */
+ public function getDescription() {
+ return array(
+ 'Enable/disable AFTv5 for a certain page.'
+ );
+ }
+
+ /**
+ * Gets an example
+ *
+ * @return array the example as the first element in an array
+ */
+ protected function getExamples() {
+ return array(
+
'api.php?action=articlefeedbackv5-set-status&pageid=1&enable=1'
+ );
+ }
+
+ /**
+ * Gets the version info
+ *
+ * @return string the SVN version info
+ */
+ public function getVersion() {
+ return __CLASS__ . ': version 1.5';
+ }
+
+ public function isWriteMode() { return true; }
+
+ public function mustBePosted() { return true; }
+
+}
diff --git
a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
index 55fef3b..f62e978 100644
--- a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
+++ b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.special.js
@@ -442,6 +442,24 @@
$( e.target ).siblings(
'.articleFeedbackv5-comment-full' ).show();
$( e.target ).hide();
} );
+
+ // switch to enable AFTv5
+ $( '#articlefeedbackv5-enable' ).on( 'click', function( e ) {
+ e.preventDefault();
+
+ $.aftUtils.setStatus( $.articleFeedbackv5special.page,
1, function( data ) {
+ if ( 'result' in data ) {
+ if ( data.result === 'Success' ) {
+ // it was just re-enabled;
remove notice that it's disabled
+ $(
'#articlefeedbackv5-disabled' ).remove();
+
+ } else if ( data.result === 'Error' &&
data.reason ) {
+ alert( mw.msg( data.reason ) );
+ }
+ }
+ } );
+
+ });
};
// }}}
@@ -744,6 +762,7 @@
return false;
};
+ // }}}
// {{{ addNote
/**
diff --git a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
index 55b11c4..d517aaa 100644
--- a/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
+++ b/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.utils.js
@@ -203,7 +203,7 @@
* The cookie name is prefixed by the extension name and a version
number,
* to avoid collisions with other extensions or code versions.
*
- * @param string $suffix
+ * @param string suffix
* @return string
*/
$.aftUtils.getCookieName = function ( suffix ) {
@@ -242,6 +242,50 @@
}
// }}}
+ // {{{ setStatus
+
+ /**
+ * Enable/disable feedback on a certain page
+ *
+ * @param int pageId the page id
+ * @param bool enable true to enable, false to disable
+ * @param function callback function to execute after setting status
+ */
+ $.aftUtils.setStatus = function ( pageId, enable, callback ) {
+ var result = [];
+ result['result'] = 'Error';
+ result['reason'] = 'articlefeedbackv5-error-unknown';
+
+ $.ajax( {
+ 'url': mw.util.wikiScript( 'api' ),
+ 'type': 'POST',
+ 'dataType': 'json',
+ 'data': {
+ 'pageid': pageId,
+ 'enable': parseInt( enable ),
+ 'format': 'json',
+ 'action': 'articlefeedbackv5-set-status'
+ },
+ 'success': function ( data ) {
+ if ( 'articlefeedbackv5-set-status' in data ) {
+ result =
data['articlefeedbackv5-set-status'];
+ }
+
+ // invoke callback function
+ if ( typeof callback == 'function' ) {
+ callback( result );
+ }
+ },
+ 'error': function ( data ) {
+ // invoke callback function
+ if ( typeof callback == 'function' ) {
+ callback( result );
+ }
+ }
+ } );
+ };
+
+ // }}}
// }}}
--
To view, visit https://gerrit.wikimedia.org/r/61797
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7029a628ba724ba53f3aaebbf98e3d652c823464
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits