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 {
|
|
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
/** @var Title */
|
2021-03-26 15:00:08 +00:00
|
|
|
private $title;
|
2011-10-29 01:53:28 +00:00
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
/** @var LocalFile */
|
2021-03-26 15:00:08 +00:00
|
|
|
private $file;
|
2007-08-20 14:49:07 +00:00
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
/** @var User */
|
2021-03-26 15:00:08 +00:00
|
|
|
private $user;
|
2020-01-26 09:58:06 +00:00
|
|
|
|
2021-03-27 02:21:32 +00:00
|
|
|
/** @var OutputPage */
|
|
|
|
|
private $out;
|
|
|
|
|
|
2021-03-26 15:00:08 +00:00
|
|
|
/** @var LocalFile|null */
|
2007-08-20 14:49:07 +00:00
|
|
|
private $oldfile = null;
|
2020-05-07 19:55:06 +00:00
|
|
|
|
2020-07-06 07:33:22 +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
|
|
|
/**
|
2019-09-04 18:46:57 +00:00
|
|
|
* @param LocalFile $file File object we're deleting
|
2020-08-26 23:48:39 +00:00
|
|
|
* @param User $user
|
2020-07-06 07:33:22 +00:00
|
|
|
* @param OutputPage $out
|
2007-08-17 20:53:17 +00:00
|
|
|
*/
|
2021-03-27 02:21:32 +00:00
|
|
|
public function __construct( LocalFile $file, User $user, OutputPage $out ) {
|
2007-08-17 20:53:17 +00:00
|
|
|
$this->title = $file->getTitle();
|
|
|
|
|
$this->file = $file;
|
2020-01-26 09:58:06 +00:00
|
|
|
$this->user = $user;
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out = $out;
|
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
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-27 03:43:40 +00:00
|
|
|
if ( $this->out->getConfig()->get( 'UploadMaintenance' ) ) {
|
2011-11-15 18:08:34 +00:00
|
|
|
throw new ErrorPageError( 'filedelete-maintenance-title', 'filedelete-maintenance' );
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-02 15:30:55 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
|
2021-03-27 03:43:40 +00:00
|
|
|
$request = $this->out->getRequest();
|
|
|
|
|
$this->oldimage = $request->getText( 'oldimage', '' );
|
|
|
|
|
$token = $request->getText( 'wpEditToken' );
|
2008-03-15 00:27:57 +00:00
|
|
|
# Flag to hide all contents of the archived revisions
|
2021-03-27 03:43:40 +00:00
|
|
|
$suppress = $request->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 ) ) {
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addHTML( $this->prepareMessage( 'filedelete-nofile' ) );
|
|
|
|
|
$this->out->addReturnTo( $this->title );
|
2007-08-17 20:53:17 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
// Perform the deletion if appropriate
|
2021-03-27 03:43:40 +00:00
|
|
|
if ( $request->wasPosted() && $this->user->matchEditToken( $token, $this->oldimage ) ) {
|
|
|
|
|
$deleteReasonList = $request->getText( 'wpDeleteReasonList' );
|
|
|
|
|
$deleteReason = $request->getText( 'wpReason' );
|
2011-11-03 08:55:04 +00:00
|
|
|
|
|
|
|
|
if ( $deleteReasonList == 'other' ) {
|
|
|
|
|
$reason = $deleteReason;
|
|
|
|
|
} elseif ( $deleteReason != '' ) {
|
2008-01-24 15:35:44 +00:00
|
|
|
// Entry from drop down menu + additional comment
|
2021-03-27 03:43:40 +00:00
|
|
|
$reason = $deleteReasonList . $this->out->msg( 'colon-separator' )
|
2012-08-19 20:44:29 +00:00
|
|
|
->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() ) {
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
|
|
|
|
|
$this->out->wrapWikiTextAsInterface(
|
2018-10-17 14:28:05 +00:00
|
|
|
'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() ) {
|
2021-03-27 03:43:40 +00:00
|
|
|
$this->out->setPageTitle( $this->out->msg( 'actioncomplete' ) );
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->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
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->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(
|
2021-03-27 03:43:40 +00:00
|
|
|
$request->getCheck( 'wpWatch' ),
|
2020-01-26 09:58:06 +00:00
|
|
|
$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-09-09 23:47:28 +00:00
|
|
|
* @param User $user
|
2020-11-20 13:12:54 +00:00
|
|
|
* @param string[] $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,
|
2020-09-09 23:47:28 +00:00
|
|
|
$suppress, User $user, $tags = []
|
2021-03-27 02:21:32 +00:00
|
|
|
) : Status {
|
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() )
|
|
|
|
|
);
|
2020-11-11 21:43:18 +00:00
|
|
|
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
|
|
|
|
|
'@phan-var WikiFilePage $page';
|
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(
|
2021-02-10 22:31:02 +00:00
|
|
|
static 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() {
|
2021-03-16 21:43:21 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$permissionManager = $services->getPermissionManager();
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addModules( 'mediawiki.action.delete' );
|
2018-02-26 18:07:11 +00:00
|
|
|
|
2021-03-16 21:43:21 +00:00
|
|
|
$checkWatch = $services->getUserOptionsLookup()
|
|
|
|
|
->getBoolOption( $this->user, 'watchdeletion' ) || $this->user->isWatched( $this->title );
|
2018-05-26 19:25:24 +00:00
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->enableOOUI();
|
2018-05-26 19:25:24 +00:00
|
|
|
|
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' );
|
2020-07-06 07:33:22 +00:00
|
|
|
$dropDownReason = $this->out->msg( 'filedelete-reason-dropdown' )->inContentLanguage()->text();
|
2020-05-23 19:27:44 +00:00
|
|
|
// Add additional specific reasons for suppress
|
|
|
|
|
if ( $suppressAllowed ) {
|
2020-07-06 07:33:22 +00:00
|
|
|
$dropDownReason .= "\n" . $this->out->msg( 'filedelete-reason-dropdown-suppress' )
|
2020-05-23 19:27:44 +00:00
|
|
|
->inContentLanguage()->text();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-26 19:25:24 +00:00
|
|
|
$options = Xml::listDropDownOptions(
|
2020-05-23 19:27:44 +00:00
|
|
|
$dropDownReason,
|
2020-07-06 07:33:22 +00:00
|
|
|
[ 'other' => $this->out->msg( 'filedelete-reason-otherlist' )->inContentLanguage()->text() ]
|
2018-05-26 19:25:24 +00:00
|
|
|
);
|
|
|
|
|
$options = Xml::listDropDownOptionsOoui( $options );
|
|
|
|
|
|
|
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\DropdownInputWidget( [
|
|
|
|
|
'name' => 'wpDeleteReasonList',
|
|
|
|
|
'inputId' => 'wpDeleteReasonList',
|
|
|
|
|
'tabIndex' => 1,
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
'value' => '',
|
|
|
|
|
'options' => $options,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
2020-07-06 07:33:22 +00:00
|
|
|
'label' => $this->out->msg( 'filedelete-comment' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'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,
|
2021-03-27 03:43:40 +00:00
|
|
|
'value' => $this->out->getRequest()->getText( 'wpReason' ),
|
2018-05-26 19:25:24 +00:00
|
|
|
'autofocus' => true,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
2020-07-06 07:33:22 +00:00
|
|
|
'label' => $this->out->msg( 'filedelete-otherreason' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'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,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
2020-07-06 07:33:22 +00:00
|
|
|
'label' => $this->out->msg( 'revdelete-suppress' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'align' => 'inline',
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 23:10:11 +00:00
|
|
|
if ( $this->user->isRegistered() ) {
|
2018-05-26 19:25:24 +00:00
|
|
|
$fields[] = new OOUI\FieldLayout(
|
|
|
|
|
new OOUI\CheckboxInputWidget( [
|
|
|
|
|
'name' => 'wpWatch',
|
|
|
|
|
'inputId' => 'wpWatch',
|
|
|
|
|
'tabIndex' => 3,
|
|
|
|
|
'selected' => $checkWatch,
|
|
|
|
|
] ),
|
|
|
|
|
[
|
2020-07-06 07:33:22 +00:00
|
|
|
'label' => $this->out->msg( 'watchthis' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'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,
|
2020-07-06 07:33:22 +00:00
|
|
|
'value' => $this->out->msg( 'filedelete-submit' )->text(),
|
|
|
|
|
'label' => $this->out->msg( 'filedelete-submit' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'flags' => [ 'primary', 'destructive' ],
|
|
|
|
|
'type' => 'submit',
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'align' => 'top',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$fieldset = new OOUI\FieldsetLayout( [
|
2020-07-06 07:33:22 +00:00
|
|
|
'label' => $this->out->msg( 'filedelete-legend' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
'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
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addHTML(
|
2018-05-26 19:25:24 +00:00
|
|
|
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(
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->msg( 'filedelete-reason-dropdown-suppress' )->inContentLanguage()->getTitle(),
|
|
|
|
|
$this->out->msg( 'filedelete-edit-reasonlist-suppress' )->text(),
|
2020-05-23 19:27:44 +00:00
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
|
);
|
2020-07-06 07:33:22 +00:00
|
|
|
$link .= $this->out->msg( 'pipe-separator' )->escaped();
|
2020-05-23 19:27:44 +00:00
|
|
|
}
|
|
|
|
|
$link .= $linkRenderer->makeKnownLink(
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->msg( 'filedelete-reason-dropdown' )->inContentLanguage()->getTitle(),
|
|
|
|
|
$this->out->msg( 'filedelete-edit-reasonlist' )->text(),
|
2018-05-26 19:25:24 +00:00
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
|
|
|
|
);
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addHTML( '<p class="mw-filedelete-editreasons">' . $link . '</p>' );
|
2018-05-26 19:25:24 +00:00
|
|
|
}
|
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() {
|
2012-06-18 22:56:55 +00:00
|
|
|
$deleteLogPage = new LogPage( 'delete' );
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->addHTML( '<h2>' . $deleteLogPage->getName()->escaped() . "</h2>\n" );
|
|
|
|
|
|
|
|
|
|
// False positive. First paramater is assigned to a string if not an instance of
|
|
|
|
|
// OutputPage, since $this->out is an OutputPage this does not occur
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchPropertyByRef
|
|
|
|
|
LogEventsList::showLogExtract( $this->out, '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
|
|
|
*/
|
2021-03-27 02:21:32 +00:00
|
|
|
private function prepareMessage( string $message ) {
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->oldimage ) {
|
2021-03-26 15:00:08 +00:00
|
|
|
$lang = $this->out->getLanguage();
|
2014-05-11 15:32:18 +00:00
|
|
|
# Message keys used:
|
|
|
|
|
# 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
|
2021-03-27 03:43:40 +00:00
|
|
|
return $this->out->msg(
|
2014-05-11 15:32:18 +00:00
|
|
|
"{$message}-old",
|
2011-06-22 14:59:05 +00:00
|
|
|
wfEscapeWikiText( $this->title->getText() ),
|
2021-03-26 15:00:08 +00:00
|
|
|
$lang->date( $this->getTimestamp(), true ),
|
|
|
|
|
$lang->time( $this->getTimestamp(), true ),
|
2021-03-27 03:43:40 +00:00
|
|
|
wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT )
|
|
|
|
|
)->parseAsBlock();
|
2007-08-17 20:53:17 +00:00
|
|
|
} else {
|
2021-03-27 03:43:40 +00:00
|
|
|
return $this->out->msg(
|
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() {
|
2021-03-27 03:43:40 +00:00
|
|
|
$this->out->setPageTitle( $this->out->msg( 'filedelete', $this->title->getText() ) );
|
2020-07-06 07:33:22 +00:00
|
|
|
$this->out->setRobotPolicy( 'noindex,nofollow' );
|
|
|
|
|
$this->out->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
|
|
|
}
|