2012-10-22 09:00:15 +00:00
|
|
|
|
<?php
|
2015-09-21 08:50:04 +00:00
|
|
|
|
|
2019-07-03 16:49:58 +00:00
|
|
|
|
use MediaWiki\User\UserIdentityValue;
|
|
|
|
|
|
|
2012-10-22 09:00:15 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @group Database
|
|
|
|
|
|
*/
|
|
|
|
|
|
class LogFormatterTest extends MediaWikiLangTestCase {
|
2017-04-14 23:13:39 +00:00
|
|
|
|
private static $oldExtMsgFiles;
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @var User
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @var Title
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @var RequestContext
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $context;
|
|
|
|
|
|
|
2015-09-21 08:50:04 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @var Title
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $target;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @var string
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $user_comment;
|
|
|
|
|
|
|
2019-11-02 04:05:36 +00:00
|
|
|
|
public static function setUpBeforeClass() : void {
|
2017-04-14 23:13:39 +00:00
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
|
|
|
|
|
|
|
|
global $wgExtensionMessagesFiles;
|
|
|
|
|
|
self::$oldExtMsgFiles = $wgExtensionMessagesFiles;
|
|
|
|
|
|
$wgExtensionMessagesFiles['LogTests'] = __DIR__ . '/LogTests.i18n.php';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-02 04:05:36 +00:00
|
|
|
|
public static function tearDownAfterClass() : void {
|
2017-04-14 23:13:39 +00:00
|
|
|
|
global $wgExtensionMessagesFiles;
|
|
|
|
|
|
$wgExtensionMessagesFiles = self::$oldExtMsgFiles;
|
|
|
|
|
|
|
|
|
|
|
|
parent::tearDownAfterClass();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-20 18:11:08 +00:00
|
|
|
|
protected function setUp() : void {
|
2012-10-22 09:00:15 +00:00
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
|
'wgLogTypes' => [ 'phpunit' ],
|
2018-01-13 00:02:09 +00:00
|
|
|
|
'wgLogActionsHandlers' => [ 'phpunit/test' => LogFormatter::class,
|
|
|
|
|
|
'phpunit/param' => LogFormatter::class ],
|
2012-10-22 09:00:15 +00:00
|
|
|
|
'wgUser' => User::newFromName( 'Testuser' ),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
$this->user = User::newFromName( 'Testuser' );
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->title = Title::newFromText( 'SomeTitle' );
|
|
|
|
|
|
$this->target = Title::newFromText( 'TestTarget' );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
$this->context = new RequestContext();
|
|
|
|
|
|
$this->context->setUser( $this->user );
|
|
|
|
|
|
$this->context->setTitle( $this->title );
|
2017-04-14 23:13:39 +00:00
|
|
|
|
$this->context->setLanguage( RequestContext::getMain()->getLanguage() );
|
2015-09-21 08:50:04 +00:00
|
|
|
|
|
|
|
|
|
|
$this->user_comment = '<User comment about action>';
|
2012-10-22 09:00:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function newLogEntry( $action, $params ) {
|
|
|
|
|
|
$logEntry = new ManualLogEntry( 'phpunit', $action );
|
|
|
|
|
|
$logEntry->setPerformer( $this->user );
|
|
|
|
|
|
$logEntry->setTarget( $this->title );
|
|
|
|
|
|
$logEntry->setComment( 'A very good reason' );
|
|
|
|
|
|
|
|
|
|
|
|
$logEntry->setParameters( $params );
|
|
|
|
|
|
|
|
|
|
|
|
return $logEntry;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testNormalLogParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$entry = $this->newLogEntry( 'test', [] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$formatter->setShowUserToolLinks( false );
|
|
|
|
|
|
$paramsWithoutTools = $formatter->getMessageParametersForTesting();
|
|
|
|
|
|
|
2018-02-06 22:25:07 +00:00
|
|
|
|
$formatter2 = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter2->setContext( $this->context );
|
|
|
|
|
|
$formatter2->setShowUserToolLinks( true );
|
|
|
|
|
|
$paramsWithTools = $formatter2->getMessageParametersForTesting();
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
$userLink = Linker::userLink(
|
|
|
|
|
|
$this->user->getId(),
|
|
|
|
|
|
$this->user->getName()
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$userTools = Linker::userToolLinksRedContribs(
|
|
|
|
|
|
$this->user->getId(),
|
|
|
|
|
|
$this->user->getName(),
|
2019-04-19 21:49:40 +00:00
|
|
|
|
$this->user->getEditCount(),
|
|
|
|
|
|
false
|
2012-10-22 09:00:15 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$titleLink = Linker::link( $this->title, null, [], [] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
// $paramsWithoutTools and $paramsWithTools should be only different
|
|
|
|
|
|
// in index 0
|
|
|
|
|
|
$this->assertEquals( $paramsWithoutTools[1], $paramsWithTools[1] );
|
|
|
|
|
|
$this->assertEquals( $paramsWithoutTools[2], $paramsWithTools[2] );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $userLink, $paramsWithoutTools[0]['raw'] );
|
|
|
|
|
|
$this->assertEquals( $userLink . $userTools, $paramsWithTools[0]['raw'] );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $this->user->getName(), $paramsWithoutTools[1] );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $titleLink, $paramsWithoutTools[2]['raw'] );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeRaw() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:raw:raw' => Linker::link( $this->title, null, [], [] ) ];
|
|
|
|
|
|
$expected = Linker::link( $this->title, null, [], [] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeMsg() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:msg:msg' => 'log-description-phpunit' ];
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$expected = wfMessage( 'log-description-phpunit' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeMsgContent() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:msg-content:msgContent' => 'log-description-phpunit' ];
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$expected = wfMessage( 'log-description-phpunit' )->inContentLanguage()->text();
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeNumber() {
|
|
|
|
|
|
global $wgLang;
|
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:number:number' => 123456789 ];
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$expected = $wgLang->formatNum( 123456789 );
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeUserLink() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:user-link:userLink' => $this->user->getName() ];
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$expected = Linker::userLink(
|
|
|
|
|
|
$this->user->getId(),
|
|
|
|
|
|
$this->user->getName()
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-03 16:49:58 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testLogParamsTypeUserLink_empty() {
|
|
|
|
|
|
$params = [ '4:user-link:userLink' => ':' ];
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
|
2019-08-26 12:24:37 +00:00
|
|
|
|
$this->context->setLanguage( 'qqx' );
|
2019-07-03 16:49:58 +00:00
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
$this->assertContains( '(empty-username)', $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypeTitleLink() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:title-link:titleLink' => $this->title->getText() ];
|
|
|
|
|
|
$expected = Linker::link( $this->title, null, [], [] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getActionText
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogParamsTypePlain() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$params = [ '4:plain:plain' => 'Some plain text' ];
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$expected = 'Some plain text';
|
|
|
|
|
|
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', $params );
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$logParam = $formatter->getActionText();
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $logParam );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-03 16:49:58 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getPerformerElement
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testGetPerformerElement() {
|
|
|
|
|
|
$entry = $this->newLogEntry( 'param', [] );
|
|
|
|
|
|
$entry->setPerformer( new UserIdentityValue( 1328435, 'Test', 0 ) );
|
|
|
|
|
|
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$element = $formatter->getPerformerElement();
|
|
|
|
|
|
$this->assertContains( 'User:Test', $element );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::newFromEntry
|
|
|
|
|
|
* @covers LogFormatter::getComment
|
|
|
|
|
|
*/
|
2012-10-22 09:00:15 +00:00
|
|
|
|
public function testLogComment() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$entry = $this->newLogEntry( 'test', [] );
|
2012-10-22 09:00:15 +00:00
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
$comment = ltrim( Linker::commentBlock( $entry->getComment() ) );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $comment, $formatter->getComment() );
|
|
|
|
|
|
}
|
2014-08-10 10:25:29 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideApiParamFormatting
|
|
|
|
|
|
* @covers LogFormatter::formatParametersForApi
|
|
|
|
|
|
* @covers LogFormatter::formatParameterValueForApi
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testApiParamFormatting( $key, $value, $expected ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$entry = $this->newLogEntry( 'param', [ $key => $value ] );
|
2014-08-10 10:25:29 +00:00
|
|
|
|
$formatter = LogFormatter::newFromEntry( $entry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
ApiResult::setIndexedTagName( $expected, 'param' );
|
|
|
|
|
|
ApiResult::setArrayType( $expected, 'assoc' );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $formatter->formatParametersForApi() );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function provideApiParamFormatting() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
return [
|
|
|
|
|
|
[ 0, 'value', [ 'value' ] ],
|
|
|
|
|
|
[ 'named', 'value', [ 'named' => 'value' ] ],
|
|
|
|
|
|
[ '::key', 'value', [ 'key' => 'value' ] ],
|
|
|
|
|
|
[ '4::key', 'value', [ 'key' => 'value' ] ],
|
|
|
|
|
|
[ '4:raw:key', 'value', [ 'key' => 'value' ] ],
|
|
|
|
|
|
[ '4:plain:key', 'value', [ 'key' => 'value' ] ],
|
|
|
|
|
|
[ '4:bool:key', '1', [ 'key' => true ] ],
|
|
|
|
|
|
[ '4:bool:key', '0', [ 'key' => false ] ],
|
|
|
|
|
|
[ '4:number:key', '123', [ 'key' => 123 ] ],
|
|
|
|
|
|
[ '4:number:key', '123.5', [ 'key' => 123.5 ] ],
|
|
|
|
|
|
[ '4:array:key', [], [ 'key' => [ ApiResult::META_TYPE => 'array' ] ] ],
|
|
|
|
|
|
[ '4:assoc:key', [], [ 'key' => [ ApiResult::META_TYPE => 'assoc' ] ] ],
|
|
|
|
|
|
[ '4:kvp:key', [], [ 'key' => [ ApiResult::META_TYPE => 'kvp' ] ] ],
|
|
|
|
|
|
[ '4:timestamp:key', '20150102030405', [ 'key' => '2015-01-02T03:04:05Z' ] ],
|
|
|
|
|
|
[ '4:msg:key', 'parentheses', [
|
2014-08-10 10:25:29 +00:00
|
|
|
|
'key_key' => 'parentheses',
|
|
|
|
|
|
'key_text' => wfMessage( 'parentheses' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
] ],
|
|
|
|
|
|
[ '4:msg-content:key', 'parentheses', [
|
2014-08-10 10:25:29 +00:00
|
|
|
|
'key_key' => 'parentheses',
|
|
|
|
|
|
'key_text' => wfMessage( 'parentheses' )->inContentLanguage()->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
] ],
|
|
|
|
|
|
[ '4:title:key', 'project:foo', [
|
2014-08-10 10:25:29 +00:00
|
|
|
|
'key_ns' => NS_PROJECT,
|
|
|
|
|
|
'key_title' => Title::newFromText( 'project:foo' )->getFullText(),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
] ],
|
|
|
|
|
|
[ '4:title-link:key', 'project:foo', [
|
2014-08-10 10:25:29 +00:00
|
|
|
|
'key_ns' => NS_PROJECT,
|
|
|
|
|
|
'key_title' => Title::newFromText( 'project:foo' )->getFullText(),
|
2016-02-17 09:09:32 +00:00
|
|
|
|
] ],
|
2017-09-28 14:06:53 +00:00
|
|
|
|
[ '4:title-link:key', '<invalid>', [
|
|
|
|
|
|
'key_ns' => NS_SPECIAL,
|
|
|
|
|
|
'key_title' => SpecialPage::getTitleFor( 'Badtitle', '<invalid>' )->getFullText(),
|
|
|
|
|
|
] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[ '4:user:key', 'foo', [ 'key' => 'Foo' ] ],
|
|
|
|
|
|
[ '4:user-link:key', 'foo', [ 'key' => 'Foo' ] ],
|
|
|
|
|
|
];
|
2014-08-10 10:25:29 +00:00
|
|
|
|
}
|
2015-09-21 08:50:04 +00:00
|
|
|
|
|
2015-09-25 15:22:22 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* The testIrcMsgForAction* tests are supposed to cover the hacky
|
2017-02-20 23:45:58 +00:00
|
|
|
|
* LogFormatter::getIRCActionText / T36508
|
2015-09-25 15:22:22 +00:00
|
|
|
|
*
|
|
|
|
|
|
* Third parties bots listen to those messages. They are clever enough
|
|
|
|
|
|
* to fetch the i18n messages from the wiki and then analyze the IRC feed
|
|
|
|
|
|
* to reverse engineer the $1, $2 messages.
|
|
|
|
|
|
* One thing bots can not detect is when MediaWiki change the meaning of
|
|
|
|
|
|
* a message like what happened when we deployed 1.19. $1 became the user
|
|
|
|
|
|
* performing the action which broke basically all bots around.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Should cover the following log actions (which are most commonly used by bots):
|
|
|
|
|
|
* - block/block
|
|
|
|
|
|
* - block/unblock
|
|
|
|
|
|
* - block/reblock
|
|
|
|
|
|
* - delete/delete
|
|
|
|
|
|
* - delete/restore
|
|
|
|
|
|
* - newusers/create
|
|
|
|
|
|
* - newusers/create2
|
|
|
|
|
|
* - newusers/autocreate
|
|
|
|
|
|
* - move/move
|
|
|
|
|
|
* - move/move_redir
|
|
|
|
|
|
* - protect/protect
|
|
|
|
|
|
* - protect/modifyprotect
|
|
|
|
|
|
* - protect/unprotect
|
|
|
|
|
|
* - protect/move_prot
|
|
|
|
|
|
* - upload/upload
|
|
|
|
|
|
* - merge/merge
|
|
|
|
|
|
* - import/upload
|
|
|
|
|
|
* - import/interwiki
|
|
|
|
|
|
*
|
|
|
|
|
|
* As well as the following Auto Edit Summaries:
|
|
|
|
|
|
* - blank
|
|
|
|
|
|
* - replace
|
|
|
|
|
|
* - rollback
|
|
|
|
|
|
* - undo
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-09-21 08:50:04 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeBlock() {
|
|
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# block/block
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
|
|
|
|
|
|
. $sep . $this->user_comment,
|
|
|
|
|
|
'block', 'block',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'5::duration' => 'duration',
|
|
|
|
|
|
'6::flags' => 'flags',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
# block/block - legacy
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
|
|
|
|
|
|
. $sep . $this->user_comment,
|
|
|
|
|
|
'block', 'block',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'duration',
|
|
|
|
|
|
'flags',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment,
|
|
|
|
|
|
'',
|
|
|
|
|
|
true
|
|
|
|
|
|
);
|
|
|
|
|
|
# block/unblock
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'block', 'unblock',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
# block/reblock
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
|
|
|
|
|
|
. $sep . $this->user_comment,
|
|
|
|
|
|
'block', 'reblock',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'5::duration' => 'duration',
|
|
|
|
|
|
'6::flags' => 'flags',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeDelete() {
|
|
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# delete/delete
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'delete', 'delete',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# delete/restore
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'delete', 'restore',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeNewusers() {
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'New user account',
|
|
|
|
|
|
'newusers', 'newusers',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[]
|
2015-09-21 08:50:04 +00:00
|
|
|
|
);
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'New user account',
|
|
|
|
|
|
'newusers', 'create',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[]
|
2015-09-21 08:50:04 +00:00
|
|
|
|
);
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'created new account SomeTitle',
|
|
|
|
|
|
'newusers', 'create2',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[]
|
2015-09-21 08:50:04 +00:00
|
|
|
|
);
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'Account created automatically',
|
|
|
|
|
|
'newusers', 'autocreate',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[]
|
2015-09-21 08:50:04 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeMove() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$move_params = [
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'4::target' => $this->target->getPrefixedText(),
|
|
|
|
|
|
'5::noredir' => 0,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# move/move
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
|
|
|
|
|
|
->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'move', 'move',
|
|
|
|
|
|
$move_params,
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# move/move_redir
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
|
|
|
|
|
|
->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'move', 'move_redir',
|
|
|
|
|
|
$move_params,
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypePatrol() {
|
|
|
|
|
|
# patrol/patrol
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
|
|
|
|
|
|
'patrol', 'patrol',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'4::curid' => '777',
|
|
|
|
|
|
'5::previd' => '666',
|
|
|
|
|
|
'6::auto' => 0,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
]
|
2015-09-21 08:50:04 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeProtect() {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$protectParams = [
|
2015-08-22 18:29:00 +00:00
|
|
|
|
'4::description' => '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# protect/protect
|
|
|
|
|
|
$this->assertIRCComment(
|
2015-08-22 18:29:00 +00:00
|
|
|
|
$this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams['4::description'] )
|
2015-09-21 08:50:04 +00:00
|
|
|
|
->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'protect', 'protect',
|
|
|
|
|
|
$protectParams,
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# protect/unprotect
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'protect', 'unprotect',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# protect/modify
|
|
|
|
|
|
$this->assertIRCComment(
|
2015-10-03 13:04:51 +00:00
|
|
|
|
$this->context->msg(
|
|
|
|
|
|
'modifiedarticleprotection',
|
|
|
|
|
|
'SomeTitle ' . $protectParams['4::description']
|
|
|
|
|
|
)->plain() . $sep . $this->user_comment,
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'protect', 'modify',
|
|
|
|
|
|
$protectParams,
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# protect/move_prot
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
|
|
|
|
|
|
->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'protect', 'move_prot',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'4::oldtitle' => 'OldTitle'
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeUpload() {
|
|
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# upload/upload
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'upload', 'upload',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# upload/overwrite
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
|
|
|
|
|
|
'upload', 'overwrite',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeMerge() {
|
|
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# merge/merge
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
|
|
|
|
|
|
. $sep . $this->user_comment,
|
|
|
|
|
|
'merge', 'merge',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[
|
2015-09-21 08:50:04 +00:00
|
|
|
|
'4::dest' => 'Dest',
|
|
|
|
|
|
'5::mergepoint' => 'timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionComment
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testIrcMsgForLogTypeImport() {
|
|
|
|
|
|
$sep = $this->context->msg( 'colon-separator' )->text();
|
|
|
|
|
|
|
|
|
|
|
|
# import/upload
|
|
|
|
|
|
$msg = $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() .
|
|
|
|
|
|
$sep .
|
|
|
|
|
|
$this->user_comment;
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$msg,
|
|
|
|
|
|
'import', 'upload',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# import/interwiki
|
|
|
|
|
|
$msg = $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() .
|
|
|
|
|
|
$sep .
|
|
|
|
|
|
$this->user_comment;
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
$msg,
|
|
|
|
|
|
'import', 'interwiki',
|
2016-02-17 09:09:32 +00:00
|
|
|
|
[],
|
2015-09-21 08:50:04 +00:00
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param string $expected Expected IRC text without colors codes
|
|
|
|
|
|
* @param string $type Log type (move, delete, suppress, patrol ...)
|
|
|
|
|
|
* @param string $action A log type action
|
|
|
|
|
|
* @param array $params
|
|
|
|
|
|
* @param string $comment (optional) A comment for the log action
|
|
|
|
|
|
* @param string $msg (optional) A message for PHPUnit :-)
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function assertIRCComment( $expected, $type, $action, $params,
|
|
|
|
|
|
$comment = null, $msg = '', $legacy = false
|
|
|
|
|
|
) {
|
|
|
|
|
|
$logEntry = new ManualLogEntry( $type, $action );
|
|
|
|
|
|
$logEntry->setPerformer( $this->user );
|
|
|
|
|
|
$logEntry->setTarget( $this->title );
|
|
|
|
|
|
if ( $comment !== null ) {
|
|
|
|
|
|
$logEntry->setComment( $comment );
|
|
|
|
|
|
}
|
|
|
|
|
|
$logEntry->setParameters( $params );
|
|
|
|
|
|
$logEntry->setLegacy( $legacy );
|
|
|
|
|
|
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $logEntry );
|
|
|
|
|
|
$formatter->setContext( $this->context );
|
|
|
|
|
|
|
|
|
|
|
|
// Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
|
|
|
|
|
|
$ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
$ircRcComment,
|
|
|
|
|
|
$msg
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-22 09:00:15 +00:00
|
|
|
|
}
|