2007-08-17 20:53:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
class FileDeleteForm {
|
|
|
|
|
|
|
|
|
|
private $title = null;
|
|
|
|
|
private $file = null;
|
2007-08-20 14:49:07 +00:00
|
|
|
|
|
|
|
|
private $oldfile = null;
|
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
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param File $file File we're deleting
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( $file ) {
|
|
|
|
|
$this->title = $file->getTitle();
|
|
|
|
|
$this->file = $file;
|
|
|
|
|
}
|
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() {
|
2007-08-21 03:57:54 +00:00
|
|
|
global $wgOut, $wgRequest, $wgUser;
|
2007-08-17 20:53:17 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
|
|
|
|
|
if( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2008-04-04 13:59:04 +00:00
|
|
|
$permission_errors = $this->title->getUserPermissionsErrors('delete', $wgUser);
|
|
|
|
|
if (count($permission_errors)>0) {
|
|
|
|
|
$wgOut->showPermissionsErrorPage( $permission_errors );
|
2007-08-17 20:53:17 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-10-01 19:50:25 +00:00
|
|
|
$this->oldimage = $wgRequest->getText( 'oldimage', false );
|
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
|
2008-05-25 00:31:28 +00:00
|
|
|
$suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('suppressrevision');
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-04 13:59:04 +00:00
|
|
|
if( $this->oldimage && !self::isValidOldSpec($this->oldimage) ) {
|
2007-08-17 20:53:17 +00:00
|
|
|
$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-08-20 14:49:07 +00:00
|
|
|
if( $this->oldimage )
|
|
|
|
|
$this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-04 13:59:04 +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
|
|
|
|
|
if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) {
|
2008-01-24 15:35:44 +00:00
|
|
|
$this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList' );
|
|
|
|
|
$this->DeleteReason = $wgRequest->getText( 'wpReason' );
|
|
|
|
|
$reason = $this->DeleteReasonList;
|
|
|
|
|
if ( $reason != 'other' && $this->DeleteReason != '') {
|
|
|
|
|
// Entry from drop down menu + additional comment
|
2009-01-07 22:49:54 +00:00
|
|
|
$reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason;
|
2008-01-24 15:35:44 +00:00
|
|
|
} elseif ( $reason == 'other' ) {
|
|
|
|
|
$reason = $this->DeleteReason;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-04-04 12:16:50 +00:00
|
|
|
$status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
if( !$status->isGood() )
|
|
|
|
|
$wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) );
|
|
|
|
|
if( $status->ok ) {
|
2007-12-11 16:45:28 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( '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() );
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-04-04 12:16:50 +00:00
|
|
|
public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) {
|
|
|
|
|
$article = null;
|
|
|
|
|
if( $oldimage ) {
|
|
|
|
|
$status = $file->deleteOld( $oldimage, $reason, $suppress );
|
|
|
|
|
if( $status->ok ) {
|
|
|
|
|
// Need to do a log item
|
|
|
|
|
$log = new LogPage( 'delete' );
|
|
|
|
|
$logComment = wfMsgForContent( 'deletedrevision', $oldimage );
|
|
|
|
|
if( trim( $reason ) != '' )
|
|
|
|
|
$logComment .= ": {$reason}";
|
|
|
|
|
$log->addEntry( 'delete', $title, $logComment );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$status = $file->delete( $reason, $suppress );
|
|
|
|
|
if( $status->ok ) {
|
2008-09-16 17:08:08 +00:00
|
|
|
$id = $title->getArticleID( GAID_FOR_UPDATE );
|
2008-04-04 12:16:50 +00:00
|
|
|
// Need to delete the associated article
|
2008-04-14 07:45:50 +00:00
|
|
|
$article = new Article( $title );
|
2009-01-29 01:04:00 +00:00
|
|
|
$error = '';
|
|
|
|
|
if( wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, &$error)) ) {
|
2008-12-29 18:49:50 +00:00
|
|
|
if( $article->doDeleteArticle( $reason, $suppress, $id ) ) {
|
|
|
|
|
global $wgRequest;
|
|
|
|
|
if( $wgRequest->getCheck( 'wpWatch' ) ) {
|
|
|
|
|
$article->doWatch();
|
2009-01-01 13:15:29 +00:00
|
|
|
} elseif( $title->userIsWatching() ) {
|
2008-12-29 18:49:50 +00:00
|
|
|
$article->doUnwatch();
|
|
|
|
|
}
|
2008-09-16 17:08:08 +00:00
|
|
|
wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
|
2008-12-29 18:49:50 +00:00
|
|
|
}
|
2008-04-04 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-16 12:47:44 +00:00
|
|
|
if( $status->isGood() )
|
|
|
|
|
wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
|
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() {
|
2008-10-06 16:14:50 +00:00
|
|
|
global $wgOut, $wgUser, $wgRequest;
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2008-05-25 00:31:28 +00:00
|
|
|
if( $wgUser->isAllowed( 'suppressrevision' ) ) {
|
2008-12-29 18:49:50 +00:00
|
|
|
$suppress = "<tr id=\"wpDeleteSuppressRow\">
|
2008-10-06 16:14:50 +00:00
|
|
|
<td></td>
|
|
|
|
|
<td class='mw-input'>" .
|
|
|
|
|
Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
|
|
|
|
|
'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '3' ) ) .
|
|
|
|
|
"</td>
|
|
|
|
|
</tr>";
|
2008-03-15 00:27:57 +00:00
|
|
|
} else {
|
|
|
|
|
$suppress = '';
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-29 18:49:50 +00:00
|
|
|
$checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->title->userIsWatching();
|
|
|
|
|
$form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction(),
|
|
|
|
|
'id' => 'mw-img-deleteconfirm' ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
Xml::openElement( 'fieldset' ) .
|
2008-01-29 09:17:24 +00:00
|
|
|
Xml::element( 'legend', null, wfMsg( 'filedelete-legend' ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) .
|
|
|
|
|
$this->prepareMessage( 'filedelete-intro' ) .
|
2008-10-06 16:14:50 +00:00
|
|
|
Xml::openElement( 'table', array( 'id' => 'mw-img-deleteconfirm-table' ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
"<tr>
|
2008-10-06 16:14:50 +00:00
|
|
|
<td class='mw-label'>" .
|
2008-01-29 06:10:12 +00:00
|
|
|
Xml::label( wfMsg( 'filedelete-comment' ), 'wpDeleteReasonList' ) .
|
|
|
|
|
"</td>
|
2008-10-06 16:14:50 +00:00
|
|
|
<td class='mw-input'>" .
|
2008-01-29 06:10:12 +00:00
|
|
|
Xml::listDropDown( 'wpDeleteReasonList',
|
2008-04-14 07:45:50 +00:00
|
|
|
wfMsgForContent( 'filedelete-reason-dropdown' ),
|
2008-01-29 06:10:12 +00:00
|
|
|
wfMsgForContent( 'filedelete-reason-otherlist' ), '', 'wpReasonDropDown', 1 ) .
|
|
|
|
|
"</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2008-10-06 16:14:50 +00:00
|
|
|
<td class='mw-label'>" .
|
2008-01-29 06:10:12 +00:00
|
|
|
Xml::label( wfMsg( 'filedelete-otherreason' ), 'wpReason' ) .
|
|
|
|
|
"</td>
|
2008-10-06 16:14:50 +00:00
|
|
|
<td class='mw-input'>" .
|
|
|
|
|
Xml::input( 'wpReason', 60, $wgRequest->getText( 'wpReason' ),
|
|
|
|
|
array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
"</td>
|
|
|
|
|
</tr>
|
2008-03-15 00:27:57 +00:00
|
|
|
{$suppress}
|
2008-12-29 18:49:50 +00:00
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td class='mw-input'>" .
|
|
|
|
|
Xml::checkLabel( wfMsg( 'watchthis' ),
|
|
|
|
|
'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
|
|
|
|
|
"</td>
|
|
|
|
|
</tr>
|
2008-01-29 06:10:12 +00:00
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
2008-10-06 16:14:50 +00:00
|
|
|
<td class='mw-submit'>" .
|
|
|
|
|
Xml::submitButton( wfMsg( 'filedelete-submit' ),
|
|
|
|
|
array( 'name' => 'mw-filedelete-submit', 'id' => 'mw-filedelete-submit', 'tabindex' => '4' ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
"</td>
|
|
|
|
|
</tr>" .
|
|
|
|
|
Xml::closeElement( 'table' ) .
|
|
|
|
|
Xml::closeElement( 'fieldset' ) .
|
|
|
|
|
Xml::closeElement( 'form' );
|
2007-09-13 08:51:13 +00:00
|
|
|
|
2008-03-06 14:59:28 +00:00
|
|
|
if ( $wgUser->isAllowed( 'editinterface' ) ) {
|
|
|
|
|
$skin = $wgUser->getSkin();
|
2009-06-05 07:33:57 +00:00
|
|
|
$title = Title::newFromText( 'Filedelete-reason-dropdown', NS_MEDIAWIKI );
|
2009-05-27 20:35:16 +00:00
|
|
|
$link = $skin->link(
|
|
|
|
|
$title,
|
|
|
|
|
wfMsgHtml( 'filedelete-edit-reasonlist' ),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'action' => 'edit' )
|
|
|
|
|
);
|
2008-03-06 14:59:28 +00:00
|
|
|
$form .= '<p class="mw-filedelete-editreasons">' . $link . '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $form );
|
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;
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( '<h2>' . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
|
2008-04-02 20:20:47 +00:00
|
|
|
LogEventsList::showLogExtract( $wgOut, 'delete', $this->title->getPrefixedText() );
|
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
|
|
|
|
|
*
|
|
|
|
|
* @param string $message Message base
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function prepareMessage( $message ) {
|
2008-02-13 05:59:14 +00:00
|
|
|
global $wgLang;
|
2007-08-17 20:53:17 +00:00
|
|
|
if( $this->oldimage ) {
|
2008-02-13 02:31:12 +00:00
|
|
|
$url = $this->file->getArchiveUrl( $this->oldimage );
|
2007-08-17 20:53:17 +00:00
|
|
|
return wfMsgExt(
|
2008-01-29 06:10:12 +00:00
|
|
|
"{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
|
2007-08-17 20:53:17 +00:00
|
|
|
'parse',
|
|
|
|
|
$this->title->getText(),
|
2007-08-20 14:35:59 +00:00
|
|
|
$wgLang->date( $this->getTimestamp(), true ),
|
|
|
|
|
$wgLang->time( $this->getTimestamp(), true ),
|
2008-02-13 05:59:14 +00:00
|
|
|
wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
|
2007-08-17 20:53:17 +00:00
|
|
|
} else {
|
|
|
|
|
return wfMsgExt(
|
|
|
|
|
$message,
|
|
|
|
|
'parse',
|
|
|
|
|
$this->title->getText()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
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() {
|
2007-08-22 05:35:40 +00:00
|
|
|
global $wgOut, $wgUser;
|
2007-08-17 20:53:17 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'filedelete', $this->title->getText() ) );
|
|
|
|
|
$wgOut->setRobotPolicy( 'noindex,nofollow' );
|
2007-08-22 05:35:40 +00:00
|
|
|
$wgOut->setSubtitle( wfMsg( 'filedelete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $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?
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-04-04 13:59:04 +00:00
|
|
|
public static function isValidOldSpec($oldimage) {
|
|
|
|
|
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?
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-04-04 13:59:04 +00:00
|
|
|
public static function haveDeletableFile(&$file, &$oldfile, $oldimage) {
|
|
|
|
|
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() {
|
|
|
|
|
$q = array();
|
|
|
|
|
$q[] = 'action=delete';
|
|
|
|
|
if( $this->oldimage )
|
|
|
|
|
$q[] = 'oldimage=' . urlencode( $this->oldimage );
|
|
|
|
|
return $this->title->getLocalUrl( implode( '&', $q ) );
|
|
|
|
|
}
|
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-04-14 07:45:50 +00:00
|
|
|
|
2008-01-25 10:15:46 +00:00
|
|
|
}
|