From: umherirrender Date: Tue, 7 Jul 2015 20:36:41 +0000 (+0200) Subject: Migrate move protect log to new log system X-Git-Tag: 1.31.0-rc.0~10355^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=3964b4cc052c0c089d701dc74b7754e9772b146c Migrate move protect log to new log system 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 --- diff --git a/autoload.php b/autoload.php index 6444e3efa8..4d2853e121 100644 --- a/autoload.php +++ b/autoload.php @@ -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', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 6050ba7bc6..dd3dbc266a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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', diff --git a/includes/MovePage.php b/includes/MovePage.php index 9891106022..aecf35e792 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -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 diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 0145b02f6b..f31a42aadf 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -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 index 0000000000..5327e07243 --- /dev/null +++ b/includes/logging/ProtectLogFormatter.php @@ -0,0 +1,70 @@ +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; + } +} diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 3a47bceca7..367f79a367 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3575,6 +3575,7 @@ "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", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 0867cf7d4d..2cdcfa1cd9 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2133,7 +2133,7 @@ "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:\n00: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.)\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:\n00: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.)\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", @@ -3746,6 +3746,7 @@ "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]]}}", diff --git a/tests/phpunit/includes/changes/RecentChangeTest.php b/tests/phpunit/includes/changes/RecentChangeTest.php index ab35453dbc..60235b8f12 100644 --- a/tests/phpunit/includes/changes/RecentChangeTest.php +++ b/tests/phpunit/includes/changes/RecentChangeTest.php @@ -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 ); } diff --git a/tests/phpunit/includes/logging/LogFormatterTestCase.php b/tests/phpunit/includes/logging/LogFormatterTestCase.php index cab6794c3d..e88452b758 100644 --- a/tests/phpunit/includes/logging/LogFormatterTestCase.php +++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php @@ -48,6 +48,7 @@ abstract class LogFormatterTestCase extends MediaWikiLangTestCase { } private static function removeSomeHtml( $html ) { + $html = str_replace( '"', '"', $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 index 0000000000..611b2dfc9e --- /dev/null +++ b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php @@ -0,0 +1,63 @@ + '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 ); + } +}