Merge "Allow API results to wrap long lines"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 19 Feb 2013 21:42:25 +0000 (21:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 19 Feb 2013 21:42:25 +0000 (21:42 +0000)
includes/api/ApiFormatBase.php
includes/api/ApiMain.php

index 5bbc62e..b9f48b3 100644 (file)
@@ -123,11 +123,13 @@ abstract class ApiFormatBase extends ApiBase {
 
        /**
         * Initialize the printer function and prepare the output headers, etc.
-        * This method must be the first outputing method during execution.
-        * A help screen's header is printed for the HTML-based output
-        * @param $isError bool Whether an error message is printed
+        * This method must be the first outputting method during execution.
+        * A human-targeted notice about available formats is printed for the HTML-based output,
+        * except for help screens (caused by either an error in the API parameters,
+        * the calling of action=help, or requesting the root script api.php).
+        * @param $isHelpScreen bool Whether a help screen is going to be shown
         */
-       function initPrinter( $isError ) {
+       function initPrinter( $isHelpScreen ) {
                if ( $this->mDisabled ) {
                        return;
                }
@@ -164,7 +166,7 @@ abstract class ApiFormatBase extends ApiBase {
 <?php
 
 
-                       if ( !$isError ) {
+                       if ( !$isHelpScreen ) {
 ?>
 <br />
 <small>
@@ -175,15 +177,18 @@ To see the non HTML representation of the <?php echo( $this->mFormat ); ?> forma
 See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>, or
 <a href='<?php echo( $script ); ?>'>API help</a> for more information.
 </small>
+<pre style='white-space: pre-wrap;'>
 <?php
 
 
-                       }
+                       } else { // don't wrap the contents of the <pre> for help screens
+                                 // because these are actually formatted to rely on
+                                 // the monospaced font for layout purposes
 ?>
 <pre>
 <?php
 
-
+                       }
                }
        }
 
index 953cec8..fed515b 100644 (file)
@@ -948,10 +948,10 @@ class ApiMain extends ApiBase {
                 * tell the printer not to escape ampersands so that our links do
                 * not break.
                 */
-               $printer->setUnescapeAmps( ( $this->mAction == 'help' || $isError )
-                               && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
+               $isHelp = $isError || $this->mAction == 'help';
+               $printer->setUnescapeAmps( $isHelp && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
 
-               $printer->initPrinter( $isError );
+               $printer->initPrinter( $isHelp );
 
                $printer->execute();
                $printer->closePrinter();