Migrate move protect log to new log system
authorumherirrender <umherirrender_de.wp@web.de>
Tue, 7 Jul 2015 20:36:41 +0000 (22:36 +0200)
committerAlex Monk <krenair@gmail.com>
Tue, 18 Aug 2015 22:20:35 +0000 (22:20 +0000)
Migrate the move protect log as first sub type of the protection log,
because it does not have complex log parameter, which needs some way of
handling/migration.
It also keeps the gerrit change smaller and hopefully makes review
easier.
The other sub types of the protection log will be migrated in a later
patch set.

This allows use of gender on Special:Log. Old message is kept for use
in IRC. A test was added to ensure an unchanged IRC message.

Bug: T47988
Change-Id: I57b3bd8a7dc823acdbb56520d2364f5542283373

autoload.php
includes/DefaultSettings.php
includes/MovePage.php
includes/logging/LogFormatter.php
includes/logging/ProtectLogFormatter.php [new file with mode: 0644]
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/changes/RecentChangeTest.php
tests/phpunit/includes/logging/LogFormatterTestCase.php
tests/phpunit/includes/logging/ProtectLogFormatterTest.php [new file with mode: 0644]

index 6444e3e..4d2853e 100644 (file)
@@ -933,6 +933,7 @@ $wgAutoloadLocalClasses = array(
        'ProfilerXhprof' => __DIR__ . '/includes/profiler/ProfilerXhprof.php',
        'Protect' => __DIR__ . '/maintenance/protect.php',
        'ProtectAction' => __DIR__ . '/includes/actions/ProtectAction.php',
+       'ProtectLogFormatter' => __DIR__ . '/includes/logging/ProtectLogFormatter.php',
        'ProtectedPagesPager' => __DIR__ . '/includes/specials/SpecialProtectedpages.php',
        'ProtectedTitlesPager' => __DIR__ . '/includes/specials/SpecialProtectedtitles.php',
        'ProtectionForm' => __DIR__ . '/includes/ProtectionForm.php',
index 6050ba7..dd3dbc2 100644 (file)
@@ -6947,7 +6947,6 @@ $wgLogHeaders = array(
  */
 $wgLogActions = array(
        'protect/modify' => 'modifiedarticleprotection',
-       'protect/move_prot' => 'movedarticleprotection',
        'protect/protect' => 'protectedarticle',
        'protect/unprotect' => 'unprotectedarticle',
 );
@@ -6977,6 +6976,7 @@ $wgLogActionsHandlers = array(
        'move/move' => 'MoveLogFormatter',
        'move/move_redir' => 'MoveLogFormatter',
        'patrol/patrol' => 'PatrolLogFormatter',
+       'protect/move_prot' => 'ProtectLogFormatter',
        'rights/autopromote' => 'RightsLogFormatter',
        'rights/rights' => 'RightsLogFormatter',
        'suppress/block' => 'BlockLogFormatter',
index 9891106..aecf35e 100644 (file)
@@ -305,8 +305,8 @@ class MovePage {
                                __METHOD__,
                                array( 'IGNORE' )
                        );
-                       # Update the protection log
-                       $log = new LogPage( 'protect' );
+
+                       // Build comment for log
                        $comment = wfMessage(
                                'prot_1movedto2',
                                $this->oldTitle->getPrefixedText(),
@@ -315,14 +315,6 @@ class MovePage {
                        if ( $reason ) {
                                $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                        }
-                       // @todo FIXME: $params?
-                       $logId = $log->addEntry(
-                               'move_prot',
-                               $this->newTitle,
-                               $comment,
-                               array( $this->oldTitle->getPrefixedText() ),
-                               $user
-                       );
 
                        // reread inserted pr_ids for log relation
                        $insertedPrIds = $dbw->select(
@@ -335,7 +327,18 @@ class MovePage {
                        foreach ( $insertedPrIds as $prid ) {
                                $logRelationsValues[] = $prid->pr_id;
                        }
-                       $log->addRelations( 'pr_id', $logRelationsValues, $logId );
+
+                       // Update the protection log
+                       $logEntry = new ManualLogEntry( 'protect', 'move_prot' );
+                       $logEntry->setTarget( $this->newTitle );
+                       $logEntry->setComment( $comment );
+                       $logEntry->setPerformer( $user );
+                       $logEntry->setParameters( array(
+                               '4::oldtitle' => $this->oldTitle->getPrefixedText(),
+                       ) );
+                       $logEntry->setRelations( array( 'pr_id' => $logRelationsValues ) );
+                       $logId = $logEntry->insert();
+                       $logEntry->publish( $logId );
                }
 
                // Update *_from_namespace fields as needed
index 0145b02..f31a42a 100644 (file)
@@ -273,6 +273,10 @@ class LogFormatter {
                                                $text = wfMessage( 'modifiedarticleprotection' )
                                                        ->rawParams( $target . ' ' . $parameters[0] )->inContentLanguage()->escaped();
                                                break;
+                                       case 'move_prot':
+                                               $text = wfMessage( 'movedarticleprotection' )
+                                                       ->rawParams( $target, $parameters['4::oldtitle'] )->inContentLanguage()->escaped();
+                                               break;
                                }
                                break;
 
diff --git a/includes/logging/ProtectLogFormatter.php b/includes/logging/ProtectLogFormatter.php
new file mode 100644 (file)
index 0000000..5327e07
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Formatter for protect log entries.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ * @since 1.26
+ */
+
+/**
+ * This class formats protect log entries.
+ *
+ * @since 1.26
+ */
+class ProtectLogFormatter extends LogFormatter {
+       public function getPreloadTitles() {
+               $subtype = $this->entry->getSubtype();
+               if ( $subtype === 'move_prot' ) {
+                       $params = $this->extractParameters();
+                       return array( Title::newFromText( $params[3] ) );
+               }
+               return array();
+       }
+
+       protected function getMessageParameters() {
+               $params = parent::getMessageParameters();
+
+               $subtype = $this->entry->getSubtype();
+               if ( $subtype === 'move_prot' ) {
+                       $oldname = $this->makePageLink( Title::newFromText( $params[3] ), array( 'redirect' => 'no' ) );
+                       $params[3] = Message::rawParam( $oldname );
+               }
+
+               return $params;
+       }
+
+       protected function getParametersForApi() {
+               $entry = $this->entry;
+               $params = $entry->getParameters();
+
+               static $map = array(
+                       // param keys for move_prot sub type
+                       '4:title:oldtitle',
+                       '4::oldtitle' => '4:title:oldtitle',
+               );
+               foreach ( $map as $index => $key ) {
+                       if ( isset( $params[$index] ) ) {
+                               $params[$key] = $params[$index];
+                               unset( $params[$index] );
+                       }
+               }
+
+               return $params;
+       }
+}
index 3a47bce..367f79a 100644 (file)
        "logentry-newusers-create2": "User account $3 was {{GENDER:$2|created}} by $1",
        "logentry-newusers-byemail": "User account $3 was {{GENDER:$2|created}} by $1 and password was sent by email",
        "logentry-newusers-autocreate": "User account $1 was {{GENDER:$2|created}} automatically",
+       "logentry-protect-move_prot": "$1 {{GENDER:$2|moved}} protection settings from $4 to $3",
        "logentry-rights-rights": "$1 {{GENDER:$2|changed}} group membership for $3 from $4 to $5",
        "logentry-rights-rights-legacy": "$1 {{GENDER:$2|changed}} group membership for $3",
        "logentry-rights-autopromote": "$1 was automatically {{GENDER:$2|promoted}} from $4 to $5",
index 0867cf7..2cdcfa1 100644 (file)
        "protectedarticle": "Text describing an action on [[Special:Log]]. $1 is a page title.",
        "modifiedarticleprotection": "Text describing an action on [[Special:Log]]. $1 is a page title.",
        "unprotectedarticle": "Used as action in the log. Parameters:\n* $1 - target page title",
-       "movedarticleprotection": "This is a log entry. It appears in the log if a protected page is renamed.\n\nExample:\n<code>00:51, 16 September 2010 Siebrand +(Talk • contribs • block) moved protection settings from \"User:Siebrand/prot-move\" to \"User:Siebrand/prot-moved\" ‎ (User:Siebrand/prot-move moved to User:Siebrand/prot-moved: prot_move test.)</code>\n\nParameters:\n* $1 - target page title\n* $2 - source page title",
+       "movedarticleprotection": "This is a ''logentry'' message only used on IRC. It appears in the log if a protected page is renamed.\n\nExample:\n<code>00:51, 16 September 2010 Siebrand +(Talk • contribs • block) moved protection settings from \"User:Siebrand/prot-move\" to \"User:Siebrand/prot-moved\" ‎ (User:Siebrand/prot-move moved to User:Siebrand/prot-moved: prot_move test.)</code>\n\nParameters:\n* $1 - target page title\n* $2 - source page title",
        "protect-title": "Title for the protection form. $1 is the title of the page to be (un)protected.",
        "protect-title-notallowed": "Same as {{msg-mw|Protect-title}}, but when the user does not have the right to change protection levels.\n\nParameters:\n* $1 - page title",
        "prot_1movedto2": "Message description: [[mw:Manual:Interface/1movedto2]]\n\nParameters:\n* $1 - source page title\n* $2 - target page title",
        "logentry-newusers-create2": "{{Logentry|[[Special:Log/newusers]]}}\n\n$4 is the name of the user that was created.",
        "logentry-newusers-byemail": "{{Logentry|[[Special:Log/newusers]]}}\n\n$4 is the name of the user that was created.",
        "logentry-newusers-autocreate": "{{Logentry|[[Special:Log/newusers]]}}\n\n$4 is the gender of the target user.",
+       "logentry-protect-move_prot": "{{Logentry|[[Special:Log/protect]]}}\n\n* $4 - the old title",
        "logentry-rights-rights": "* $1 - username\n* $2 - (see below)\n* $3 - username\n* $4 - list of user groups or {{msg-mw|Rightsnone}}\n* $5 - list of user groups or {{msg-mw|Rightsnone}}\n----\n{{Logentry|[[Special:Log/rights]]}}",
        "logentry-rights-rights-legacy": "* $1 - username\n* $2 - (see below)\n* $3 - username\n----\n{{Logentry|[[Special:Log/rights]]}}",
        "logentry-rights-autopromote": "* $1 - username\n* $2 - (see below)\n* $3 - (see below)\n* $4 - comma separated list of old user groups or {{msg-mw|Rightsnone}}\n* $5 - comma separated list of new user groups\n----\n{{Logentry|[[Special:Log/rights]]}}",
index ab35453..60235b8 100644 (file)
@@ -243,7 +243,9 @@ class RecentChangeTest extends MediaWikiTestCase {
                        $this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
                                ->plain() . $sep . $this->user_comment,
                        'protect', 'move_prot',
-                       array( 'OldTitle' ),
+                       array(
+                               '4::oldtitle' => 'OldTitle'
+                       ),
                        $this->user_comment
                );
        }
index cab6794..e88452b 100644 (file)
@@ -48,6 +48,7 @@ abstract class LogFormatterTestCase extends MediaWikiLangTestCase {
        }
 
        private static function removeSomeHtml( $html ) {
+               $html = str_replace( '&quot;', '"', $html );
                return trim( preg_replace( '/<(a|span)[^>]*>([^<]*)<\/\1>/', '$2', $html ) );
        }
 
diff --git a/tests/phpunit/includes/logging/ProtectLogFormatterTest.php b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
new file mode 100644 (file)
index 0000000..611b2df
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+class ProtectLogFormatterTest extends LogFormatterTestCase {
+
+       /**
+        * Provide different rows from the logging table to test
+        * for backward compatibility.
+        * Do not change the existing data, just add a new database row
+        */
+       public static function provideMoveProtLogDatabaseRows() {
+               return array(
+                       // Current format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'move_prot',
+                                       'comment' => 'Move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'NewPage',
+                                       'params' => array(
+                                               '4::oldtitle' => 'OldPage',
+                                       ),
+                               ),
+                               array(
+                                       'text' => 'User moved protection settings from OldPage to NewPage',
+                                       'api' => array(
+                                               'oldtitle_ns' => 0,
+                                               'oldtitle_title' => 'OldPage',
+                                       ),
+                               ),
+                       ),
+
+                       // Legacy format
+                       array(
+                               array(
+                                       'type' => 'protect',
+                                       'action' => 'move_prot',
+                                       'comment' => 'Move comment',
+                                       'namespace' => NS_MAIN,
+                                       'title' => 'NewPage',
+                                       'params' => array(
+                                               'OldPage',
+                                       ),
+                               ),
+                               array(
+                                       'legacy' => true,
+                                       'text' => 'User moved protection settings from OldPage to NewPage',
+                                       'api' => array(
+                                               'oldtitle_ns' => 0,
+                                               'oldtitle_title' => 'OldPage',
+                                       ),
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider provideMoveProtLogDatabaseRows
+        */
+       public function testMoveProtLogDatabaseRows( $row, $extra ) {
+               $this->doTestLogFormatter( $row, $extra );
+       }
+}