jenkins-bot has submitted this change and it was merged.
Change subject: When changing AFT visibility in action=protect, add to log
......................................................................
When changing AFT visibility in action=protect, add to log
Change-Id: Icee466faa962ad4c4e49b68dbb054e543b93b0a7
---
M ArticleFeedbackv5.hooks.php
M ArticleFeedbackv5.i18n.php
M ArticleFeedbackv5.log.php
M ArticleFeedbackv5.permissions.php
M ArticleFeedbackv5.php
5 files changed, 137 insertions(+), 21 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index 7f3f4bc..63bacda 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -656,11 +656,11 @@
// on a per-page basis, AFT can only be restricted from these
levels
$levels = array(
- 'aft-reader' =>
'articlefeedbackv5-protection-permission-reader',
- 'aft-member' =>
'articlefeedbackv5-protection-permission-member',
- 'aft-editor' =>
'articlefeedbackv5-protection-permission-editor',
- 'aft-administrator' =>
'articlefeedbackv5-protection-permission-administrator',
- 'aft-noone' =>
'articlefeedbackv5-protection-permission-noone',
+ 'aft-reader' => 'protect-level-aft-reader',
+ 'aft-member' => 'protect-level-aft-member',
+ 'aft-editor' => 'protect-level-aft-editor',
+ 'aft-administrator' =>
'protect-level-aft-administrator',
+ 'aft-noone' => 'protect-level-aft-noone',
);
// build permissions dropdown
@@ -673,7 +673,7 @@
) + $disabledAttrib;
$permissionsDropdown = Xml::openElement( 'select', $attribs );
foreach( $levels as $key => $label ) {
- // possible labels:
articlefeedbackv5-protection-permission-(reader|member|editor|administrator|noone)
+ // possible labels:
protect-level-aft-(reader|member|editor|administrator|noone)
$permissionsDropdown .= Xml::option( wfMessage( $label
)->escaped(), $key, $key == $existingRestriction->pr_level );
}
$permissionsDropdown .= Xml::closeElement( 'select' );
@@ -786,10 +786,11 @@
* Parts of code are heavily "inspired" by ProtectionForm.
*
* @param Page $article
- * @param string $errorMsg
+ * @param string &$errorMsg
+ * @param string $reason
* @return bool
*/
- public static function onProtectionSave( Page $article, &$errorMsg ) {
+ public static function onProtectionSave( Page $article, &$errorMsg,
$reason ) {
global $wgRequest,
$wgArticleFeedbackv5Namespaces,
$wgArticleFeedbackv5EnableProtection;
@@ -840,13 +841,36 @@
$success = ArticleFeedbackv5Permissions::setRestriction(
$article->getId(),
$requestPermission,
- $expirationTime
+ $expirationTime,
+ $reason
);
return $success;
}
/**
+ * Add AFT permission logs to action=protect.
+ *
+ * @param Page $article
+ * @param OutputPage $out
+ * @return bool
+ */
+ public static function onShowLogExtract( Page $article, OutputPage $out
) {
+ global $wgArticleFeedbackv5Namespaces;
+
+ // only on pages in namespaces where it is enabled
+ if ( !$article->getTitle()->inNamespaces(
$wgArticleFeedbackv5Namespaces ) ) {
+ return true;
+ }
+
+ $protectLogPage = new LogPage( 'articlefeedbackv5' );
+ $out->addHTML( Xml::element( 'h2', null,
$protectLogPage->getName()->text() ) );
+ LogEventsList::showLogExtract( $out, 'articlefeedbackv5',
$article->getTitle() );
+
+ return true;
+ }
+
+ /**
* Post-login update new user's last feedback with his new id
*
* @param User $currentUser
diff --git a/ArticleFeedbackv5.i18n.php b/ArticleFeedbackv5.i18n.php
index bc0442f..b984adf 100644
--- a/ArticleFeedbackv5.i18n.php
+++ b/ArticleFeedbackv5.i18n.php
@@ -66,11 +66,13 @@
/* Page protection */
'articlefeedbackv5-protection-level' => 'Article feedback',
'articlefeedbackv5-protection-level-error' => 'Article feedback
protection level cannot be higher than Edit protection level',
- 'articlefeedbackv5-protection-permission-reader' => 'Enable for all
users',
- '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-protection-permission-noone' => 'Disable for all
users',
+ 'protect-level-aft-reader' => 'Enable for all users',
+ 'protect-level-aft-member' => 'Enable for logged-in users only',
+ 'protect-level-aft-editor' => 'Enable for autoconfirmed users only',
+ 'protect-level-aft-administrator' => 'Enable for administrators only',
+ 'protect-level-aft-noone' => 'Disable for all users',
+ 'articlefeedbackv5-protection-title' => 'Changed visibility of the
article feedback tool on "[[$1]]"',
+ 'restriction-articlefeedbackv5' => 'Visibility',
'articlefeedbackv5-disabled' => "Feedback has been disabled",
'articlefeedbackv5-disabled-admin-admin' => "Feedback has been disabled
for readers and editors. They cannot post new feedback on this page.",
'articlefeedbackv5-disabled-admin-editor' => "Feedback has been
disabled for readers. They cannot post new feedback on this page.",
@@ -642,6 +644,7 @@
'logentry-articlefeedbackv5-undo-helpful' => '$1 {{GENDER:$2|un-marked
as helpful}} [[$3|feedback post #$4]] on [[$5]]',
'logentry-articlefeedbackv5-undo-unhelpful' => '$1
{{GENDER:$2|un-marked as unhelpful}} [[$3|feedback post #$4]] on [[$5]]',
'logentry-articlefeedbackv5-clear-flags' => '$1 {{GENDER:$2|cleared all
flags}} [[$3|feedback post #$4]] on [[$5]]',
+ 'logentry-articlefeedbackv5-protect' => '$1 changed visibility of the
article feedback tool on "$3" $4',
/* Activity Pane phrases */
'articlefeedbackv5-activity-pane-header' => 'Activity Log',
@@ -816,17 +819,20 @@
'articlefeedbackv5-error-throttled' => 'Error message to be displayed
when a user attempts to post too much feedback in too little time.',
'articlefeedbackv5-protection-level' => 'Fieldset label to be used for
AFT page protection levels',
'articlefeedbackv5-protection-level-error' => "Error message when
protection level is too high compared to the page's edit protection level",
- 'articlefeedbackv5-protection-permission-reader' => 'Dropdown menu
option to enable AFT for all users',
- '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-protection-permission-noone' => 'Dropdown menu
option to disable AFT for all users',
'articlefeedbackv5-disabled' => 'Title for the message that article
feedback has been disabled for this page on this page',
'articlefeedbackv5-disabled-admin-admin' => 'Message, to an admin, that
feedback has been disabled for both editors and readers on this page',
'articlefeedbackv5-disabled-admin-editor' => 'Message, to an admin,
that feedback has been disabled for readers on this page',
'articlefeedbackv5-disabled-editor-admin' => "Message, to an editor,
that feedback has been disabled for both editors and readers on this page (an
editor can't edit this setting)",
'articlefeedbackv5-disabled-editor-editor' => 'Message, to an editor,
that feedback has been disabled for readers on this page',
'articlefeedbackv5-disabled-reader' => "Message, to a reader, that
feedback has been disabled on this page (a reader can't edit this setting)",
+ 'protect-level-aft-reader' => 'Dropdown menu option to enable AFT for
all users',
+ 'protect-level-aft-member' => 'Dropdown menu option to enable AFT for
registered users only',
+ 'protect-level-aft-editor' => 'Dropdown menu option to enable AFT for
editors only',
+ 'protect-level-aft-administrator' => 'Dropdown menu option to enable
AFT for administrators only',
+ 'protect-level-aft-noone' => 'Dropdown menu option to disable AFT for
all users',
+ 'articlefeedbackv5-protection-title' => 'Comment for the empty revision
created when changing visibility of AFT on that page. Parameters:
+* $1 is the title of the page whose protection was changed',
+ 'restriction-articlefeedbackv5' => 'Clarification of the exact setting
that changed, in the detailed visibility section added to the comment of an
empty revision created after changing AFT visibility for a page. The
"Visibility" part in e.g. [Visibility=Enable for all users]',
'articlefeedbackv5-disabled-admin-button-text' => 'Button text for link
to page protection, where admins can enable/disable the article feedback tool.
{{Identical|Change protection}}',
'articlefeedbackv5-disabled-editor-button-text' => 'Button text for
link that will (re-)enable the article feedback tool at once, for editors',
@@ -1941,6 +1947,11 @@
* $4 - The feedback's id
* $5 - A link to the article the feedback was posted to
{{Related|Logentry-articlefeedbackv5}}",
+ 'logentry-articlefeedbackv5-protect' => "Log entry for when article
feedback tool visibility changes in page protection settings. Parameters:
+* $1 - A link to the performer
+* $2 - The performer's id, gender support
+* $3 - A link to the page
+* $4 - The selected protection level (e.g. [articlefeedbackv5=aft-editor])",
'articlefeedbackv5-activity-pane-header' => 'Flyover panel caption',
'articlefeedbackv5-activity-feedback-info' => 'Post information
template. Parameters:
* $1 - the feedback post ID (parameter currently unused)
diff --git a/ArticleFeedbackv5.log.php b/ArticleFeedbackv5.log.php
index 49c4fa7..a1382b5 100644
--- a/ArticleFeedbackv5.log.php
+++ b/ArticleFeedbackv5.log.php
@@ -150,3 +150,53 @@
return $this->plaintext ? strip_tags( $text ) : $text;
}
}
+
+/**
+ * This class formats AFTv5 protection log entries.
+ *
+ * @package ArticleFeedback
+ * @author Matthias Mullie <[email protected]>
+ * @version $Id$
+ */
+class ArticleFeedbackv5ProtectionLogFormatter extends LogFormatter {
+ /**
+ * @return array
+ */
+ protected function getMessageParameters() {
+ $params = parent::getMessageParameters();
+
+ $articleId = $this->entry->getTarget()->getArticleID();
+ $page = WikiPage::newFromID( $articleId );
+ if ( $page ) {
+ $parameters = $this->entry->getParameters();
+ $permission = array( 'articlefeedbackv5' =>
$parameters['permission'] );
+ $expiry = array( 'articlefeedbackv5' =>
$parameters['expiry'] );
+
+ $params[] = $page->protectDescriptionLog( $permission,
$expiry );
+ }
+
+ return $params;
+ }
+
+ /**
+ * Returns extra links that comes after the action text, like "revert",
etc.
+ *
+ * @return string
+ */
+ public function getActionLinks() {
+ $links = array(
+ Linker::link(
+ $this->entry->getTarget(),
+ $this->msg( 'hist' )->escaped(),
+ array(),
+ array(
+ 'action' => 'history',
+ 'offset' => $this->entry->getTimestamp()
+ )
+ )
+ );
+
+ return $this->msg( 'parentheses' )->rawParams(
+ $this->context->getLanguage()->pipeList( $links )
)->escaped();
+ }
+}
diff --git a/ArticleFeedbackv5.permissions.php
b/ArticleFeedbackv5.permissions.php
index 4dcb309..dc114c0 100644
--- a/ArticleFeedbackv5.permissions.php
+++ b/ArticleFeedbackv5.permissions.php
@@ -175,9 +175,10 @@
* @param int $articleId
* @param string $permission
* @param string $expiry
+ * @param string[optional] $reason
* @return bool
*/
- public static function setRestriction( $articleId, $permission, $expiry
) {
+ public static function setRestriction( $articleId, $permission,
$expiry, $reason = '' ) {
// check if opt-in/-out is enabled
global $wgArticleFeedbackv5EnableProtection;
if ( !$wgArticleFeedbackv5EnableProtection ) {
@@ -194,6 +195,8 @@
if ( !self::isValidPermission( $permission ) ) {
return false;
}
+
+ global $wgUser;
$dbw = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_SLAVE );
@@ -232,9 +235,32 @@
);
}
- // purge page's cache, to accurately expose updated changes to
JS
if ( $dbw->affectedRows() > 0 ) {
+ // purge page's cache, to accurately expose updated
changes to JS
$pageObj->doPurge();
+
+ // make sure timestamp doesn't overlap with protection
log's null revision (if any)
+ $timestamp = Revision::getTimestampFromId(
$pageObj->getTitle(), $pageObj->getLatest() );
+ if ( $timestamp === wfTimestampNow() ) {
+ sleep( 1 );
+ }
+
+ $pageObj->insertProtectNullRevision(
+ 'articlefeedbackv5-protection-title',
+ array( 'articlefeedbackv5' => $permission ),
+ array( 'articlefeedbackv5' => $expiry ),
+ false,
+ $reason
+ );
+
+ // insert into log
+ $logEntry = new ManualLogEntry( 'articlefeedbackv5',
'protect' );
+ $logEntry->setTarget( $pageObj->getTitle() );
+ $logEntry->setPerformer( $wgUser );
+ $logEntry->setParameters( array( 'permission' =>
$permission, 'expiry' => $expiry ) );
+ $logEntry->setComment( $reason );
+ $logId = $logEntry->insert();
+ $logEntry->publish( $logId );
}
return true;
diff --git a/ArticleFeedbackv5.php b/ArticleFeedbackv5.php
index 5500595..7c0e9df 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -415,6 +415,7 @@
$wgAutoloadClasses['ArticleFeedbackv5Permissions'] = __DIR__ .
'/ArticleFeedbackv5.permissions.php';
$wgAutoloadClasses['ArticleFeedbackv5Log'] = __DIR__ .
'/ArticleFeedbackv5.log.php';
$wgAutoloadClasses['ArticleFeedbackv5LogFormatter'] = __DIR__ .
'/ArticleFeedbackv5.log.php';
+$wgAutoloadClasses['ArticleFeedbackv5ProtectionLogFormatter'] = __DIR__ .
'/ArticleFeedbackv5.log.php';
$wgAutoloadClasses['ArticleFeedbackv5Flagging'] = __DIR__ .
'/ArticleFeedbackv5.flagging.php';
$wgAutoloadClasses['ArticleFeedbackv5MailerJob'] = __DIR__ .
'/ArticleFeedbackv5.mailerJob.php';
$wgAutoloadClasses['ArticleFeedbackv5Render'] = __DIR__ .
'/ArticleFeedbackv5.render.php';
@@ -439,6 +440,7 @@
$wgHooks['ContributionsLineEnding'][] =
'ArticleFeedbackv5Hooks::contributionsLineEnding';
$wgHooks['ProtectionForm::buildForm'][] =
'ArticleFeedbackv5Hooks::onProtectionForm';
$wgHooks['ProtectionForm::save'][] =
'ArticleFeedbackv5Hooks::onProtectionSave';
+$wgHooks['ProtectionForm::showLogExtract'][] =
'ArticleFeedbackv5Hooks::onShowLogExtract';
$wgHooks['UserLoginComplete'][] = 'ArticleFeedbackv5Hooks::userLoginComplete';
// API Registration
@@ -471,6 +473,9 @@
// Logging
$wgLogTypes[] = 'articlefeedbackv5';
+// register log handler for AFT protection log
+$wgLogActionsHandlers['articlefeedbackv5/protect'] =
'ArticleFeedbackv5ProtectionLogFormatter';
+
// register log handler for feedback submission
$wgLogActionsHandlers['articlefeedbackv5/create'] =
'ArticleFeedbackv5LogFormatter';
--
To view, visit https://gerrit.wikimedia.org/r/64621
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icee466faa962ad4c4e49b68dbb054e543b93b0a7
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/ArticleFeedbackv5
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: EBernhardson (WMF) <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits