Merge "Revert "ApiSandbox: Display params as JSON on request page""
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index 9dfa97c..7bf848f 100644 (file)
@@ -188,9 +188,14 @@ class ParserOutput extends CacheTime {
         */
        private $mExtensionData = [];
 
-       /** @var array $mLimitReportData Parser limit report data. */
+       /**
+        * @var array $mLimitReportData Parser limit report data.
+        */
        private $mLimitReportData = [];
 
+       /** @var array Parser limit report data for JSON */
+       private $mLimitReportJSData = [];
+
        /**
         * @var array $mParseStartTime Timestamps for getTimeSinceStart().
         */
@@ -213,7 +218,7 @@ class ParserOutput extends CacheTime {
        private $mMaxAdaptiveExpiry = INF;
 
        const EDITSECTION_REGEX =
-               '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#';
+               '#<(?:mw:)?editsection page="(.*?)" section="(.*?)"(?:/>|>(.*?)(</(?:mw:)?editsection>))#s';
 
        // finalizeAdaptiveCacheExpiry() uses TTL = MAX( m * PARSE_TIME + b, MIN_AR_TTL)
        // Current values imply that m=3933.333333 and b=-333.333333
@@ -409,6 +414,10 @@ class ParserOutput extends CacheTime {
                return $this->mLimitReportData;
        }
 
+       public function getLimitReportJSData() {
+               return $this->mLimitReportJSData;
+       }
+
        public function getTOCEnabled() {
                return $this->mTOCEnabled;
        }
@@ -821,7 +830,6 @@ class ParserOutput extends CacheTime {
         * @code
         *    $parser->getOutput()->my_ext_foo = '...';
         * @endcode
-        *
         */
        public function setProperty( $name, $value ) {
                $this->mProperties[$name] = $value;
@@ -991,15 +999,25 @@ class ParserOutput extends CacheTime {
        /**
         * Sets parser limit report data for a key
         *
-        * If $value consist of a list of two floats, it will be interpreted as
-        * (actual value, maximum allowed value). The presence of a "-" in $key will cause
-        * the first part of the key to be interpreted as a namespace.
+        * The key is used as the prefix for various messages used for formatting:
+        *  - $key: The label for the field in the limit report
+        *  - $key-value-text: Message used to format the value in the "NewPP limit
+        *      report" HTML comment. If missing, uses $key-format.
+        *  - $key-value-html: Message used to format the value in the preview
+        *      limit report table. If missing, uses $key-format.
+        *  - $key-value: Message used to format the value. If missing, uses "$1".
+        *
+        * Note that all values are interpreted as wikitext, and so should be
+        * encoded with htmlspecialchars() as necessary, but should avoid complex
+        * HTML for sanity of display in the "NewPP limit report" comment.
         *
         * @since 1.22
-        * @param string $key Data key
-        * @param mixed $value Data value One of (float, string, bool, JSON serializable array)
+        * @param string $key Message key
+        * @param mixed $value Appropriate for Message::params()
         */
        public function setLimitReportData( $key, $value ) {
+               $this->mLimitReportData[$key] = $value;
+
                if ( is_array( $value ) ) {
                        if ( array_keys( $value ) === [ 0, 1 ]
                                && is_numeric( $value[0] )
@@ -1015,9 +1033,9 @@ class ParserOutput extends CacheTime {
 
                if ( strpos( $key, '-' ) ) {
                        list( $ns, $name ) = explode( '-', $key, 2 );
-                       $this->mLimitReportData[$ns][$name] = $data;
+                       $this->mLimitReportJSData[$ns][$name] = $data;
                } else {
-                       $this->mLimitReportData[$key] = $data;
+                       $this->mLimitReportJSData[$key] = $data;
                }
        }