r25481 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25480‎ | r25481 | r25482 >
Date:15:56, 4 September 2007
Author:brion
Status:old
Tags:
Comment:
Fix the fix in r25439, which incorrectly assumed that normalized extensions are the same length as their non-normalized forms. This isn't true: JPEG vs jpg for instance. :)
Additionally, makes the AJAX checks for non-exact matches work when an exact match isn't present; wfFindFile() checks local and shared repository, but returns no object if there isn't an exact match. Falling back to wfLocalFile() to get an object so the checks go through.
Modified paths:
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialUpload.php
@@ -459,19 +459,33 @@
460460 // Check for uppercase extension. We allow these filenames but check if an image
461461 // with lowercase extension exists already
462462 $warning = '';
463 - $ext = substr( $file->getName(), strlen( $file->getName() ) - strlen( $file->getExtension() ), strlen( $file->getExtension() ) );
464 - $sk = $wgUser->getSkin();
465 - if ( $ext !== '' ) {
466 - $partname = substr( $file->getName(), 0, -strlen( $ext ) - 1 );
 463+ wfDebugLog( 'borko', 'wtf' );
 464+
 465+ if( strpos( $file->getName(), '.' ) == false ) {
 466+ $partname = $file->getName();
 467+ $rawExtension = '';
467468 } else {
468 - $partname = $file->getName();
 469+ list( $partname, $rawExtension ) = explode( '.', $file->getName(), 2 );
469470 }
 471+ wfDebugLog( 'borko', sprintf( "%s - %s - %s", $partname, $rawExtension, $file->getExtension() ) );
 472+ $sk = $wgUser->getSkin();
470473
471 - if ( $ext != strtolower( $ext ) ) {
472 - $nt_lc = Title::newFromText( $partname . '.' . strtolower( $ext ) );
 474+ if ( $rawExtension != $file->getExtension() ) {
 475+ // We're not using the normalized form of the extension.
 476+ // Normal form is lowercase, using most common of alternate
 477+ // extensions (eg 'jpg' rather than 'JPEG').
 478+ //
 479+ // Check for another file using the normalized form...
 480+ $nt_lc = Title::newFromText( $partname . '.' . $file->getExtension() );
473481 $file_lc = wfLocalFile( $nt_lc );
 482+ if( $file_lc ) {
 483+ wfDebugLog( 'borko', 'whee: ' . $file_lc->getName() );
 484+ } else {
 485+ wfDebugLog( 'borko', 'no lc match');
 486+ }
474487 } else {
475488 $file_lc = false;
 489+ wfDebugLog( 'borko', 'extensions ok');
476490 }
477491
478492 if( $file->exists() ) {
@@ -490,6 +504,7 @@
491505 $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2;
492506
493507 } elseif ( $file_lc && $file_lc->exists() ) {
 508+ wfDebugLog( 'borko', 'whee: ' . $file_lc->getName() );
494509 # Check if image with lowercase extension exists.
495510 # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension
496511 $dlink = $sk->makeKnownLinkObj( $nt_lc );
@@ -504,14 +519,13 @@
505520 $dlink2 = '';
506521 }
507522
508 - $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag' , $partname . '.'
509 - . $ext , $dlink ) . '</li>' . $dlink2;
 523+ $warning .= '<li>' . wfMsgExt( 'fileexists-extension', 'parsemag', $file->getName(), $dlink ) . '</li>' . $dlink2;
510524
511525 } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' )
512526 && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) )
513527 {
514528 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
515 - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $ext );
 529+ $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension );
516530 $file_thb = wfLocalFile( $nt_thb );
517531 if ($file_thb->exists() ) {
518532 # Check if an image without leading '180px-' (or similiar) exists
@@ -550,6 +564,11 @@
551565
552566 static function ajaxGetExistsWarning( $filename ) {
553567 $file = wfFindFile( $filename );
 568+ if( !$file ) {
 569+ // Force local file so we have an object to do further checks against
 570+ // if there isn't an exact match...
 571+ $file = wfLocalFile( $filename );
 572+ }
554573 $s = '&nbsp;';
555574 if ( $file ) {
556575 $warning = self::getExistsWarning( $file );

Follow-up revisions

RevisionCommit summaryAuthorDate
r25530Merged revisions 25454-25529 via svnmerge from...david08:28, 5 September 2007
r31246(bug 13143) Fix regression in r25481, in which file extensions were incorrect...werdna10:10, 25 February 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r25439Fix a regression from the file repo stuff....raymond15:06, 3 September 2007

Status & tagging log