MediaWiki REL1_28
TestRecentChangesHelper.php
Go to the documentation of this file.
1<?php
4
11
12 public function makeEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
13 $timestamp, $counter, $watchingUsers
14 ) {
15
16 $attribs = array_merge(
17 $this->getDefaultAttributes( $titleText, $timestamp ),
18 [
19 'rc_user' => $user->getId(),
20 'rc_user_text' => $user->getName(),
21 'rc_this_oldid' => $thisid,
22 'rc_last_oldid' => $lastid,
23 'rc_cur_id' => $curid
24 ]
25 );
26
27 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
28 }
29
30 public function makeLogRecentChange(
31 $logType, $logAction, User $user, $titleText, $timestamp, $counter, $watchingUsers
32 ) {
33 $attribs = array_merge(
34 $this->getDefaultAttributes( $titleText, $timestamp ),
35 [
36 'rc_cur_id' => 0,
37 'rc_user' => $user->getId(),
38 'rc_user_text' => $user->getName(),
39 'rc_this_oldid' => 0,
40 'rc_last_oldid' => 0,
41 'rc_old_len' => null,
42 'rc_new_len' => null,
43 'rc_type' => 3,
44 'rc_logid' => 25,
45 'rc_log_type' => $logType,
46 'rc_log_action' => $logAction,
47 'rc_source' => 'mw.log'
48 ]
49 );
50
51 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
52 }
53
54 public function makeDeletedEditRecentChange( User $user, $titleText, $timestamp, $curid,
55 $thisid, $lastid, $counter, $watchingUsers
56 ) {
57 $attribs = array_merge(
58 $this->getDefaultAttributes( $titleText, $timestamp ),
59 [
60 'rc_user' => $user->getId(),
61 'rc_user_text' => $user->getName(),
62 'rc_deleted' => 5,
63 'rc_cur_id' => $curid,
64 'rc_this_oldid' => $thisid,
65 'rc_last_oldid' => $lastid
66 ]
67 );
68
69 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
70 }
71
72 public function makeNewBotEditRecentChange( User $user, $titleText, $curid, $thisid, $lastid,
73 $timestamp, $counter, $watchingUsers
74 ) {
75
76 $attribs = array_merge(
77 $this->getDefaultAttributes( $titleText, $timestamp ),
78 [
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,
84 'rc_type' => 1,
85 'rc_bot' => 1,
86 'rc_source' => 'mw.new'
87 ]
88 );
89
90 return $this->makeRecentChange( $attribs, $counter, $watchingUsers );
91 }
92
93 private function makeRecentChange( $attribs, $counter, $watchingUsers ) {
94 $change = new RecentChange();
95 $change->setAttribs( $attribs );
96 $change->counter = $counter;
97 $change->numberofWatchingusers = $watchingUsers;
98
99 return $change;
100 }
101
102 public function getCacheEntry( $recentChange ) {
103 $rcCacheFactory = new RCCacheEntryFactory(
104 new RequestContext(),
105 [ 'diff' => 'diff', 'cur' => 'cur', 'last' => 'last' ],
106 MediaWikiServices::getInstance()->getLinkRenderer()
107 );
108 return $rcCacheFactory->newFromRecentChange( $recentChange, false );
109 }
110
112 User $user, $titleText, $curid, $thisid, $lastid, $timestamp
113 ) {
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_old_len' => 0,
126 'rc_new_len' => 0,
127 ]
128 );
129
130 return $this->makeRecentChange( $attribs, 0, 0 );
131 }
132
133 private function getDefaultAttributes( $titleText, $timestamp ) {
134 return [
135 'rc_id' => 545,
136 'rc_user' => 0,
137 'rc_user_text' => '127.0.0.1',
138 'rc_ip' => '127.0.0.1',
139 'rc_title' => $titleText,
140 'rc_namespace' => 0,
141 'rc_timestamp' => $timestamp,
142 'rc_old_len' => 212,
143 'rc_new_len' => 188,
144 'rc_comment' => '',
145 'rc_minor' => 0,
146 'rc_bot' => 0,
147 'rc_type' => 0,
148 'rc_patrolled' => 1,
149 'rc_deleted' => 0,
150 'rc_logid' => 0,
151 'rc_log_type' => null,
152 'rc_log_action' => '',
153 'rc_params' => '',
154 'rc_source' => 'mw.edit'
155 ];
156 }
157
158 public function getTestContext( User $user ) {
159 $context = new RequestContext();
160 $context->setLanguage( 'en' );
161
162 $context->setUser( $user );
163
164 $title = Title::newFromText( 'RecentChanges', NS_SPECIAL );
165 $context->setTitle( $title );
166
167 return $context;
168 }
169}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Class that generates HTML links for pages.
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:48
const NS_SPECIAL
Definition Defines.php:45
const RC_CATEGORIZE
Definition Defines.php:140
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:249
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
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:1958
if( $limit) $timestamp
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$context
Definition load.php:50