2012-02-25 21:22:49 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
class RecentChangeTest extends MediaWikiTestCase {
|
|
|
|
|
|
protected $title;
|
|
|
|
|
|
protected $target;
|
|
|
|
|
|
protected $user;
|
|
|
|
|
|
protected $user_comment;
|
2012-03-05 21:21:34 +00:00
|
|
|
|
protected $context;
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
|
|
$this->title = Title::newFromText( 'SomeTitle' );
|
|
|
|
|
|
$this->target = Title::newFromText( 'TestTarget' );
|
|
|
|
|
|
$this->user = User::newFromName( 'UserName' );
|
|
|
|
|
|
|
|
|
|
|
|
$this->user_comment = '<User comment about action>';
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context = RequestContext::newExtraneousContext( $this->title );
|
2012-02-25 21:22:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The testIrcMsgForAction* tests are supposed to cover the hacky
|
|
|
|
|
|
* LogFormatter::getIRCActionText / bug 34508
|
|
|
|
|
|
*
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*
|
2012-02-28 00:39:01 +00:00
|
|
|
|
* Should cover the following log actions (which are most commonly used by bots):
|
|
|
|
|
|
* - block/block
|
|
|
|
|
|
* - block/unblock
|
|
|
|
|
|
* - delete/delete
|
|
|
|
|
|
* - delete/restore
|
|
|
|
|
|
* - newusers/create
|
|
|
|
|
|
* - newusers/create2
|
|
|
|
|
|
* - newusers/autocreate
|
|
|
|
|
|
* - move/move
|
|
|
|
|
|
* - move/move_redir
|
|
|
|
|
|
* - protect/protect
|
|
|
|
|
|
* - protect/modifyprotect
|
|
|
|
|
|
* - protect/unprotect
|
|
|
|
|
|
* - upload/upload
|
|
|
|
|
|
*
|
|
|
|
|
|
* As well as the following Auto Edit Summaries:
|
|
|
|
|
|
* - blank
|
|
|
|
|
|
* - replace
|
|
|
|
|
|
* - rollback
|
|
|
|
|
|
* - undo
|
2012-02-25 21:22:49 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForLogTypeBlock() {
|
|
|
|
|
|
# block/block
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'block', 'block',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
# block/unblock
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'block', 'unblock',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
2012-02-28 00:39:01 +00:00
|
|
|
|
}
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
2012-02-28 00:39:01 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
function testIrcMsgForLogTypeDelete() {
|
|
|
|
|
|
# delete/delete
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'delete', 'delete',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
2012-02-28 00:39:01 +00:00
|
|
|
|
# delete/restore
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'delete', 'restore',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForLogTypeNewusers() {
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'New user account',
|
|
|
|
|
|
'newusers', 'newusers',
|
|
|
|
|
|
array()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'New user account',
|
|
|
|
|
|
'newusers', 'create',
|
|
|
|
|
|
array()
|
|
|
|
|
|
);
|
|
|
|
|
|
$this->assertIRCComment(
|
|
|
|
|
|
'created new account SomeTitle',
|
|
|
|
|
|
'newusers', 'create2',
|
|
|
|
|
|
array()
|
|
|
|
|
|
);
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'Account created automatically',
|
|
|
|
|
|
'newusers', 'autocreate',
|
|
|
|
|
|
array()
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
2012-02-28 00:39:01 +00:00
|
|
|
|
}
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
2012-02-28 00:39:01 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
|
|
|
|
|
function testIrcMsgForLogTypeMove() {
|
|
|
|
|
|
$move_params = array(
|
|
|
|
|
|
'4::target' => $this->target->getPrefixedText(),
|
|
|
|
|
|
'5::noredir' => 0,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# move/move
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'move', 'move',
|
|
|
|
|
|
$move_params,
|
|
|
|
|
|
$this->user_comment
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# move/move_redir
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'move', 'move_redir',
|
|
|
|
|
|
$move_params,
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForLogTypePatrol() {
|
2012-02-25 21:22:49 +00:00
|
|
|
|
# patrol/patrol
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'patrol', 'patrol',
|
|
|
|
|
|
array(
|
2012-02-25 21:22:49 +00:00
|
|
|
|
'4::curid' => '777',
|
|
|
|
|
|
'5::previd' => '666',
|
|
|
|
|
|
'6::auto' => 0,
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForLogTypeProtect() {
|
2012-02-28 01:56:15 +00:00
|
|
|
|
$protectParams = array(
|
|
|
|
|
|
'[edit=sysop] (indefinite) [move=sysop] (indefinite)'
|
|
|
|
|
|
);
|
2012-02-28 00:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
# protect/protect
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'protect', 'protect',
|
2012-02-28 01:56:15 +00:00
|
|
|
|
$protectParams,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
2012-02-28 00:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
# protect/unprotect
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'protect', 'unprotect',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
2012-02-28 00:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
# protect/modify
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'protect', 'modify',
|
2012-02-28 01:56:15 +00:00
|
|
|
|
$protectParams,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @covers LogFormatter::getIRCActionText
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForLogTypeUpload() {
|
2012-02-25 21:22:49 +00:00
|
|
|
|
# upload/upload
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'upload', 'upload',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
# upload/overwrite
|
|
|
|
|
|
$this->assertIRCComment(
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment,
|
2012-02-28 00:39:01 +00:00
|
|
|
|
'upload', 'overwrite',
|
|
|
|
|
|
array(),
|
|
|
|
|
|
$this->user_comment
|
2012-02-25 21:22:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-28 00:39:01 +00:00
|
|
|
|
* @todo: Emulate these edits somehow and extract
|
|
|
|
|
|
* raw edit summary from RecentChange object
|
|
|
|
|
|
* --
|
|
|
|
|
|
|
|
|
|
|
|
function testIrcMsgForBlankingAES() {
|
2012-03-05 21:21:34 +00:00
|
|
|
|
// $this->context->msg( 'autosumm-blank', .. );
|
2012-02-28 00:39:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function testIrcMsgForReplaceAES() {
|
2012-03-05 21:21:34 +00:00
|
|
|
|
// $this->context->msg( 'autosumm-replace', .. );
|
2012-02-25 21:22:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function testIrcMsgForRollbackAES() {
|
2012-03-05 21:21:34 +00:00
|
|
|
|
// $this->context->msg( 'revertpage', .. );
|
2012-02-28 00:39:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function testIrcMsgForUndoAES() {
|
2012-03-05 21:21:34 +00:00
|
|
|
|
// $this->context->msg( 'undo-summary', .. );
|
2012-02-28 00:39:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
* --
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2012-02-25 21:22:49 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $expected String Expected IRC text without colors codes
|
|
|
|
|
|
* @param $type String Log type (move, delete, suppress, patrol ...)
|
|
|
|
|
|
* @param $action String A log type action
|
2012-02-28 00:39:01 +00:00
|
|
|
|
* @param $comment String (optional) A comment for the log action
|
2012-02-25 21:22:49 +00:00
|
|
|
|
* @param $msg String (optional) A message for PHPUnit :-)
|
|
|
|
|
|
*/
|
2012-02-28 00:39:01 +00:00
|
|
|
|
function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
|
|
|
|
|
$logEntry = new ManualLogEntry( $type, $action );
|
2012-02-28 00:39:01 +00:00
|
|
|
|
$logEntry->setPerformer( $this->user );
|
|
|
|
|
|
$logEntry->setTarget( $this->title );
|
|
|
|
|
|
if ( $comment !== null ) {
|
|
|
|
|
|
$logEntry->setComment( $comment );
|
|
|
|
|
|
}
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$logEntry->setParameters( $params );
|
|
|
|
|
|
|
|
|
|
|
|
$formatter = LogFormatter::newFromEntry( $logEntry );
|
2012-03-05 21:21:34 +00:00
|
|
|
|
$formatter->setContext( $this->context );
|
2012-02-25 21:22:49 +00:00
|
|
|
|
|
2012-02-28 00:39:01 +00:00
|
|
|
|
// Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
|
|
|
|
|
|
$ircRcComment = RecentChange::cleanupForIRC( $formatter->getIRCActionComment() );
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
$ircRcComment,
|
2012-02-25 21:22:49 +00:00
|
|
|
|
$msg
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|