jenkins-bot has submitted this change and it was merged.
Change subject: Migrate move protect log to new log system
......................................................................
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
---
M autoload.php
M includes/DefaultSettings.php
M includes/MovePage.php
M includes/logging/LogFormatter.php
A includes/logging/ProtectLogFormatter.php
M languages/i18n/en.json
M languages/i18n/qqq.json
M tests/phpunit/includes/changes/RecentChangeTest.php
M tests/phpunit/includes/logging/LogFormatterTestCase.php
A tests/phpunit/includes/logging/ProtectLogFormatterTest.php
10 files changed, 160 insertions(+), 14 deletions(-)
Approvals:
Alex Monk: Looks good to me, approved
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index 6444e3e..4d2853e 100644
--- a/autoload.php
+++ b/autoload.php
@@ -933,6 +933,7 @@
'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 6050ba7..dd3dbc2 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6947,7 +6947,6 @@
*/
$wgLogActions = array(
'protect/modify' => 'modifiedarticleprotection',
- 'protect/move_prot' => 'movedarticleprotection',
'protect/protect' => 'protectedarticle',
'protect/unprotect' => 'unprotectedarticle',
);
@@ -6977,6 +6976,7 @@
'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 9891106..aecf35e 100644
--- a/includes/MovePage.php
+++ b/includes/MovePage.php
@@ -305,8 +305,8 @@
__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 @@
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 @@
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 0145b02..f31a42a 100644
--- a/includes/logging/LogFormatter.php
+++ b/includes/logging/LogFormatter.php
@@ -273,6 +273,10 @@
$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 0000000..5327e07
--- /dev/null
+++ b/includes/logging/ProtectLogFormatter.php
@@ -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;
+ }
+}
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index 3a47bce..367f79a 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 0867cf7..2cdcfa1 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:\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",
@@ -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 ab35453d..60235b8 100644
--- a/tests/phpunit/includes/changes/RecentChangeTest.php
+++ b/tests/phpunit/includes/changes/RecentChangeTest.php
@@ -243,7 +243,9 @@
$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 cab6794..e88452b 100644
--- a/tests/phpunit/includes/logging/LogFormatterTestCase.php
+++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php
@@ -48,6 +48,7 @@
}
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 0000000..611b2df
--- /dev/null
+++ b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
@@ -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 );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/223440
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I57b3bd8a7dc823acdbb56520d2364f5542283373
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits