Merge "Fix API output formatting (change lines delimited with * as bold)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 20 Feb 2013 14:55:45 +0000 (14:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 20 Feb 2013 14:55:45 +0000 (14:55 +0000)
1  2 
includes/api/ApiFormatBase.php

@@@ -58,7 -58,7 +58,7 @@@ abstract class ApiFormatBase extends Ap
         * This method is not called if getIsHtml() returns true.
         * @return string
         */
 -      public abstract function getMimeType();
 +      abstract public function getMimeType();
  
        /**
         * Whether this formatter needs raw data such as _element tags
  
        /**
         * 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;
                }
  <?php
  
  
 -                      if ( !$isError ) {
 +                      if ( !$isHelpScreen ) {
  ?>
  <br />
  <small>
@@@ -177,18 -175,15 +177,18 @@@ To see the non HTML representation of t
  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
  
 -
 +                      }
                }
        }
  
        }
  
        /**
-        * Sets whether the pretty-printer should format *bold* and $italics$
+        * Sets whether the pretty-printer should format *bold*
         * @param $help bool
         */
        public function setHelp( $help = true ) {
        protected function formatHTML( $text ) {
                // Escape everything first for full coverage
                $text = htmlspecialchars( $text );
                // encode all comments or tags as safe blue strings
                $text = str_replace( '&lt;', '<span style="color:blue;">&lt;', $text );
                $text = str_replace( '&gt;', '&gt;</span>', $text );
-               // identify URLs
-               $protos = wfUrlProtocolsWithoutProtRel();
-               // This regex hacks around bug 13218 (&quot; included in the URL)
-               $text = preg_replace( "#(((?i)$protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
                // identify requests to api.php
                $text = preg_replace( "#api\\.php\\?[^ <\n\t]+#", '<a href="\\0">\\0</a>', $text );
                if ( $this->mHelp ) {
                        // make strings inside * bold
                        $text = preg_replace( "#\\*[^<>\n]+\\*#", '<b>\\0</b>', $text );
-                       // make strings inside $ italic
-                       $text = preg_replace( "#\\$[^<>\n]+\\$#", '<b><i>\\0</i></b>', $text );
                }
+               // identify URLs
+               $protos = wfUrlProtocolsWithoutProtRel();
+               // This regex hacks around bug 13218 (&quot; included in the URL)
+               $text = preg_replace( "#(((?i)$protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
  
                /**
                 * Temporary fix for bad links in help messages. As a special case,
        public function getDescription() {
                return $this->getIsHtml() ? ' (pretty-print in HTML)' : '';
        }
 -
 -      public static function getBaseVersion() {
 -              return __CLASS__ . ': $Id$';
 -      }
  }
  
  /**
@@@ -382,4 -378,8 +379,4 @@@ class ApiFormatFeedWrapper extends ApiF
                        ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
                }
        }
 -
 -      public function getVersion() {
 -              return __CLASS__ . ': $Id$';
 -      }
  }