r33001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r33000‎ | r33001 | r33002 >
Date:00:26, 9 April 2008
Author:brion
Status:old
Tags:
Comment:
* (bug 13532) Use proper timestamp call when reverting images
backport r32817 from trunk
Modified paths:
  • /branches/REL1_12/phase3/RELEASE-NOTES (modified) (history)
  • /branches/REL1_12/phase3/includes/FileRevertForm.php (modified) (history)
  • /branches/REL1_12/phase3/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: branches/REL1_12/phase3/includes/FileRevertForm.php
@@ -8,10 +8,11 @@
99 */
1010 class FileRevertForm {
1111
12 - private $title = null;
13 - private $file = null;
14 - private $oldimage = '';
15 - private $timestamp = false;
 12+ protected $title = null;
 13+ protected $file = null;
 14+ protected $archiveName = '';
 15+ protected $timestamp = false;
 16+ protected $oldFile;
1617
1718 /**
1819 * Constructor
@@ -48,10 +49,10 @@
4950 return;
5051 }
5152
52 - $this->oldimage = $wgRequest->getText( 'oldimage' );
 53+ $this->archiveName = $wgRequest->getText( 'oldimage' );
5354 $token = $wgRequest->getText( 'wpEditToken' );
5455 if( !$this->isValidOldSpec() ) {
55 - $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) );
 56+ $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->archiveName ) );
5657 return;
5758 }
5859
@@ -62,8 +63,8 @@
6364 }
6465
6566 // Perform the reversion if appropriate
66 - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) {
67 - $source = $this->file->getArchiveVirtualUrl( $this->oldimage );
 67+ if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->archiveName ) ) {
 68+ $source = $this->file->getArchiveVirtualUrl( $this->archiveName );
6869 $comment = $wgRequest->getText( 'wpComment' );
6970 // TODO: Preserve file properties from database instead of reloading from file
7071 $status = $this->file->upload( $source, $comment, $comment );
@@ -71,7 +72,7 @@
7273 $wgOut->addHtml( wfMsgExt( 'filerevert-success', 'parse', $this->title->getText(),
7374 $wgLang->date( $this->getTimestamp(), true ),
7475 $wgLang->time( $this->getTimestamp(), true ),
75 - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ) );
 76+ wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ) );
7677 $wgOut->returnToMain( false, $this->title );
7778 } else {
7879 $wgOut->addWikiText( $status->getWikiText() );
@@ -86,16 +87,16 @@
8788 /**
8889 * Show the confirmation form
8990 */
90 - private function showForm() {
 91+ protected function showForm() {
9192 global $wgOut, $wgUser, $wgRequest, $wgLang, $wgContLang;
9293 $timestamp = $this->getTimestamp();
9394
9495 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction() ) );
95 - $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) );
 96+ $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->archiveName ) );
9697 $form .= '<fieldset><legend>' . wfMsgHtml( 'filerevert-legend' ) . '</legend>';
9798 $form .= wfMsgExt( 'filerevert-intro', 'parse', $this->title->getText(),
9899 $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ),
99 - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
 100+ wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) );
