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 {
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var File
|
|
|
|
|
*/
|
2007-08-17 20:53:17 +00:00
|
|
|
private $file = null;
|
2007-08-20 14:49:07 +00:00
|
|
|
|
2011-10-29 01:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* @var File
|
|
|
|
|
*/
|
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
|
|
|
|
|
*
|
2010-01-13 21:25:03 +00:00
|
|
|
* @param $file File object we're deleting
|
2007-08-17 20:53:17 +00:00
|
|
|
*/
|
|
|
|
|
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() {
|
2011-11-15 18:08:34 +00:00
|
|
|
global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance;
|
2007-08-17 20:53:17 +00:00
|
|
|
|
2011-11-02 15:30:55 +00:00
|
|
|
$permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser );
|
|
|
|
|
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();
|
|
|
|
|
|
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
|
|
|
|
2011-09-23 16:15:30 +00:00
|
|
|
if( $this->oldimage ) {
|
2007-08-20 14:49:07 +00:00
|
|
|
$this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage );
|
2011-09-23 16:15:30 +00:00
|
|
|
}
|
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 ) ) {
|
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
|
2011-11-03 08:55:04 +00:00
|
|
|
$reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
|
|
|
|
|
} else {
|
|
|
|
|
$reason = $deleteReasonList;
|
2008-01-24 15:35:44 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-11-15 18:08:34 +00:00
|
|
|
$status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-08-19 23:30:12 +00:00
|
|
|
if( !$status->isGood() ) {
|
|
|
|
|
$wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
|
2012-03-17 21:19:31 +00:00
|
|
|
$wgOut->addWikiText( '<div class="error">' . $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) . '</div>' );
|
2011-08-19 23:30:12 +00:00
|
|
|
}
|
2007-08-17 20:53:17 +00:00
|
|
|
if( $status->ok ) {
|
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
|
|
|
|
|
|
|
|
if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
|
2011-12-31 08:29:22 +00:00
|
|
|
WatchAction::doWatch( $this->title, $wgUser );
|
2011-11-15 18:08:34 +00:00
|
|
|
} elseif ( $this->title->userIsWatching() ) {
|
2011-12-31 08:29:22 +00:00
|
|
|
WatchAction::doUnwatch( $this->title, $wgUser );
|
2011-11-15 18:08:34 +00:00
|
|
|
}
|
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
|
|
|
|
|
*
|
|
|
|
|
* @param $title Title object
|
2012-02-06 15:21:10 +00:00
|
|
|
* @param File $file: file object
|
2010-01-13 21:25:03 +00:00
|
|
|
* @param $oldimage String: archive name
|
|
|
|
|
* @param $reason String: reason of the deletion
|
|
|
|
|
* @param $suppress Boolean: whether to mark all deleted versions as restricted
|
2011-11-15 18:08:34 +00:00
|
|
|
* @param $user User object performing the request
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool|Status
|
2010-01-13 21:25:03 +00:00
|
|
|
*/
|
2011-11-15 18:08:34 +00:00
|
|
|
public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress, User $user = null ) {
|
|
|
|
|
if ( $user === null ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$user = $wgUser;
|
|
|
|
|
}
|
2010-02-26 20:14:28 +00:00
|
|
|
|
2008-04-04 12:16:50 +00:00
|
|
|
if( $oldimage ) {
|
2011-11-15 18:08:34 +00:00
|
|
|
$page = null;
|
2008-04-04 12:16:50 +00:00
|
|
|
$status = $file->deleteOld( $oldimage, $reason, $suppress );
|
|
|
|
|
if( $status->ok ) {
|
|
|
|
|
// Need to do a log item
|
|
|
|
|
$log = new LogPage( 'delete' );
|
2009-11-02 17:12:37 +00:00
|
|
|
$logComment = wfMsgForContent( 'deletedrevision', $oldimage );
|
2010-08-29 19:11:23 +00:00
|
|
|
if( trim( $reason ) != '' ) {
|
2009-11-02 19:06:16 +00:00
|
|
|
$logComment .= wfMsgForContent( 'colon-separator' ) . $reason;
|
2010-08-29 19:11:23 +00:00
|
|
|
}
|
|
|
|
|
$log->addEntry( 'delete', $title, $logComment );
|
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 );
|
|
|
|
|
try {
|
2011-03-23 21:54:59 +00:00
|
|
|
// delete the associated article first
|
2011-11-15 18:08:34 +00:00
|
|
|
$error = '';
|
2012-02-07 09:40:08 +00:00
|
|
|
if ( $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user ) >= WikiPage::DELETE_SUCCESS ) {
|
2011-03-23 21:54:59 +00:00
|
|
|
$status = $file->delete( $reason, $suppress );
|
2012-02-06 15:21:10 +00:00
|
|
|
if( $status->isOK() ) {
|
2012-02-24 17:00:52 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2011-03-23 21:54:59 +00:00
|
|
|
} else {
|
2012-02-24 17:00:52 +00:00
|
|
|
$dbw->rollback( __METHOD__ );
|
2008-12-29 18:49:50 +00:00
|
|
|
}
|
2008-04-04 12:16:50 +00:00
|
|
|
}
|
2010-02-26 20:14:28 +00:00
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
// rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"
|
2012-02-24 17:00:52 +00:00
|
|
|
$dbw->rollback( __METHOD__ );
|
2010-02-26 20:14:28 +00:00
|
|
|
throw $e;
|
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() ) {
|
2011-11-15 18:08:34 +00:00
|
|
|
wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$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>
|
2009-10-15 10:36:29 +00:00
|
|
|
<td class='mw-input'><strong>" .
|
2008-10-06 16:14:50 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
|
|
|
|
|
'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '3' ) ) .
|
2009-10-15 10:36:29 +00:00
|
|
|
"</strong></td>
|
2008-10-06 16:14:50 +00:00
|
|
|
</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' ) ) .
|
2011-11-16 04:37:17 +00:00
|
|
|
Html::hidden( 'wpEditToken', $wgUser->getEditToken( $this->oldimage ) ) .
|
2008-01-29 06:10:12 +00:00
|
|
|
$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>
|
2009-11-14 11:07:46 +00:00
|
|
|
{$suppress}";
|
2011-08-19 23:30:12 +00:00
|
|
|
if( $wgUser->isLoggedIn() ) {
|
2009-11-14 11:07:46 +00:00
|
|
|
$form .= "
|
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>
|
2009-11-14 11:07:46 +00:00
|
|
|
</tr>";
|
|
|
|
|
}
|
|
|
|
|
$form .= "
|
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' ) ) {
|
2009-06-05 13:12:15 +00:00
|
|
|
$title = Title::makeTitle( NS_MEDIAWIKI, 'Filedelete-reason-dropdown' );
|
2011-09-23 16:15:30 +00:00
|
|
|
$link = Linker::link(
|
2009-05-27 20:35:16 +00:00
|
|
|
$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;
|
2011-12-13 21:34:16 +00:00
|
|
|
$wgOut->addHTML( '<h2>' . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</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
|
|
|
|
|
*
|
2010-01-13 21:25:03 +00:00
|
|
|
* @param $message String: 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;
|
2007-08-17 20:53:17 +00:00
|
|
|
if( $this->oldimage ) {
|
|
|
|
|
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',
|
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 ),
|
2011-08-19 15:46:08 +00:00
|
|
|
wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT ) );
|
2007-08-17 20:53:17 +00:00
|
|
|
} else {
|
|
|
|
|
return wfMsgExt(
|
|
|
|
|
$message,
|
|
|
|
|
'parse',
|
2011-06-22 14:59:05 +00:00
|
|
|
wfEscapeWikiText( $this->title->getText() )
|
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?
|
|
|
|
|
*
|
|
|
|
|
* @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?
|
|
|
|
|
*
|
2011-10-29 01:53:28 +00:00
|
|
|
* @param $file File
|
|
|
|
|
* @param $oldfile File
|
|
|
|
|
* @param $oldimage File
|
2007-08-17 20:53:17 +00:00
|
|
|
* @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() {
|
2009-06-07 10:34:02 +00:00
|
|
|
$q = array();
|
2009-06-06 22:42:48 +00:00
|
|
|
$q['action'] = 'delete';
|
2009-06-07 10:34:02 +00:00
|
|
|
|
2007-08-17 20:53:17 +00:00
|
|
|
if( $this->oldimage )
|
2009-06-06 22:42:48 +00:00
|
|
|
$q['oldimage'] = $this->oldimage;
|
2009-06-07 10:34:02 +00:00
|
|
|
|
2009-06-06 22:42:48 +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
|
|
|
}
|