Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -965,44 +965,56 @@ |
966 | 966 | */ |
967 | 967 | public static function getExistsWarning( $file ) { |
968 | 968 | if( $file->exists() ) |
969 | | - return array( 'exists', $file ); |
| 969 | + return array( 'warning' => 'exists', 'file' => $file ); |
970 | 970 | |
971 | 971 | if( $file->getTitle()->getArticleID() ) |
972 | | - return array( 'page-exists', $file ); |
973 | | - |
| 972 | + return array( 'warning' => 'page-exists', 'file' => $file ); |
| 973 | + |
| 974 | + if ( $file->wasDeleted() && !$file->exists() ) |
| 975 | + return array( 'warning' => 'was-deleted', 'file' => $file ); |
| 976 | + |
974 | 977 | if( strpos( $file->getName(), '.' ) == false ) { |
975 | 978 | $partname = $file->getName(); |
976 | | - $rawExtension = ''; |
| 979 | + $extension = ''; |
977 | 980 | } else { |
978 | 981 | $n = strrpos( $file->getName(), '.' ); |
979 | | - $rawExtension = substr( $file->getName(), $n + 1 ); |
| 982 | + $extension = substr( $file->getName(), $n + 1 ); |
980 | 983 | $partname = substr( $file->getName(), 0, $n ); |
981 | 984 | } |
| 985 | + $normalizedExtension = File::normalizeExtension( $extension ); |
982 | 986 | |
983 | | - if ( $rawExtension != $file->getExtension() ) { |
| 987 | + if ( $normalizedExtension != $extension ) { |
984 | 988 | // We're not using the normalized form of the extension. |
985 | 989 | // Normal form is lowercase, using most common of alternate |
986 | 990 | // extensions (eg 'jpg' rather than 'JPEG'). |
987 | 991 | // |
988 | 992 | // Check for another file using the normalized form... |
989 | | - $nt_lc = Title::makeTitle( NS_FILE, $partname . '.' . $file->getExtension() ); |
| 993 | + $nt_lc = Title::makeTitle( NS_FILE, "{$partname}.{$normalizedExtension}" ); |
990 | 994 | $file_lc = wfLocalFile( $nt_lc ); |
991 | 995 | |
992 | 996 | if( $file_lc->exists() ) |
993 | | - return array( 'exists-normalized', $file_lc ); |
| 997 | + return array( 'warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc ); |
994 | 998 | } |
995 | 999 | |
996 | 1000 | if ( self::isThumbName( $file->getName() ) ) { |
997 | 1001 | # Check for filenames like 50px- or 180px-, these are mostly thumbnails |
998 | | - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension ); |
| 1002 | + $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $extension, NS_FILE ); |
999 | 1003 | $file_thb = wfLocalFile( $nt_thb ); |
1000 | 1004 | if( $file_thb->exists() ) |
1001 | | - return array( 'thumb', $file_thb ); |
| 1005 | + return array( 'warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb ); |
1002 | 1006 | else |
1003 | 1007 | // File does not exist, but we just don't like the name |
1004 | | - return array( 'thumb-name', $file_thb ); |
| 1008 | + return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb ); |
1005 | 1009 | } |
| 1010 | + |
1006 | 1011 | |
| 1012 | + foreach( self::getFilenamePrefixBlacklist() as $prefix ) { |
| 1013 | + if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) |
| 1014 | + return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix ); |
| 1015 | + } |
| 1016 | + |
| 1017 | + |
| 1018 | + |
1007 | 1019 | return false; |
1008 | 1020 | } |
1009 | 1021 | |
Index: trunk/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | if( !$this->mTokenOk && !$this->mReUpload && ($this->mUpload && ( |
133 | 133 | 'submit' == $this->mAction || $this->mUploadClicked ) ) ) |
134 | 134 | { |
135 | | - $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) ); |
| 135 | + $this->mainUploadForm ( wfMsg( 'session_fail_preview', 'parseinline' ) ); |
136 | 136 | return ; |
137 | 137 | } |
138 | 138 | |
— | — | @@ -333,105 +333,34 @@ |
334 | 334 | if ( !$exists ) |
335 | 335 | return ''; |
336 | 336 | |
337 | | - $warning = ''; |
338 | | - $align = $wgContLang->alignEnd(); |
| 337 | + $file = $exists['file']; |
| 338 | + $filename = $file->getTitle()->getPrefixedText(); |
| 339 | + $warning = array(); |
339 | 340 | |
340 | | - list( $existsType, $file ) = $exists; |
341 | | - |
342 | | - if ( strpos( $file->getName(), '.' ) == false ) { |
343 | | - // File does not have an extension or starts with a dot |
344 | | - $partname = $file->getName(); |
345 | | - $rawExtension = ''; |
346 | | - } else { |
347 | | - $n = strrpos( $file->getName(), '.' ); |
348 | | - $rawExtension = substr( $file->getName(), $n + 1 ); |
349 | | - $partname = substr( $file->getName(), 0, $n ); |
350 | | - } |
351 | | - |
352 | 341 | $sk = $wgUser->getSkin(); |
353 | 342 | |
354 | | - if( $existsType == 'exists' ) { |
| 343 | + if( $exists['warning'] == 'exists' ) { |
355 | 344 | // Exact match |
356 | | - $dlink = $sk->linkKnown( $file->getTitle() ); |
357 | | - if ( $file->allowInlineDisplay() ) { |
358 | | - $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ), |
359 | | - $file->getName(), $align, array(), false, true ); |
360 | | - } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { |
361 | | - $icon = $file->iconThumb(); |
362 | | - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' . |
363 | | - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>'; |
364 | | - } else { |
365 | | - $dlink2 = ''; |
366 | | - } |
367 | | - |
368 | | - $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2; |
369 | | - |
370 | | - } elseif( $existsType == 'page-exists' ) { |
| 345 | + $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>'; |
| 346 | + } elseif( $exists['warning'] == 'page-exists' ) { |
371 | 347 | // Page exists but file does not |
372 | | - $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') ); |
373 | | - $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>'; |
374 | | - } elseif ( $existsType == 'exists-normalized' ) { |
375 | | - # Check if image with lowercase extension exists. |
376 | | - # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension |
377 | | - $normalizedTitle = $file->getTitle(); |
378 | | - $dlink = $sk->linkKnown( $normalizedTitle ); |
379 | | - if ( $file->allowInlineDisplay() ) { |
380 | | - // FIXME: replace deprecated makeImageLinkObj by link() |
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(); |
385 | | - $dlink2 = '<div style="float:' . $align . '" id="mw-media-icon">' . |
386 | | - $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>'; |
387 | | - } else { |
388 | | - $dlink2 = ''; |
389 | | - } |
390 | | - |
391 | | - $warning .= '<li>' . |
392 | | - wfMsgExt( 'fileexists-extension', 'parsemag', |
393 | | - $file->getTitle()->getPrefixedText(), $dlink ) . |
394 | | - '</li>' . $dlink2; |
395 | | - |
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>'; |
409 | | - } else { |
410 | | - $dlink2 = ''; |
411 | | - } |
412 | | - |
413 | | - $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . |
414 | | - '</li>' . $dlink2; |
415 | | - } elseif ( $existsType == 'thumb-name' ) { |
416 | | - # Image w/o '180px-' does not exists, but we do not like these filenames |
417 | | - $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , |
418 | | - substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>'; |
419 | | - } |
420 | | - |
421 | | - $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist(); |
422 | | - # Do the match |
423 | | - if( !isset( $partname ) ) |
424 | | - $partname = ''; |
425 | | - foreach( $filenamePrefixBlacklist as $prefix ) { |
426 | | - if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) { |
427 | | - $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>'; |
428 | | - break; |
429 | | - } |
430 | | - } |
431 | | - |
432 | | - // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning) |
433 | | - if ( $file->wasDeleted() && !$file->exists() ) { |
| 348 | + $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>'; |
| 349 | + } elseif ( $exists['warning'] == 'exists-normalized' ) { |
| 350 | + $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename, |
| 351 | + $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>'; |
| 352 | + } elseif ( $exists['warning'] == 'thumb' ) { |
| 353 | + // Swapped argument order compared with other messages for backwards compatibility |
| 354 | + $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline', |
| 355 | + $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>'; |
| 356 | + } elseif ( $exists['warning'] == 'thumb-name' ) { |
| 357 | + # Image w/o '180px-' does not exists, but we do not like these filenames |
| 358 | + $name = $file->getName(); |
| 359 | + $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 ); |
| 360 | + $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>'; |
| 361 | + } elseif ( $exists['warning'] == 'bad-prefix' ) { |
| 362 | + $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>'; |
| 363 | + } elseif ( $exists['warning'] == 'was-deleted' ) { |
434 | 364 | # If the file existed before and was deleted, warn the user of this |
435 | | - # Don't bother doing so if the file exists now, however |
436 | 365 | $ltitle = SpecialPage::getTitleFor( 'Log' ); |
437 | 366 | $llink = $sk->linkKnown( |
438 | 367 | $ltitle, |
— | — | @@ -439,12 +368,13 @@ |
440 | 369 | array(), |
441 | 370 | array( |
442 | 371 | 'type' => 'delete', |
443 | | - 'page' => $file->getTitle()->getPrefixedText() |
| 372 | + 'page' => $filename |
444 | 373 | ) |
445 | 374 | ); |
446 | | - $warning .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>'; |
| 375 | + $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>'; |
447 | 376 | } |
448 | | - return $warning; |
| 377 | + |
| 378 | + return implode( "\n", $warning ); |
449 | 379 | } |
450 | 380 | |
451 | 381 | /** |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2078,17 +2078,16 @@ |
2079 | 2079 | 'emptyfile' => 'The file you uploaded seems to be empty. |
2080 | 2080 | This might be due to a typo in the file name. |
2081 | 2081 | Please check whether you really want to upload this file.', |
2082 | | -'fileexists' => "A file with this name exists already, please check '''<tt>$1</tt>''' if you are not sure if you want to change it.", |
2083 | | -'filepageexists' => "The description page for this file has already been created at '''<tt>$1</tt>''', but no file with this name currently exists. |
| 2082 | +'fileexists' => "A file with this name exists already, please check '''<tt>[[:$1]]</tt>''' if you are not sure if you want to change it. [[$1|thumb]]", |
| 2083 | +'filepageexists' => "The description page for this file has already been created at '''<tt>[[:$1]]</tt>''', but no file with this name currently exists. |
2084 | 2084 | The summary you enter will not appear on the description page. |
2085 | | -To make your summary appear there, you will need to manually edit it", |
2086 | | -'fileexists-extension' => "A file with a similar name exists:<br /> |
2087 | | -Name of the uploading file: '''<tt>$1</tt>'''<br /> |
2088 | | -Name of the existing file: '''<tt>$2</tt>'''<br /> |
| 2085 | +To make your summary appear there, you will need to manually edit it. [[$1|thumb]]", |
| 2086 | +'fileexists-extension' => "A file with a similar name exists: [[$2|thumb]] |
| 2087 | +* Name of the uploading file: '''<tt>[[:$1]]</tt>''' |
| 2088 | +* Name of the existing file: '''<tt>[[:$2]]</tt>''' |
2089 | 2089 | Please choose a different name.", |
2090 | | -'fileexists-thumb' => "<center>'''Existing file'''</center>", |
2091 | | -'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''. |
2092 | | -Please check the file '''<tt>$1</tt>'''.<br /> |
| 2090 | +'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''. [[$1|thumb]] |
| 2091 | +Please check the file '''<tt>[[:$1]]</tt>'''. |
2093 | 2092 | If the checked file is the same image of original size it is not necessary to upload an extra thumbnail.", |
2094 | 2093 | 'file-thumbnail-no' => "The filename begins with '''<tt>$1</tt>'''. |
2095 | 2094 | It seems to be an image of reduced size ''(thumbnail)''. |