3 use MediaWiki\MediaWikiServices
;
6 * Helper for generating test recent changes entries.
8 * @author Katie Filbert < aude.wiki@gmail.com >
10 class TestRecentChangesHelper
{
12 public function makeEditRecentChange( User
$user, $titleText, $curid, $thisid, $lastid,
13 $timestamp, $counter, $watchingUsers
16 $attribs = array_merge(
17 $this->getDefaultAttributes( $titleText, $timestamp ),
19 'rc_user' => $user->getId(),
20 'rc_user_text' => $user->getName(),
21 'rc_this_oldid' => $thisid,
22 'rc_last_oldid' => $lastid,
27 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
30 public function makeLogRecentChange(
31 $logType, $logAction, User
$user, $titleText, $timestamp, $counter, $watchingUsers
33 $attribs = array_merge(
34 $this->getDefaultAttributes( $titleText, $timestamp ),
37 'rc_user' => $user->getId(),
38 'rc_user_text' => $user->getName(),
45 'rc_log_type' => $logType,
46 'rc_log_action' => $logAction,
47 'rc_source' => 'mw.log'
51 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
54 public function makeDeletedEditRecentChange( User
$user, $titleText, $timestamp, $curid,
55 $thisid, $lastid, $counter, $watchingUsers
57 $attribs = array_merge(
58 $this->getDefaultAttributes( $titleText, $timestamp ),
60 'rc_user' => $user->getId(),
61 'rc_user_text' => $user->getName(),
63 'rc_cur_id' => $curid,
64 'rc_this_oldid' => $thisid,
65 'rc_last_oldid' => $lastid
69 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
72 public function makeNewBotEditRecentChange( User
$user, $titleText, $curid, $thisid, $lastid,
73 $timestamp, $counter, $watchingUsers
76 $attribs = array_merge(
77 $this->getDefaultAttributes( $titleText, $timestamp ),
79 'rc_user' => $user->getId(),
80 'rc_user_text' => $user->getName(),
81 'rc_this_oldid' => $thisid,
82 'rc_last_oldid' => $lastid,
83 'rc_cur_id' => $curid,
86 'rc_source' => 'mw.new'
90 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
93 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
94 $change = new RecentChange();
95 $change->setAttribs( $attribs );
96 $change->counter
= $counter;
97 $change->numberofWatchingusers
= $watchingUsers;
102 public function getCacheEntry( $recentChange ) {
103 $rcCacheFactory = new RCCacheEntryFactory(
104 new RequestContext(),
105 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
106 MediaWikiServices
::getInstance()->getLinkRenderer()
108 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
111 public function makeCategorizationRecentChange(
112 User
$user, $titleText, $curid, $thisid, $lastid, $timestamp
115 $attribs = array_merge(
116 $this->getDefaultAttributes( $titleText, $timestamp ),
118 'rc_type' => RC_CATEGORIZE
,
119 'rc_user' => $user->getId(),
120 'rc_user_text' => $user->getName(),
121 'rc_this_oldid' => $thisid,
122 'rc_last_oldid' => $lastid,
123 'rc_cur_id' => $curid,
124 'rc_comment' => '[[:Testpage]] added to category',
130 return $this->makeRecentChange( $attribs, 0, 0 );
133 private function getDefaultAttributes( $titleText, $timestamp ) {
137 'rc_user_text' => '127.0.0.1',
138 'rc_ip' => '127.0.0.1',
139 'rc_title' => $titleText,
141 'rc_timestamp' => $timestamp,
151 'rc_log_type' => null,
152 'rc_log_action' => '',
154 'rc_source' => 'mw.edit'
158 public function getTestContext( User
$user ) {
159 $context = new RequestContext();
160 $context->setLanguage( 'en' );
162 $context->setUser( $user );
164 $title = Title
::newFromText( 'RecentChanges', NS_SPECIAL
);
165 $context->setTitle( $title );