Use ImageGallery directly in SpecialUpload::getDupeWarning()
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 24 Aug 2012 10:20:27 +0000 (12:20 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 24 Aug 2012 10:20:27 +0000 (12:20 +0200)
There is no need to go through a complete parse operation to
show the image gallery of duplicate files, instead the class
can be used directly.

Also refactored the code to do an early return if there are
no duplicated to not nest the code unnecessarily.

Change-Id: I459e539cf8140ef978388b3a65c644a0eb6c9a46

includes/specials/SpecialUpload.php

index d1a9b16..43ea345 100644 (file)
@@ -702,21 +702,18 @@ class SpecialUpload extends SpecialPage {
         * @return string
         */
        public static function getDupeWarning( $dupes ) {
-               global $wgOut;
-               if( $dupes ) {
-                       $msg = '<gallery>';
-                       foreach( $dupes as $file ) {
-                               $title = $file->getTitle();
-                               $msg .= $title->getPrefixedText() .
-                                       '|' . $title->getText() . "\n";
-                       }
-                       $msg .= '</gallery>';
-                       return '<li>' .
-                               wfMessage( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
-                               $wgOut->parse( $msg ) . "</li>\n";
-               } else {
+               if ( !$dupes ) {
                        return '';
                }
+
+               $gallery = new ImageGallery;
+               $gallery->setShowBytes( false );
+               foreach( $dupes as $file ) {
+                       $gallery->add( $file->getTitle() );
+               }
+               return '<li>' .
+                       wfMessage( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
+                       $gallery->toHtml() . "</li>\n";
        }
 
 }