MediaWiki REL1_31
TestRecentChangesHelper.php
Go to the documentation of this file.
1<?php
2
4
11
12 public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
13 $timestamp, $counter, $watchingUsers
14 ) {
15 $attribs = array_merge(
16 $this->getDefaultAttributes( $titleText, $timestamp ),
17 [
18 'rc_user' => $user->getId(),
19 'rc_user_text' => $user->getName(),
20 'rc_this_oldid' => $thisid,
21 'rc_last_oldid' => $lastid,
22 'rc_cur_id' => $curid
23 ]
24 );
25
26 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
27 }
28
29 public function makeLogRecentChange(
30 $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
31 ) {
32 $attribs = array_merge(
33 $this->getDefaultAttributes( $titleText, $timestamp ),
34 [
35 'rc_cur_id' => 0,
36 'rc_user' => $user->getId(),
37 'rc_user_text' => $user->getName(),
38 'rc_this_oldid' => 0,
39 'rc_last_oldid' => 0,
40 'rc_old_len' => null,
41 'rc_new_len' => null,
42 'rc_type' => 3,
43 'rc_logid' => 25,
44 'rc_log_type' => $logType,
45 'rc_log_action' => $logAction,
46 'rc_source' => 'mw.log'
47 ]
48 );
49
50 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
51 }
52
53 public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
54 $thisid, $lastid, $counter, $watchingUsers
55 ) {
56 $attribs = array_merge(
57 $this->getDefaultAttributes( $titleText, $timestamp ),
58 [
59 'rc_user' => $user->getId(),
60 'rc_user_text' => $user->getName(),
61 'rc_deleted' => 5,
62 'rc_cur_id' => $curid,
63 'rc_this_oldid' => $thisid,
64 'rc_last_oldid' => $lastid
65 ]
66 );
67
68 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
69 }
70
71 public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
72 $timestamp, $counter, $watchingUsers
73 ) {
74 $attribs = array_merge(
75 $this->getDefaultAttributes( $titleText, $timestamp ),
76 [
77 'rc_user' => $user->getId(),
78 'rc_user_text' => $user->getName(),
79 'rc_this_oldid' => $thisid,
80 'rc_last_oldid' => $lastid,
81 'rc_cur_id' => $curid,
82 'rc_type' => 1,
83 'rc_bot' => 1,
84 'rc_source' => 'mw.new'
85 ]
86 );
87
88 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
89 }
90
91 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
92 $change = new RecentChange();
93 $change->setAttribs( $attribs );
94 $change->counter = $counter;
95 $change->numberofWatchingusers = $watchingUsers;
96
97 return $change;
98 }
99
100 public function getCacheEntry( $recentChange ) {
101 $rcCacheFactory = new RCCacheEntryFactory(
102 new RequestContext(),
103 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
104 MediaWikiServices::getInstance()->getLinkRenderer()
105 );
106 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
107 }
108
110 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
111 ) {
112 $attribs = array_merge(
113 $this->getDefaultAttributes( $titleText, $timestamp ),
114 [
115 'rc_type' => RC_CATEGORIZE,
116 'rc_user' => $user->getId(),
117 'rc_user_text' => $user->getName(),
118 'rc_this_oldid' => $thisid,
119 'rc_last_oldid' => $lastid,
120 'rc_cur_id' => $curid,
121 'rc_comment' => '[[:Testpage]] added to category',
122 'rc_comment_text' => '[[:Testpage]] added to category',
123 'rc_comment_data' => null,
124 'rc_old_len' => 0,
125 'rc_new_len' => 0,
126 ]
127 );
128
129 return $this->makeRecentChange( $attribs, 0, 0 );
130 }
131
132 private function getDefaultAttributes( $titleText, $timestamp ) {
133 return [
134 'rc_id' => 545,
135 'rc_user' => 0,
136 'rc_user_text' => '127.0.0.1',
137 'rc_ip' => '127.0.0.1',
138 'rc_title' => $titleText,
139 'rc_namespace' => 0,
140 'rc_timestamp' => $timestamp,
141 'rc_old_len' => 212,
142 'rc_new_len' => 188,
143 'rc_comment' => '',
144 'rc_comment_text' => '',
145 'rc_comment_data' => null,
146 'rc_minor' => 0,
147 'rc_bot' => 0,
148 'rc_type' => 0,
149 'rc_patrolled' => 1,
150 'rc_deleted' => 0,
151 'rc_logid' => 0,
152 'rc_log_type' => null,
153 'rc_log_action' => '',
154 'rc_params' => '',
155 'rc_source' => 'mw.edit'
156 ];
157 }
158
159 public function getTestContext( User $user ) {
160 $context = new RequestContext();
161 $context->setLanguage( 'en' );
162
163 $context->setUser( $user );
164
165 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
166 $context->setTitle( $title );
167
168 return $context;
169 }
170}
MediaWikiServices is the service locator for the application scope of MediaWiki.
Utility class for creating new RC entries.
Group all the pieces relevant to the context of a request into one instance.
Helper for generating test recent changes entries.
makeDeletedEditRecentChange(User $user, $titleText, $timestamp, $curid, $thisid, $lastid, $counter, $watchingUsers)
makeNewBotEditRecentChange(User $user, $titleText, $curid, $thisid, $lastid, $timestamp, $counter, $watchingUsers)
makeRecentChange( $attribs, $counter, $watchingUsers)
makeCategorizationRecentChange(User $user, $titleText, $curid, $thisid, $lastid, $timestamp)
makeEditRecentChange(User $user, $titleText, $curid, $thisid, $lastid, $timestamp, $counter, $watchingUsers)
makeLogRecentChange( $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers)
getDefaultAttributes( $titleText, $timestamp)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2811
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2014
const NS_SPECIAL
Definition Defines.php:63
const RC_CATEGORIZE
Definition Defines.php:156