69 if (
$user ===
null ) {
71 'Construction of ' . __CLASS__ .
' without a $user parameter ' .
72 'was deprecated in MediaWiki 1.35',
88 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
89 $permissionErrors = $permissionManager->getPermissionErrors(
94 if ( count( $permissionErrors ) ) {
103 throw new ErrorPageError(
'filedelete-maintenance-title',
'filedelete-maintenance' );
108 $this->oldimage =
$wgRequest->getText(
'oldimage',
'' );
109 $token =
$wgRequest->getText(
'wpEditToken' );
110 # Flag to hide all contents of the archived revisions
111 $suppress =
$wgRequest->getCheck(
'wpSuppress' ) &&
112 $permissionManager->userHasRight( $this->user,
'suppressrevision' );
114 if ( $this->oldimage ) {
115 $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
116 $this->oldfile = $repoGroup->getLocalRepo()->newFromArchiveName(
122 if ( !self::haveDeletableFile( $this->file, $this->oldfile, $this->oldimage ) ) {
124 $wgOut->addReturnTo( $this->title );
129 if (
$wgRequest->wasPosted() && $this->user->matchEditToken( $token, $this->oldimage ) ) {
130 $deleteReasonList =
$wgRequest->getText(
'wpDeleteReasonList' );
131 $deleteReason =
$wgRequest->getText(
'wpReason' );
133 if ( $deleteReasonList ==
'other' ) {
134 $reason = $deleteReason;
135 } elseif ( $deleteReason !=
'' ) {
137 $reason = $deleteReasonList .
wfMessage(
'colon-separator' )
138 ->inContentLanguage()->text() . $deleteReason;
140 $reason = $deleteReasonList;
152 if ( !$status->isGood() ) {
154 $wgOut->wrapWikiTextAsInterface(
156 $status->getWikiText(
'filedeleteerror-short',
'filedeleteerror-long' )
159 if ( $status->isOK() ) {
164 $wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() );
196 if (
$user ===
null ) {
197 wfDeprecated( __METHOD__ .
' without passing a $user parameter',
'1.35' );
205 if ( $status->isOK() ) {
208 if ( trim( $reason ) !=
'' ) {
209 $logComment .=
wfMessage(
'colon-separator' )
210 ->inContentLanguage()->text() . $reason;
213 $logtype = $suppress ?
'suppress' :
'delete';
216 $logEntry->setPerformer(
$user );
217 $logEntry->setTarget(
$title );
218 $logEntry->setComment( $logComment );
219 $logEntry->addTags( $tags );
220 $logid = $logEntry->insert();
221 $logEntry->publish( $logid );
223 $status->value = $logid;
226 $status = Status::newFatal(
'cannotdelete',
229 $page = WikiPage::factory(
$title );
231 $dbw->startAtomic( __METHOD__ );
234 $deleteStatus = $page->doDeleteArticleReal(
245 if ( $deleteStatus->isOK() ) {
247 if ( $status->isOK() ) {
248 if ( $deleteStatus->value ===
null ) {
252 $logtype = $suppress ?
'suppress' :
'delete';
254 $logEntry->setPerformer(
$user );
255 $logEntry->setTarget( clone
$title );
256 $logEntry->setComment( $reason );
257 $logEntry->addTags( $tags );
258 $logid = $logEntry->insert();
259 $dbw->onTransactionPreCommitOrIdle(
260 function () use ( $logEntry, $logid ) {
261 $logEntry->publish( $logid );
265 $status->value = $logid;
267 $status->value = $deleteStatus->value;
269 $dbw->endAtomic( __METHOD__ );
272 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
273 $lbFactory->rollbackMasterChanges( __METHOD__ );
276 $dbw->endAtomic( __METHOD__ );
280 if ( $status->isOK() ) {
292 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
294 $wgOut->addModules(
'mediawiki.action.delete.file' );
296 $checkWatch = $this->user->getBoolOption(
'watchdeletion' ) ||
297 $this->user->isWatched( $this->title );
303 $fields[] =
new OOUI\LabelWidget( [
'label' =>
new OOUI\HtmlSnippet(
307 $suppressAllowed = $permissionManager->userHasRight( $this->user,
'suppressrevision' );
308 $dropDownReason =
$wgOut->msg(
'filedelete-reason-dropdown' )->inContentLanguage()->text();
310 if ( $suppressAllowed ) {
311 $dropDownReason .=
"\n" .
$wgOut->msg(
'filedelete-reason-dropdown-suppress' )
312 ->inContentLanguage()->text();
315 $options = Xml::listDropDownOptions(
317 [
'other' =>
$wgOut->msg(
'filedelete-reason-otherlist' )->inContentLanguage()->text() ]
319 $options = Xml::listDropDownOptionsOoui( $options );
321 $fields[] =
new OOUI\FieldLayout(
322 new OOUI\DropdownInputWidget( [
323 'name' =>
'wpDeleteReasonList',
324 'inputId' =>
'wpDeleteReasonList',
328 'options' => $options,
331 'label' =>
$wgOut->msg(
'filedelete-comment' )->text(),
339 $fields[] =
new OOUI\FieldLayout(
340 new OOUI\TextInputWidget( [
341 'name' =>
'wpReason',
342 'inputId' =>
'wpReason',
344 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
350 'label' =>
$wgOut->msg(
'filedelete-otherreason' )->text(),
355 if ( $suppressAllowed ) {
356 $fields[] =
new OOUI\FieldLayout(
357 new OOUI\CheckboxInputWidget( [
358 'name' =>
'wpSuppress',
359 'inputId' =>
'wpSuppress',
364 'label' =>
$wgOut->msg(
'revdelete-suppress' )->text(),
371 if ( $this->user->isLoggedIn() ) {
372 $fields[] =
new OOUI\FieldLayout(
373 new OOUI\CheckboxInputWidget( [
375 'inputId' =>
'wpWatch',
377 'selected' => $checkWatch,
380 'label' =>
$wgOut->msg(
'watchthis' )->text(),
387 $fields[] =
new OOUI\FieldLayout(
388 new OOUI\ButtonInputWidget( [
389 'name' =>
'mw-filedelete-submit',
390 'inputId' =>
'mw-filedelete-submit',
392 'value' =>
$wgOut->msg(
'filedelete-submit' )->text(),
393 'label' =>
$wgOut->msg(
'filedelete-submit' )->text(),
394 'flags' => [
'primary',
'destructive' ],
402 $fieldset =
new OOUI\FieldsetLayout( [
403 'label' =>
$wgOut->msg(
'filedelete-legend' )->text(),
407 $form =
new OOUI\FormLayout( [
410 'id' =>
'mw-img-deleteconfirm',
412 $form->appendContent(
414 new OOUI\HtmlSnippet(
415 Html::hidden(
'wpEditToken', $this->user->getEditToken( $this->oldimage ) )
420 new OOUI\PanelLayout( [
421 'classes' => [
'deletepage-wrapper' ],
429 if ( $permissionManager->userHasRight( $this->user,
'editinterface' ) ) {
431 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
432 if ( $suppressAllowed ) {
433 $link .= $linkRenderer->makeKnownLink(
434 $wgOut->msg(
'filedelete-reason-dropdown-suppress' )->inContentLanguage()->getTitle(),
435 $wgOut->msg(
'filedelete-edit-reasonlist-suppress' )->text(),
437 [
'action' =>
'edit' ]
439 $link .=
$wgOut->msg(
'pipe-separator' )->escaped();
441 $link .= $linkRenderer->makeKnownLink(
442 $wgOut->msg(
'filedelete-reason-dropdown' )->inContentLanguage()->getTitle(),
443 $wgOut->msg(
'filedelete-edit-reasonlist' )->text(),
445 [
'action' =>
'edit' ]
447 $wgOut->addHTML(
'<p class="mw-filedelete-editreasons">' . $link .
'</p>' );
456 $deleteLogPage =
new LogPage(
'delete' );
457 $wgOut->addHTML(
'<h2>' . $deleteLogPage->getName()->escaped() .
"</h2>\n" );
458 LogEventsList::showLogExtract(
$wgOut,
'delete', $this->title );
471 if ( $this->oldimage ) {
473 # 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
477 $wgLang->date( $this->getTimestamp(),
true ),
478 $wgLang->time( $this->getTimestamp(),
true ),
493 $wgOut->setPageTitle(
wfMessage(
'filedelete', $this->title->getText() ) );
494 $wgOut->setRobotPolicy(
'noindex,nofollow' );
495 $wgOut->addBacklinkSubtitle( $this->title );
533 $q[
'action'] =
'delete';
535 if ( $this->oldimage ) {
539 return $this->title->getLocalURL( $q );
548 return $this->oldfile->getTimestamp();
$wgUploadMaintenance
To disable file delete/restore temporarily.
wfReadOnly()
Check whether the wiki is in read-only mode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
if(! $wgDBerrorLogTZ) $wgRequest
An error page which can definitely be safely rendered using the OutputPage.
isLocal()
Returns true if the file comes from the local file repository.
getTitle()
Return the associated title object.
Class to represent a local file in the wiki's own database.
exists()
canRender inherited
deleteFile( $reason, User $user, $suppress=false)
Delete all versions of the file.
deleteOldFile( $archiveName, $reason, User $user, $suppress=false)
Delete an old version of the file.
Class to simplify the use of log pages.
Class for creating new log entries and inserting them into the database.
Show an error when a user tries to do something they do not have the necessary permissions for.
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Represents a title within MediaWiki.
getPrefixedText()
Get the prefixed title with spaces.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static doWatchOrUnwatch( $watch, Title $title, User $user, string $expiry=null)
Watch or unwatch a page.