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
24 use MediaWiki\Block\DatabaseBlock
;
25 use MediaWiki\MediaWikiServices
;
28 * Implements Special:DeletedContributions to display archived revisions
29 * @ingroup SpecialPage
31 class DeletedContributionsPage
extends SpecialPage
{
32 /** @var FormOptions */
35 function __construct() {
36 parent
::__construct( 'DeletedContributions', 'deletedhistory' );
40 * Special page "deleted user contributions".
41 * Shows a list of the deleted contributions of a user.
43 * @param string $par (optional) user name of the user for which to show the contributions
45 function execute( $par ) {
47 $this->outputHeader();
48 $this->checkPermissions();
49 $this->addHelpLink( 'Help:User contributions' );
51 $out = $this->getOutput();
52 $out->setPageTitle( $this->msg( 'deletedcontributions-title' ) );
54 $opts = new FormOptions();
56 $opts->add( 'target', '' );
57 $opts->add( 'namespace', '' );
58 $opts->add( 'limit', 20 );
60 $opts->fetchValuesFromRequest( $this->getRequest() );
61 $opts->validateIntBounds( 'limit', 0, $this->getConfig()->get( 'QueryPageDefaultLimit' ) );
63 if ( $par !== null ) {
64 // Beautify the username
65 $par = User
::getCanonicalName( $par, false );
66 $opts->setValue( 'target', (string)$par );
69 $ns = $opts->getValue( 'namespace' );
70 if ( $ns !== null && $ns !== '' ) {
71 $opts->setValue( 'namespace', intval( $ns ) );
76 $target = trim( $opts->getValue( 'target' ) );
77 if ( !strlen( $target ) ) {
83 $userObj = User
::newFromName( $target, false );
89 $this->getSkin()->setRelevantUser( $userObj );
91 $target = $userObj->getName();
92 $out->addSubtitle( $this->getSubTitle( $userObj ) );
96 $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ) );
97 if ( !$pager->getNumRows() ) {
98 $out->addWikiMsg( 'nocontribs' );
103 # Show a message about replica DB lag, if applicable
104 $lag = $pager->getDatabase()->getSessionLagStatus()['lag'];
106 $out->showLagWarning( $lag );
110 '<p>' . $pager->getNavigationBar() . '</p>' .
112 '<p>' . $pager->getNavigationBar() . '</p>' );
114 # If there were contributions, and it was a valid user or IP, show
115 # the appropriate "footer" message - WHOIS tools, etc.
116 $message = IP
::isIPAddress( $target ) ?
117 'sp-contributions-footer-anon' :
118 'sp-contributions-footer';
120 if ( !$this->msg( $message )->isDisabled() ) {
122 "<div class='mw-contributions-footer'>\n$1\n</div>",
123 [ $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 = DatabaseBlock
::newFromTarget( $userObj, $userObj );
163 if ( !is_null( $block ) && $block->getType() != DatabaseBlock
::TYPE_AUTO
) {
164 if ( $block->getType() == DatabaseBlock
::TYPE_RANGE
) {
165 $nt = MediaWikiServices
::getInstance()->getNamespaceInfo()->
166 getCanonicalName( NS_USER
) . ':' . $block->getTarget();
169 // LogEventsList::showLogExtract() wants the first parameter by ref
170 $out = $this->getOutput();
171 LogEventsList
::showLogExtract(
178 'showIfEmpty' => false,
180 'sp-contributions-blocked-notice',
181 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
183 'offset' => '' # don't use $this->getRequest() parameter offset
189 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
193 * Generates the namespace selector form with hidden attributes.
196 $opts = $this->mOpts
;
202 'label-message' => 'sp-contributions-username',
203 'default' => $opts->getValue( 'target' ),
208 'type' => 'namespaceselect',
209 'name' => 'namespace',
210 'label-message' => 'namespace',
215 HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
216 ->setWrapperLegendMsg( 'sp-contributions-search' )
217 ->setSubmitTextMsg( 'sp-contributions-submit' )
218 // prevent setting subpage and 'target' parameter at the same time
219 ->setAction( $this->getPageTitle()->getLocalURL() )
222 ->displayForm( false );
226 * Return an array of subpages beginning with $search that this special page will accept.
228 * @param string $search Prefix to search for
229 * @param int $limit Maximum number of results to return (usually 10)
230 * @param int $offset Number of results to skip (usually 0)
231 * @return string[] Matching subpages
233 public function prefixSearchSubpages( $search, $limit, $offset ) {
234 $user = User
::newFromName( $search );
236 // No prefix suggestion for invalid user
239 // Autocomplete subpage as user list - public to allow caching
240 return UserNamePrefixSearch
::search( 'public', $search, $limit, $offset );
243 protected function getGroupName() {