Index: branches/REL1_12/phase3/includes/FileRevertForm.php |
— | — | @@ -8,10 +8,11 @@ |
9 | 9 | */ |
10 | 10 | class FileRevertForm { |
11 | 11 | |
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; |
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Constructor |
— | — | @@ -48,10 +49,10 @@ |
49 | 50 | return; |
50 | 51 | } |
51 | 52 | |
52 | | - $this->oldimage = $wgRequest->getText( 'oldimage' ); |
| 53 | + $this->archiveName = $wgRequest->getText( 'oldimage' ); |
53 | 54 | $token = $wgRequest->getText( 'wpEditToken' ); |
54 | 55 | if( !$this->isValidOldSpec() ) { |
55 | | - $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->oldimage ) ); |
| 56 | + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars( $this->archiveName ) ); |
56 | 57 | return; |
57 | 58 | } |
58 | 59 | |
— | — | @@ -62,8 +63,8 @@ |
63 | 64 | } |
64 | 65 | |
65 | 66 | // 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 ); |
68 | 69 | $comment = $wgRequest->getText( 'wpComment' ); |
69 | 70 | // TODO: Preserve file properties from database instead of reloading from file |
70 | 71 | $status = $this->file->upload( $source, $comment, $comment ); |
— | — | @@ -71,7 +72,7 @@ |
72 | 73 | $wgOut->addHtml( wfMsgExt( 'filerevert-success', 'parse', $this->title->getText(), |
73 | 74 | $wgLang->date( $this->getTimestamp(), true ), |
74 | 75 | $wgLang->time( $this->getTimestamp(), true ), |
75 | | - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ) ); |
| 76 | + wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ) ); |
76 | 77 | $wgOut->returnToMain( false, $this->title ); |
77 | 78 | } else { |
78 | 79 | $wgOut->addWikiText( $status->getWikiText() ); |
— | — | @@ -86,16 +87,16 @@ |
87 | 88 | /** |
88 | 89 | * Show the confirmation form |
89 | 90 | */ |
90 | | - private function showForm() { |
| 91 | + protected function showForm() { |
91 | 92 | global $wgOut, $wgUser, $wgRequest, $wgLang, $wgContLang; |
92 | 93 | $timestamp = $this->getTimestamp(); |
93 | 94 | |
94 | 95 | $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 ) ); |
96 | 97 | $form .= '<fieldset><legend>' . wfMsgHtml( 'filerevert-legend' ) . '</legend>'; |
97 | 98 | $form .= wfMsgExt( 'filerevert-intro', 'parse', $this->title->getText(), |
98 | 99 | $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ), |
99 | | - wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) ); |
| 100 | + wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ); |
100 | 101 | $form .= '<p>' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment', |
101 | 102 | 60, wfMsgForContent( 'filerevert-defaultcomment', |
102 | 103 | $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '</p>'; |
— | — | @@ -109,7 +110,7 @@ |
110 | 111 | /** |
111 | 112 | * Set headers, titles and other bits |
112 | 113 | */ |
113 | | - private function setHeaders() { |
| 114 | + protected function setHeaders() { |
114 | 115 | global $wgOut, $wgUser; |
115 | 116 | $wgOut->setPageTitle( wfMsg( 'filerevert', $this->title->getText() ) ); |
116 | 117 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
— | — | @@ -121,10 +122,10 @@ |
122 | 123 | * |
123 | 124 | * @return bool |
124 | 125 | */ |
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; |
129 | 130 | } |
130 | 131 | |
131 | 132 | /** |
— | — | @@ -133,9 +134,8 @@ |
134 | 135 | * |
135 | 136 | * @return bool |
136 | 137 | */ |
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(); |
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
— | — | @@ -143,10 +143,10 @@ |
144 | 144 | * |
145 | 145 | * @return string |
146 | 146 | */ |
147 | | - private function getAction() { |
| 147 | + protected function getAction() { |
148 | 148 | $q = array(); |
149 | 149 | $q[] = 'action=revert'; |
150 | | - $q[] = 'oldimage=' . urlencode( $this->oldimage ); |
| 150 | + $q[] = 'oldimage=' . urlencode( $this->archiveName ); |
151 | 151 | return $this->title->getLocalUrl( implode( '&', $q ) ); |
152 | 152 | } |
153 | 153 | |
— | — | @@ -155,12 +155,17 @@ |
156 | 156 | * |
157 | 157 | * @return string |
158 | 158 | */ |
159 | | - private function getTimestamp() { |
| 159 | + protected function getTimestamp() { |
160 | 160 | 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(); |
163 | 162 | } |
164 | 163 | return $this->timestamp; |
165 | 164 | } |
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 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | function getCacheKey() { |
46 | | - $hashedName = md5($this->getName()); |
47 | | - return wfMemcKey( 'oldfile', $hashedName ); |
| 46 | + return false; |
48 | 47 | } |
49 | 48 | |
50 | 49 | function getArchiveName() { |
— | — | @@ -57,105 +56,6 @@ |
58 | 57 | return true; |
59 | 58 | } |
60 | 59 | |
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 | | - |
160 | 60 | function loadFromDB() { |
161 | 61 | wfProfileIn( __METHOD__ ); |
162 | 62 | $this->dataLoaded = true; |
Index: branches/REL1_12/phase3/RELEASE-NOTES |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | |
12 | 12 | * (bug 13522) Fix fatal error in Parser::extractTagsAndParams |
13 | 13 | * (bug 12077) Fix HTML nesting for TOC |
| 14 | +* (bug 13532) Use proper timestamp call when reverting images |
14 | 15 | * (bug 13649) Bad call to wfTimestamp() |
15 | 16 | |
16 | 17 | |