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
21 * @ingroup SpecialPage
25 * Implements Special:DeletedContributions to display archived revisions
26 * @ingroup SpecialPage
28 class DeletedContributionsPage
extends SpecialPage
{
29 /** @var FormOptions */
32 function __construct() {
33 parent
::__construct( 'DeletedContributions', 'deletedhistory' );
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 ) {
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 // Beautify the username
63 $par = User
::getCanonicalName( $par, false );
64 $opts->setValue( 'target', (string)$par );
67 $ns = $opts->getValue( 'namespace' );
68 if ( $ns !== null && $ns !== '' ) {
69 $opts->setValue( 'namespace', intval( $ns ) );
74 $target = trim( $opts->getValue( 'target' ) );
75 if ( !strlen( $target ) ) {
81 $userObj = User
::newFromName( $target, false );
87 $this->getSkin()->setRelevantUser( $userObj );
89 $target = $userObj->getName();
90 $out->addSubtitle( $this->getSubTitle( $userObj ) );
94 $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ) );
95 if ( !$pager->getNumRows() ) {
96 $out->addWikiMsg( 'nocontribs' );
101 # Show a message about replica DB lag, if applicable
102 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
104 $out->showLagWarning( $lag );
108 '<p>' . $pager->getNavigationBar() . '</p>' .
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() ) {
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
133 function getSubTitle( $userObj ) {
134 $linkRenderer = $this->getLinkRenderer();
135 if ( $userObj->isAnon() ) {
136 $user = htmlspecialchars( $userObj->getName() );
138 $user = $linkRenderer->makeLink( $userObj->getUserPage(), $userObj->getName() );
141 $nt = $userObj->getUserPage();
142 $talk = $nt->getTalkPage();
144 $tools = SpecialContributions
::getUserLinks( $this, $userObj );
146 $contributionsLink = $linkRenderer->makeKnownLink(
147 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
148 $this->msg( 'sp-deletedcontributions-contribs' )->text()
150 if ( isset( $tools['deletedcontribs'] ) ) {
151 // Swap out the deletedcontribs link for our contribs one
152 $tools = wfArrayInsertAfter(
153 $tools, [ 'contribs' => $contributionsLink ], 'deletedcontribs' );
154 unset( $tools['deletedcontribs'] );
156 $tools['contribs'] = $contributionsLink;
159 $links = $this->getLanguage()->pipeList( $tools );
161 // Show a note if the user is blocked and display the last block log entry.
162 $block = Block
::newFromTarget( $userObj, $userObj );
163 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
164 if ( $block->getType() == Block
::TYPE_RANGE
) {
165 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
168 // LogEventsList::showLogExtract() wants the first parameter by ref
169 $out = $this->getOutput();
170 LogEventsList
::showLogExtract(
177 'showIfEmpty' => false,
179 'sp-contributions-blocked-notice',
180 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
182 'offset' => '' # don't use $this->getRequest() parameter offset
188 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
192 * Generates the namespace selector form with hidden attributes.
195 $opts = $this->mOpts
;
201 'label-message' => 'sp-contributions-username',
202 'default' => $opts->getValue( 'target' ),
207 'type' => 'namespaceselect',
208 'name' => 'namespace',
209 'label-message' => 'namespace',
214 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
215 ->setWrapperLegendMsg( 'sp-contributions-search' )
216 ->setSubmitTextMsg( 'sp-contributions-submit' )
217 // prevent setting subpage and 'target' parameter at the same time
218 ->setAction( $this->getPageTitle()->getLocalURL() )
221 ->displayForm( false );
225 * Return an array of subpages beginning with $search that this special page will accept.
227 * @param string $search Prefix to search for
228 * @param int $limit Maximum number of results to return (usually 10)
229 * @param int $offset Number of results to skip (usually 0)
230 * @return string[] Matching subpages
232 public function prefixSearchSubpages( $search, $limit, $offset ) {
233 $user = User
::newFromName( $search );
235 // No prefix suggestion for invalid user
238 // Autocomplete subpage as user list - public to allow caching
239 return UserNamePrefixSearch
::search( 'public', $search, $limit, $offset );
242 protected function getGroupName() {