Merge "RCFilters: Add title attribute to [x] button"
[lhc/web/wiklou.git] / includes / parser / ParserOutput.php
index b0768b6..2dd4085 100644 (file)
@@ -193,6 +193,9 @@ class ParserOutput extends CacheTime {
         */
        private $mLimitReportData = [];
 
+       /** @var array Parser limit report data for JSON */
+       private $mLimitReportJSData = [];
+
        /**
         * @var array $mParseStartTime Timestamps for getTimeSinceStart().
         */
@@ -208,14 +211,14 @@ class ParserOutput extends CacheTime {
         */
        private $mFlags = [];
 
-       /** @var integer|null Assumed rev ID for {{REVISIONID}} if no revision is set */
+       /** @var int|null Assumed rev ID for {{REVISIONID}} if no revision is set */
        private $mSpeculativeRevId;
 
-       /** @var integer Upper bound of expiry based on parse duration */
+       /** @var int Upper bound of expiry based on parse duration */
        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
@@ -250,7 +253,7 @@ class ParserOutput extends CacheTime {
                $text = $this->mText;
                if ( $this->mEditSectionTokens ) {
                        $text = preg_replace_callback(
-                               ParserOutput::EDITSECTION_REGEX,
+                               self::EDITSECTION_REGEX,
                                function ( $m ) {
                                        global $wgOut, $wgLang;
                                        $editsectionPage = Title::newFromText( htmlspecialchars_decode( $m[1] ) );
@@ -271,7 +274,7 @@ class ParserOutput extends CacheTime {
                                $text
                        );
                } else {
-                       $text = preg_replace( ParserOutput::EDITSECTION_REGEX, '', $text );
+                       $text = preg_replace( self::EDITSECTION_REGEX, '', $text );
                }
 
                // If you have an old cached version of this class - sorry, you can't disable the TOC
@@ -288,7 +291,7 @@ class ParserOutput extends CacheTime {
        }
 
        /**
-        * @param integer $id
+        * @param int $id
         * @since 1.28
         */
        public function setSpeculativeRevIdUsed( $id ) {
@@ -411,6 +414,10 @@ class ParserOutput extends CacheTime {
                return $this->mLimitReportData;
        }
 
+       public function getLimitReportJSData() {
+               return $this->mLimitReportJSData;
+       }
+
        public function getTOCEnabled() {
                return $this->mTOCEnabled;
        }
@@ -528,6 +535,10 @@ class ParserOutput extends CacheTime {
                # We don't register links pointing to our own server, unless... :-)
                global $wgServer, $wgRegisterInternalExternals;
 
+               # Replace unnecessary URL escape codes with the referenced character
+               # This prevents spammers from hiding links from the filters
+               $url = parser::normalizeLinkUrl( $url );
+
                $registerExternalLink = true;
                if ( !$wgRegisterInternalExternals ) {
                        $registerExternalLink = !self::isLinkInternal( $wgServer, $url );
@@ -689,18 +700,20 @@ class ParserOutput extends CacheTime {
         * to SpecialTrackingCategories::$coreTrackingCategories, and extensions
         * should add to "TrackingCategories" in their extension.json.
         *
+        * @todo Migrate some code to TrackingCategories
+        *
         * @param string $msg Message key
         * @param Title $title title of the page which is being tracked
         * @return bool Whether the addition was successful
         * @since 1.25
         */
        public function addTrackingCategory( $msg, $title ) {
-               if ( $title->getNamespace() === NS_SPECIAL ) {
+               if ( $title->isSpecialPage() ) {
                        wfDebug( __METHOD__ . ": Not adding tracking category $msg to special page!\n" );
                        return false;
                }
 
-               // Important to parse with correct title (bug 31469)
+               // Important to parse with correct title (T33469)
                $cat = wfMessage( $msg )
                        ->title( $title )
                        ->inContentLanguage()
@@ -1010,6 +1023,26 @@ class ParserOutput extends CacheTime {
         */
        public function setLimitReportData( $key, $value ) {
                $this->mLimitReportData[$key] = $value;
+
+               if ( is_array( $value ) ) {
+                       if ( array_keys( $value ) === [ 0, 1 ]
+                               && is_numeric( $value[0] )
+                               && is_numeric( $value[1] )
+                       ) {
+                               $data = [ 'value' => $value[0], 'limit' => $value[1] ];
+                       } else {
+                               $data = $value;
+                       }
+               } else {
+                       $data = $value;
+               }
+
+               if ( strpos( $key, '-' ) ) {
+                       list( $ns, $name ) = explode( '-', $key, 2 );
+                       $this->mLimitReportJSData[$ns][$name] = $data;
+               } else {
+                       $this->mLimitReportJSData[$key] = $data;
+               }
        }
 
        /**
@@ -1042,7 +1075,7 @@ class ParserOutput extends CacheTime {
        /**
         * Lower the runtime adaptive TTL to at most this value
         *
-        * @param integer $ttl
+        * @param int $ttl
         * @since 1.28
         */
        public function updateRuntimeAdaptiveExpiry( $ttl ) {