From: Reedy Date: Sat, 13 Apr 2019 23:27:04 +0000 (+0100) Subject: Fix a couple of Generic.Files.OneObjectStructurePerFile.MultipleFound in api X-Git-Tag: 1.34.0-rc.0~2008^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=821a4e84dddf89e903db953246cc638cf97294ad;hp=c81654bcdd821e7b59279be99119942b2a9c4559 Fix a couple of Generic.Files.OneObjectStructurePerFile.MultipleFound in api Change-Id: Ibb6b324b286f62153ce5d08a66454e0b05a0ef78 --- diff --git a/.phpcs.xml b/.phpcs.xml index 170e16d4cb..3a5b95c3f5 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -208,8 +208,6 @@ */includes/api/ApiErrorFormatter\.php */includes/api/ApiImport\.php */includes/api/ApiMessage\.php - */includes/api/ApiOpenSearch\.php - */includes/api/ApiRsd\.php */includes/compat/XMPReader\.php */includes/diff/DairikiDiff\.php */includes/Feed\.php diff --git a/autoload.php b/autoload.php index a74a0b8b34..41e384ac98 100644 --- a/autoload.php +++ b/autoload.php @@ -52,7 +52,7 @@ $wgAutoloadLocalClasses = [ 'ApiFormatPhp' => __DIR__ . '/includes/api/ApiFormatPhp.php', 'ApiFormatRaw' => __DIR__ . '/includes/api/ApiFormatRaw.php', 'ApiFormatXml' => __DIR__ . '/includes/api/ApiFormatXml.php', - 'ApiFormatXmlRsd' => __DIR__ . '/includes/api/ApiRsd.php', + 'ApiFormatXmlRsd' => __DIR__ . '/includes/api/ApiFormatXmlRsd.php', 'ApiHelp' => __DIR__ . '/includes/api/ApiHelp.php', 'ApiHelpParamValueMessage' => __DIR__ . '/includes/api/ApiHelpParamValueMessage.php', 'ApiImageRotate' => __DIR__ . '/includes/api/ApiImageRotate.php', @@ -69,7 +69,7 @@ $wgAutoloadLocalClasses = [ 'ApiModuleManager' => __DIR__ . '/includes/api/ApiModuleManager.php', 'ApiMove' => __DIR__ . '/includes/api/ApiMove.php', 'ApiOpenSearch' => __DIR__ . '/includes/api/ApiOpenSearch.php', - 'ApiOpenSearchFormatJson' => __DIR__ . '/includes/api/ApiOpenSearch.php', + 'ApiOpenSearchFormatJson' => __DIR__ . '/includes/api/ApiOpenSearchFormatJson.php', 'ApiOptions' => __DIR__ . '/includes/api/ApiOptions.php', 'ApiPageSet' => __DIR__ . '/includes/api/ApiPageSet.php', 'ApiParamInfo' => __DIR__ . '/includes/api/ApiParamInfo.php', diff --git a/includes/api/ApiFormatXmlRsd.php b/includes/api/ApiFormatXmlRsd.php new file mode 100644 index 0000000000..6b892fa8ce --- /dev/null +++ b/includes/api/ApiFormatXmlRsd.php @@ -0,0 +1,38 @@ +setRootElement( 'rsd' ); + } + + public function getMimeType() { + return 'application/rsd+xml'; + } + + public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) { + unset( $attributes['_idx'] ); + return parent::recXmlPrint( $name, $value, $indent, $attributes ); + } +} diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 416fc7f6e4..8e2837b324 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -379,41 +379,3 @@ class ApiOpenSearch extends ApiBase { } } } - -/** - * @ingroup API - */ -class ApiOpenSearchFormatJson extends ApiFormatJson { - private $warningsAsError = false; - - public function __construct( ApiMain $main, $fm, $warningsAsError ) { - parent::__construct( $main, "json$fm" ); - $this->warningsAsError = $warningsAsError; - } - - public function execute() { - $result = $this->getResult(); - if ( !$result->getResultData( 'error' ) && !$result->getResultData( 'errors' ) ) { - // Ignore warnings or treat as errors, as requested - $warnings = $result->removeValue( 'warnings', null ); - if ( $this->warningsAsError && $warnings ) { - $this->dieWithError( - 'apierror-opensearch-json-warnings', - 'warnings', - [ 'warnings' => $warnings ] - ); - } - - // Ignore any other unexpected keys (e.g. from $wgDebugToolbar) - $remove = array_keys( array_diff_key( - $result->getResultData(), - [ 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ] - ) ); - foreach ( $remove as $key ) { - $result->removeValue( $key, null ); - } - } - - parent::execute(); - } -} diff --git a/includes/api/ApiOpenSearchFormatJson.php b/includes/api/ApiOpenSearchFormatJson.php new file mode 100644 index 0000000000..b1903f2060 --- /dev/null +++ b/includes/api/ApiOpenSearchFormatJson.php @@ -0,0 +1,61 @@ +@gmail.com" + * Copyright © 2008 Brion Vibber + * Copyright © 2014 Wikimedia Foundation and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + */ + +/** + * @ingroup API + */ +class ApiOpenSearchFormatJson extends ApiFormatJson { + private $warningsAsError = false; + + public function __construct( ApiMain $main, $fm, $warningsAsError ) { + parent::__construct( $main, "json$fm" ); + $this->warningsAsError = $warningsAsError; + } + + public function execute() { + $result = $this->getResult(); + if ( !$result->getResultData( 'error' ) && !$result->getResultData( 'errors' ) ) { + // Ignore warnings or treat as errors, as requested + $warnings = $result->removeValue( 'warnings', null ); + if ( $this->warningsAsError && $warnings ) { + $this->dieWithError( + 'apierror-opensearch-json-warnings', + 'warnings', + [ 'warnings' => $warnings ] + ); + } + + // Ignore any other unexpected keys (e.g. from $wgDebugToolbar) + $remove = array_keys( array_diff_key( + $result->getResultData(), + [ 0 => 'search', 1 => 'terms', 2 => 'descriptions', 3 => 'urls' ] + ) ); + foreach ( $remove as $key ) { + $result->removeValue( $key, null ); + } + } + + parent::execute(); + } +} diff --git a/includes/api/ApiRsd.php b/includes/api/ApiRsd.php index 71bab365af..00ab77bab3 100644 --- a/includes/api/ApiRsd.php +++ b/includes/api/ApiRsd.php @@ -149,19 +149,3 @@ class ApiRsd extends ApiBase { return $outputData; } } - -class ApiFormatXmlRsd extends ApiFormatXml { - public function __construct( ApiMain $main, $format ) { - parent::__construct( $main, $format ); - $this->setRootElement( 'rsd' ); - } - - public function getMimeType() { - return 'application/rsd+xml'; - } - - public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) { - unset( $attributes['_idx'] ); - return parent::recXmlPrint( $name, $value, $indent, $attributes ); - } -}