Fix several messages generated by SpecialUpload::getExistsWarning which were malforma...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 19 Sep 2009 15:42:06 +0000 (15:42 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 19 Sep 2009 15:42:06 +0000 (15:42 +0000)
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php
languages/messages/MessagesEn.php

index 0ea6f9a..e69e73a 100644 (file)
@@ -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 = '<div style="float:' . $align . '" id="mw-media-icon">' .
-                                       $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
-                       } else {
-                               $dlink2 = '';
-                       }
-
-                       $warning .= '<li>' . wfMsgExt( 'fileexists', array('parseinline','replaceafter'), $dlink ) . '</li>' . $dlink2;
-
-               } elseif( $existsType == 'page-exists' ) {
+                       $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
+               } elseif( $exists['warning'] == 'page-exists' ) {
                        // Page exists but file does not
-                       $lnk = $sk->linkKnown( $file->getTitle(), '', '',array('redirect'=>'no') );
-                       $warning .= '<li>' . wfMsgExt( 'filepageexists', array( 'parseinline', 'replaceafter' ), $lnk ) . '</li>';
-               } 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 = '<div style="float:' . $align . '" id="mw-media-icon">' .
-                                       $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' . $dlink . '</div>';
-                       } else {
-                               $dlink2 = '';
-                       }
-
-                       $warning .= '<li>' .
-                               wfMsgExt( 'fileexists-extension', 'parsemag',
-                                       $file->getTitle()->getPrefixedText(), $dlink ) .
-                               '</li>' . $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 = '<div style="float:' . $align . '" id="mw-media-icon">' .
-                                       $icon->toHtml( array( 'desc-link' => true ) ) . '<br />' .
-                                       $dlink . '</div>';
-                       } else {
-                               $dlink2 = '';
-                       }
-
-                       $warning .= '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parsemag', $dlink ) .
-                               '</li>' . $dlink2;
-               } elseif ( $existsType == 'thumb-name' ) {
-                               # Image w/o '180px-' does not exists, but we do not like these filenames
-                               $warning .= '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline' ,
-                                       substr( $partname , 0, strpos( $partname , '-' ) +1 ) ) . '</li>';
-               }
-
-               $filenamePrefixBlacklist = UploadBase::getFilenamePrefixBlacklist();
-               # Do the match
-               if( !isset( $partname ) )
-                       $partname = '';
-               foreach( $filenamePrefixBlacklist as $prefix ) {
-                       if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
-                               $warning .= '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $prefix ) . '</li>';
-                               break;
-                       }
-               }
-
-               // TODO: This should be put deeper down (i.e. UploadBase::getExistsWarning)
-               if ( $file->wasDeleted() && !$file->exists() ) {
+                       $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
+               } elseif ( $exists['warning'] == 'exists-normalized' ) {
+                       $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename, 
+                               $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
+               } elseif ( $exists['warning'] == 'thumb' ) {
+                       // Swapped argument order compared with other messages for backwards compatibility
+                       $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline', 
+                               $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
+               } 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[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
+               } elseif ( $exists['warning'] == 'bad-prefix' ) {
+                       $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
+               } 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 .= '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
+                       $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
                }
-               return $warning;
+               
+               return implode( "\n", $warning );
        }
 
        /**
index 7610107..8795d76 100644 (file)
@@ -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;
        }
index 99e0039..bd2860a 100644 (file)
@@ -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 '''<tt>$1</tt>''' if you are not sure if you want to change it.",
-'filepageexists'              => "The description page for this file has already been created at '''<tt>$1</tt>''', but no file with this name currently exists.
+'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]]",
+'filepageexists'              => "The description page for this file has already been created at '''<tt>[[:$1]]</tt>''', 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:<br />
-Name of the uploading file: '''<tt>$1</tt>'''<br />
-Name of the existing file: '''<tt>$2</tt>'''<br />
+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: '''<tt>[[:$1]]</tt>'''
+* Name of the existing file: '''<tt>[[:$2]]</tt>''' 
 Please choose a different name.",
-'fileexists-thumb'            => "<center>'''Existing file'''</center>",
-'fileexists-thumbnail-yes'    => "The file seems to be an image of reduced size ''(thumbnail)''.
-Please check the file '''<tt>$1</tt>'''.<br />
+'fileexists-thumbnail-yes'    => "The file seems to be an image of reduced size ''(thumbnail)''. [[$1|thumb]]
+Please check the file '''<tt>[[:$1]]</tt>'''.
 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 '''<tt>$1</tt>'''.
 It seems to be an image of reduced size ''(thumbnail)''.