Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -994,6 +994,9 @@ |
995 | 995 | $file_thb = wfLocalFile( $nt_thb ); |
996 | 996 | if( $file_thb->exists() ) |
997 | 997 | return array( 'thumb', $file_thb ); |
| 998 | + else |
| 999 | + // File does not exist, but we just don't like the name |
| 1000 | + return array( 'thumb-name', $file_thb ); |
998 | 1001 | } |
999 | 1002 | |
1000 | 1003 | return false; |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -320,16 +320,17 @@ |
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
324 | | - * Do existence checks on a file and produce a warning |
| 324 | + * Formats a result of UploadBase::getExistsWarning as HTML |
325 | 325 | * This check is static and can be done pre-upload via AJAX |
326 | | - * Returns an HTML fragment consisting of one or more LI elements if there is a warning |
327 | | - * Returns an empty string if there is no warning |
| 326 | + * |
| 327 | + * @param array $exists The result of UploadBase::getExistsWarning |
| 328 | + * @return string Empty string if there is no warning or an HTML fragment |
| 329 | + * consisting of one or more <li> elements if there is a warning. |
328 | 330 | */ |
329 | | - static function getExistsWarning( $exists ) { |
| 331 | + public static function getExistsWarning( $exists ) { |
330 | 332 | global $wgUser, $wgContLang; |
331 | | - // Check for uppercase extension. We allow these filenames but check if an image |
332 | | - // with lowercase extension exists already |
333 | | - if( $exists === false ) |
| 333 | + |
| 334 | + if ( !$exists ) |
334 | 335 | return ''; |
335 | 336 | |
336 | 337 | $warning = ''; |
— | — | @@ -337,7 +338,8 @@ |
338 | 339 | |
339 | 340 | list( $existsType, $file ) = $exists; |
340 | 341 | |
341 | | - if( strpos( $file->getName(), '.' ) == false ) { |
| 342 | + if ( strpos( $file->getName(), '.' ) == false ) { |
| 343 | + // File does not have an extension or starts with a dot |
342 | 344 | $partname = $file->getName(); |
343 | 345 | $rawExtension = ''; |
344 | 346 | } else { |
— | — | @@ -365,18 +367,20 @@ |
366 | 368 | $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2; |
367 | 369 | |
368 | 370 | } elseif( $existsType == 'page-exists' ) { |
| 371 | + // Page exists but file does not |
369 | 372 | $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') ); |
370 | 373 | $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>'; |
371 | 374 | } elseif ( $existsType == 'exists-normalized' ) { |
372 | 375 | # Check if image with lowercase extension exists. |
373 | 376 | # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension |
374 | | - $dlink = $sk->linkKnown( $nt_lc ); |
375 | | - if ( $file_lc->allowInlineDisplay() ) { |
| 377 | + $normalizedTitle = $file->getTitle(); |
| 378 | + $dlink = $sk->linkKnown( $normalizedTitle ); |
| 379 | + if ( $file->allowInlineDisplay() ) { |
376 | 380 | // FIXME: replace deprecated makeImageLinkObj by link() |
377 | | - $dlink2 = $sk->makeImageLinkObj( $nt_lc, wfMsgExt( 'fileexists-thumb', 'parseinline' ), |
378 | | - $nt_lc->getText(), $align, array(), false, true ); |
379 | | - } elseif ( !$file_lc->allowInlineDisplay() && $file_lc->isSafeFile() ) { |
380 | | - $icon = $file_lc->iconThumb(); |
| 381 | + $dlink2 = $sk->makeImageLinkObj( $normalizedTitle, wfMsgExt( 'fileexists-thumb', 'parseinline' ), |
| 382 | + $normalizedTitle->getText(), $align, array(), false, true ); |
| 383 | + } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { |
| 384 | + $icon = $file->iconThumb(); |
381 | 385 | $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' . |
382 | 386 | $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>'; |
383 | 387 | } else { |
— | — | @@ -388,41 +392,34 @@ |
389 | 393 | $file->getTitle()->getPrefixedText(), $dlink ) . |
390 | 394 | '</li>' . $dlink2; |
391 | 395 | |
392 | | - } elseif ( ( substr( $partname , 3, 3 ) == 'px-' || substr( $partname , 2, 3 ) == 'px-' ) |
393 | | - && preg_match( "/[0-9]{2}/" , substr( $partname , 0, 2 ) ) ) |
394 | | - { |
395 | | - # Check for filenames like 50px- or 180px-, these are mostly thumbnails |
396 | | - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension ); |
397 | | - $file_thb = wfLocalFile( $nt_thb ); |
398 | | - if ($file_thb->exists() ) { |
399 | | - # Check if an image without leading '180px-' (or similiar) exists |
400 | | - $dlink = $sk->linkKnown( $nt_thb ); |
401 | | - if ( $file_thb->allowInlineDisplay() ) { |
402 | | - // FIXME: replace deprecated makeImageLinkObj by link() |
403 | | - $dlink2 = $sk->makeImageLinkObj( $nt_thb, |
404 | | - wfMsgExt( 'fileexists-thumb', 'parseinline' ), |
405 | | - $nt_thb->getText(), $align, array(), false, true ); |
406 | | - } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) { |
407 | | - $icon = $file_thb->iconThumb(); |
408 | | - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' . |
409 | | - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . |
410 | | - $dlink . '</div>'; |
411 | | - } else { |
412 | | - $dlink2 = ''; |
413 | | - } |
414 | | - |
415 | | - $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . |
416 | | - '</li>' . $dlink2; |
| 396 | + } elseif ( $existsType == 'thumb' ) { |
| 397 | + $nt_thb = $file->getTitle(); |
| 398 | + $dlink = $sk->linkKnown( $nt_thb ); |
| 399 | + if ( $file->allowInlineDisplay() ) { |
| 400 | + // FIXME: replace deprecated makeImageLinkObj by link() |
| 401 | + $dlink2 = $sk->makeImageLinkObj( $nt_thb, |
| 402 | + wfMsgExt( 'fileexists-thumb', 'parseinline' ), |
| 403 | + $nt_thb->getText(), $align, array(), false, true ); |
| 404 | + } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) { |
| 405 | + $icon = $file_thb->iconThumb(); |
| 406 | + $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' . |
| 407 | + $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . |
| 408 | + $dlink . '</div>'; |
417 | 409 | } else { |
| 410 | + $dlink2 = ''; |
| 411 | + } |
| 412 | + |
| 413 | + $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . |
| 414 | + '</li>' . $dlink2; |
| 415 | + } elseif ( $existsType == 'thumb-name' ) { |
418 | 416 | # Image w/o '180px-' does not exists, but we do not like these filenames |
419 | 417 | $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , |
420 | 418 | substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>'; |
421 | | - } |
422 | 419 | } |
423 | 420 | |
424 | 421 | $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist(); |
425 | 422 | # Do the match |
426 | | - if(!isset($partname)) |
| 423 | + if( !isset( $partname ) ) |
427 | 424 | $partname = ''; |
428 | 425 | foreach( $filenamePrefixBlacklist as $prefix ) { |
429 | 426 | if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) { |
— | — | @@ -431,6 +428,7 @@ |
432 | 429 | } |
433 | 430 | } |
434 | 431 | |
| 432 | + // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning) |
435 | 433 | if ( $file->wasDeleted() && !$file->exists() ) { |
436 | 434 | # If the file existed before and was deleted, warn the user of this |
437 | 435 | # Don't bother doing so if the file exists now, however |