MediaWiki REL1_37
SpecialDeletedContributions.php
Go to the documentation of this file.
1<?php
29use Wikimedia\IPUtils;
31
38 protected $mOpts;
39
42
45
48
51
54
57
60
70 public function __construct(
78 ) {
79 parent::__construct( 'DeletedContributions', 'deletedhistory' );
80 $this->permissionManager = $permissionManager;
81 $this->loadBalancer = $loadBalancer;
82 $this->commentStore = $commentStore;
83 $this->revisionFactory = $revisionFactory;
84 $this->namespaceInfo = $namespaceInfo;
85 $this->userNameUtils = $userNameUtils;
86 $this->userNamePrefixSearch = $userNamePrefixSearch;
87 }
88
95 public function execute( $par ) {
96 $this->setHeaders();
97 $this->outputHeader();
98 $this->checkPermissions();
99 $this->addHelpLink( 'Help:User contributions' );
100
101 $opts = new FormOptions();
102
103 $opts->add( 'target', '' );
104 $opts->add( 'namespace', '' );
105 $opts->add( 'limit', 20 );
106
107 $opts->fetchValuesFromRequest( $this->getRequest() );
108 $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
109
110 if ( $par !== null ) {
111 // Beautify the username
112 $par = $this->userNameUtils->getCanonical( $par, UserNameUtils::RIGOR_NONE );
113 $opts->setValue( 'target', (string)$par );
114 }
115
116 $ns = $opts->getValue( 'namespace' );
117 if ( $ns !== null && $ns !== '' ) {
118 $opts->setValue( 'namespace', intval( $ns ) );
119 }
120
121 $this->mOpts = $opts;
122
123 $target = trim( $opts->getValue( 'target' ) );
124 if ( !strlen( $target ) ) {
125 $this->getForm();
126
127 return;
128 }
129
130 $userObj = User::newFromName( $target, false );
131 if ( !$userObj ) {
132 $this->getForm();
133
134 return;
135 }
136 $this->getSkin()->setRelevantUser( $userObj );
137
138 $target = $userObj->getName();
139
140 $out = $this->getOutput();
141 $out->addSubtitle( $this->getSubTitle( $userObj ) );
142 $out->setPageTitle( $this->msg( 'deletedcontributions-title', $target ) );
143
144 $this->getForm();
145
146 $pager = new DeletedContribsPager(
147 $this->getContext(),
148 $target,
149 $opts->getValue( 'namespace' ),
150 $this->getLinkRenderer(),
151 $this->getHookContainer(),
152 $this->loadBalancer,
153 $this->commentStore,
154 $this->revisionFactory
155 );
156 if ( !$pager->getNumRows() ) {
157 $out->addWikiMsg( 'nocontribs' );
158
159 return;
160 }
161
162 # Show a message about replica DB lag, if applicable
163 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
164 if ( $lag > 0 ) {
165 $out->showLagWarning( $lag );
166 }
167
168 $out->addHTML(
169 '<p>' . $pager->getNavigationBar() . '</p>' .
170 $pager->getBody() .
171 '<p>' . $pager->getNavigationBar() . '</p>' );
172
173 # If there were contributions, and it was a valid user or IP, show
174 # the appropriate "footer" message - WHOIS tools, etc.
175 $message = IPUtils::isIPAddress( $target ) ?
176 'sp-contributions-footer-anon' :
177 'sp-contributions-footer';
178
179 if ( !$this->msg( $message )->isDisabled() ) {
180 $out->wrapWikiMsg(
181 "<div class='mw-contributions-footer'>\n$1\n</div>",
182 [ $message, $target ]
183 );
184 }
185 }
186
192 private function getSubTitle( $userObj ) {
194 if ( $userObj->isAnon() ) {
195 $user = htmlspecialchars( $userObj->getName() );
196 } else {
197 $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
198 }
199 $links = '';
200 $nt = $userObj->getUserPage();
201 $talk = $nt->getTalkPage();
202 if ( $talk ) {
203 $tools = SpecialContributions::getUserLinks(
204 $this,
205 $userObj,
206 $this->permissionManager,
207 $this->getHookRunner()
208 );
209
210 $contributionsLink = $linkRenderer->makeKnownLink(
211 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
212 $this->msg( 'sp-deletedcontributions-contribs' )->text()
213 );
214 if ( isset( $tools['deletedcontribs'] ) ) {
215 // Swap out the deletedcontribs link for our contribs one
216 $tools = wfArrayInsertAfter(
217 $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
218 unset( $tools['deletedcontribs'] );
219 } else {
220 $tools['contribs'] = $contributionsLink;
221 }
222
223 $links = $this->getLanguage()->pipeList( $tools );
224
225 // Show a note if the user is blocked and display the last block log entry.
226 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
227 if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
228 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
229 $nt = $this->namespaceInfo->getCanonicalName( NS_USER )
230 . ':' . $block->getTargetName();
231 }
232
233 // LogEventsList::showLogExtract() wants the first parameter by ref
234 $out = $this->getOutput();
235 LogEventsList::showLogExtract(
236 $out,
237 'block',
238 $nt,
239 '',
240 [
241 'lim' => 1,
242 'showIfEmpty' => false,
243 'msgKey' => [
244 'sp-contributions-blocked-notice',
245 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
246 ],
247 'offset' => '' # don't use $this->getRequest() parameter offset
248 ]
249 );
250 }
251 }
252
253 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
254 }
255
259 private function getForm() {
260 $opts = $this->mOpts;
261
262 $formDescriptor = [
263 'target' => [
264 'type' => 'user',
265 'name' => 'target',
266 'label-message' => 'sp-contributions-username',
267 'default' => $opts->getValue( 'target' ),
268 'ipallowed' => true,
269 ],
270
271 'namespace' => [
272 'type' => 'namespaceselect',
273 'name' => 'namespace',
274 'label-message' => 'namespace',
275 'all' => '',
276 ],
277 ];
278
279 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
280 ->setWrapperLegendMsg( 'sp-contributions-search' )
281 ->setSubmitTextMsg( 'sp-contributions-submit' )
282 // prevent setting subpage and 'target' parameter at the same time
283 ->setAction( $this->getPageTitle()->getLocalURL() )
284 ->setMethod( 'get' )
285 ->prepareForm()
286 ->displayForm( false );
287 }
288
297 public function prefixSearchSubpages( $search, $limit, $offset ) {
298 $search = $this->userNameUtils->getCanonical( $search );
299 if ( !$search ) {
300 // No prefix suggestion for invalid user
301 return [];
302 }
303 // Autocomplete subpage as user list - public to allow caching
304 return $this->userNamePrefixSearch
305 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
306 }
307
308 protected function getGroupName() {
309 return 'users';
310 }
311}
const NS_USER
Definition Defines.php:66
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
Handle database storage of comments such as edit summaries and log reasons.
Helper class to keep track of options when mixing links and form elements.
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
makeKnownLink( $target, $text=null, array $extraAttribs=[], array $query=[])
makeLink( $target, $text=null, array $extraAttribs=[], array $query=[])
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Handles searching prefixes of user names.
UserNameUtils service.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Implements Special:DeletedContributions to display archived revisions.
getSubTitle( $userObj)
Generates the subheading with links.
execute( $par)
Special page "deleted user contributions".
getForm()
Generates the namespace selector form with hidden attributes.
__construct(PermissionManager $permissionManager, ILoadBalancer $loadBalancer, CommentStore $commentStore, RevisionFactory $revisionFactory, NamespaceInfo $namespaceInfo, UserNameUtils $userNameUtils, UserNamePrefixSearch $userNamePrefixSearch)
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getSkin()
Shortcut to get the skin being used for this instance.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
LinkRenderer null $linkRenderer
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFromName( $name, $validate='valid')
Definition User.php:607
Service for constructing RevisionRecord objects.
Database cluster connection, tracking, load balancing, and transaction manager interface.