r111076 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111075‎ | r111076 | r111077 >
Date:19:45, 9 February 2012
Author:aaron
Status:ok
Tags:core 
Comment:
(bug 34231) - 'Make thumb.php error or redirect for urls with bogus paths but valid file & thumb names.'
Modified paths:
  • /trunk/phase3/thumb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/thumb.php
@@ -173,6 +173,17 @@
174174 try {
175175 $thumbName = $img->thumbName( $params );
176176 if ( strlen( $thumbName ) ) { // valid params?
 177+ // For 404 handled thumbnails, we only use the the base name of the URI
 178+ // for the thumb params and the parent directory for the source file name.
 179+ // Check that the zone relative path matches up so squid caches won't pick
 180+ // up thumbs that would not be purged on source file deletion (bug 34231).
 181+ if ( isset( $params['rel404'] ) // thumbnail was handled via 404
 182+ && $params['rel404'] !== $img->getThumbRel( $thumbName ) )
 183+ {
 184+ wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
 185+ wfProfileOut( __METHOD__ );
 186+ return;
 187+ }
177188 $thumbPath = $img->getThumbPath( $thumbName );
178189 if ( $img->getRepo()->fileExists( $thumbPath ) ) {
179190 $img->getRepo()->streamFile( $thumbPath, $headers );
@@ -244,18 +255,18 @@
245256 $hashDirRegex .= "$subdirRegex/";
246257 }
247258
248 - $thumbUrlRegex = "!^$zoneUrlRegex(/archive|/temp|)/$hashDirRegex([^/]*)/([^/]*)$!";
 259+ $thumbUrlRegex = "!^$zoneUrlRegex/((archive/|temp/)?$hashDirRegex([^/]*)/([^/]*))$!";
249260
250261 // Check if this is a valid looking thumbnail request...
251262 if ( preg_match( $thumbUrlRegex, $uri, $matches ) ) {
252 - list( /* all */, $archOrTemp, $filename, $thumbname ) = $matches;
 263+ list( /* all */, $rel, $archOrTemp, $filename, $thumbname ) = $matches;
253264 $filename = urldecode( $filename );
254265 $thumbname = urldecode( $thumbname );
255266
256 - $params = array( 'f' => $filename );
257 - if ( $archOrTemp == '/archive' ) {
 267+ $params = array( 'f' => $filename, 'rel404' => $rel );
 268+ if ( $archOrTemp == 'archive/' ) {
258269 $params['archived'] = 1;
259 - } elseif ( $archOrTemp == '/temp' ) {
 270+ } elseif ( $archOrTemp == 'temp/' ) {
260271 $params['temp'] = 1;
261272 }
262273

Follow-up revisions

RevisionCommit summaryAuthorDate
r111144r111076: url decode the 'rel404' path...*ahem*. Archived files and files with...aaron01:35, 10 February 2012
r111175REL1_19: MFT r111029, r111034, r111067, r111076, r111085, r111128, r111144reedy18:37, 10 February 2012

Status & tagging log