ApiFormatXml: remove broken xmldoublequote param
authorKevin Israel <pleasestand@live.com>
Tue, 9 Apr 2013 00:25:47 +0000 (20:25 -0400)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 10 Apr 2013 00:32:43 +0000 (00:32 +0000)
r55641 was a refactoring of ApiFormatXml::recXmlPrint() that added
a $doublequote parameter, yet the parameter was not actually passed
along in recursive calls, rendering the formatter's xmldoublequote
parameter useless.

XPath support was the sole reason this parameter was added. It was
argued that because in the XPath 1.0 grammar, a Literal is:

    '"' [^"]* '"' | "'" [^']* "'"

it is not possible to match attribute values that contain both an
apostrophe and a double quote.

However, conforming XPath implementations include a concat() function
that can be used to work around this limitation. Furthermore, XPath 2.0
allows escaping a double-quoted " as "" (and a single-quoted ' as '').

Because there was no Bugzilla report (other than mine) filed in the
last 3-1/2 years, and working around the XPath flaw is possible, I
think it's safe to remove the parameter. The worst that could happen
is that a not-very-robust API client chokes on the "Unrecognized
parameter" warning.

Bug: 46626
Change-Id: I9a4d8c13b78ffd2634d03c8c8b4bbeff69f4bc08

RELEASE-NOTES-1.22
includes/api/ApiFormatXml.php

index 95da63b..116c58e 100644 (file)
@@ -17,6 +17,9 @@ production.
 === Bug fixes in 1.22 ===
 
 === API changes in 1.22 ===
+* (bug 46626) xmldoublequote parameter was removed. Because of a bug, the
+  parameter has had no effect since MediaWiki 1.16, and so its removal is
+  unlikely to impact existing clients.
 
 === Languages updated in 1.22===
 
index 183d48c..f9b85ef 100644 (file)
@@ -32,7 +32,6 @@ class ApiFormatXml extends ApiFormatBase {
 
        private $mRootElemName = 'api';
        public static $namespace = 'http://www.mediawiki.org/xml/api/';
-       private $mDoubleQuote = false;
        private $mIncludeNamespace = false;
        private $mXslt = null;
 
@@ -50,7 +49,6 @@ class ApiFormatXml extends ApiFormatBase {
 
        public function execute() {
                $params = $this->extractRequestParams();
-               $this->mDoubleQuote = $params['xmldoublequote'];
                $this->mIncludeNamespace = $params['includexmlnamespace'];
                $this->mXslt = $params['xslt'];
 
@@ -71,8 +69,7 @@ class ApiFormatXml extends ApiFormatBase {
                $this->printText(
                        self::recXmlPrint( $this->mRootElemName,
                                $data,
-                               $this->getIsHtml() ? - 2 : null,
-                               $this->mDoubleQuote
+                               $this->getIsHtml() ? - 2 : null
                        )
                );
        }
@@ -117,11 +114,10 @@ class ApiFormatXml extends ApiFormatBase {
         * @param $elemName
         * @param $elemValue
         * @param $indent
-        * @param $doublequote bool
         *
         * @return string
         */
-       public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) {
+       public static function recXmlPrint( $elemName, $elemValue, $indent ) {
                $retval = '';
                if ( !is_null( $indent ) ) {
                        $indent += 2;
@@ -134,9 +130,6 @@ class ApiFormatXml extends ApiFormatBase {
                if ( is_array( $elemValue ) ) {
                        if ( isset( $elemValue['*'] ) ) {
                                $subElemContent = $elemValue['*'];
-                               if ( $doublequote ) {
-                                       $subElemContent = Sanitizer::encodeAttribute( $subElemContent );
-                               }
                                unset( $elemValue['*'] );
 
                                // Add xml:space="preserve" to the
@@ -157,10 +150,6 @@ class ApiFormatXml extends ApiFormatBase {
                        $indElements = array();
                        $subElements = array();
                        foreach ( $elemValue as $subElemId => & $subElemValue ) {
-                               if ( is_string( $subElemValue ) && $doublequote ) {
-                                       $subElemValue = Sanitizer::encodeAttribute( $subElemValue );
-                               }
-
                                if ( is_int( $subElemId ) ) {
                                        $indElements[] = $subElemValue;
                                        unset( $elemValue[$subElemId] );
@@ -226,7 +215,6 @@ class ApiFormatXml extends ApiFormatBase {
 
        public function getAllowedParams() {
                return array(
-                       'xmldoublequote' => false,
                        'xslt' => null,
                        'includexmlnamespace' => false,
                );
@@ -234,7 +222,6 @@ class ApiFormatXml extends ApiFormatBase {
 
        public function getParamDescription() {
                return array(
-                       'xmldoublequote' => 'If specified, double quotes all attributes and content',
                        'xslt' => 'If specified, adds <xslt> as stylesheet. This should be a wiki page '
                                . 'in the MediaWiki namespace whose page name ends with ".xsl"',
                        'includexmlnamespace' => 'If specified, adds an XML namespace'