Merge "mediawiki.util: Add mw.log.deprecate to #jsMessage"
[lhc/web/wiklou.git] / includes / api / ApiFormatBase.php
index 49a02fe..15b97d8 100644 (file)
@@ -36,7 +36,7 @@ abstract class ApiFormatBase extends ApiBase {
        /**
         * Constructor
         * If $format ends with 'fm', pretty-print the output in HTML.
-        * @param $main ApiMain
+        * @param ApiMain $main
         * @param string $format Format name
         */
        public function __construct( $main, $format ) {
@@ -120,6 +120,16 @@ abstract class ApiFormatBase extends ApiBase {
                return $this->mDisabled;
        }
 
+       /**
+        * Whether this formatter can handle printing API errors. If this returns
+        * false, then on API errors the default printer will be instantiated.
+        * @since 1.23
+        * @return bool
+        */
+       public function canPrintErrors() {
+               return true;
+       }
+
        /**
         * Initialize the printer function and prepare the output headers, etc.
         * This method must be the first outputting method during execution.
@@ -214,7 +224,7 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
         * The main format printing function. Call it to output the result
         * string to the user. This function will automatically output HTML
         * when format name ends in 'fm'.
-        * @param $text string
+        * @param string $text
         */
        public function printText( $text ) {
                if ( $this->mDisabled ) {
@@ -245,7 +255,7 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
 
        /**
         * Set the flag to buffer the result instead of printing it.
-        * @param $value bool
+        * @param bool $value
         */
        public function setBufferResult( $value ) {
                $this->mBufferResult = $value;
@@ -253,7 +263,7 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
 
        /**
         * Sets whether the pretty-printer should format *bold*
-        * @param $help bool
+        * @param bool $help
         */
        public function setHelp( $help = true ) {
                $this->mHelp = $help;
@@ -262,7 +272,7 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
        /**
         * Pretty-print various elements in HTML format, such as xml tags and
         * URLs. This method also escapes characters like <
-        * @param $text string
+        * @param string $text
         * @return string
         */
        protected function formatHTML( $text ) {
@@ -275,8 +285,8 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
                // identify requests to api.php
                $text = preg_replace( '#^(\s*)(api\.php\?[^ <\n\t]+)$#m', '\1<a href="\2">\2</a>', $text );
                if ( $this->mHelp ) {
-                       // make strings inside * bold
-                       $text = preg_replace( "#\\*[^<>\n]+\\*#", '<b>\\0</b>', $text );
+                       // make lines inside * bold
+                       $text = preg_replace( '#^(\s*)(\*[^<>\n]+\*)(\s*)$#m', '$1<b>$2</b>$3', $text );
                }
 
                // Armor links (bug 61362)
@@ -343,8 +353,8 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
 
        /**
         * Call this method to initialize output data. See execute()
-        * @param $result ApiResult
-        * @param $feed object an instance of one of the $wgFeedClasses classes
+        * @param ApiResult $result
+        * @param object $feed An instance of one of the $wgFeedClasses classes
         * @param array $feedItems of FeedItem objects
         */
        public static function setResult( $result, $feed, $feedItems ) {
@@ -377,6 +387,15 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
                return true;
        }
 
+       /**
+        * ChannelFeed doesn't give us a method to print errors in a friendly
+        * manner, so just punt errors to the default printer.
+        * @return bool
+        */
+       public function canPrintErrors() {
+               return false;
+       }
+
        /**
         * This class expects the result data to be in a custom format set by self::setResult()
         * $result['_feed'] - an instance of one of the $wgFeedClasses classes