API: Clean up invalid UTF-8 in the result before feeding it to the formatter. This...
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 14 Jan 2009 21:22:00 +0000 (21:22 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 14 Jan 2009 21:22:00 +0000 (21:22 +0000)
RELEASE-NOTES
includes/api/ApiMain.php
includes/api/ApiResult.php

index 06621c7..4feeb46 100644 (file)
@@ -50,6 +50,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions
   and listing all deleted pages possible
 * (bug 16844) Added clcategories parameter to prop=categories
+* (bug 15261, 16262) API no longer outputs invalid UTF-8
 
 === Languages updated in 1.15 ===
 
index e94f173..ce4547a 100644 (file)
@@ -438,6 +438,7 @@ class ApiMain extends ApiBase {
         * Print results using the current printer
         */
        protected function printResult($isError) {
+               $this->getResult()->cleanupUTF8();
                $printer = $this->mPrinter;
                $printer->profileIn();
 
index a3a1209..3071015 100644 (file)
@@ -186,6 +186,15 @@ class ApiResult extends ApiBase {
                        ApiResult :: setElement($data, $name, $value);  // Add named element
        }
 
+       /**
+        * Ensure all values in this result are valid UTF-8.
+        */
+       public function cleanUpUTF8()
+       {
+               $data = & $this->getData();
+               array_walk_recursive($data, array('UtfNormal', 'cleanUp'));
+       }
+
        public function execute() {
                ApiBase :: dieDebug(__METHOD__, 'execute() is not supported on Result object');
        }