From 3cfc7d5df1f1013a7083c8225fae716660a06ad6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 25 Sep 2013 12:52:00 -0700 Subject: [PATCH] Remove duplicate file extensions from output messages 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 | 2 +- includes/api/ApiUpload.php | 2 +- .../resourceloader/ResourceLoaderStartUpModule.php | 2 +- includes/specials/SpecialUpload.php | 11 ++++++----- includes/upload/UploadBase.php | 5 +++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 3c22a73275..fbba98cb88 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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' ); diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 6f6b08010b..467eccf862 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -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' ); diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 861ff18c29..64915e563b 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -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 diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 985de80f63..51a0a867d1 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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 = '
' . - $this->msg( 'upload-permitted', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) )->parseAsBlock() . + $this->msg( 'upload-permitted', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() . "
\n"; } else { # We have to list both preferred and prohibited $extensionsList = '
' . - $this->msg( 'upload-preferred', $this->getContext()->getLanguage()->commaList( $wgFileExtensions ) )->parseAsBlock() . + $this->msg( 'upload-preferred', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileExtensions ) ) )->parseAsBlock() . "
\n" . '
' . - $this->msg( 'upload-prohibited', $this->getContext()->getLanguage()->commaList( $wgFileBlacklist ) )->parseAsBlock() . + $this->msg( 'upload-prohibited', $this->getContext()->getLanguage()->commaList( array_unique( $wgFileBlacklist ) ) )->parseAsBlock() . "
\n"; } } else { diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 37dc7cba30..4b8a562a45 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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 ) ); } } -- 2.20.1