2007-08-17 20:53:17 +00:00
|
|
|
<?php
|
2012-05-14 17:59:58 +00:00
|
|
|
/**
|
|
|
|
|
* File deletion user interface.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
* @ingroup Media
|
|
|
|
|
*/
|
2017-01-18 20:55:20 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2007-08-17 20:53:17 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* File deletion user interface
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Media
|
2007-08-17 20:53:17 +00:00
|
|
|
*/
|
|
|
|
|
class FileDeleteForm {
|
|
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
2007-08-17 20:53:17 +00:00
|
|
|
private $title = null;
|
2011-10-29 01:53:28 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-09-04 18:46:57 +00:00
|
|
|
* @var LocalFile
|
2011-10-29 01:53:28 +00:00
|
|
|
*/
|
2007-08-17 20:53:17 +00:00
|
|
|
private $file = null;
|
2007-08-20 14:49:07 +00:00
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
|
|
|
|
private $user = null;
|
|
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
2019-09-04 18:46:57 +00:00
|
|
|
* @var LocalFile
|
2011-10-29 01:53:28 +00:00
|
|
|
*/
|
2007-08-20 14:49:07 +00:00
|
|
|
private $oldfile = null;
|
2020-05-07 19:55:06 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2007-08-17 20:53:17 +00:00
|
|
|
private $oldimage = '';
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
2020-01-26 09:58:06 +00:00
|
|
|
* Option to pass a user added in 1.35
|
|
|
|
|
* Constructing without passing a user is hard deprecated in 1.35
|
|
|
|
|
*
|
2019-09-04 18:46:57 +00:00
|
|
|
* @param LocalFile $file File object we're deleting
|
2020-01-26 09:58:06 +00:00
|
|
|
* @param User|null $user
|
2007-08-17 20:53:17 +00:00
|
|
|
*/
|
2020-01-26 09:58:06 +00:00
|
|
|
public function __construct( $file, $user = null ) {
|
2007-08-17 20:53:17 +00:00
|
|
|
$this->title = $file->getTitle();
|
|
|
|
|
$this->file = $file;
|
2020-01-26 09:58:06 +00:00
|
|
|
|
|
|
|
|
if ( $user === null ) {
|
Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.
However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."
So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().
Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-12 04:18:35 +00:00
|
|
|
wfDeprecatedMsg(
|
|
|
|
|
'Construction of ' . __CLASS__ . ' without a $user parameter ' .
|
|
|
|
|
'was deprecated in MediaWiki 1.35',
|
2020-01-26 09:58:06 +00:00
|
|
|
'1.35'
|
|
|
|
|
);
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
|
|
|
|
$this->user = $user;
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Fulfil the request; shows the form or deletes the file,
|
|
|
|
|
* pending authentication, confirmation, etc.
|
|
|
|
|
*/
|
|
|
|
|
public function execute() {
|
2020-01-26 09:58:06 +00:00
|
|
|
global $wgOut, $wgRequest, $wgUploadMaintenance;
|
2007-08-17 20:53:17 +00:00
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
|
|
|
|
|
$permissionErrors = $permissionManager->getPermissionErrors(
|
|
|
|
|
'delete',
|
|
|
|
|
$this->user,
|
|
|
|
|
$this->title
|
|
|
|
|
);
|
2011-11-02 15:30:55 +00:00
|
|
|
if ( count( $permissionErrors ) ) {
|
|
|
|
|
throw new PermissionsError( 'delete', $permissionErrors );
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-09-23 16:15:30 +00:00
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
throw new ReadOnlyError;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 18:08:34 +00:00
|
|
|
if ( $wgUploadMaintenance ) {
|
|
|
|
|
throw new ErrorPageError( 'filedelete-maintenance-title', 'filedelete-maintenance' );
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-02 15:30:55 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
|
2020-05-07 19:55:06 +00:00
|
|
|
$this->oldimage = $wgRequest->getText( 'oldimage', '' );
|
2007-08-17 20:53:17 +00:00
|
|
|
$token = $wgRequest->getText( 'wpEditToken' );
|
2008-03-15 00:27:57 +00:00
|
|
|
# Flag to hide all contents of the archived revisions
|
2019-08-16 18:13:56 +00:00
|
|
|
$suppress = $wgRequest->getCheck( 'wpSuppress' ) &&
|
2020-01-26 09:58:06 +00:00
|
|
|
$permissionManager->userHasRight( $this->user, 'suppressrevision' );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->oldimage ) {
|
2020-03-08 21:38:47 +00:00
|
|
|
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
|
|
|
|
|
$this->oldfile = $repoGroup->getLocalRepo()->newFromArchiveName(
|
2014-05-11 15:32:18 +00:00
|
|
|
$this->title,
|
|
|
|
|
$this->oldimage
|
|
|
|
|
);
|
2011-09-23 16:15:30 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !self::haveDeletableFile( $this->file, $this->oldfile, $this->oldimage ) ) {
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $this->prepareMessage( 'filedelete-nofile' ) );
|
2007-08-17 20:53:17 +00:00
|
|
|
$wgOut->addReturnTo( $this->title );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
// Perform the deletion if appropriate
|
2020-01-26 09:58:06 +00:00
|
|
|
if ( $wgRequest->wasPosted() && $this->user->matchEditToken( $token, $this->oldimage ) ) {
|
2011-11-03 08:55:04 +00:00
|
|
|
$deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList' );
|
|
|
|
|
$deleteReason = $wgRequest->getText( 'wpReason' );
|
|
|
|
|
|
|
|
|
|
if ( $deleteReasonList == 'other' ) {
|
|
|
|
|
$reason = $deleteReason;
|
|
|
|
|
} elseif ( $deleteReason != '' ) {
|
2008-01-24 15:35:44 +00:00
|
|
|
// Entry from drop down menu + additional comment
|
2012-08-19 20:44:29 +00:00
|
|
|
$reason = $deleteReasonList . wfMessage( 'colon-separator' )
|
|
|
|
|
->inContentLanguage()->text() . $deleteReason;
|
2011-11-03 08:55:04 +00:00
|
|
|
} else {
|
|
|
|
|
$reason = $deleteReasonList;
|
2008-01-24 15:35:44 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-05-11 15:32:18 +00:00
|
|
|
$status = self::doDelete(
|
|
|
|
|
$this->title,
|
|
|
|
|
$this->file,
|
|
|
|
|
$this->oldimage,
|
|
|
|
|
$reason,
|
|
|
|
|
$suppress,
|
2020-01-26 09:58:06 +00:00
|
|
|
$this->user
|
2014-05-11 15:32:18 +00:00
|
|
|
);
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$status->isGood() ) {
|
2011-08-19 23:30:12 +00:00
|
|
|
$wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
|
2018-10-17 14:28:05 +00:00
|
|
|
$wgOut->wrapWikiTextAsInterface(
|
|
|
|
|
'error',
|
2014-05-11 15:32:18 +00:00
|
|
|
$status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' )
|
2018-10-17 14:28:05 +00:00
|
|
|
);
|
2011-08-19 23:30:12 +00:00
|
|
|
}
|
2016-09-20 22:57:35 +00:00
|
|
|
if ( $status->isOK() ) {
|
2011-10-27 20:23:16 +00:00
|
|
|
$wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $this->prepareMessage( 'filedelete-success' ) );
|
2007-08-17 20:53:17 +00:00
|
|
|
// Return to the main page if we just deleted all versions of the
|
|
|
|
|
// file, otherwise go back to the description page
|
|
|
|
|
$wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() );
|
2011-11-15 18:08:34 +00:00
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
WatchAction::doWatchOrUnwatch(
|
|
|
|
|
$wgRequest->getCheck( 'wpWatch' ),
|
|
|
|
|
$this->title,
|
|
|
|
|
$this->user
|
|
|
|
|
);
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-27 15:55:02 +00:00
|
|
|
$this->showForm();
|
|
|
|
|
$this->showLogEntries();
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-13 21:25:03 +00:00
|
|
|
/**
|
|
|
|
|
* Really delete the file
|
|
|
|
|
*
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param Title &$title
|
2019-08-31 16:14:38 +00:00
|
|
|
* @param LocalFile &$file
|
2019-12-22 10:29:30 +00:00
|
|
|
* @param ?string &$oldimage Archive name
|
2014-04-08 15:29:17 +00:00
|
|
|
* @param string $reason Reason of the deletion
|
|
|
|
|
* @param bool $suppress Whether to mark all deleted versions as restricted
|
2020-02-20 02:50:54 +00:00
|
|
|
* @param User|null $user User object performing the request (null defaults to $wgUser
|
|
|
|
|
* and is deprecated as of 1.35)
|
2016-09-21 17:18:08 +00:00
|
|
|
* @param array $tags Tags to apply to the deletion action
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2016-10-19 16:54:25 +00:00
|
|
|
* @return Status
|
2010-01-13 21:25:03 +00:00
|
|
|
*/
|
2014-05-11 15:32:18 +00:00
|
|
|
public static function doDelete( &$title, &$file, &$oldimage, $reason,
|
2016-09-21 17:18:08 +00:00
|
|
|
$suppress, User $user = null, $tags = []
|
2014-05-11 15:32:18 +00:00
|
|
|
) {
|
2011-11-15 18:08:34 +00:00
|
|
|
if ( $user === null ) {
|
2020-02-20 02:50:54 +00:00
|
|
|
wfDeprecated( __METHOD__ . ' without passing a $user parameter', '1.35' );
|
2011-11-15 18:08:34 +00:00
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2010-02-26 20:14:28 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $oldimage ) {
|
2011-11-15 18:08:34 +00:00
|
|
|
$page = null;
|
2020-02-25 22:33:18 +00:00
|
|
|
$status = $file->deleteOldFile( $oldimage, $reason, $user, $suppress );
|
2019-08-31 16:14:38 +00:00
|
|
|
if ( $status->isOK() ) {
|
2008-04-04 12:16:50 +00:00
|
|
|
// Need to do a log item
|
2012-08-19 20:44:29 +00:00
|
|
|
$logComment = wfMessage( 'deletedrevision', $oldimage )->inContentLanguage()->text();
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( trim( $reason ) != '' ) {
|
2012-08-19 20:44:29 +00:00
|
|
|
$logComment .= wfMessage( 'colon-separator' )
|
|
|
|
|
->inContentLanguage()->text() . $reason;
|
2010-08-29 19:11:23 +00:00
|
|
|
}
|
2012-07-01 20:09:11 +00:00
|
|
|
|
|
|
|
|
$logtype = $suppress ? 'suppress' : 'delete';
|
|
|
|
|
|
|
|
|
|
$logEntry = new ManualLogEntry( $logtype, 'delete' );
|
|
|
|
|
$logEntry->setPerformer( $user );
|
|
|
|
|
$logEntry->setTarget( $title );
|
|
|
|
|
$logEntry->setComment( $logComment );
|
2019-07-07 22:07:56 +00:00
|
|
|
$logEntry->addTags( $tags );
|
2012-07-01 20:09:11 +00:00
|
|
|
$logid = $logEntry->insert();
|
|
|
|
|
$logEntry->publish( $logid );
|
2015-10-07 14:19:36 +00:00
|
|
|
|
|
|
|
|
$status->value = $logid;
|
2008-04-04 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2012-02-06 15:21:10 +00:00
|
|
|
$status = Status::newFatal( 'cannotdelete',
|
|
|
|
|
wfEscapeWikiText( $title->getPrefixedText() )
|
|
|
|
|
);
|
2011-11-15 18:08:34 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
2010-02-26 20:14:28 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2016-08-19 20:17:33 +00:00
|
|
|
$dbw->startAtomic( __METHOD__ );
|
|
|
|
|
// delete the associated article first
|
|
|
|
|
$error = '';
|
2020-03-19 00:47:20 +00:00
|
|
|
$deleteStatus = $page->doDeleteArticleReal(
|
|
|
|
|
$reason,
|
|
|
|
|
$user,
|
|
|
|
|
$suppress,
|
|
|
|
|
null,
|
|
|
|
|
$error,
|
|
|
|
|
null,
|
|
|
|
|
$tags
|
|
|
|
|
);
|
2016-08-19 20:17:33 +00:00
|
|
|
// doDeleteArticleReal() returns a non-fatal error status if the page
|
|
|
|
|
// or revision is missing, so check for isOK() rather than isGood()
|
|
|
|
|
if ( $deleteStatus->isOK() ) {
|
2020-03-20 20:46:28 +00:00
|
|
|
$status = $file->deleteFile( $reason, $user, $suppress );
|
2016-08-19 20:17:33 +00:00
|
|
|
if ( $status->isOK() ) {
|
2017-06-12 17:19:57 +00:00
|
|
|
if ( $deleteStatus->value === null ) {
|
|
|
|
|
// No log ID from doDeleteArticleReal(), probably
|
|
|
|
|
// because the page/revision didn't exist, so create
|
|
|
|
|
// one here.
|
|
|
|
|
$logtype = $suppress ? 'suppress' : 'delete';
|
|
|
|
|
$logEntry = new ManualLogEntry( $logtype, 'delete' );
|
|
|
|
|
$logEntry->setPerformer( $user );
|
|
|
|
|
$logEntry->setTarget( clone $title );
|
|
|
|
|
$logEntry->setComment( $reason );
|
2019-07-07 22:07:56 +00:00
|
|
|
$logEntry->addTags( $tags );
|
2017-06-12 17:19:57 +00:00
|
|
|
$logid = $logEntry->insert();
|
|
|
|
|
$dbw->onTransactionPreCommitOrIdle(
|
2018-04-17 04:39:02 +00:00
|
|
|
function () use ( $logEntry, $logid ) {
|
2017-06-12 17:19:57 +00:00
|
|
|
$logEntry->publish( $logid );
|
|
|
|
|
},
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$status->value = $logid;
|
|
|
|
|
} else {
|
|
|
|
|
$status->value = $deleteStatus->value; // log id
|
|
|
|
|
}
|
2015-10-07 18:48:23 +00:00
|
|
|
$dbw->endAtomic( __METHOD__ );
|
2016-08-19 20:17:33 +00:00
|
|
|
} else {
|
|
|
|
|
// Page deleted but file still there? rollback page delete
|
2017-02-07 13:31:46 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
|
|
|
$lbFactory->rollbackMasterChanges( __METHOD__ );
|
2008-04-04 12:16:50 +00:00
|
|
|
}
|
2016-08-19 20:17:33 +00:00
|
|
|
} else {
|
|
|
|
|
$dbw->endAtomic( __METHOD__ );
|
2008-04-04 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-15 18:08:34 +00:00
|
|
|
|
2012-02-06 15:21:10 +00:00
|
|
|
if ( $status->isOK() ) {
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
Hooks::runner()->onFileDeleteComplete( $file, $oldimage, $page, $user, $reason );
|
2011-11-15 18:08:34 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-04 12:16:50 +00:00
|
|
|
return $status;
|
|
|
|
|
}
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Show the confirmation form
|
|
|
|
|
*/
|
|
|
|
|
private function showForm() {
|
2020-01-26 09:58:06 +00:00
|
|
|
global $wgOut, $wgRequest;
|
2019-08-16 18:13:56 +00:00
|
|
|
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2020-04-13 21:16:34 +00:00
|
|
|
$wgOut->addModules( 'mediawiki.action.delete' );
|
2018-02-26 18:07:11 +00:00
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
$checkWatch = $this->user->getBoolOption( 'watchdeletion' ) ||
|
|
|
|
|
$this->user->isWatched( $this->title );
|
2018-05-26 19:25:24 +00:00
|
|
|
|
|
|
|
|
$wgOut->enableOOUI();
|
|
|
|
|
|
2019-09-03 17:38:57 +00:00
|
|
|
$fields = [];
|
|
|
|
|
|
|
|
|
|
$fields[] = new OOUI\LabelWidget( [ 'label' => new OOUI\HtmlSnippet(
|
|
|
|
|
$this->prepareMessage( 'filedelete-intro' ) ) ]
|
|
|
|
|
);
|
|
|
|
|
|
2020-05-23 19:27:44 +00:00
|
|
|
$suppressAllowed = $permissionManager->userHasRight( $this->user, 'suppressrevision' );
|
|
|
|
|
$dropDownReason = $wgOut->msg( 'filedelete-reason-dropdown' )->inContentLanguage()->text();
|
|
|
|
|
// Add additional specific reasons for suppress
|
|
|
|
|
if ( $suppressAllowed ) {
|
|
|
|
|
$dropDownReason .= "\n" . $wgOut->msg( 'filedelete-reason-dropdown-suppress' )
|
|
|
|
|
->inContentLanguage()->text();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-26 19:25:24 +00:00
|
|
|
$options = Xml::listDropDownOptions(
|
2020-05-23 19:27:44 +00:00
|
|
|
$dropDownReason,
|
2018-05-26 19:25:24 +00:00
|
|
|
[ 'other' => $wgOut->msg( 'filedelete-reason-otherlist' )->inContentLanguage()->text() ]
|
|
|
|
|
);
|
|
|
|
|
$options = Xml::listDropDownOptionsOoui( $options );
|
|
|
|
|
|
|
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\DropdownInputWidget( [
|
|
|
|
|
'name' => 'wpDeleteReasonList',
|
|
|
|
|
'inputId' => 'wpDeleteReasonList',
|
|
|
|
|
'tabIndex' => 1,
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
'value' => '',
|
|
|
|
|
'options' => $options,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'label' => $wgOut->msg( 'filedelete-comment' )->text(),
|
|
|
|
|
'align' => 'top',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
|
|
|
|
|
// (e.g. emojis) count for two each. This limit is overridden in JS to instead count
|
2019-01-04 18:55:11 +00:00
|
|
|
// Unicode codepoints.
|
2018-05-26 19:25:24 +00:00
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\TextInputWidget( [
|
|
|
|
|
'name' => 'wpReason',
|
|
|
|
|
'inputId' => 'wpReason',
|
|
|
|
|
'tabIndex' => 2,
|
2019-01-04 18:55:11 +00:00
|
|
|
'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
|
2018-05-26 19:25:24 +00:00
|
|
|
'infusable' => true,
|
|
|
|
|
'value' => $wgRequest->getText( 'wpReason' ),
|
|
|
|
|
'autofocus' => true,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'label' => $wgOut->msg( 'filedelete-otherreason' )->text(),
|
|
|
|
|
'align' => 'top',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
2020-05-23 19:27:44 +00:00
|
|
|
if ( $suppressAllowed ) {
|
2018-05-26 19:25:24 +00:00
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
|
'name' => 'wpSuppress',
|
|
|
|
|
'inputId' => 'wpSuppress',
|
|
|
|
|
'tabIndex' => 3,
|
|
|
|
|
'selected' => false,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'label' => $wgOut->msg( 'revdelete-suppress' )->text(),
|
|
|
|
|
'align' => 'inline',
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
if ( $this->user->isLoggedIn() ) {
|
2018-05-26 19:25:24 +00:00
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
|
'name' => 'wpWatch',
|
|
|
|
|
'inputId' => 'wpWatch',
|
|
|
|
|
'tabIndex' => 3,
|
|
|
|
|
'selected' => $checkWatch,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'label' => $wgOut->msg( 'watchthis' )->text(),
|
|
|
|
|
'align' => 'inline',
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
]
|
|
|
|
|
);
|
2009-11-14 11:07:46 +00:00
|
|
|
}
|
2008-03-06 14:59:28 +00:00
|
|
|
|
2018-05-26 19:25:24 +00:00
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\ButtonInputWidget( [
|
|
|
|
|
'name' => 'mw-filedelete-submit',
|
|
|
|
|
'inputId' => 'mw-filedelete-submit',
|
|
|
|
|
'tabIndex' => 4,
|
|
|
|
|
'value' => $wgOut->msg( 'filedelete-submit' )->text(),
|
|
|
|
|
'label' => $wgOut->msg( 'filedelete-submit' )->text(),
|
|
|
|
|
'flags' => [ 'primary', 'destructive' ],
|
|
|
|
|
'type' => 'submit',
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'align' => 'top',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$fieldset = new OOUI\FieldsetLayout( [
|
|
|
|
|
'label' => $wgOut->msg( 'filedelete-legend' )->text(),
|
|
|
|
|
'items' => $fields,
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$form = new OOUI\FormLayout( [
|
|
|
|
|
'method' => 'post',
|
|
|
|
|
'action' => $this->getAction(),
|
|
|
|
|
'id' => 'mw-img-deleteconfirm',
|
|
|
|
|
] );
|
|
|
|
|
$form->appendContent(
|
|
|
|
|
$fieldset,
|
|
|
|
|
new OOUI\HtmlSnippet(
|
2020-01-26 09:58:06 +00:00
|
|
|
Html::hidden( 'wpEditToken', $this->user->getEditToken( $this->oldimage ) )
|
2018-05-26 19:25:24 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML(
|
|
|
|
|
new OOUI\PanelLayout( [
|
|
|
|
|
'classes' => [ 'deletepage-wrapper' ],
|
|
|
|
|
'expanded' => false,
|
|
|
|
|
'padded' => true,
|
|
|
|
|
'framed' => true,
|
|
|
|
|
'content' => $form,
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
|
2020-01-26 09:58:06 +00:00
|
|
|
if ( $permissionManager->userHasRight( $this->user, 'editinterface' ) ) {
|
2020-05-23 19:27:44 +00:00
|
|
|
$link = '';
|
2018-05-26 19:25:24 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
2020-05-23 19:27:44 +00:00
|
|
|
if ( $suppressAllowed ) {
|
|
|
|
|
$link .= $linkRenderer->makeKnownLink(
|
|
|
|
|
$wgOut->msg( 'filedelete-reason-dropdown-suppress' )->inContentLanguage()->getTitle(),
|
|
|
|
|
$wgOut->msg( 'filedelete-edit-reasonlist-suppress' )->text(),
|
|
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
|
);
|
|
|
|
|
$link .= $wgOut->msg( 'pipe-separator' )->escaped();
|
|
|
|
|
}
|
|
|
|
|
$link .= $linkRenderer->makeKnownLink(
|
2018-05-26 19:25:24 +00:00
|
|
|
$wgOut->msg( 'filedelete-reason-dropdown' )->inContentLanguage()->getTitle(),
|
2020-05-23 19:27:44 +00:00
|
|
|
$wgOut->msg( 'filedelete-edit-reasonlist' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
|
);
|
|
|
|
|
$wgOut->addHTML( '<p class="mw-filedelete-editreasons">' . $link . '</p>' );
|
|
|
|
|
}
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2007-08-27 15:55:02 +00:00
|
|
|
/**
|
|
|
|
|
* Show deletion log fragments pertaining to the current file
|
|
|
|
|
*/
|
|
|
|
|
private function showLogEntries() {
|
|
|
|
|
global $wgOut;
|
2012-06-18 22:56:55 +00:00
|
|
|
$deleteLogPage = new LogPage( 'delete' );
|
|
|
|
|
$wgOut->addHTML( '<h2>' . $deleteLogPage->getName()->escaped() . "</h2>\n" );
|
2011-09-24 17:52:53 +00:00
|
|
|
LogEventsList::showLogExtract( $wgOut, 'delete', $this->title );
|
2007-08-27 15:55:02 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Prepare a message referring to the file being deleted,
|
|
|
|
|
* showing an appropriate message depending upon whether
|
|
|
|
|
* it's a current file or an old version
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $message Message base
|
|
|
|
|
* @return string
|
2007-08-17 20:53:17 +00:00
|
|
|
*/
|
|
|
|
|
private function prepareMessage( $message ) {
|
2008-02-13 05:59:14 +00:00
|
|
|
global $wgLang;
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->oldimage ) {
|
2014-05-11 15:32:18 +00:00
|
|
|
# Message keys used:
|
|
|
|
|
# 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
|
2012-08-19 20:44:29 +00:00
|
|
|
return wfMessage(
|
2014-05-11 15:32:18 +00:00
|
|
|
"{$message}-old",
|
2011-06-22 14:59:05 +00:00
|
|
|
wfEscapeWikiText( $this->title->getText() ),
|
2007-08-20 14:35:59 +00:00
|
|
|
$wgLang->date( $this->getTimestamp(), true ),
|
|
|
|
|
$wgLang->time( $this->getTimestamp(), true ),
|
2012-08-19 20:44:29 +00:00
|
|
|
wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT ) )->parseAsBlock();
|
2007-08-17 20:53:17 +00:00
|
|
|
} else {
|
2012-08-19 20:44:29 +00:00
|
|
|
return wfMessage(
|
2007-08-17 20:53:17 +00:00
|
|
|
$message,
|
2011-06-22 14:59:05 +00:00
|
|
|
wfEscapeWikiText( $this->title->getText() )
|
2012-08-19 20:44:29 +00:00
|
|
|
)->parseAsBlock();
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Set headers, titles and other bits
|
|
|
|
|
*/
|
|
|
|
|
private function setHeaders() {
|
2011-09-23 16:15:30 +00:00
|
|
|
global $wgOut;
|
2011-10-27 20:23:16 +00:00
|
|
|
$wgOut->setPageTitle( wfMessage( 'filedelete', $this->title->getText() ) );
|
2007-08-17 20:53:17 +00:00
|
|
|
$wgOut->setRobotPolicy( 'noindex,nofollow' );
|
2011-11-08 18:01:22 +00:00
|
|
|
$wgOut->addBacklinkSubtitle( $this->title );
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Is the provided `oldimage` value valid?
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $oldimage
|
2007-08-17 20:53:17 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2013-02-03 20:05:24 +00:00
|
|
|
public static function isValidOldSpec( $oldimage ) {
|
2008-04-04 13:59:04 +00:00
|
|
|
return strlen( $oldimage ) >= 16
|
|
|
|
|
&& strpos( $oldimage, '/' ) === false
|
|
|
|
|
&& strpos( $oldimage, '\\' ) === false;
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Could we delete the file specified? If an `oldimage`
|
|
|
|
|
* value was provided, does it correspond to an
|
|
|
|
|
* existing, local, old version of this file?
|
|
|
|
|
*
|
2019-09-04 18:46:57 +00:00
|
|
|
* @param LocalFile &$file
|
|
|
|
|
* @param LocalFile &$oldfile
|
2020-05-07 19:55:06 +00:00
|
|
|
* @param string $oldimage
|
2007-08-17 20:53:17 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2013-02-03 20:05:24 +00:00
|
|
|
public static function haveDeletableFile( &$file, &$oldfile, $oldimage ) {
|
2008-04-04 13:59:04 +00:00
|
|
|
return $oldimage
|
|
|
|
|
? $oldfile && $oldfile->exists() && $oldfile->isLocal()
|
|
|
|
|
: $file && $file->exists() && $file->isLocal();
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Prepare the form action
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getAction() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$q = [];
|
2009-06-06 22:42:48 +00:00
|
|
|
$q['action'] = 'delete';
|
2009-06-07 10:34:02 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->oldimage ) {
|
2009-06-06 22:42:48 +00:00
|
|
|
$q['oldimage'] = $this->oldimage;
|
2012-09-27 19:46:22 +00:00
|
|
|
}
|
2009-06-07 10:34:02 +00:00
|
|
|
|
2013-03-27 13:36:05 +00:00
|
|
|
return $this->title->getLocalURL( $q );
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
/**
|
|
|
|
|
* Extract the timestamp of the old version
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getTimestamp() {
|
2007-08-20 14:49:07 +00:00
|
|
|
return $this->oldfile->getTimestamp();
|
2007-08-17 20:53:17 +00:00
|
|
|
}
|
2008-01-25 10:15:46 +00:00
|
|
|
}
|