76dc7ada61b698c990d61490c6123ab204ad1678
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 $opts->setValue( 'target', $par );
65 $ns = $opts->getValue( 'namespace' );
66 if ( $ns !== null && $ns !== '' ) {
67 $opts->setValue( 'namespace', intval( $ns ) );
72 $target = $opts->getValue( 'target' );
73 if ( !strlen( $target ) ) {
79 $userObj = User
::newFromName( $target, false );
85 $this->getSkin()->setRelevantUser( $userObj );
87 $target = $userObj->getName();
88 $out->addSubtitle( $this->getSubTitle( $userObj ) );
92 $pager = new DeletedContribsPager( $this->getContext(), $target, $opts->getValue( 'namespace' ) );
93 if ( !$pager->getNumRows() ) {
94 $out->addWikiMsg( 'nocontribs' );
99 # Show a message about slave lag, if applicable
100 $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
102 $out->showLagWarning( $lag );
106 '<p>' . $pager->getNavigationBar() . '</p>' .
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() ) {
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
130 * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined.
132 function getSubTitle( $userObj ) {
133 if ( $userObj->isAnon() ) {
134 $user = htmlspecialchars( $userObj->getName() );
136 $user = Linker
::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) );
139 $nt = $userObj->getUserPage();
140 $id = $userObj->getId();
141 $talk = $nt->getTalkPage();
144 $tools[] = Linker
::link( $talk, $this->msg( 'sp-contributions-talk' )->escaped() );
145 if ( ( $id !== null ) ||
( $id === null && IP
::isIPAddress( $nt->getText() ) ) ) {
146 # Block / Change block / Unblock links
147 if ( $this->getUser()->isAllowed( 'block' ) ) {
148 if ( $userObj->isBlocked() && $userObj->getBlock()->getType() !== Block
::TYPE_AUTO
) {
149 $tools[] = Linker
::linkKnown( # Change block link
150 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
151 $this->msg( 'change-blocklink' )->escaped()
153 $tools[] = Linker
::linkKnown( # Unblock link
154 SpecialPage
::getTitleFor( 'BlockList' ),
155 $this->msg( 'unblocklink' )->escaped(),
158 'action' => 'unblock',
159 'ip' => $nt->getDBkey()
163 # User is not blocked
164 $tools[] = Linker
::linkKnown( # Block link
165 SpecialPage
::getTitleFor( 'Block', $nt->getDBkey() ),
166 $this->msg( 'blocklink' )->escaped()
171 $tools[] = Linker
::linkKnown(
172 SpecialPage
::getTitleFor( 'Log' ),
173 $this->msg( 'sp-contributions-blocklog' )->escaped(),
177 'page' => $nt->getPrefixedText()
180 # Suppression log link (bug 59120)
181 if ( $this->getUser()->isAllowed( 'suppressionlog' ) ) {
182 $tools[] = Linker
::linkKnown(
183 SpecialPage
::getTitleFor( 'Log', 'suppress' ),
184 $this->msg( 'sp-contributions-suppresslog' )->escaped(),
186 [ 'offender' => $userObj->getName() ]
192 $tools[] = Linker
::linkKnown(
193 SpecialPage
::getTitleFor( 'Listfiles', $userObj->getName() ),
194 $this->msg( 'sp-contributions-uploads' )->escaped()
198 $tools[] = Linker
::linkKnown(
199 SpecialPage
::getTitleFor( 'Log' ),
200 $this->msg( 'sp-contributions-logs' )->escaped(),
202 [ 'user' => $nt->getText() ]
204 # Link to contributions
205 $tools[] = Linker
::linkKnown(
206 SpecialPage
::getTitleFor( 'Contributions', $nt->getDBkey() ),
207 $this->msg( 'sp-deletedcontributions-contribs' )->escaped()
210 # Add a link to change user rights for privileged users
211 $userrightsPage = new UserrightsPage();
212 $userrightsPage->setContext( $this->getContext() );
213 if ( $userrightsPage->userCanChangeRights( $userObj ) ) {
214 $tools[] = Linker
::linkKnown(
215 SpecialPage
::getTitleFor( 'Userrights', $nt->getDBkey() ),
216 $this->msg( 'sp-contributions-userrights' )->escaped()
220 Hooks
::run( 'ContributionsToolLinks', [ $id, $nt, &$tools ] );
222 $links = $this->getLanguage()->pipeList( $tools );
224 // Show a note if the user is blocked and display the last block log entry.
225 $block = Block
::newFromTarget( $userObj, $userObj );
226 if ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
227 if ( $block->getType() == Block
::TYPE_RANGE
) {
228 $nt = MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget();
231 // LogEventsList::showLogExtract() wants the first parameter by ref
232 $out = $this->getOutput();
233 LogEventsList
::showLogExtract(
240 'showIfEmpty' => false,
242 'sp-contributions-blocked-notice',
243 $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice'
245 'offset' => '' # don't use $this->getRequest() parameter offset
251 return $this->msg( 'contribsub2' )->rawParams( $user, $links )->params( $userObj->getName() );
255 * Generates the namespace selector form with hidden attributes.
258 $opts = $this->mOpts
;
264 'label-message' => 'sp-contributions-username',
265 'default' => $opts->getValue( 'target' ),
270 'type' => 'namespaceselect',
271 'name' => 'namespace',
272 'label-message' => 'namespace',
277 $form = HTMLForm
::factory( 'ooui', $formDescriptor, $this->getContext() )
278 ->setWrapperLegendMsg( 'sp-contributions-search' )
279 ->setSubmitTextMsg( 'sp-contributions-submit' )
280 // prevent setting subpage and 'target' parameter at the same time
281 ->setAction( $this->getPageTitle()->getLocalURL() )
284 ->displayForm( false );
288 * Return an array of subpages beginning with $search that this special page will accept.
290 * @param string $search Prefix to search for
291 * @param int $limit Maximum number of results to return (usually 10)
292 * @param int $offset Number of results to skip (usually 0)
293 * @return string[] Matching subpages
295 public function prefixSearchSubpages( $search, $limit, $offset ) {
296 $user = User
::newFromName( $search );
298 // No prefix suggestion for invalid user
301 // Autocomplete subpage as user list - public to allow caching
302 return UserNamePrefixSearch
::search( 'public', $search, $limit, $offset );
305 protected function getGroupName() {