100101 $form .= '<p>' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment',
101102 60, wfMsgForContent( 'filerevert-defaultcomment',
102103 $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '</p>';
@@ -109,7 +110,7 @@
110111 /**
111112 * Set headers, titles and other bits
112113 */
113 - private function setHeaders() {
 114+ protected function setHeaders() {
114115 global $wgOut, $wgUser;
115116 $wgOut->setPageTitle( wfMsg( 'filerevert', $this->title->getText() ) );
116117 $wgOut->setRobotPolicy( 'noindex,nofollow' );
@@ -121,10 +122,10 @@
122123 *
123124 * @return bool
124125 */
125 - private function isValidOldSpec() {
126 - return strlen( $this->oldimage ) >= 16
127 - && strpos( $this->oldimage, '/' ) === false
128 - && strpos( $this->oldimage, '\\' ) === false;
 126+ protected function isValidOldSpec() {
 127+ return strlen( $this->archiveName ) >= 16
 128+ && strpos( $this->archiveName, '/' ) === false
 129+ && strpos( $this->archiveName, '\\' ) === false;
129130 }
130131
131132 /**
@@ -133,9 +134,8 @@
134135 *
135136 * @return bool
136137 */
137 - private function haveOldVersion() {
138 - $file = wfFindFile( $this->title, $this->oldimage );
139 - return $file && $file->exists() && $file->isLocal();
 138+ protected function haveOldVersion() {
 139+ return $this->getOldFile()->exists();
140140 }
141141
142142 /**
@@ -143,10 +143,10 @@
144144 *
145145 * @return string
146146 */
147 - private function getAction() {
 147+ protected function getAction() {
148148 $q = array();
149149 $q[] = 'action=revert';
150 - $q[] = 'oldimage=' . urlencode( $this->oldimage );
 150+ $q[] = 'oldimage=' . urlencode( $this->archiveName );
151151 return $this->title->getLocalUrl( implode( '&', $q ) );
152152 }
153153
@@ -155,12 +155,17 @@
156156 *
157157 * @return string
158158 */
159 - private function getTimestamp() {
 159+ protected function getTimestamp() {
160160 if( $this->timestamp === false ) {
161 - $file = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage );
162 - $this->timestamp = $file->getTimestamp();
 161+ $this->timestamp = $this->getOldFile()->getTimestamp();
163162 }
164163 return $this->timestamp;
165164 }
166 -
167 -}
\ No newline at end of file
 165+
 166+ protected function getOldFile() {
 167+ if ( !isset( $this->oldFile ) ) {
 168+ $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->archiveName );
 169+ }
 170+ return $this->oldFile;
 171+ }
 172+}
Index: branches/REL1_12/phase3/includes/filerepo/OldLocalFile.php
@@ -42,8 +42,7 @@
4343 }
4444
4545 function getCacheKey() {
46 - $hashedName = md5($this->getName());
47 - return wfMemcKey( 'oldfile', $hashedName );
 46+ return false;
4847 }
4948
5049 function getArchiveName() {
@@ -57,105 +56,6 @@
5857 return true;
5958 }
6059
61 - /**
62 - * Try to load file metadata from memcached. Returns true on success.
63 - */
64 - function loadFromCache() {
65 - global $wgMemc;
66 - wfProfileIn( __METHOD__ );
67 - $this->dataLoaded = false;
68 - $key = $this->getCacheKey();
69 - if ( !$key ) {
70 - return false;
71 - }
72 - $oldImages = $wgMemc->get( $key );
73 -
74 - if ( isset( $oldImages['version'] ) && $oldImages['version'] == self::CACHE_VERSION ) {
75 - unset( $oldImages['version'] );
76 - $more = isset( $oldImages['more'] );
77 - unset( $oldImages['more'] );
78 - $found = false;
79 - if ( is_null( $this->requestedTime ) ) {
80 - foreach ( $oldImages as $timestamp => $info ) {
81 - if ( $info['archive_name'] == $this->archive_name ) {
82 - $found = true;
83 - break;
84 - }
85 - }
86 - } else {
87 - krsort( $oldImages );
88 - foreach ( $oldImages as $timestamp => $info ) {
89 - if ( $timestamp <= $this->requestedTime ) {
90 - $found = true;
91 - break;
92 - }
93 - }
94 - }
95 - if ( $found ) {
96 - wfDebug( "Pulling file metadata from cache key {$key}[{$timestamp}]\n" );
97 - $this->dataLoaded = true;
98 - $this->fileExists = true;
99 - foreach ( $info as $name => $value ) {
100 - $this->$name = $value;
101 - }
102 - } elseif ( $more ) {
103 - wfDebug( "Cache key was truncated, oldimage row might be found in the database\n" );
104 - } else {
105 - wfDebug( "Image did not exist at the specified time.\n" );
106 - $this->fileExists = false;
107 - $this->dataLoaded = true;
108 - }
109 - }
110 -
111 - if ( $this->dataLoaded ) {
112 - wfIncrStats( 'image_cache_hit' );
113 - } else {
114 - wfIncrStats( 'image_cache_miss' );
115 - }
116 -
117 - wfProfileOut( __METHOD__ );
118 - return $this->dataLoaded;
119 - }
120 -
121 - function saveToCache() {
122 - // If a timestamp was specified, cache the entire history of the image (up to MAX_CACHE_ROWS).
123 - if ( is_null( $this->requestedTime ) ) {
124 - return;
125 - }
126 - // This is expensive, so we only do it if $wgMemc is real
127 - global $wgMemc;
128 - if ( $wgMemc instanceof FakeMemcachedClient ) {
129 - return;
130 - }
131 - $key = $this->getCacheKey();
132 - if ( !$key ) {
133 - return;
134 - }
135 - wfProfileIn( __METHOD__ );
136 -
137 - $dbr = $this->repo->getSlaveDB();
138 - $res = $dbr->select( 'oldimage', $this->getCacheFields( 'oi_' ),
139 - array( 'oi_name' => $this->getName() ), __METHOD__,
140 - array(
141 - 'LIMIT' => self::MAX_CACHE_ROWS + 1,
142 - 'ORDER BY' => 'oi_timestamp DESC',
143 - ));
144 - $cache = array( 'version' => self::CACHE_VERSION );
145 - $numRows = $dbr->numRows( $res );
146 - if ( $numRows > self::MAX_CACHE_ROWS ) {
147 - $cache['more'] = true;
148 - $numRows--;
149 - }
150 - for ( $i = 0; $i < $numRows; $i++ ) {
151 - $row = $dbr->fetchObject( $res );
152 - $decoded = $this->decodeRow( $row, 'oi_' );
153 - $cache[$row->oi_timestamp] = $decoded;
154 - }
155 - $dbr->freeResult( $res );
156 - $wgMemc->set( $key, $cache, 7*86400 /* 1 week */ );
157 - wfProfileOut( __METHOD__ );
158 - }
159 -
16060 function loadFromDB() {
16161 wfProfileIn( __METHOD__ );
16262 $this->dataLoaded = true;
Index: branches/REL1_12/phase3/RELEASE-NOTES
@@ -10,6 +10,7 @@
1111
1212 * (bug 13522) Fix fatal error in Parser::extractTagsAndParams
1313 * (bug 12077) Fix HTML nesting for TOC
 14+* (bug 13532) Use proper timestamp call when reverting images
1415 * (bug 13649) Bad call to wfTimestamp()
1516
1617

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r32526Wrap timestamp for DB query in $dbr->timestamp() call. Bug 13532.greg21:55, 27 March 2008
r32527Note bug 13532greg21:57, 27 March 2008
r32817* Fixed bug 13532, incorrect use of wfFindFile() causing total breakage of fi...tstarling16:46, 5 April 2008

Status & tagging log