Umherirrender has uploaded a new change for review.
https://gerrit.wikimedia.org/r/233166
Change subject: [WIP] Migrate protect log to new log system
......................................................................
[WIP] Migrate protect log to new log system
*************
WIP, because it needs some refactor to avoid duplication of code for the
localized text.
Uploaded to get feedback about the new format of the log_params
IRC: Should the old format stored or created on the fly when needed?
API: Remove old format completly from api? Create on fly?
*************
This localize the protect type, level and expiry.
For the localize details are stored in new log items, these details also
used for the api.
In the api and for IRC the old description text is still stored in the
log params.
This allows use of gender on Special:Log. Old messages are kept for use
in IRC. Tests already exists to ensure an unchanged IRC message.
Bug: T47988
Change-Id: I3bb85c61b857972e66c99c499d7d785c88cafb25
---
M includes/DefaultSettings.php
M includes/logging/LogFormatter.php
M includes/logging/LogPage.php
M includes/logging/ProtectLogFormatter.php
M includes/page/WikiPage.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
M tests/phpunit/includes/logging/ProtectLogFormatterTest.php
10 files changed, 542 insertions(+), 71 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/66/233166/1
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index f1e8f44..f4270f7 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6938,11 +6938,7 @@
*
* Extensions with custom log types may add to this array.
*/
-$wgLogActions = array(
- 'protect/modify' => 'modifiedarticleprotection',
- 'protect/protect' => 'protectedarticle',
- 'protect/unprotect' => 'unprotectedarticle',
-);
+$wgLogActions = array();
/**
* The same as above, but here values are names of classes,
@@ -6969,7 +6965,10 @@
'move/move' => 'MoveLogFormatter',
'move/move_redir' => 'MoveLogFormatter',
'patrol/patrol' => 'PatrolLogFormatter',
+ 'protect/modify' => 'ProtectLogFormatter',
'protect/move_prot' => 'ProtectLogFormatter',
+ 'protect/protect' => 'ProtectLogFormatter',
+ 'protect/unprotect' => 'ProtectLogFormatter',
'rights/autopromote' => 'RightsLogFormatter',
'rights/rights' => 'RightsLogFormatter',
'suppress/block' => 'BlockLogFormatter',
diff --git a/includes/logging/LogFormatter.php
b/includes/logging/LogFormatter.php
index f31a42a..1d31088 100644
--- a/includes/logging/LogFormatter.php
+++ b/includes/logging/LogFormatter.php
@@ -263,7 +263,7 @@
switch ( $entry->getSubtype() ) {
case 'protect':
$text = wfMessage(
'protectedarticle' )
- ->rawParams( $target .
' ' . $parameters[0] )->inContentLanguage()->escaped();
+ ->rawParams( $target .
' ' . $parameters['4::description'] )->inContentLanguage()->escaped();
break;
case 'unprotect':
$text = wfMessage(
'unprotectedarticle' )
@@ -271,7 +271,7 @@
break;
case 'modify':
$text = wfMessage(
'modifiedarticleprotection' )
- ->rawParams( $target .
' ' . $parameters[0] )->inContentLanguage()->escaped();
+ ->rawParams( $target .
' ' . $parameters['4::description'] )->inContentLanguage()->escaped();
break;
case 'move_prot':
$text = wfMessage(
'movedarticleprotection' )
@@ -931,32 +931,6 @@
$title = $this->entry->getTarget();
$type = $this->entry->getType();
$subtype = $this->entry->getSubtype();
-
- if ( $type == 'protect'
- && ( $subtype == 'protect' || $subtype == 'modify' ||
$subtype == 'unprotect' )
- ) {
- $links = array(
- Linker::link( $title,
- $this->msg( 'hist' )->escaped(),
- array(),
- array(
- 'action' => 'history',
- 'offset' =>
$this->entry->getTimestamp()
- )
- )
- );
- if ( $this->context->getUser()->isAllowed( 'protect' )
) {
- $links[] = Linker::linkKnown(
- $title,
- $this->msg( 'protect_change'
)->escaped(),
- array(),
- array( 'action' => 'protect' )
- );
- }
-
- return $this->msg( 'parentheses' )->rawParams(
- $this->context->getLanguage()->pipeList( $links
) )->escaped();
- }
// Do nothing. The implementation is handled by the hook
modifiying the
// passed-by-ref parameters. This also changes the default
value so that
diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php
index 82e5808..2e28917 100644
--- a/includes/logging/LogPage.php
+++ b/includes/logging/LogPage.php
@@ -285,30 +285,10 @@
$rv = wfMessage( $wgLogActions[$key]
)->rawParams( $titleLink )
->inLanguage( $langObj
)->escaped();
} else {
- $details = '';
array_unshift( $params, $titleLink );
- // Page protections
- if ( $type == 'protect' && count(
$params ) == 3 ) {
- // Restrictions and expiries
- if ( $skin ) {
- $details .=
$wgLang->getDirMark() . htmlspecialchars( " {$params[1]}" );
- } else {
- $details .= "
{$params[1]}";
- }
-
- // Cascading flag...
- if ( $params[2] ) {
- $text = wfMessage(
'protect-summary-cascade' )
- ->inLanguage(
$langObj )->text();
- $details .= ' ';
- $details .= wfMessage(
'brackets', $text )->inLanguage( $langObj )->text();
-
- }
- }
-
$rv = wfMessage( $wgLogActions[$key]
)->rawParams( $params )
- ->inLanguage( $langObj
)->escaped() . $details;
+ ->inLanguage( $langObj
)->escaped();
}
}
} else {
diff --git a/includes/logging/ProtectLogFormatter.php
b/includes/logging/ProtectLogFormatter.php
index 5327e07..84952a7 100644
--- a/includes/logging/ProtectLogFormatter.php
+++ b/includes/logging/ProtectLogFormatter.php
@@ -37,11 +37,38 @@
return array();
}
+ protected function getMessageKey() {
+ $key = parent::getMessageKey();
+ $params = $this->extractParameters();
+ if ( isset( $params[4] ) && $params[4] ) {
+ // Messages: logentry-protect-protect-cascade,
logentry-protect-modify-cascade
+ $key .= '-cascade';
+ }
+
+ return $key;
+ }
+
protected function getMessageParameters() {
$params = parent::getMessageParameters();
$subtype = $this->entry->getSubtype();
- if ( $subtype === 'move_prot' ) {
+ if ( $subtype === 'protect' || $subtype === 'modify' ) {
+ $rawParams = $this->entry->getParameters();
+ if ( isset( $rawParams['details'] ) ) {
+ $params[3] = $this->protectDescriptionLog(
$rawParams['details'] );
+ } elseif ( isset( $params[3] ) ) {
+ // Old way of Restrictions and expiries
+ $params[3] =
$this->context->getLanguage()->getDirMark() . $params[3];
+ } else {
+ // Very old way (nothing set)
+ $params[3] = '';
+ }
+ // Cascading flag
+ if ( isset( $params[4] ) ) {
+ // handled in getMessageKey
+ unset( $params[4] );
+ }
+ } elseif ( $subtype === 'move_prot' ) {
$oldname = $this->makePageLink( Title::newFromText(
$params[3] ), array( 'redirect' => 'no' ) );
$params[3] = Message::rawParam( $oldname );
}
@@ -49,15 +76,59 @@
return $params;
}
+ public function getActionLinks() {
+ $subtype = $this->entry->getSubtype();
+ if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) //
Action is hidden
+ || $subtype === 'move_prot' // the move log entry has
the right action link
+ ) {
+ return '';
+ }
+
+ // Show history link for all changes after the protection
+ $title = $this->entry->getTarget();
+ $links = array(
+ Linker::link( $title,
+ $this->msg( 'hist' )->escaped(),
+ array(),
+ array(
+ 'action' => 'history',
+ 'offset' =>
$this->entry->getTimestamp(),
+ )
+ )
+ );
+
+ // Show change protection link
+ if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
+ $links[] = Linker::linkKnown(
+ $title,
+ $this->msg( 'protect_change' )->escaped(),
+ array(),
+ array( 'action' => 'protect' )
+ );
+ }
+
+ return $this->msg( 'parentheses' )->rawParams(
+ $this->context->getLanguage()->pipeList( $links )
)->escaped();
+ }
+
protected function getParametersForApi() {
$entry = $this->entry;
+ $subtype = $this->entry->getSubtype();
$params = $entry->getParameters();
- static $map = array(
- // param keys for move_prot sub type
- '4:title:oldtitle',
- '4::oldtitle' => '4:title:oldtitle',
- );
+ $map = array();
+ if ( $subtype === 'protect' || $subtype === 'modify' ) {
+ $map = array(
+ '4::description',
+ '5:bool:cascade',
+ 'details' => ':array:details',
+ );
+ } elseif ( $subtype === 'move_prot' ) {
+ $map = array(
+ '4:title:oldtitle',
+ '4::oldtitle' => '4:title:oldtitle',
+ );
+ }
foreach ( $map as $index => $key ) {
if ( isset( $params[$index] ) ) {
$params[$key] = $params[$index];
@@ -65,6 +136,58 @@
}
}
+ // Change string to explicit boolean
+ if ( isset( $params['5:bool:cascade'] ) && is_string(
$params['5:bool:cascade'] ) ) {
+ $params['5:bool:cascade'] = $params['5:bool:cascade']
=== 'cascade';
+ }
+
return $params;
}
+
+ /**
+ * Builds the description to serve as comment for the log entry.
+ *
+ * @param array $details
+ * @return string
+ */
+ public function protectDescriptionLog( array $details ) {
+ $protectDescriptionLog = '';
+
+ foreach ( $details as $param ) {
+ $expiryText = $this->formatExpiry( $param['expiry'] );
+ $action = $this->context->msg( 'restriction-' .
$param['type'] )->text();
+ $protectionLevel = $param['level'];
+ // Messages: protect-level-autoconfirmed,
protect-level-sysop
+ $message = $this->context->msg(
"protect-level-$protectionLevel" );
+ if ( $message->isDisabled() ) {
+ // Require "$1" permission
+ $restrictions = $this->context->msg(
"protect-fallback", $protectionLevel )->parse();
+ } else {
+ $restrictions = $message->escaped();
+ }
+ $protectDescriptionLog .=
$this->context->getLanguage()->getDirMark() . "[$action=$restrictions]
($expiryText)";
+ }
+
+ return trim( $protectDescriptionLog );
+ }
+
+ /**
+ * @param string $expiry 14-char timestamp or "infinity", or false if
the input was invalid
+ * @return string
+ */
+ protected function formatExpiry( $expiry ) {
+ if ( $expiry != 'infinity' ) {
+ $lang = $this->context->getLanguage();
+ $user = $this->context->getUser();
+ return $this->context->msg(
+ 'protect-expiring-local',
+ $lang->userTimeAndDate( $expiry, $user ),
+ $lang->userDate( $expiry, $user ),
+ $lang->userTime( $expiry, $user )
+ )->text();
+ } else {
+ return $this->context->msg( 'protect-expiry-indefinite'
)->text();
+ }
+ }
+
}
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index b129bd2..ad2763e 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -2407,6 +2407,7 @@
$logRelationsValues = array();
$logRelationsField = null;
+ $logParamsDetails = array();
if ( $id ) { // Protection of existing page
if ( !Hooks::run( 'ArticleProtect', array( &$this,
&$user, $limit, $reason ) ) ) {
@@ -2465,6 +2466,7 @@
__METHOD__
);
if ( $restrictions != '' ) {
+ $cascadeValue = ( $cascade && $action
== 'edit' ) ? 1 : 0;
$dbw->insert(
'page_restrictions',
array(
@@ -2472,12 +2474,18 @@
'pr_page' => $id,
'pr_type' => $action,
'pr_level' =>
$restrictions,
- 'pr_cascade' => (
$cascade && $action == 'edit' ) ? 1 : 0,
+ 'pr_cascade' =>
$cascadeValue,
'pr_expiry' =>
$dbw->encodeExpiry( $expiry[$action] )
),
__METHOD__
);
$logRelationsValues[] =
$dbw->insertId();
+ $logParamsDetails[] = array(
+ 'type' => $action,
+ 'level' => $restrictions,
+ 'expiry' => $expiry[$action],
+ 'cascade' =>
(bool)$cascadeValue,
+ );
}
}
@@ -2508,6 +2516,11 @@
'pt_reason' => $reason,
), __METHOD__
);
+ $logParamsDetails[] = array(
+ 'type' => 'create',
+ 'level' => $limit['create'],
+ 'expiry' => $expiry['create'],
+ );
} else {
$dbw->delete( 'protected_titles',
array(
@@ -2525,15 +2538,24 @@
$params = array();
} else {
$protectDescriptionLog = $this->protectDescriptionLog(
$limit, $expiry );
- $params = array( $protectDescriptionLog, $cascade ?
'cascade' : '' );
+ $params = array(
+ '4::description' => $protectDescriptionLog, //
parameter for IRC
+ '5:bool:cascade' => $cascade,
+ 'details' => $logParamsDetails, // parameter
for localize and api
+ );
}
// Update the protection log
- $log = new LogPage( 'protect' );
- $logId = $log->addEntry( $logAction, $this->mTitle, $reason,
$params, $user );
+ $logEntry = new ManualLogEntry( 'protect', $logAction );
+ $logEntry->setTarget( $this->mTitle );
+ $logEntry->setComment( $reason );
+ $logEntry->setPerformer( $user );
+ $logEntry->setParameters( $params );
if ( $logRelationsField !== null && count( $logRelationsValues
) ) {
- $log->addRelations( $logRelationsField,
$logRelationsValues, $logId );
+ $logEntry->setRelations( array( $logRelationsField =>
$logRelationsValues ) );
}
+ $logId = $logEntry->insert();
+ $logEntry->publish( $logId );
return Status::newGood();
}
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index 51cc927..73f9f3c 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -3595,6 +3595,12 @@
"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-protect-unprotect": "$1 {{GENDER:$2|removed}} protection from
$3",
+ "logentry-protect-protect": "$1 {{GENDER:$2|protected}} $3 $4",
+ "logentry-protect-protect-cascade": "$1 {{GENDER:$2|protected}} $3 $4
[cascading]",
+ "logentry-protect-modify": "$1 {{GENDER:$2|changed}} protection level
for $3 $4",
+ "logentry-protect-modify-cascade": "$1 {{GENDER:$2|changed}} protection
level for $3 $4 [cascading]",
+ "logentry-protect-unprotect": "$1 {{GENDER:$2|removed}} protection from
$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 0cf37cd..98f6264 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -2144,9 +2144,9 @@
"logentry-contentmodel-change-revert": "Prefilled edit summary when
reverting a content model change. {{identical|revertmove}}",
"protectlogpage": "{{doc-logpage}}\n\nTitle of
[[Special:Log/protect]].",
"protectlogtext": "Text in [[Special:Log/protect]].",
- "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",
+ "protectedarticle": "This is a ''logentry'' message only used on
IRC.\nText describing an action. $1 is a page title.",
+ "modifiedarticleprotection": "This is a ''logentry'' message only used
on IRC.\nText describing an action. $1 is a page title.",
+ "unprotectedarticle": "This is a ''logentry'' message only used on
IRC.\nUsed as action. Parameters:\n* $1 - target 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",
@@ -3766,6 +3766,11 @@
"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*
$4 - the old title",
+ "logentry-protect-protect": "{{Logentry|[[Special:Log/protect]]}}\n\n*
$4 - protect expiry (formatted)",
+ "logentry-protect-protect-cascade":
"{{Logentry|[[Special:Log/protect]]}}\n\n* $4 - protect expiry (formatted)\nFor
word \"cascading\" see {{msg-mw|protect-summary-cascade}}",
+ "logentry-protect-modify": "{{Logentry|[[Special:Log/protect]]}}\n\n*
$4 - protect expiry (formatted)",
+ "logentry-protect-modify-cascade":
"{{Logentry|[[Special:Log/protect]]}}\n\n* $4 - protect expiry (formatted)\nFor
word \"cascading\" see {{msg-mw|protect-summary-cascade}}",
+ "logentry-protect-unprotect": "{{Logentry|[[Special:Log/protect]]}}",
"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 60235b8..f982ae4 100644
--- a/tests/phpunit/includes/changes/RecentChangeTest.php
+++ b/tests/phpunit/includes/changes/RecentChangeTest.php
@@ -208,13 +208,13 @@
*/
public function testIrcMsgForLogTypeProtect() {
$protectParams = array(
- '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
+ '4::description' => '[edit=sysop] (indefinite)
[move=sysop] (indefinite)'
);
$sep = $this->context->msg( 'colon-separator' )->text();
# protect/protect
$this->assertIRCComment(
- $this->context->msg( 'protectedarticle', 'SomeTitle ' .
$protectParams[0] )
+ $this->context->msg( 'protectedarticle', 'SomeTitle ' .
$protectParams['4::description'] )
->plain() . $sep . $this->user_comment,
'protect', 'protect',
$protectParams,
@@ -231,7 +231,7 @@
# protect/modify
$this->assertIRCComment(
- $this->context->msg( 'modifiedarticleprotection',
'SomeTitle ' . $protectParams[0] )
+ $this->context->msg( 'modifiedarticleprotection',
'SomeTitle ' . $protectParams['4::description'] )
->plain() . $sep . $this->user_comment,
'protect', 'modify',
$protectParams,
diff --git a/tests/phpunit/includes/logging/LogFormatterTestCase.php
b/tests/phpunit/includes/logging/LogFormatterTestCase.php
index e88452b..f175482 100644
--- a/tests/phpunit/includes/logging/LogFormatterTestCase.php
+++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php
@@ -49,6 +49,7 @@
private static function removeSomeHtml( $html ) {
$html = str_replace( '"', '"', $html );
+ $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); //
Strip lrm/rlm
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
index 611b2df..937f7ad 100644
--- a/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
+++ b/tests/phpunit/includes/logging/ProtectLogFormatterTest.php
@@ -7,6 +7,367 @@
* for backward compatibility.
* Do not change the existing data, just add a new database row
*/
+ public static function provideProtectLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'protect',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '4::description' =>
'[edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ '5:bool:cascade' => false,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ array(
+
+ 'text' => 'User protected ProtectPage
[Edit=Allow only administrators] (indefinite)[Move=Allow only administrators]
(indefinite)',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => false,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ ),
+
+ // Current format with cascade
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'protect',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '4::description' =>
'[edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ '5:bool:cascade' => true,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
true,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ array(
+ 'text' => 'User protected ProtectPage
[Edit=Allow only administrators] (indefinite)[Move=Allow only administrators]
(indefinite) [cascading]',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => true,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
true,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'protect',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ '',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User protected ProtectPage
[edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => false,
+ ),
+ ),
+ ),
+
+ // Legacy format with cascade
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'protect',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User protected ProtectPage
[edit=sysop] (indefinite)[move=sysop] (indefinite) [cascading]',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => true,
+ ),
+ ),
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider provideProtectLogDatabaseRows
+ */
+ public function testProtectLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * 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 provideModifyLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'modify',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '4::description' =>
'[edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ '5:bool:cascade' => false,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ array(
+
+ 'text' => 'User changed protection
level for ProtectPage [Edit=Allow only administrators] (indefinite)[Move=Allow
only administrators] (indefinite)',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => false,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ ),
+
+ // Current format with cascade
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'modify',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '4::description' =>
'[edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ '5:bool:cascade' => true,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
true,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ array(
+ 'text' => 'User changed protection
level for ProtectPage [Edit=Allow only administrators] (indefinite)[Move=Allow
only administrators] (indefinite) [cascading]',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => true,
+ 'details' => array(
+ array(
+ 'type' =>
'edit',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
true,
+ ),
+ array(
+ 'type' =>
'move',
+ 'level' =>
'sysop',
+ 'expiry' =>
'infinity',
+ 'cascade' =>
false,
+ ),
+ ),
+ ),
+ ),
+ ),
+
+ // Legacy format
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'modify',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ '',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User changed protection
level for ProtectPage [edit=sysop] (indefinite)[move=sysop] (indefinite)',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => false,
+ ),
+ ),
+ ),
+
+ // Legacy format with cascade
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'modify',
+ 'comment' => 'protect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(
+ '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade',
+ ),
+ ),
+ array(
+ 'legacy' => true,
+ 'text' => 'User changed protection
level for ProtectPage [edit=sysop] (indefinite)[move=sysop] (indefinite)
[cascading]',
+ 'api' => array(
+ 'description' => '[edit=sysop]
(indefinite)[move=sysop] (indefinite)',
+ 'cascade' => true,
+ ),
+ ),
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider provideModifyLogDatabaseRows
+ */
+ public function testModifyLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * 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 provideUnprotectLogDatabaseRows() {
+ return array(
+ // Current format
+ array(
+ array(
+ 'type' => 'protect',
+ 'action' => 'unprotect',
+ 'comment' => 'unprotect comment',
+ 'namespace' => NS_MAIN,
+ 'title' => 'ProtectPage',
+ 'params' => array(),
+ ),
+ array(
+ 'text' => 'User removed protection from
ProtectPage',
+ 'api' => array(),
+ ),
+ ),
+ );
+ }
+
+
+ /**
+ * @dataProvider provideUnprotectLogDatabaseRows
+ */
+ public function testUnprotectLogDatabaseRows( $row, $extra ) {
+ $this->doTestLogFormatter( $row, $extra );
+ }
+
+ /**
+ * 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
--
To view, visit https://gerrit.wikimedia.org/r/233166
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3bb85c61b857972e66c99c499d7d785c88cafb25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits