From b1876e3dd73894b7827739a00b43b2d05233879a Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 10 Apr 2015 19:34:11 +0300 Subject: [PATCH] API: Remove WDDX and dump formats Per RFC: https://www.mediawiki.org/wiki/Requests_for_comment/Ditch_crappy_API_formats Change-Id: I4c9e64875be509906021255d70b90688f2e5ddf3 --- RELEASE-NOTES-1.26 | 2 + autoload.php | 2 - includes/api/ApiFormatBase.php | 4 +- includes/api/ApiFormatDump.php | 58 ------- includes/api/ApiFormatWddx.php | 162 ------------------ includes/api/ApiMain.php | 4 - includes/api/i18n/en.json | 4 - includes/api/i18n/qqq.json | 4 - .../includes/api/format/ApiFormatDumpTest.php | 63 ------- .../includes/api/format/ApiFormatWddxTest.php | 80 --------- 10 files changed, 4 insertions(+), 379 deletions(-) delete mode 100644 includes/api/ApiFormatDump.php delete mode 100644 includes/api/ApiFormatWddx.php delete mode 100644 tests/phpunit/includes/api/format/ApiFormatDumpTest.php delete mode 100644 tests/phpunit/includes/api/format/ApiFormatWddxTest.php diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index 5675956d73..aed6de9790 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -14,6 +14,7 @@ production. * New-style continuation is now the default for API action=continue. Clients may use the 'rawcontinue' parameter to receive raw query-continue data, but the new style is encouraged as it's harder to implement incorrectly. +* Deprecated API formats dump and wddx have been completely removed. === New features in 1.26 === * (T51506) Now action=info gives estimates of actual watchers for a page. @@ -55,6 +56,7 @@ production. * New-style continuation is now the default for action=continue. Clients may use the 'rawcontinue' parameter to receive raw query-continue data, but the new style is encouraged as it's harder to implement incorrectly. +* Deprecated API formats dump and wddx have been completely removed. * API action=query&list=tags: The displayname can now be boolean false if the tag is meant to be hidden from user interfaces. * action=import no longer allows both the namespace= and rootpage= parameters diff --git a/autoload.php b/autoload.php index 926677622f..8e4da1e4c3 100644 --- a/autoload.php +++ b/autoload.php @@ -37,14 +37,12 @@ $wgAutoloadLocalClasses = array( 'ApiFileRevert' => __DIR__ . '/includes/api/ApiFileRevert.php', 'ApiFormatBase' => __DIR__ . '/includes/api/ApiFormatBase.php', 'ApiFormatDbg' => __DIR__ . '/includes/api/ApiFormatDbg.php', - 'ApiFormatDump' => __DIR__ . '/includes/api/ApiFormatDump.php', 'ApiFormatFeedWrapper' => __DIR__ . '/includes/api/ApiFormatFeedWrapper.php', 'ApiFormatJson' => __DIR__ . '/includes/api/ApiFormatJson.php', 'ApiFormatNone' => __DIR__ . '/includes/api/ApiFormatNone.php', 'ApiFormatPhp' => __DIR__ . '/includes/api/ApiFormatPhp.php', 'ApiFormatRaw' => __DIR__ . '/includes/api/ApiFormatRaw.php', 'ApiFormatTxt' => __DIR__ . '/includes/api/ApiFormatTxt.php', - 'ApiFormatWddx' => __DIR__ . '/includes/api/ApiFormatWddx.php', 'ApiFormatXml' => __DIR__ . '/includes/api/ApiFormatXml.php', 'ApiFormatXmlRsd' => __DIR__ . '/includes/api/ApiRsd.php', 'ApiFormatYaml' => __DIR__ . '/includes/api/ApiFormatYaml.php', diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php index 47c8128cc7..4d80163457 100644 --- a/includes/api/ApiFormatBase.php +++ b/includes/api/ApiFormatBase.php @@ -246,7 +246,7 @@ abstract class ApiFormatBase extends ApiBase { } /** - * To avoid code duplication with the deprecation of dbg, dump, txt, wddx, + * To avoid code duplication with the deprecation of dbg, txt * and yaml, this method is added to do the necessary work. It should be * removed when those deprecated formats are removed. */ @@ -312,7 +312,7 @@ abstract class ApiFormatBase extends ApiBase { // Escape everything first for full coverage $text = htmlspecialchars( $text ); - if ( $this->mFormat === 'XML' || $this->mFormat === 'WDDX' ) { + if ( $this->mFormat === 'XML' ) { // encode all comments or tags as safe blue strings $text = str_replace( '<', '<', $text ); $text = str_replace( '>', '>', $text ); diff --git a/includes/api/ApiFormatDump.php b/includes/api/ApiFormatDump.php deleted file mode 100644 index f34e1ae4d7..0000000000 --- a/includes/api/ApiFormatDump.php +++ /dev/null @@ -1,58 +0,0 @@ -markDeprecated(); - $data = $this->getResult()->getResultData( null, array( - 'BC' => array(), - 'Types' => array(), - 'Strip' => 'all', - ) ); - ob_start(); - var_dump( $data ); - $result = ob_get_contents(); - ob_end_clean(); - $this->printText( $result ); - } - - public function isDeprecated() { - return true; - } -} diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php deleted file mode 100644 index c18353fe45..0000000000 --- a/includes/api/ApiFormatWddx.php +++ /dev/null @@ -1,162 +0,0 @@ -@gmail.com" - * - * 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 - */ - -/** - * API WDDX output formatter - * @deprecated since 1.24 - * @ingroup API - */ -class ApiFormatWddx extends ApiFormatBase { - - public function getMimeType() { - return 'text/xml'; - } - - public function execute() { - $this->markDeprecated(); - - $data = $this->getResult()->getResultData( null, array( - 'BC' => array(), - 'Types' => array( 'AssocAsObject' => true ), - 'Strip' => 'all', - ) ); - - if ( !$this->getIsHtml() && !static::useSlowPrinter() ) { - $txt = wddx_serialize_value( $data ); - $txt = str_replace( - 'stdClass', - '', - $txt - ); - $this->printText( $txt ); - } else { - // Don't do newlines and indentation if we weren't asked - // for pretty output - $nl = ( $this->getIsHtml() ? "\n" : '' ); - $indstr = ( $this->getIsHtml() ? ' ' : '' ); - $this->printText( "$nl" ); - $this->printText( "$nl" ); - $this->printText( "$indstr
$nl" ); - $this->printText( "$indstr$nl" ); - $this->slowWddxPrinter( $data, 4 ); - $this->printText( "$indstr$nl" ); - $this->printText( "$nl" ); - } - } - - public static function useSlowPrinter() { - if ( !function_exists( 'wddx_serialize_value' ) ) { - return true; - } - - // Some versions of PHP have a broken wddx_serialize_value, see - // PHP bug 45314. Test encoding an affected character (U+00A0) - // to avoid this. - $expected = - "
\xc2\xa0"; - if ( wddx_serialize_value( "\xc2\xa0" ) !== $expected ) { - return true; - } - - // Some versions of HHVM don't correctly encode ampersands. - $expected = - "
&"; - if ( wddx_serialize_value( '&' ) !== $expected ) { - return true; - } - - // Some versions of HHVM don't correctly encode empty arrays as subvalues. - $expected = - "
"; - if ( wddx_serialize_value( array( array() ) ) !== $expected ) { - return true; - } - - // Some versions of HHVM don't correctly encode associative arrays with numeric keys. - $expected = - "
1"; - if ( wddx_serialize_value( array( 2 => 1 ) ) !== $expected ) { - return true; - } - - return false; - } - - /** - * Recursively go through the object and output its data in WDDX format. - * @param mixed $elemValue - * @param int $indent - */ - function slowWddxPrinter( $elemValue, $indent = 0 ) { - $indstr = ( $this->getIsHtml() ? str_repeat( ' ', $indent ) : '' ); - $indstr2 = ( $this->getIsHtml() ? str_repeat( ' ', $indent + 2 ) : '' ); - $nl = ( $this->getIsHtml() ? "\n" : '' ); - - if ( is_array( $elemValue ) ) { - $cnt = count( $elemValue ); - if ( $cnt != 0 && array_keys( $elemValue ) !== range( 0, $cnt - 1 ) ) { - $elemValue = (object)$elemValue; - } - } - - if ( is_array( $elemValue ) ) { - // Regular array - $this->printText( $indstr . Xml::element( 'array', array( - 'length' => count( $elemValue ) ), null ) . $nl ); - foreach ( $elemValue as $subElemValue ) { - $this->slowWddxPrinter( $subElemValue, $indent + 2 ); - } - $this->printText( "$indstr$nl" ); - } elseif ( is_object( $elemValue ) ) { - // Associative array () - $this->printText( "$indstr$nl" ); - foreach ( $elemValue as $subElemName => $subElemValue ) { - $this->printText( $indstr2 . Xml::element( 'var', array( - 'name' => $subElemName - ), null ) . $nl ); - $this->slowWddxPrinter( $subElemValue, $indent + 4 ); - $this->printText( "$indstr2$nl" ); - } - $this->printText( "$indstr$nl" ); - } elseif ( is_int( $elemValue ) || is_float( $elemValue ) ) { - $this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl ); - } elseif ( is_string( $elemValue ) ) { - $this->printText( $indstr . Xml::element( 'string', null, $elemValue, false ) . $nl ); - } elseif ( is_bool( $elemValue ) ) { - $this->printText( $indstr . Xml::element( 'boolean', - array( 'value' => $elemValue ? 'true' : 'false' ) ) . $nl - ); - } elseif ( $elemValue === null ) { - $this->printText( $indstr . Xml::element( 'null', array() ) . $nl ); - } else { - ApiBase::dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) ); - } - } - - public function isDeprecated() { - return true; - } -} diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index a8db20cedf..f2059d759e 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -100,8 +100,6 @@ class ApiMain extends ApiBase { 'jsonfm' => 'ApiFormatJson', 'php' => 'ApiFormatPhp', 'phpfm' => 'ApiFormatPhp', - 'wddx' => 'ApiFormatWddx', - 'wddxfm' => 'ApiFormatWddx', 'xml' => 'ApiFormatXml', 'xmlfm' => 'ApiFormatXml', 'yaml' => 'ApiFormatYaml', @@ -111,8 +109,6 @@ class ApiMain extends ApiBase { 'txtfm' => 'ApiFormatTxt', 'dbg' => 'ApiFormatDbg', 'dbgfm' => 'ApiFormatDbg', - 'dump' => 'ApiFormatDump', - 'dumpfm' => 'ApiFormatDump', 'none' => 'ApiFormatNone', ); diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 6d1b1ec967..8a1eb963e3 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1117,8 +1117,6 @@ "apihelp-format-example-generic": "Format the query result in the $1 format.", "apihelp-dbg-description": "Output data in PHP's var_export() format.", "apihelp-dbgfm-description": "Output data in PHP's var_export() format (pretty-print in HTML).", - "apihelp-dump-description": "Output data in PHP's var_dump() format.", - "apihelp-dumpfm-description": "Output data in PHP's var_dump() format (pretty-print in HTML).", "apihelp-json-description": "Output data in JSON format.", "apihelp-json-param-callback": "If specified, wraps the output into a given function call. For safety, all user-specific data will be restricted.", "apihelp-json-param-utf8": "If specified, encodes most (but not all) non-ASCII characters as UTF-8 instead of replacing them with hexadecimal escape sequences. Default when formatversion is not 1.", @@ -1132,8 +1130,6 @@ "apihelp-rawfm-description": "Output data with the debugging elements in JSON format (pretty-print in HTML).", "apihelp-txt-description": "Output data in PHP's print_r() format.", "apihelp-txtfm-description": "Output data in PHP's print_r() format (pretty-print in HTML).", - "apihelp-wddx-description": "Output data in WDDX format.", - "apihelp-wddxfm-description": "Output data in WDDX format (pretty-print in HTML).", "apihelp-xml-description": "Output data in XML format.", "apihelp-xml-param-xslt": "If specified, adds the named page as an XSL stylesheet. The value must be a title in the {{ns:mediawiki}} namespace ending in .xsl.", "apihelp-xml-param-includexmlnamespace": "If specified, adds an XML namespace.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index c436d4f9e2..7a0f702f91 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1025,8 +1025,6 @@ "apihelp-format-example-generic": "{{doc-apihelp-example|format|params=* $1 - Format name|paramstart=2|noseealso=1}}", "apihelp-dbg-description": "{{doc-apihelp-description|dbg|seealso=* {{msg-mw|apihelp-dbgfm-description}}}}", "apihelp-dbgfm-description": "{{doc-apihelp-description|dbgfm|seealso=* {{msg-mw|apihelp-dbg-description}}}}", - "apihelp-dump-description": "{{doc-apihelp-description|dump|seealso=* {{msg-mw|apihelp-dumpfm-description}}}}", - "apihelp-dumpfm-description": "{{doc-apihelp-description|dumpfm|seealso=* {{msg-mw|apihelp-dump-description}}}}", "apihelp-json-description": "{{doc-apihelp-description|json|seealso=* {{msg-mw|apihelp-jsonfm-description}}}}", "apihelp-json-param-callback": "{{doc-apihelp-param|json|callback}}", "apihelp-json-param-utf8": "{{doc-apihelp-param|json|utf8}}", @@ -1040,8 +1038,6 @@ "apihelp-rawfm-description": "{{doc-apihelp-description|rawfm|seealso=* {{msg-mw|apihelp-raw-description}}}}", "apihelp-txt-description": "{{doc-apihelp-description|txt|seealso=* {{msg-mw|apihelp-txtfm-description}}}}", "apihelp-txtfm-description": "{{doc-apihelp-description|txtfm|seealso=* {{msg-mw|apihelp-txt-description}}}}", - "apihelp-wddx-description": "{{doc-apihelp-description|wddx|seealso=* {{msg-mw|apihelp-wddxfm-description}}}}", - "apihelp-wddxfm-description": "{{doc-apihelp-description|wddxfm|seealso=* {{msg-mw|apihelp-wddx-description}}}}", "apihelp-xml-description": "{{doc-apihelp-description|xml|seealso=* {{msg-mw|apihelp-xmlfm-description}}}}", "apihelp-xml-param-xslt": "{{doc-apihelp-param|xml|xslt}}", "apihelp-xml-param-includexmlnamespace": "{{doc-apihelp-param|xml|includexmlnamespace}}", diff --git a/tests/phpunit/includes/api/format/ApiFormatDumpTest.php b/tests/phpunit/includes/api/format/ApiFormatDumpTest.php deleted file mode 100644 index c0f67f8d82..0000000000 --- a/tests/phpunit/includes/api/format/ApiFormatDumpTest.php +++ /dev/null @@ -1,63 +0,0 @@ - true ) ), - ); - } - - $warning = "\n [\"warnings\"]=>\n array(1) {\n [\"dump\"]=>\n array(1) {\n [\"*\"]=>\n" . - " string(64) \"format=dump has been deprecated. Please use format=json instead.\"\n" . - " }\n }"; - - return array( - // Basic types - array( array( null ), "array(2) {{$warning}\n [0]=>\n NULL\n}\n" ), - array( array( true ), "array(2) {{$warning}\n [0]=>\n string(0) \"\"\n}\n" ), - array( array( false ), "array(1) {{$warning}\n}\n" ), - array( array( true, ApiResult::META_BC_BOOLS => array( 0 ) ), - "array(2) {{$warning}\n [0]=>\n bool(true)\n}\n" ), - array( array( false, ApiResult::META_BC_BOOLS => array( 0 ) ), - "array(2) {{$warning}\n [0]=>\n bool(false)\n}\n" ), - array( array( 42 ), "array(2) {{$warning}\n [0]=>\n int(42)\n}\n" ), - array( array( 42.5 ), "array(2) {{$warning}\n [0]=>\n float(42.5)\n}\n" ), - array( array( 1e42 ), "array(2) {{$warning}\n [0]=>\n float(1.0E+42)\n}\n" ), - array( array( 'foo' ), "array(2) {{$warning}\n [0]=>\n string(3) \"foo\"\n}\n" ), - array( array( 'fóo' ), "array(2) {{$warning}\n [0]=>\n string(4) \"fóo\"\n}\n" ), - - // Arrays - array( array( array() ), "array(2) {{$warning}\n [0]=>\n array(0) {\n }\n}\n" ), - array( array( array( 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [0]=>\n int(1)\n }\n}\n" ), - array( array( array( 'x' => 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [\"x\"]=>\n int(1)\n }\n}\n" ), - array( array( array( 2 => 1 ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [2]=>\n int(1)\n }\n}\n" ), - array( array( (object)array() ), "array(2) {{$warning}\n [0]=>\n array(0) {\n }\n}\n" ), - array( array( array( 1, ApiResult::META_TYPE => 'assoc' ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [0]=>\n int(1)\n }\n}\n" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'array' ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [0]=>\n int(1)\n }\n}\n" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'kvp' ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [\"x\"]=>\n int(1)\n }\n}\n" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ) ), - "array(2) {{$warning}\n [0]=>\n array(1) {\n [0]=>\n array(2) {\n [\"key\"]=>\n string(1) \"x\"\n [\"*\"]=>\n int(1)\n }\n }\n}\n" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'BCarray' ) ), "array(2) {{$warning}\n [0]=>\n array(1) {\n [\"x\"]=>\n int(1)\n }\n}\n" ), - array( array( array( 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ) ), "array(2) {{$warning}\n [0]=>\n array(2) {\n [0]=>\n string(1) \"a\"\n [1]=>\n string(1) \"b\"\n }\n}\n" ), - - // Content - array( array( 'content' => 'foo', ApiResult::META_CONTENT => 'content' ), - "array(2) {{$warning}\n [\"*\"]=>\n string(3) \"foo\"\n}\n" ), - - // BC Subelements - array( array( 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => array( 'foo' ) ), - "array(2) {{$warning}\n [\"foo\"]=>\n array(1) {\n [\"*\"]=>\n string(3) \"foo\"\n }\n}\n" ), - ); - } - -} diff --git a/tests/phpunit/includes/api/format/ApiFormatWddxTest.php b/tests/phpunit/includes/api/format/ApiFormatWddxTest.php deleted file mode 100644 index 07111300ae..0000000000 --- a/tests/phpunit/includes/api/format/ApiFormatWddxTest.php +++ /dev/null @@ -1,80 +0,0 @@ - true ) ) - ); - } - return self::provideEncoding(); - } - - public static function provideEncoding() { - $p = '
format=wddx has been deprecated. Please use format=json instead.'; - $s = ''; - - return array( - // Basic types - array( array( null ), "{$p}{$s}" ), - array( array( true ), "{$p}{$s}" ), - array( array( false ), "{$p}{$s}" ), - array( array( true, ApiResult::META_BC_BOOLS => array( 0 ) ), - "{$p}{$s}" ), - array( array( false, ApiResult::META_BC_BOOLS => array( 0 ) ), - "{$p}{$s}" ), - array( array( 42 ), "{$p}42{$s}" ), - array( array( 42.5 ), "{$p}42.5{$s}" ), - array( array( 1e42 ), "{$p}1.0E+42{$s}" ), - array( array( 'foo' ), "{$p}foo{$s}" ), - array( array( 'fóo' ), "{$p}fóo{$s}" ), - - // Arrays and objects - array( array( array() ), "{$p}{$s}" ), - array( array( array( 1 ) ), "{$p}1{$s}" ), - array( array( array( 'x' => 1 ) ), "{$p}1{$s}" ), - array( array( array( 2 => 1 ) ), "{$p}1{$s}" ), - array( array( (object)array() ), "{$p}{$s}" ), - array( array( array( 1, ApiResult::META_TYPE => 'assoc' ) ), "{$p}1{$s}" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'array' ) ), "{$p}1{$s}" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'kvp' ) ), "{$p}1{$s}" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ) ), - "{$p}x1{$s}" ), - array( array( array( 'x' => 1, ApiResult::META_TYPE => 'BCarray' ) ), "{$p}1{$s}" ), - array( array( array( 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ) ), "{$p}ab{$s}" ), - - // Content - array( array( 'content' => 'foo', ApiResult::META_CONTENT => 'content' ), - "{$p}foo{$s}" ), - - // BC Subelements - array( array( 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => array( 'foo' ) ), - "{$p}foo{$s}" ), - ); - } - - /** - * @dataProvider provideEncoding - */ - public function testSlowEncoding( array $data, $expect, array $params = array() ) { - // Adjust expectation for differences between fast and slow printers. - $expect = str_replace( '\'', '"', $expect ); - $expect = str_replace( '/>', ' />', $expect ); - $expect = '' . $expect; - - $this->assertSame( $expect, $this->encodeData( $params, $data, 'ApiFormatWddxTest_SlowWddx' ) ); - } -} - -class ApiFormatWddxTest_SlowWddx extends ApiFormatWddx { - public static function useSlowPrinter() { - return true; - } -} -- 2.20.1