| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\RequestContext; |
| 4 |
use MediaWiki\MediaWikiServices; |
| 5 |
use MediaWiki\Title\Title; |
| 6 |
use MediaWiki\User\User; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class TestRecentChangesHelper { |
| 14 |
|
| 15 |
public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid, |
| 16 |
$timestamp, $counter, $watchingUsers |
| 17 |
) { |
| 18 |
$attribs = array_merge( |
| 19 |
$this->getDefaultAttributes( $titleText, $timestamp ), |
| 20 |
[ |
| 21 |
'rc_user' => $user->getId(), |
| 22 |
'rc_user_text' => $user->getName(), |
| 23 |
'rc_this_oldid' => $thisid, |
| 24 |
'rc_last_oldid' => $lastid, |
| 25 |
'rc_cur_id' => $curid |
| 26 |
] |
| 27 |
); |
| 28 |
|
| 29 |
return $this->makeRecentChange( $attribs, $counter, $watchingUsers ); |
| 30 |
} |
| 31 |
|
| 32 |
public function makeLogRecentChange( |
| 33 |
$logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers |
| 34 |
) { |
| 35 |
$attribs = array_merge( |
| 36 |
$this->getDefaultAttributes( $titleText, $timestamp ), |
| 37 |
[ |
| 38 |
'rc_cur_id' => 0, |
| 39 |
'rc_user' => $user->getId(), |
| 40 |
'rc_user_text' => $user->getName(), |
| 41 |
'rc_this_oldid' => 0, |
| 42 |
'rc_last_oldid' => 0, |
| 43 |
'rc_old_len' => null, |
| 44 |
'rc_new_len' => null, |
| 45 |
'rc_type' => 3, |
| 46 |
'rc_logid' => 25, |
| 47 |
'rc_log_type' => $logType, |
| 48 |
'rc_log_action' => $logAction, |
| 49 |
'rc_source' => 'mw.log' |
| 50 |
] |
| 51 |
); |
| 52 |
|
| 53 |
return $this->makeRecentChange( $attribs, $counter, $watchingUsers ); |
| 54 |
} |
| 55 |
|
| 56 |
public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid, |
| 57 |
$thisid, $lastid, $counter, $watchingUsers |
| 58 |
) { |
| 59 |
$attribs = array_merge( |
| 60 |
$this->getDefaultAttributes( $titleText, $timestamp ), |
| 61 |
[ |
| 62 |
'rc_user' => $user->getId(), |
| 63 |
'rc_user_text' => $user->getName(), |
| 64 |
'rc_deleted' => 5, |
| 65 |
'rc_cur_id' => $curid, |
| 66 |
'rc_this_oldid' => $thisid, |
| 67 |
'rc_last_oldid' => $lastid |
| 68 |
] |
| 69 |
); |
| 70 |
|
| 71 |
return $this->makeRecentChange( $attribs, $counter, $watchingUsers ); |
| 72 |
} |
| 73 |
|
| 74 |
public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid, |
| 75 |
$timestamp, $counter, $watchingUsers |
| 76 |
) { |
| 77 |
$attribs = array_merge( |
| 78 |
$this->getDefaultAttributes( $titleText, $timestamp ), |
| 79 |
[ |
| 80 |
'rc_user' => $user->getId(), |
| 81 |
'rc_user_text' => $user->getName(), |
| 82 |
'rc_this_oldid' => $thisid, |
| 83 |
'rc_last_oldid' => $lastid, |
| 84 |
'rc_cur_id' => $curid, |
| 85 |
'rc_type' => 1, |
| 86 |
'rc_bot' => 1, |
| 87 |
'rc_source' => 'mw.new' |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
return $this->makeRecentChange( $attribs, $counter, $watchingUsers ); |
| 92 |
} |
| 93 |
|
| 94 |
private function makeRecentChange( $attribs, $counter, $watchingUsers ) { |
| 95 |
$change = new RecentChange(); |
| 96 |
$change->setAttribs( $attribs ); |
| 97 |
$change->counter = $counter; |
| 98 |
$change->numberofWatchingusers = $watchingUsers; |
| 99 |
|
| 100 |
return $change; |
| 101 |
} |
| 102 |
|
| 103 |
public function getCacheEntry( $recentChange ) { |
| 104 |
$rcCacheFactory = new RCCacheEntryFactory( |
| 105 |
new RequestContext(), |
| 106 |
[ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ], |
| 107 |
MediaWikiServices::getInstance()->getLinkRenderer() |
| 108 |
); |
| 109 |
return $rcCacheFactory->newFromRecentChange( $recentChange, false ); |
| 110 |
} |
| 111 |
|
| 112 |
public function makeCategorizationRecentChange( |
| 113 |
User $user, $titleText, $curid, $thisid, $lastid, $timestamp |
| 114 |
) { |
| 115 |
$attribs = array_merge( |
| 116 |
$this->getDefaultAttributes( $titleText, $timestamp ), |
| 117 |
[ |
| 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', |
| 125 |
'rc_comment_text' => '[[:Testpage]] added to category', |
| 126 |
'rc_comment_data' => null, |
| 127 |
'rc_old_len' => 0, |
| 128 |
'rc_new_len' => 0, |
| 129 |
] |
| 130 |
); |
| 131 |
|
| 132 |
return $this->makeRecentChange( $attribs, 0, 0 ); |
| 133 |
} |
| 134 |
|
| 135 |
private function getDefaultAttributes( $titleText, $timestamp ) { |
| 136 |
return [ |
| 137 |
'rc_id' => 545, |
| 138 |
'rc_user' => 0, |
| 139 |
'rc_user_text' => '127.0.0.1', |
| 140 |
'rc_ip' => '127.0.0.1', |
| 141 |
'rc_title' => $titleText, |
| 142 |
'rc_namespace' => 0, |
| 143 |
'rc_timestamp' => $timestamp, |
| 144 |
'rc_old_len' => 212, |
| 145 |
'rc_new_len' => 188, |
| 146 |
'rc_comment' => '', |
| 147 |
'rc_comment_text' => '', |
| 148 |
'rc_comment_data' => null, |
| 149 |
'rc_minor' => 0, |
| 150 |
'rc_bot' => 0, |
| 151 |
'rc_type' => 0, |
| 152 |
'rc_patrolled' => 1, |
| 153 |
'rc_deleted' => 0, |
| 154 |
'rc_logid' => 0, |
| 155 |
'rc_log_type' => null, |
| 156 |
'rc_log_action' => '', |
| 157 |
'rc_params' => '', |
| 158 |
'rc_source' => 'mw.edit' |
| 159 |
]; |
| 160 |
} |
| 161 |
|
| 162 |
public function getTestContext( User $user ) { |
| 163 |
$context = new RequestContext(); |
| 164 |
$context->setLanguage( 'en' ); |
| 165 |
|
| 166 |
$context->setUser( $user ); |
| 167 |
|
| 168 |
$title = Title::makeTitle( NS_SPECIAL, 'RecentChanges' ); |
| 169 |
$context->setTitle( $title ); |
| 170 |
|
| 171 |
return $context; |
| 172 |
} |
| 173 |
} |