Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -459,19 +459,33 @@ |
460 | 460 | // Check for uppercase extension. We allow these filenames but check if an image |
461 | 461 | // with lowercase extension exists already |
462 | 462 | $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 = ''; |
467 | 468 | } else { |
468 | | - $partname = $file->getName(); |
| 469 | + list( $partname, $rawExtension ) = explode( '.', $file->getName(), 2 ); |
469 | 470 | } |
| 471 | + wfDebugLog( 'borko', sprintf( "%s - %s - %s", $partname, $rawExtension, $file->getExtension() ) ); |
| 472 | + $sk = $wgUser->getSkin(); |
470 | 473 | |
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() ); |
473 | 481 | $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 | + } |
474 | 487 | } else { |
475 | 488 | $file_lc = false; |
| 489 | + wfDebugLog( 'borko', 'extensions ok'); |
476 | 490 | } |
477 | 491 | |
478 | 492 | if( $file->exists() ) { |
— | — | @@ -490,6 +504,7 @@ |
491 | 505 | $warning .= '<li>' . wfMsgExt( 'fileexists', 'parseline', $dlink ) . '</li>' . $dlink2; |
492 | 506 | |
493 | 507 | } elseif ( $file_lc && $file_lc->exists() ) { |
| 508 | + wfDebugLog( 'borko', 'whee: ' . $file_lc->getName() ); |
494 | 509 | # Check if image with lowercase extension exists. |
495 | 510 | # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension |
496 | 511 | $dlink = $sk->makeKnownLinkObj( $nt_lc ); |
— | — | @@ -504,14 +519,13 @@ |
505 | 520 | $dlink2 = ''; |
506 | 521 | } |
507 | 522 | |
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; |
510 | 524 | |
511 | 525 | } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) |
512 | 526 | && ereg( "[0-9]{2}" , substr( $partname , 0, 2) ) ) |
513 | 527 | { |
514 | 528 | # 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 ); |
516 | 530 | $file_thb = wfLocalFile( $nt_thb ); |
517 | 531 | if ($file_thb->exists() ) { |
518 | 532 | # Check if an image without leading '180px-' (or similiar) exists |
— | — | @@ -550,6 +564,11 @@ |
551 | 565 | |
552 | 566 | static function ajaxGetExistsWarning( $filename ) { |
553 | 567 | $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 | + } |
554 | 573 | $s = ' '; |
555 | 574 | if ( $file ) { |
556 | 575 | $warning = self::getExistsWarning( $file ); |