MediaWiki REL1_35
SpecialDeletedContributions.php
Go to the documentation of this file.
1<?php
26use Wikimedia\IPUtils;
27
34 protected $mOpts;
35
36 public function __construct() {
37 parent::__construct( 'DeletedContributions', 'deletedhistory' );
38 }
39
46 public function execute( $par ) {
47 $this->setHeaders();
48 $this->outputHeader();
49 $this->checkPermissions();
50 $this->addHelpLink( 'Help:User contributions' );
51
52 $out = $this->getOutput();
53 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
54
55 $opts = new FormOptions();
56
57 $opts->add( 'target', '' );
58 $opts->add( 'namespace', '' );
59 $opts->add( 'limit', 20 );
60
61 $opts->fetchValuesFromRequest( $this->getRequest() );
62 $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
63
64 if ( $par !== null ) {
65 // Beautify the username
66 $par = User::getCanonicalName( $par, false );
67 $opts->setValue( 'target', (string)$par );
68 }
69
70 $ns = $opts->getValue( 'namespace' );
71 if ( $ns !== null && $ns !== '' ) {
72 $opts->setValue( 'namespace', intval( $ns ) );
73 }
74
75 $this->mOpts = $opts;
76
77 $target = trim( $opts->getValue( 'target' ) );
78 if ( !strlen( $target ) ) {
79 $this->getForm();
80
81 return;
82 }
83
84 $userObj = User::newFromName( $target, false );
85 if ( !$userObj ) {
86 $this->getForm();
87
88 return;
89 }
90 $this->getSkin()->setRelevantUser( $userObj );
91
92 $target = $userObj->getName();
93 $out->addSubtitle( $this->getSubTitle( $userObj ) );
94
95 $this->getForm();
96
97 $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ),
98 $this->getLinkRenderer() );
99 if ( !$pager->getNumRows() ) {
100 $out->addWikiMsg( 'nocontribs' );
101
102 return;
103 }
104
105 # Show a message about replica DB lag, if applicable
106 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
107 if ( $lag > 0 ) {
108 $out->showLagWarning( $lag );
109 }
110
111 $out->addHTML(
112 '<p>' . $pager->getNavigationBar() . '</p>' .
113 $pager->getBody() .
114 '<p>' . $pager->getNavigationBar() . '</p>' );
115
116 # If there were contributions, and it was a valid user or IP, show
117 # the appropriate "footer" message - WHOIS tools, etc.
118 $message = IPUtils::isIPAddress( $target ) ?
119 'sp-contributions-footer-anon' :
120 'sp-contributions-footer';
121
122 if ( !$this->msg( $message )->isDisabled() ) {
123 $out->wrapWikiMsg(
124 "<div class='mw-contributions-footer'>\n$1\n</div>",
125 [ $message, $target ]
126 );
127 }
128 }
129
135 private function getSubTitle( $userObj ) {
137 if ( $userObj->isAnon() ) {
138 $user = htmlspecialchars( $userObj->getName() );
139 } else {
140 $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
141 }
142 $links = '';
143 $nt = $userObj->getUserPage();
144 $talk = $nt->getTalkPage();
145 if ( $talk ) {
146 $tools = SpecialContributions::getUserLinks( $this, $userObj );
147
148 $contributionsLink = $linkRenderer->makeKnownLink(
149 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
150 $this->msg( 'sp-deletedcontributions-contribs' )->text()
151 );
152 if ( isset( $tools['deletedcontribs'] ) ) {
153 // Swap out the deletedcontribs link for our contribs one
154 $tools = wfArrayInsertAfter(
155 $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
156 unset( $tools['deletedcontribs'] );
157 } else {
158 $tools['contribs'] = $contributionsLink;
159 }
160
161 $links = $this->getLanguage()->pipeList( $tools );
162
163 // Show a note if the user is blocked and display the last block log entry.
164 $block = DatabaseBlock::newFromTarget( $userObj, $userObj );
165 if ( $block !== null && $block->getType() != DatabaseBlock::TYPE_AUTO ) {
166 if ( $block->getType() == DatabaseBlock::TYPE_RANGE ) {
167 $nt = MediaWikiServices::getInstance()->getNamespaceInfo()->
168 getCanonicalName( NS_USER ) . ':' . $block->getTarget();
169 }
170
171 // LogEventsList::showLogExtract() wants the first parameter by ref
172 $out = $this->getOutput();
173 LogEventsList::showLogExtract(
174 $out,
175 'block',
176 $nt,
177 '',
178 [
179 'lim' => 1,
180 'showIfEmpty' => false,
181 'msgKey' => [
182 'sp-contributions-blocked-notice',
183 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
184 ],
185 'offset' => '' # don't use $this->getRequest() parameter offset
186 ]
187 );
188 }
189 }
190
191 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
192 }
193
197 private function getForm() {
198 $opts = $this->mOpts;
199
200 $formDescriptor = [
201 'target' => [
202 'type' => 'user',
203 'name' => 'target',
204 'label-message' => 'sp-contributions-username',
205 'default' => $opts->getValue( 'target' ),
206 'ipallowed' => true,
207 ],
208
209 'namespace' => [
210 'type' => 'namespaceselect',
211 'name' => 'namespace',
212 'label-message' => 'namespace',
213 'all' => '',
214 ],
215 ];
216
217 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
218 ->setWrapperLegendMsg( 'sp-contributions-search' )
219 ->setSubmitTextMsg( 'sp-contributions-submit' )
220 // prevent setting subpage and 'target' parameter at the same time
221 ->setAction( $this->getPageTitle()->getLocalURL() )
222 ->setMethod( 'get' )
223 ->prepareForm()
224 ->displayForm( false );
225 }
226
235 public function prefixSearchSubpages( $search, $limit, $offset ) {
236 $user = User::newFromName( $search );
237 if ( !$user ) {
238 // No prefix suggestion for invalid user
239 return [];
240 }
241 // Autocomplete subpage as user list - public to allow caching
242 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
243 }
244
245 protected function getGroupName() {
246 return 'users';
247 }
248}
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
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...
MediaWikiServices is the service locator for the application scope of MediaWiki.
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.
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.
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.
MediaWiki Linker LinkRenderer null $linkRenderer
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:541
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition User.php:1130
const NS_USER
Definition Defines.php:72