Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / specials / SpecialDeletedContributions.php
blob190bf9f981c4144ad07375a6ca1a8cd26b42ff65
1 <?php
2 /**
3 * Implements Special:DeletedContributions
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * Implements Special:DeletedContributions to display archived revisions
26 * @ingroup SpecialPage
28 class DeletedContributionsPage extends SpecialPage {
29 function __construct() {
30 parent::__construct( 'DeletedContributions', 'deletedhistory',
31 /*listed*/true, /*function*/false, /*file*/false );
34 /**
35 * Special page "deleted user contributions".
36 * Shows a list of the deleted contributions of a user.
38 * @param string $par (optional) user name of the user for which to show the contributions
40 function execute( $par ) {
41 $this->setHeaders();
42 $this->outputHeader();
44 $user = $this->getUser();
46 if ( !$this->userCanExecute( $user ) ) {
47 $this->displayRestrictionError();
49 return;
52 $request = $this->getRequest();
53 $out = $this->getOutput();
54 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
56 $options = [];
58 if ( $par !== null ) {
59 $target = $par;
60 } else {
61 $target = $request->getVal( 'target' );
64 if ( !strlen( $target ) ) {
65 $out->addHTML( $this->getForm( '' ) );
67 return;
70 $options['limit'] = $request->getInt( 'limit',
71 $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
72 $options['target'] = $target;
74 $userObj = User::newFromName( $target, false );
75 if ( !$userObj ) {
76 $out->addHTML( $this->getForm( '' ) );
78 return;
80 $this->getSkin()->setRelevantUser( $userObj );
82 $target = $userObj->getName();
83 $out->addSubtitle( $this->getSubTitle( $userObj ) );
85 $ns = $request->getVal( 'namespace', null );
86 if ( $ns !== null && $ns !== '' ) {
87 $options['namespace'] = intval( $ns );
88 } else {
89 $options['namespace'] = '';
92 $out->addHTML( $this->getForm( $options ) );
94 $pager = new DeletedContribsPager( $this->getContext(), $target, $options['namespace'] );
95 if ( !$pager->getNumRows() ) {
96 $out->addWikiMsg( 'nocontribs' );
98 return;
101 # Show a message about slave lag, if applicable
102 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
103 if ( $lag > 0 ) {
104 $out->showLagWarning( $lag );
107 $out->addHTML(
108 '<p>' . $pager->getNavigationBar() . '</p>' .
109 $pager->getBody() .
110 '<p>' . $pager->getNavigationBar() . '</p>' );
112 # If there were contributions, and it was a valid user or IP, show
113 # the appropriate "footer" message - WHOIS tools, etc.
114 if ( $target != 'newbies' ) {
115 $message = IP::isIPAddress( $target ) ?
116 'sp-contributions-footer-anon' :
117 'sp-contributions-footer';
119 if ( !$this->msg( $message )->isDisabled() ) {
120 $out->wrapWikiMsg(
121 "<div class='mw-contributions-footer'>\n$1\n</div>",
122 [ $message, $target ]
129 * Generates the subheading with links
130 * @param User $userObj User object for the target
131 * @return string Appropriately-escaped HTML to be output literally
132 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
134 function getSubTitle( $userObj ) {
135 if ( $userObj->isAnon() ) {
136 $user = htmlspecialchars( $userObj->getName() );
137 } else {
138 $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
140 $links = '';
141 $nt = $userObj->getUserPage();
142 $id = $userObj->getId();
143 $talk = $nt->getTalkPage();
144 if ( $talk ) {
145 # Talk page link
146 $tools[] = Linker::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
147 if ( ( $id !== null ) || ( $id === null && IP::isIPAddress( $nt->getText() ) ) ) {
148 # Block / Change block / Unblock links
149 if ( $this->getUser()->isAllowed( 'block' ) ) {
150 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() !== Block::TYPE_AUTO ) {
151 $tools[] = Linker::linkKnown( # Change block link
152 SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ),
153 $this->msg( 'change-blocklink' )->escaped()
155 $tools[] = Linker::linkKnown( # Unblock link
156 SpecialPage::getTitleFor( 'BlockList' ),
157 $this->msg( 'unblocklink' )->escaped(),
160 'action' => 'unblock',
161 'ip' => $nt->getDBkey()
164 } else {
165 # User is not blocked
166 $tools[] = Linker::linkKnown( # Block link
167 SpecialPage::getTitleFor( 'Block', $nt->getDBkey() ),
168 $this->msg( 'blocklink' )->escaped()
172 # Block log link
173 $tools[] = Linker::linkKnown(
174 SpecialPage::getTitleFor( 'Log' ),
175 $this->msg( 'sp-contributions-blocklog' )->escaped(),
178 'type' => 'block',
179 'page' => $nt->getPrefixedText()
182 # Suppression log link (bug 59120)
183 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
184 $tools[] = Linker::linkKnown(
185 SpecialPage::getTitleFor( 'Log', 'suppress' ),
186 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
188 [ 'offender' => $userObj->getName() ]
193 # Uploads
194 $tools[] = Linker::linkKnown(
195 SpecialPage::getTitleFor( 'Listfiles', $userObj->getName() ),
196 $this->msg( 'sp-contributions-uploads' )->escaped()
199 # Other logs link
200 $tools[] = Linker::linkKnown(
201 SpecialPage::getTitleFor( 'Log' ),
202 $this->msg( 'sp-contributions-logs' )->escaped(),
204 [ 'user' => $nt->getText() ]
206 # Link to contributions
207 $tools[] = Linker::linkKnown(
208 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
209 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
212 # Add a link to change user rights for privileged users
213 $userrightsPage = new UserrightsPage();
214 $userrightsPage->setContext( $this->getContext() );
215 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
216 $tools[] = Linker::linkKnown(
217 SpecialPage::getTitleFor( 'Userrights', $nt->getDBkey() ),
218 $this->msg( 'sp-contributions-userrights' )->escaped()
222 Hooks::run( 'ContributionsToolLinks', [ $id, $nt, &$tools ] );
224 $links = $this->getLanguage()->pipeList( $tools );
226 // Show a note if the user is blocked and display the last block log entry.
227 $block = Block::newFromTarget( $userObj, $userObj );
228 if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) {
229 if ( $block->getType() == Block::TYPE_RANGE ) {
230 $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget();
233 // LogEventsList::showLogExtract() wants the first parameter by ref
234 $out = $this->getOutput();
235 LogEventsList::showLogExtract(
236 $out,
237 'block',
238 $nt,
241 'lim' => 1,
242 'showIfEmpty' => false,
243 'msgKey' => [
244 'sp-contributions-blocked-notice',
245 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
247 'offset' => '' # don't use $this->getRequest() parameter offset
253 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
257 * Generates the namespace selector form with hidden attributes.
258 * @param array $options The options to be included.
259 * @return string
261 function getForm( $options ) {
262 $options['title'] = $this->getPageTitle()->getPrefixedText();
263 if ( !isset( $options['target'] ) ) {
264 $options['target'] = '';
265 } else {
266 $options['target'] = str_replace( '_', ' ', $options['target'] );
269 if ( !isset( $options['namespace'] ) ) {
270 $options['namespace'] = '';
273 if ( !isset( $options['contribs'] ) ) {
274 $options['contribs'] = 'user';
277 if ( $options['contribs'] == 'newbie' ) {
278 $options['target'] = '';
281 $f = Xml::openElement( 'form', [ 'method' => 'get', 'action' => wfScript() ] );
283 foreach ( $options as $name => $value ) {
284 if ( in_array( $name, [ 'namespace', 'target', 'contribs' ] ) ) {
285 continue;
287 $f .= "\t" . Html::hidden( $name, $value ) . "\n";
290 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
292 $f .= Xml::openElement( 'fieldset' );
293 $f .= Xml::element( 'legend', [], $this->msg( 'sp-contributions-search' )->text() );
294 $f .= Xml::tags(
295 'label',
296 [ 'for' => 'target' ],
297 $this->msg( 'sp-contributions-username' )->parse()
298 ) . ' ';
299 $f .= Html::input(
300 'target',
301 $options['target'],
302 'text',
304 'size' => '20',
305 'required' => '',
306 'class' => [
307 'mw-autocomplete-user', // used by mediawiki.userSuggest
309 ] + ( $options['target'] ? [] : [ 'autofocus' ] )
310 ) . ' ';
311 $f .= Html::namespaceSelector(
313 'selected' => $options['namespace'],
314 'all' => '',
315 'label' => $this->msg( 'namespace' )->text()
318 'name' => 'namespace',
319 'id' => 'namespace',
320 'class' => 'namespaceselector',
322 ) . ' ';
323 $f .= Xml::submitButton( $this->msg( 'sp-contributions-submit' )->text() );
324 $f .= Xml::closeElement( 'fieldset' );
325 $f .= Xml::closeElement( 'form' );
327 return $f;
331 * Return an array of subpages beginning with $search that this special page will accept.
333 * @param string $search Prefix to search for
334 * @param int $limit Maximum number of results to return (usually 10)
335 * @param int $offset Number of results to skip (usually 0)
336 * @return string[] Matching subpages
338 public function prefixSearchSubpages( $search, $limit, $offset ) {
339 $user = User::newFromName( $search );
340 if ( !$user ) {
341 // No prefix suggestion for invalid user
342 return [];
344 // Autocomplete subpage as user list - public to allow caching
345 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
348 protected function getGroupName() {
349 return 'users';