2014-07-25 07:30:09 +00:00
|
|
|
<?php
|
2017-01-10 10:49:58 +00:00
|
|
|
|
2016-05-13 07:24:29 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2014-07-25 07:30:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for generating test recent changes entries.
|
|
|
|
|
*
|
|
|
|
|
* @author Katie Filbert < aude.wiki@gmail.com >
|
|
|
|
|
*/
|
|
|
|
|
class TestRecentChangesHelper {
|
|
|
|
|
|
|
|
|
|
public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
|
|
|
|
|
$timestamp, $counter, $watchingUsers
|
|
|
|
|
) {
|
|
|
|
|
$attribs = array_merge(
|
|
|
|
|
$this->getDefaultAttributes( $titleText, $timestamp ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-07-25 07:30:09 +00:00
|
|
|
'rc_user' => $user->getId(),
|
|
|
|
|
'rc_user_text' => $user->getName(),
|
|
|
|
|
'rc_this_oldid' => $thisid,
|
|
|
|
|
'rc_last_oldid' => $lastid,
|
|
|
|
|
'rc_cur_id' => $curid
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-07-25 07:30:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 13:04:51 +00:00
|
|
|
public function makeLogRecentChange(
|
|
|
|
|
$logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
|
2014-07-25 07:30:09 +00:00
|
|
|
) {
|
|
|
|
|
$attribs = array_merge(
|
|
|
|
|
$this->getDefaultAttributes( $titleText, $timestamp ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-07-25 07:30:09 +00:00
|
|
|
'rc_cur_id' => 0,
|
|
|
|
|
'rc_user' => $user->getId(),
|
|
|
|
|
'rc_user_text' => $user->getName(),
|
|
|
|
|
'rc_this_oldid' => 0,
|
|
|
|
|
'rc_last_oldid' => 0,
|
|
|
|
|
'rc_old_len' => null,
|
|
|
|
|
'rc_new_len' => null,
|
|
|
|
|
'rc_type' => 3,
|
|
|
|
|
'rc_logid' => 25,
|
2014-07-25 13:05:39 +00:00
|
|
|
'rc_log_type' => $logType,
|
2014-07-25 16:39:07 +00:00
|
|
|
'rc_log_action' => $logAction,
|
2014-07-25 13:05:39 +00:00
|
|
|
'rc_source' => 'mw.log'
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-07-25 07:30:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
|
|
|
|
|
$thisid, $lastid, $counter, $watchingUsers
|
|
|
|
|
) {
|
|
|
|
|
$attribs = array_merge(
|
|
|
|
|
$this->getDefaultAttributes( $titleText, $timestamp ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-07-25 07:30:09 +00:00
|
|
|
'rc_user' => $user->getId(),
|
|
|
|
|
'rc_user_text' => $user->getName(),
|
|
|
|
|
'rc_deleted' => 5,
|
|
|
|
|
'rc_cur_id' => $curid,
|
|
|
|
|
'rc_this_oldid' => $thisid,
|
|
|
|
|
'rc_last_oldid' => $lastid
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-07-25 07:30:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 13:05:39 +00:00
|
|
|
public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
|
|
|
|
|
$timestamp, $counter, $watchingUsers
|
|
|
|
|
) {
|
|
|
|
|
$attribs = array_merge(
|
|
|
|
|
$this->getDefaultAttributes( $titleText, $timestamp ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-07-25 13:05:39 +00:00
|
|
|
'rc_user' => $user->getId(),
|
|
|
|
|
'rc_user_text' => $user->getName(),
|
|
|
|
|
'rc_this_oldid' => $thisid,
|
|
|
|
|
'rc_last_oldid' => $lastid,
|
|
|
|
|
'rc_cur_id' => $curid,
|
|
|
|
|
'rc_type' => 1,
|
|
|
|
|
'rc_bot' => 1,
|
|
|
|
|
'rc_source' => 'mw.new'
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-07-25 13:05:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 07:30:09 +00:00
|
|
|
private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
|
|
|
|
|
$change = new RecentChange();
|
|
|
|
|
$change->setAttribs( $attribs );
|
|
|
|
|
$change->counter = $counter;
|
|
|
|
|
$change->numberofWatchingusers = $watchingUsers;
|
|
|
|
|
|
|
|
|
|
return $change;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-24 17:40:06 +00:00
|
|
|
public function getCacheEntry( $recentChange ) {
|
|
|
|
|
$rcCacheFactory = new RCCacheEntryFactory(
|
|
|
|
|
new RequestContext(),
|
2016-05-13 07:24:29 +00:00
|
|
|
[ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
|
2016-05-27 16:11:58 +00:00
|
|
|
MediaWikiServices::getInstance()->getLinkRenderer()
|
2015-08-24 17:40:06 +00:00
|
|
|
);
|
|
|
|
|
return $rcCacheFactory->newFromRecentChange( $recentChange, false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function makeCategorizationRecentChange(
|
|
|
|
|
User $user, $titleText, $curid, $thisid, $lastid, $timestamp
|
|
|
|
|
) {
|
|
|
|
|
$attribs = array_merge(
|
|
|
|
|
$this->getDefaultAttributes( $titleText, $timestamp ),
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-08-24 17:40:06 +00:00
|
|
|
'rc_type' => RC_CATEGORIZE,
|
|
|
|
|
'rc_user' => $user->getId(),
|
|
|
|
|
'rc_user_text' => $user->getName(),
|
|
|
|
|
'rc_this_oldid' => $thisid,
|
|
|
|
|
'rc_last_oldid' => $lastid,
|
|
|
|
|
'rc_cur_id' => $curid,
|
|
|
|
|
'rc_comment' => '[[:Testpage]] added to category',
|
2017-06-06 17:39:14 +00:00
|
|
|
'rc_comment_text' => '[[:Testpage]] added to category',
|
|
|
|
|
'rc_comment_data' => null,
|
2015-08-24 17:40:06 +00:00
|
|
|
'rc_old_len' => 0,
|
|
|
|
|
'rc_new_len' => 0,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2015-08-24 17:40:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this->makeRecentChange( $attribs, 0, 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-25 07:30:09 +00:00
|
|
|
private function getDefaultAttributes( $titleText, $timestamp ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-07-25 07:30:09 +00:00
|
|
|
'rc_id' => 545,
|
|
|
|
|
'rc_user' => 0,
|
|
|
|
|
'rc_user_text' => '127.0.0.1',
|
|
|
|
|
'rc_ip' => '127.0.0.1',
|
|
|
|
|
'rc_title' => $titleText,
|
|
|
|
|
'rc_namespace' => 0,
|
|
|
|
|
'rc_timestamp' => $timestamp,
|
|
|
|
|
'rc_old_len' => 212,
|
|
|
|
|
'rc_new_len' => 188,
|
|
|
|
|
'rc_comment' => '',
|
2017-06-06 17:39:14 +00:00
|
|
|
'rc_comment_text' => '',
|
|
|
|
|
'rc_comment_data' => null,
|
2014-07-25 07:30:09 +00:00
|
|
|
'rc_minor' => 0,
|
|
|
|
|
'rc_bot' => 0,
|
|
|
|
|
'rc_type' => 0,
|
|
|
|
|
'rc_patrolled' => 1,
|
|
|
|
|
'rc_deleted' => 0,
|
|
|
|
|
'rc_logid' => 0,
|
|
|
|
|
'rc_log_type' => null,
|
|
|
|
|
'rc_log_action' => '',
|
|
|
|
|
'rc_params' => '',
|
|
|
|
|
'rc_source' => 'mw.edit'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-07-25 07:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-25 13:05:39 +00:00
|
|
|
public function getTestContext( User $user ) {
|
2014-07-25 07:30:09 +00:00
|
|
|
$context = new RequestContext();
|
2016-03-09 16:47:58 +00:00
|
|
|
$context->setLanguage( 'en' );
|
2014-07-25 07:30:09 +00:00
|
|
|
|
|
|
|
|
$context->setUser( $user );
|
|
|
|
|
|
2014-09-01 10:22:50 +00:00
|
|
|
$title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
|
|
|
|
|
$context->setTitle( $title );
|
|
|
|
|
|
2014-07-25 07:30:09 +00:00
|
|
|
return $context;
|
|
|
|
|
}
|
|
|
|
|
}
|