diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2008-08-15 01:29:47 +0200 |
commit | 370e83bb0dfd0c70de268c93bf07ad5ee0897192 (patch) | |
tree | 491674f4c242e4d6ba0d04eafa305174c35a3391 /includes/FileRevertForm.php | |
parent | f4debf0f12d0524d2b2427c55ea3f16b680fad97 (diff) |
Update auf 1.13.0
Diffstat (limited to 'includes/FileRevertForm.php')
-rw-r--r-- | includes/FileRevertForm.php | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/includes/FileRevertForm.php b/includes/FileRevertForm.php index f335d024..385d83bc 100644 --- a/includes/FileRevertForm.php +++ b/includes/FileRevertForm.php @@ -3,16 +3,17 @@ /** * File reversion user interface * - * @addtogroup Media + * @ingroup Media * @author Rob Church <robchur@gmail.com> */ class FileRevertForm { - private $title = null; - private $file = null; - private $oldimage = ''; - private $timestamp = false; - + protected $title = null; + protected $file = null; + protected $archiveName = ''; + protected $timestamp = false; + protected $oldFile; + /** * Constructor * @@ -22,7 +23,7 @@ class FileRevertForm { $this->title = $file->getTitle(); $this->file = $file; } - + /** * Fulfil the request; shows the form or reverts the file, * pending authentication, confirmation, etc. @@ -37,7 +38,7 @@ class FileRevertForm { } elseif( !$wgUser->isLoggedIn() ) { $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); return; - } elseif( !$this->title->userCan( 'edit' ) ) { + } elseif( !$this->title->userCan( 'edit' ) || !$this->title->userCan( 'upload' ) ) { // The standard read-only thing doesn't make a whole lot of sense // here; surely it should show the image or something? -- RC $article = new Article( $this->title ); @@ -47,23 +48,23 @@ class FileRevertForm { $wgOut->blockedPage(); return; } - - $this->oldimage = $wgRequest->getText( 'oldimage' ); + + $this->archiveName = $wgRequest->getText( 'oldimage' ); $token = $wgRequest->getText( 'wpEditToken' ); if( !$this->isValidOldSpec() ) { - $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) ); + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->archiveName ) ); return; } - + if( !$this->haveOldVersion() ) { $wgOut->addHtml( wfMsgExt( 'filerevert-badversion', 'parse' ) ); $wgOut->returnToMain( false, $this->title ); return; } - + // Perform the reversion if appropriate - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) { - $source = $this->file->getArchiveVirtualUrl( $this->oldimage ); + if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->archiveName ) ) { + $source = $this->file->getArchiveVirtualUrl( $this->archiveName ); $comment = $wgRequest->getText( 'wpComment' ); // TODO: Preserve file properties from database instead of reloading from file $status = $this->file->upload( $source, $comment, $comment ); @@ -71,96 +72,100 @@ class FileRevertForm { $wgOut->addHtml( wfMsgExt( 'filerevert-success', 'parse', $this->title->getText(), $wgLang->date( $this->getTimestamp(), true ), $wgLang->time( $this->getTimestamp(), true ), - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ) ); + wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ) ); $wgOut->returnToMain( false, $this->title ); } else { $wgOut->addWikiText( $status->getWikiText() ); } return; } - + // Show the form - $this->showForm(); + $this->showForm(); } - + /** * Show the confirmation form */ - private function showForm() { + protected function showForm() { global $wgOut, $wgUser, $wgRequest, $wgLang, $wgContLang; $timestamp = $this->getTimestamp(); $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction() ) ); - $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ); + $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->archiveName ) ); $form .= '<fieldset><legend>' . wfMsgHtml( 'filerevert-legend' ) . '</legend>'; $form .= wfMsgExt( 'filerevert-intro', 'parse', $this->title->getText(), $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ), - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ); + wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ); $form .= '<p>' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment', 60, wfMsgForContent( 'filerevert-defaultcomment', $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '</p>'; $form .= '<p>' . Xml::submitButton( wfMsg( 'filerevert-submit' ) ) . '</p>'; $form .= '</fieldset>'; $form .= '</form>'; - + $wgOut->addHtml( $form ); } - + /** * Set headers, titles and other bits */ - private function setHeaders() { + protected function setHeaders() { global $wgOut, $wgUser; $wgOut->setPageTitle( wfMsg( 'filerevert', $this->title->getText() ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setSubtitle( wfMsg( 'filerevert-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->title ) ) ); } - + /** * Is the provided `oldimage` value valid? * * @return bool */ - private function isValidOldSpec() { - return strlen( $this->oldimage ) >= 16 - && strpos( $this->oldimage, '/' ) === false - && strpos( $this->oldimage, '\\' ) === false; + protected function isValidOldSpec() { + return strlen( $this->archiveName ) >= 16 + && strpos( $this->archiveName, '/' ) === false + && strpos( $this->archiveName, '\\' ) === false; } - + /** * Does the provided `oldimage` value correspond * to an existing, local, old version of this file? * * @return bool */ - private function haveOldVersion() { - $file = wfFindFile( $this->title, $this->oldimage ); - return $file && $file->exists() && $file->isLocal(); + protected function haveOldVersion() { + return $this->getOldFile()->exists(); } - + /** * Prepare the form action * * @return string */ - private function getAction() { + protected function getAction() { $q = array(); $q[] = 'action=revert'; - $q[] = 'oldimage=' . urlencode( $this->oldimage ); + $q[] = 'oldimage=' . urlencode( $this->archiveName ); return $this->title->getLocalUrl( implode( '&', $q ) ); } - + /** * Extract the timestamp of the old version * * @return string */ - private function getTimestamp() { + protected function getTimestamp() { if( $this->timestamp === false ) { - $file = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage ); - $this->timestamp = $file->getTimestamp(); + $this->timestamp = $this->getOldFile()->getTimestamp(); } return $this->timestamp; } - -}
\ No newline at end of file + + protected function getOldFile() { + if ( !isset( $this->oldFile ) ) { + $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->archiveName ); + } + return $this->oldFile; + } +} |