From cbb7dbda4b234dfb627ae9c43707507c1704c7ad Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 19 Sep 2009 15:42:06 +0000 Subject: [PATCH] Fix several messages generated by SpecialUpload::getExistsWarning which were malformatted. Also removed all HTML generation from that function. --- includes/specials/SpecialUpload.php | 124 ++++++---------------------- includes/upload/UploadBase.php | 34 +++++--- languages/messages/MessagesEn.php | 17 ++-- 3 files changed, 58 insertions(+), 117 deletions(-) diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 0ea6f9aac8..e69e73a450 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -131,7 +131,7 @@ class UploadForm extends SpecialPage { if( !$this->mTokenOk && !$this->mReUpload && ($this->mUpload && ( 'submit' == $this->mAction || $this->mUploadClicked ) ) ) { - $this->mainUploadForm ( wfMsg( 'session_fail_preview' ) ); + $this->mainUploadForm ( wfMsg( 'session_fail_preview', 'parseinline' ) ); return ; } @@ -333,105 +333,34 @@ class UploadForm extends SpecialPage { if ( !$exists ) return ''; - $warning = ''; - $align = $wgContLang->alignEnd(); - - list( $existsType, $file ) = $exists; - - if ( strpos( $file->getName(), '.' ) == false ) { - // File does not have an extension or starts with a dot - $partname = $file->getName(); - $rawExtension = ''; - } else { - $n = strrpos( $file->getName(), '.' ); - $rawExtension = substr( $file->getName(), $n + 1 ); - $partname = substr( $file->getName(), 0, $n ); - } + $file = $exists['file']; + $filename = $file->getTitle()->getPrefixedText(); + $warning = array(); $sk = $wgUser->getSkin(); - if( $existsType == 'exists' ) { + if( $exists['warning'] == 'exists' ) { // Exact match - $dlink = $sk->linkKnown( $file->getTitle() ); - if ( $file->allowInlineDisplay() ) { - $dlink2 = $sk->makeImageLinkObj( $file->getTitle(), wfMsgExt( 'fileexists-thumb', 'parseinline' ), - $file->getName(), $align, array(), false, true ); - } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { - $icon = $file->iconThumb(); - $dlink2 = '
' . - $icon->toHtml( array( 'desc-link' => true ) ) . '
' . $dlink . '
'; - } else { - $dlink2 = ''; - } - - $warning .= '
  • ' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '
  • ' . $dlink2; - - } elseif( $existsType == 'page-exists' ) { + $warning[] = '
  • ' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '
  • '; + } elseif( $exists['warning'] == 'page-exists' ) { // Page exists but file does not - $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') ); - $warning .= '
  • ' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '
  • '; - } elseif ( $existsType == 'exists-normalized' ) { - # Check if image with lowercase extension exists. - # It's not forbidden but in 99% it makes no sense to upload the same filename with uppercase extension - $normalizedTitle = $file->getTitle(); - $dlink = $sk->linkKnown( $normalizedTitle ); - if ( $file->allowInlineDisplay() ) { - // FIXME: replace deprecated makeImageLinkObj by link() - $dlink2 = $sk->makeImageLinkObj( $normalizedTitle, wfMsgExt( 'fileexists-thumb', 'parseinline' ), - $normalizedTitle->getText(), $align, array(), false, true ); - } elseif ( !$file->allowInlineDisplay() && $file->isSafeFile() ) { - $icon = $file->iconThumb(); - $dlink2 = '
    ' . - $icon->toHtml( array( 'desc-link' => true ) ) . '
    ' . $dlink . '
    '; - } else { - $dlink2 = ''; - } - - $warning .= '
  • ' . - wfMsgExt( 'fileexists-extension', 'parsemag', - $file->getTitle()->getPrefixedText(), $dlink ) . - '
  • ' . $dlink2; - - } elseif ( $existsType == 'thumb' ) { - $nt_thb = $file->getTitle(); - $dlink = $sk->linkKnown( $nt_thb ); - if ( $file->allowInlineDisplay() ) { - // FIXME: replace deprecated makeImageLinkObj by link() - $dlink2 = $sk->makeImageLinkObj( $nt_thb, - wfMsgExt( 'fileexists-thumb', 'parseinline' ), - $nt_thb->getText(), $align, array(), false, true ); - } elseif ( !$file_thb->allowInlineDisplay() && $file_thb->isSafeFile() ) { - $icon = $file_thb->iconThumb(); - $dlink2 = '
    ' . - $icon->toHtml( array( 'desc-link' => true ) ) . '
    ' . - $dlink . '
    '; - } else { - $dlink2 = ''; - } - - $warning .= '
  • ' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) . - '
  • ' . $dlink2; - } elseif ( $existsType == 'thumb-name' ) { - # Image w/o '180px-' does not exists, but we do not like these filenames - $warning .= '
  • ' . wfMsgExt( 'file-thumbnail-no', 'parseinline' , - substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '
  • '; - } - - $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist(); - # Do the match - if( !isset( $partname ) ) - $partname = ''; - foreach( $filenamePrefixBlacklist as $prefix ) { - if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) { - $warning .= '
  • ' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '
  • '; - break; - } - } - - // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning) - if ( $file->wasDeleted() && !$file->exists() ) { + $warning[] = '
  • ' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '
  • '; + } elseif ( $exists['warning'] == 'exists-normalized' ) { + $warning[] = '
  • ' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename, + $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '
  • '; + } elseif ( $exists['warning'] == 'thumb' ) { + // Swapped argument order compared with other messages for backwards compatibility + $warning[] = '
  • ' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline', + $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '
  • '; + } elseif ( $exists['warning'] == 'thumb-name' ) { + # Image w/o '180px-' does not exists, but we do not like these filenames + $name = $file->getName(); + $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 ); + $warning[] = '
  • ' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '
  • '; + } elseif ( $exists['warning'] == 'bad-prefix' ) { + $warning[] = '
  • ' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '
  • '; + } elseif ( $exists['warning'] == 'was-deleted' ) { # If the file existed before and was deleted, warn the user of this - # Don't bother doing so if the file exists now, however $ltitle = SpecialPage::getTitleFor( 'Log' ); $llink = $sk->linkKnown( $ltitle, @@ -439,12 +368,13 @@ class UploadForm extends SpecialPage { array(), array( 'type' => 'delete', - 'page' => $file->getTitle()->getPrefixedText() + 'page' => $filename ) ); - $warning .= '
  • ' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '
  • '; + $warning[] = '
  • ' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '
  • '; } - return $warning; + + return implode( "\n", $warning ); } /** diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 76101075a4..8795d76340 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -965,43 +965,55 @@ abstract class UploadBase { */ public static function getExistsWarning( $file ) { if( $file->exists() ) - return array( 'exists', $file ); + return array( 'warning' => 'exists', 'file' => $file ); if( $file->getTitle()->getArticleID() ) - return array( 'page-exists', $file ); - + return array( 'warning' => 'page-exists', 'file' => $file ); + + if ( $file->wasDeleted() && !$file->exists() ) + return array( 'warning' => 'was-deleted', 'file' => $file ); + if( strpos( $file->getName(), '.' ) == false ) { $partname = $file->getName(); - $rawExtension = ''; + $extension = ''; } else { $n = strrpos( $file->getName(), '.' ); - $rawExtension = substr( $file->getName(), $n + 1 ); + $extension = substr( $file->getName(), $n + 1 ); $partname = substr( $file->getName(), 0, $n ); } + $normalizedExtension = File::normalizeExtension( $extension ); - if ( $rawExtension != $file->getExtension() ) { + if ( $normalizedExtension != $extension ) { // We're not using the normalized form of the extension. // Normal form is lowercase, using most common of alternate // extensions (eg 'jpg' rather than 'JPEG'). // // Check for another file using the normalized form... - $nt_lc = Title::makeTitle( NS_FILE, $partname . '.' . $file->getExtension() ); + $nt_lc = Title::makeTitle( NS_FILE, "{$partname}.{$normalizedExtension}" ); $file_lc = wfLocalFile( $nt_lc ); if( $file_lc->exists() ) - return array( 'exists-normalized', $file_lc ); + return array( 'warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc ); } if ( self::isThumbName( $file->getName() ) ) { # Check for filenames like 50px- or 180px-, these are mostly thumbnails - $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $rawExtension ); + $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $extension, NS_FILE ); $file_thb = wfLocalFile( $nt_thb ); if( $file_thb->exists() ) - return array( 'thumb', $file_thb ); + return array( 'warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb ); else // File does not exist, but we just don't like the name - return array( 'thumb-name', $file_thb ); + return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb ); + } + + + foreach( self::getFilenamePrefixBlacklist() as $prefix ) { + if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) + return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix ); } + + return false; } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 99e003937c..bd2860aef9 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2078,17 +2078,16 @@ this file is $2.', 'emptyfile' => 'The file you uploaded seems to be empty. This might be due to a typo in the file name. Please check whether you really want to upload this file.', -'fileexists' => "A file with this name exists already, please check '''$1''' if you are not sure if you want to change it.", -'filepageexists' => "The description page for this file has already been created at '''$1''', but no file with this name currently exists. +'fileexists' => "A file with this name exists already, please check '''[[:$1]]''' if you are not sure if you want to change it. [[$1|thumb]]", +'filepageexists' => "The description page for this file has already been created at '''[[:$1]]''', but no file with this name currently exists. The summary you enter will not appear on the description page. -To make your summary appear there, you will need to manually edit it", -'fileexists-extension' => "A file with a similar name exists:
    -Name of the uploading file: '''$1'''
    -Name of the existing file: '''$2'''
    +To make your summary appear there, you will need to manually edit it. [[$1|thumb]]", +'fileexists-extension' => "A file with a similar name exists: [[$2|thumb]] +* Name of the uploading file: '''[[:$1]]''' +* Name of the existing file: '''[[:$2]]''' Please choose a different name.", -'fileexists-thumb' => "
    '''Existing file'''
    ", -'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''. -Please check the file '''$1'''.
    +'fileexists-thumbnail-yes' => "The file seems to be an image of reduced size ''(thumbnail)''. [[$1|thumb]] +Please check the file '''[[:$1]]'''. If the checked file is the same image of original size it is not necessary to upload an extra thumbnail.", 'file-thumbnail-no' => "The filename begins with '''$1'''. It seems to be an image of reduced size ''(thumbnail)''. -- 2.20.1