'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',
*/
$wgLogActions = array(
'protect/modify' => 'modifiedarticleprotection',
- 'protect/move_prot' => 'movedarticleprotection',
'protect/protect' => 'protectedarticle',
'protect/unprotect' => 'unprotectedarticle',
);
'move/move' => 'MoveLogFormatter',
'move/move_redir' => 'MoveLogFormatter',
'patrol/patrol' => 'PatrolLogFormatter',
+ 'protect/move_prot' => 'ProtectLogFormatter',
'rights/autopromote' => 'RightsLogFormatter',
'rights/rights' => 'RightsLogFormatter',
'suppress/block' => 'BlockLogFormatter',
__METHOD__,
array( 'IGNORE' )
);
- # Update the protection log
- $log = new LogPage( 'protect' );
+
+ // Build comment for log
$comment = wfMessage(
'prot_1movedto2',
$this->oldTitle->getPrefixedText(),
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(
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
$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;
--- /dev/null
+<?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;
+ }
+}
"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",
"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]]}}",
$this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
->plain() . $sep . $this->user_comment,
'protect', 'move_prot',
- array( 'OldTitle' ),
+ array(
+ '4::oldtitle' => 'OldTitle'
+ ),
$this->user_comment
);
}
}
private static function removeSomeHtml( $html ) {
+ $html = str_replace( '"', '"', $html );
return trim( preg_replace( '/<(a|span)[^>]*>([^<]*)<\/\1>/', '$2', $html ) );
}
--- /dev/null
+<?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 );
+ }
+}