*/ class FileDeleteForm { private $title = null; private $file = null; private $oldfile = null; private $oldimage = ''; /** * Constructor * * @param File $file File we're deleting */ public function __construct( $file ) { $this->title = $file->getTitle(); $this->file = $file; } /** * Fulfil the request; shows the form or deletes the file, * pending authentication, confirmation, etc. */ public function execute() { global $wgOut, $wgRequest, $wgUser; $this->setHeaders(); if( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } elseif( !$wgUser->isLoggedIn() ) { $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); return; } elseif( !$wgUser->isAllowed( 'delete' ) ) { $wgOut->permissionRequired( 'delete' ); return; } elseif( $wgUser->isBlocked() ) { $wgOut->blockedPage(); return; } $this->oldimage = $wgRequest->getText( 'oldimage', false ); $token = $wgRequest->getText( 'wpEditToken' ); if( $this->oldimage && !$this->isValidOldSpec() ) { $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) ); return; } if( $this->oldimage ) $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage ); if( !$this->haveDeletableFile() ) { $wgOut->addHtml( $this->prepareMessage( 'filedelete-nofile' ) ); $wgOut->addReturnTo( $this->title ); return; } // Perform the deletion if appropriate if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) { $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 $reason .= ': ' . $this->DeleteReason; } elseif ( $reason == 'other' ) { $reason = $this->DeleteReason; } $article = null; if( $this->oldimage ) { $status = $this->file->deleteOld( $this->oldimage, $reason ); if( $status->ok ) { // Need to do a log item $log = new LogPage( 'delete' ); $logComment = wfMsgForContent( 'deletedrevision', $this->oldimage ); if( trim( $reason ) != '' ) $logComment .= ": {$reason}"; $log->addEntry( 'delete', $this->title, $logComment ); } } else { $status = $this->file->delete( $reason ); if( $status->ok ) { // Need to delete the associated article $article = new Article( $this->title ); $article->doDeleteArticle( $reason ); } } if( $status->isGood() ) wfRunHooks('FileDeleteComplete', array( &$this->file, &$this->oldimage, &$article, &$wgUser, &$reason)); if( !$status->isGood() ) $wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) ); if( $status->ok ) { $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->addHtml( $this->prepareMessage( 'filedelete-success' ) ); // 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; } $this->showForm(); $this->showLogEntries(); } /** * Show the confirmation form */ private function showForm() { global $wgOut, $wgUser, $wgRequest, $wgContLang; $align = $wgContLang->isRtl() ? 'left' : 'right'; $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction() ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMsg( 'filedelete-legend' ) ) . Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) . $this->prepareMessage( 'filedelete-intro' ) . Xml::openElement( 'table' ) . "
' . $link . '
'; } $wgOut->addHtml( $form ); } /** * Show deletion log fragments pertaining to the current file */ private function showLogEntries() { global $wgOut; $wgOut->addHtml( '