Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/64621


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, 141 insertions(+), 19 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticleFeedbackv5 
refs/changes/21/64621/1

diff --git a/ArticleFeedbackv5.hooks.php b/ArticleFeedbackv5.hooks.php
index d4e1534..16b81d3 100644
--- a/ArticleFeedbackv5.hooks.php
+++ b/ArticleFeedbackv5.hooks.php
@@ -636,11 +636,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
@@ -655,7 +655,7 @@
                ) + $disabledAttrib;
                $permissionsDropdown = Xml::openElement( 'select', $attribs );
                foreach( $levels as $key => $label ) {
-                       // possible labels: 
articlefeedbackv5-protection-permission-(all|reader|editor)
+                       // possible labels: 
protect-level-aft-(reader|member|editor|administrator|noone)
                        $permissionsDropdown .= Xml::option( wfMessage( $label 
)->escaped(), $key, $key == $existingPermissionLevel );
                }
                $permissionsDropdown .= Xml::closeElement( 'select' );
@@ -769,9 +769,10 @@
         *
         * @param Page $article
         * @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;
 
                // only on pages in namespaces where it is enabled
@@ -822,13 +823,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, $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 6de87e1..f7ebd0b 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 can not 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 for "[[$1]]"',
+       'restriction-articlefeedbackv5' => 'Visibility',
        '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.",
@@ -646,6 +648,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 "$3" $4',
 
        /* Activity Pane phrases */
        'articlefeedbackv5-activity-pane-header' => 'Activity Log',
@@ -818,11 +821,14 @@
        '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',
+       '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' => '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',
@@ -1899,6 +1905,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
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 6e83837..e2c515d 100644
--- a/ArticleFeedbackv5.permissions.php
+++ b/ArticleFeedbackv5.permissions.php
@@ -113,13 +113,16 @@
         * @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 valid permission
                if ( !self::isValidPermission( $permission ) ) {
                        return false;
                }
+
+               global $wgUser;
 
                $dbw = wfGetDB( DB_MASTER );
                $dbr = wfGetDB( DB_SLAVE );
@@ -158,6 +161,35 @@
                        );
                }
 
+               if ( $dbw->affectedRows() > 0 ) {
+                       $page = WikiPage::newFromID( $articleId );
+                       if ( $page ) {
+                               // make sure timestamp doesn't overlap with 
protection log's null revision (if any)
+                               $timestamp = Revision::getTimestampFromId( 
$page->getTitle(), $page->getLatest() );
+                               if ( $timestamp === wfTimestampNow() ) {
+                                       sleep( 1 );
+                               }
+
+                               $page->insertNullRevision(
+                                       'articlefeedbackv5-protection-title',
+                                       array( 'articlefeedbackv5' => 
$permission ),
+                                       array( 'articlefeedbackv5' => $expiry ),
+                                       false,
+                                       $reason,
+                                       $wgUser
+                               );
+
+                               // insert into log
+                               $logEntry = new ManualLogEntry( 
'articlefeedbackv5', 'protect' );
+                               $logEntry->setTarget( $page->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 cd34678..00eec84 100644
--- a/ArticleFeedbackv5.php
+++ b/ArticleFeedbackv5.php
@@ -408,6 +408,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';
@@ -432,6 +433,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
@@ -464,6 +466,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: newchange
Gerrit-Change-Id: Icee466faa962ad4c4e49b68dbb054e543b93b0a7
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

Reply via email to