(bug 11296) Introduced special case pretty-printer rendering of the help document...
authorDaniel Cannon <amidaniel@users.mediawiki.org>
Tue, 18 Sep 2007 22:10:09 +0000 (22:10 +0000)
committerDaniel Cannon <amidaniel@users.mediawiki.org>
Tue, 18 Sep 2007 22:10:09 +0000 (22:10 +0000)
RELEASE-NOTES
includes/api/ApiFormatBase.php
includes/api/ApiMain.php

index 5a9945a..addd0d4 100644 (file)
@@ -66,6 +66,8 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API
 
 * (bug 11275) Enable descending sort in categorymembers
 * (bug 11308) Allow the API to output the image metadata
+* (bug 11296) Temporary fix for escaping of ampersands inside links in pretty-printed
+  help document.
 
 === Languages updated in 1.12 ===
 
index b69ebaf..cead9fc 100644 (file)
@@ -35,7 +35,7 @@ if (!defined('MEDIAWIKI')) {
  */
 abstract class ApiFormatBase extends ApiBase {
 
-       private $mIsHtml, $mFormat;
+       private $mIsHtml, $mFormat, $mUnescapeAmps;
 
        /**
        * Create a new instance of the formatter.
@@ -68,6 +68,18 @@ abstract class ApiFormatBase extends ApiBase {
                return false;
        }
 
+       /**
+        * Specify whether or not ampersands should be escaped to '&amp;' when rendering. This
+        * should only be set to true for the help message when rendered in the default (xmlfm)
+        * format. This is a temporary special-case fix that should be removed once the help
+        * has been reworked to use a fully html interface.
+        *
+        * @param boolean Whether or not ampersands should be escaped.
+        */
+       public function setUnescapeAmps ( $b ) {
+               $this->mUnescapeAmps = $b;
+       }
+
        /**
         * Returns true when an HTML filtering printer should be used.
         * The default implementation assumes that formats ending with 'fm' 
@@ -161,6 +173,12 @@ See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or
                // Escape everything first for full coverage
                $text = htmlspecialchars($text);
                
+               /* Temporary fix for bad links in help messages. As a special case, ampersands
+                * are not escaped in the help message. Should be removed once we have completed
+                * a fully-html version of the help message. */
+               if ( $this->mUnescapeAmps )
+                       $text = ereg_replace ( '&amp;', '&', $text );
+
                // encode all comments or tags as safe blue strings
                $text = preg_replace('/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text);
                // identify URLs
index 87e7766..3e8700f 100644 (file)
@@ -319,6 +319,14 @@ class ApiMain extends ApiBase {
                $printer = $this->mPrinter;
                $printer->profileIn();
                $printer->initPrinter($isError);
+       
+               /* If the help message is requested in the default (xmlfm) format,
+                * tell the printer not to escape ampersands so that our links do
+                * not break. */
+               $params = $this->extractRequestParams();
+               $printer->setUnescapeAmps ( $this->mAction == 'help' 
+                               && $params['format'] = ApiMain::API_DEFAULT_FORMAT );
+
                $printer->execute();
                $printer->closePrinter();
                $printer->profileOut();