Special:Upload should not crash on failing previews
[mediawiki.git] / includes / specials / SpecialDeletedContributions.php
blob5c8b3a620604272a0b08fddb4e7df154b0c1d49e
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 /** @var FormOptions */
30 protected $mOpts;
32 function __construct() {
33 parent::__construct( 'DeletedContributions', 'deletedhistory' );
36 /**
37 * Special page "deleted user contributions".
38 * Shows a list of the deleted contributions of a user.
40 * @param string $par (optional) user name of the user for which to show the contributions
42 function execute( $par ) {
43 $this->setHeaders();
44 $this->outputHeader();
45 $this->checkPermissions();
47 $user = $this->getUser();
49 $out = $this->getOutput();
50 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
52 $opts = new FormOptions();
54 $opts->add( 'target', '' );
55 $opts->add( 'namespace', '' );
56 $opts->add( 'limit', 20 );
58 $opts->fetchValuesFromRequest( $this->getRequest() );
59 $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
61 if ( $par !== null ) {
62 $opts->setValue( 'target', $par );
65 $ns = $opts->getValue( 'namespace' );
66 if ( $ns !== null && $ns !== '' ) {
67 $opts->setValue( 'namespace', intval( $ns ) );
70 $this->mOpts = $opts;
72 $target = $opts->getValue( 'target' );
73 if ( !strlen( $target ) ) {
74 $this->getForm();
76 return;
79 $userObj = User::newFromName( $target, false );
80 if ( !$userObj ) {
81 $this->getForm();
83 return;
85 $this->getSkin()->setRelevantUser( $userObj );
87 $target = $userObj->getName();
88 $out->addSubtitle( $this->getSubTitle( $userObj ) );
90 $this->getForm();
92 $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ) );
93 if ( !$pager->getNumRows() ) {
94 $out->addWikiMsg( 'nocontribs' );
96 return;
99 # Show a message about replica DB lag, if applicable
100 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
101 if ( $lag > 0 ) {
102 $out->showLagWarning( $lag );
105 $out->addHTML(
106 '<p>' . $pager->getNavigationBar() . '</p>' .
107 $pager->getBody() .
108 '<p>' . $pager->getNavigationBar() . '</p>' );
110 # If there were contributions, and it was a valid user or IP, show
111 # the appropriate "footer" message - WHOIS tools, etc.
112 if ( $target != 'newbies' ) {
113 $message = IP::isIPAddress( $target ) ?
114 'sp-contributions-footer-anon' :
115 'sp-contributions-footer';
117 if ( !$this->msg( $message )->isDisabled() ) {
118 $out->wrapWikiMsg(
119 "<div class='mw-contributions-footer'>\n$1\n</div>",
120 [ $message, $target ]
127 * Generates the subheading with links
128 * @param User $userObj User object for the target
129 * @return string Appropriately-escaped HTML to be output literally
131 function getSubTitle( $userObj ) {
132 $linkRenderer = $this->getLinkRenderer();
133 if ( $userObj->isAnon() ) {
134 $user = htmlspecialchars( $userObj->getName() );
135 } else {
136 $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
138 $links = '';
139 $nt = $userObj->getUserPage();
140 $talk = $nt->getTalkPage();
141 if ( $talk ) {
142 $tools = SpecialContributions::getUserLinks( $this, $userObj );
144 # Link to contributions
145 $insert['contribs'] = $linkRenderer->makeKnownLink(
146 SpecialPage::getTitleFor( 'Contributions', $nt->getDBkey() ),
147 $this->msg( 'sp-deletedcontributions-contribs' )->text()
150 // Swap out the deletedcontribs link for our contribs one
151 $tools = wfArrayInsertAfter( $tools, $insert, 'deletedcontribs' );
152 unset( $tools['deletedcontribs'] );
154 $links = $this->getLanguage()->pipeList( $tools );
156 // Show a note if the user is blocked and display the last block log entry.
157 $block = Block::newFromTarget( $userObj, $userObj );
158 if ( !is_null( $block ) && $block->getType() != Block::TYPE_AUTO ) {
159 if ( $block->getType() == Block::TYPE_RANGE ) {
160 $nt = MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget();
163 // LogEventsList::showLogExtract() wants the first parameter by ref
164 $out = $this->getOutput();
165 LogEventsList::showLogExtract(
166 $out,
167 'block',
168 $nt,
171 'lim' => 1,
172 'showIfEmpty' => false,
173 'msgKey' => [
174 'sp-contributions-blocked-notice',
175 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
177 'offset' => '' # don't use $this->getRequest() parameter offset
183 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
187 * Generates the namespace selector form with hidden attributes.
189 function getForm() {
190 $opts = $this->mOpts;
192 $formDescriptor = [
193 'target' => [
194 'type' => 'user',
195 'name' => 'target',
196 'label-message' => 'sp-contributions-username',
197 'default' => $opts->getValue( 'target' ),
198 'ipallowed' => true,
201 'namespace' => [
202 'type' => 'namespaceselect',
203 'name' => 'namespace',
204 'label-message' => 'namespace',
205 'all' => '',
209 HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() )
210 ->setWrapperLegendMsg( 'sp-contributions-search' )
211 ->setSubmitTextMsg( 'sp-contributions-submit' )
212 // prevent setting subpage and 'target' parameter at the same time
213 ->setAction( $this->getPageTitle()->getLocalURL() )
214 ->setMethod( 'get' )
215 ->prepareForm()
216 ->displayForm( false );
220 * Return an array of subpages beginning with $search that this special page will accept.
222 * @param string $search Prefix to search for
223 * @param int $limit Maximum number of results to return (usually 10)
224 * @param int $offset Number of results to skip (usually 0)
225 * @return string[] Matching subpages
227 public function prefixSearchSubpages( $search, $limit, $offset ) {
228 $user = User::newFromName( $search );
229 if ( !$user ) {
230 // No prefix suggestion for invalid user
231 return [];
233 // Autocomplete subpage as user list - public to allow caching
234 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
237 protected function getGroupName() {
238 return 'users';