Remove duplicate file extensions from output messages
authorBrion Vibber <brion@pobox.com>
Wed, 25 Sep 2013 19:52:00 +0000 (12:52 -0700)
committerKrinkle <krinklemail@gmail.com>
Fri, 27 Sep 2013 17:49:21 +0000 (17:49 +0000)
If a file type was added to $wgFileExtensions by both local configuration
and defaults in an extension (eg TimedMediaHandler and LocalSettings.php
both adding 'ogg' and 'ogv') it was being listed twice in the UI messages
listing acceptable types.

Runs array_unique() over the array on various outputs.

Bug: 54378
Change-Id: I14cd098d8b27099f8f803630535f33549740295c

includes/api/ApiQuerySiteinfo.php
includes/api/ApiUpload.php
includes/resourceloader/ResourceLoaderStartUpModule.php
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php

index 3c22a73..fbba98c 100644 (file)
@@ -473,7 +473,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                global $wgFileExtensions;
 
                $data = array();
-               foreach ( $wgFileExtensions as $ext ) {
+               foreach ( array_unique( $wgFileExtensions ) as $ext ) {
                        $data[] = array( 'ext' => $ext );
                }
                $this->getResult()->setIndexedTagName( $data, 'fe' );
index 6f6b080..467eccf 100644 (file)
@@ -504,7 +504,7 @@ class ApiUpload extends ApiBase {
                        case UploadBase::FILETYPE_BADTYPE:
                                $extradata = array(
                                        'filetype' => $verification['finalExt'],
-                                       'allowed' => $wgFileExtensions
+                                       'allowed' => array_values( array_unique( $wgFileExtensions ) )
                                );
                                $this->getResult()->setIndexedTagName( $extradata['allowed'], 'ext' );
 
index 861ff18..64915e5 100644 (file)
@@ -84,7 +84,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
                        'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
                        'wgNamespaceIds' => $namespaceIds,
                        'wgSiteName' => $wgSitename,
-                       'wgFileExtensions' => array_values( $wgFileExtensions ),
+                       'wgFileExtensions' => array_values( array_unique( $wgFileExtensions ) ),
                        'wgDBname' => $wgDBname,
                        // This sucks, it is only needed on Special:Upload, but I could
                        // not find a way to add vars only for a certain module
index 985de80..51a0a86 100644 (file)
@@ -570,8 +570,9 @@ class SpecialUpload extends SpecialPage {
                                } else {
                                        $msg->params( $details['finalExt'] );
                                }
-                               $msg->params( $this->getLanguage()->commaList( $wgFileExtensions ),
-                                       count( $wgFileExtensions ) );
+                               $extensions = array_unique( $wgFileExtensions );
+                               $msg->params( $this->getLanguage()->commaList( $extensions ),
+                                       count( $extensions ) );
 
                                // Add PLURAL support for the first parameter. This results
                                // in a bit unlogical parameter sequence, but does not break
@@ -877,16 +878,16 @@ class UploadForm extends HTMLForm {
                                # Everything not permitted is banned
                                $extensionsList =
                                        '<div id="mw-upload-permitted">' .
-                                       $this->msg( 'upload-permitted', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) )->parseAsBlock() .
+                                       $this->msg( 'upload-permitted', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() .
                                        "</div>\n";
                        } else {
                                # We have to list both preferred and prohibited
                                $extensionsList =
                                        '<div id="mw-upload-preferred">' .
-                                               $this->msg( 'upload-preferred', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) )->parseAsBlock() .
+                                               $this->msg( 'upload-preferred', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() .
                                        "</div>\n" .
                                        '<div id="mw-upload-prohibited">' .
-                                               $this->msg( 'upload-prohibited', $this->getContext()->getLanguage()->commaList( $wgFileBlacklist ) )->parseAsBlock() .
+                                               $this->msg( 'upload-prohibited', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileBlacklist ) ) )->parseAsBlock() .
                                        "</div>\n";
                        }
                } else {
index 37dc7cb..4b8a562 100644 (file)
@@ -618,9 +618,10 @@ abstract class UploadBase {
                // Check whether the file extension is on the unwanted list
                global $wgCheckFileExtensions, $wgFileExtensions;
                if ( $wgCheckFileExtensions ) {
-                       if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) {
+                       $extensions = array_unique( $wgFileExtensions );
+                       if ( !$this->checkFileExtension( $this->mFinalExtension, $extensions ) ) {
                                $warnings['filetype-unwanted-type'] = array( $this->mFinalExtension,
-                                       $wgLang->commaList( $wgFileExtensions ), count( $wgFileExtensions ) );
+                                       $wgLang->commaList( $extensions ), count( $extensions ) );
                        }
                }