Remove ParserOptions::optionsHashPre30()
[lhc/web/wiklou.git] / includes / parser / ParserOptions.php
index f8ed63f..4809917 100644 (file)
@@ -60,7 +60,6 @@ class ParserOptions {
         */
        private static $inCacheKey = [
                'dateformat' => true,
-               'editsection' => true,
                'numberheadings' => true,
                'thumbsize' => true,
                'stubthreshold' => true,
@@ -82,6 +81,13 @@ class ParserOptions {
         */
        private $mTimestamp;
 
+       /**
+        * The edit section flag is in ParserOptions for historical reasons, but
+        * doesn't actually affect the parser output since Feb 2015.
+        * @var bool
+        */
+       private $mEditSection = true;
+
        /**
         * Stored user object
         * @var User
@@ -244,23 +250,6 @@ class ParserOptions {
                return $this->setOptionLegacy( 'enableImageWhitelist', $x );
        }
 
-       /**
-        * Create "edit section" links?
-        * @return bool
-        */
-       public function getEditSection() {
-               return $this->getOption( 'editsection' );
-       }
-
-       /**
-        * Create "edit section" links?
-        * @param bool|null $x New value (null is no change)
-        * @return bool Old value
-        */
-       public function setEditSection( $x ) {
-               return $this->setOptionLegacy( 'editsection', $x );
-       }
-
        /**
         * Automatically number headings?
         * @return bool
@@ -878,6 +867,23 @@ class ParserOptions {
                return wfSetVar( $this->mTimestamp, $x );
        }
 
+       /**
+        * Create "edit section" links?
+        * @return bool
+        */
+       public function getEditSection() {
+               return $this->mEditSection;
+       }
+
+       /**
+        * Create "edit section" links?
+        * @param bool|null $x New value (null is no change)
+        * @return bool Old value
+        */
+       public function setEditSection( $x ) {
+               return wfSetVar( $this->mEditSection, $x );
+       }
+
        /**
         * Set the redirect target.
         *
@@ -1041,7 +1047,6 @@ class ParserOptions {
                        // *UPDATE* ParserOptions::matches() if any of this changes as needed
                        self::$defaults = [
                                'dateformat' => null,
-                               'editsection' => true,
                                'tidy' => false,
                                'interfaceMessage' => false,
                                'targetLanguage' => null,
@@ -1256,16 +1261,31 @@ class ParserOptions {
        public function optionsHash( $forOptions, $title = null ) {
                global $wgRenderHashAppend;
 
+               $options = $this->options;
+               $defaults = self::getCanonicalOverrides() + self::getDefaults();
+               $inCacheKey = self::$inCacheKey;
+
+               // Historical hack: 'editsection' hasn't been a true parser option since
+               // Feb 2015 (instead the parser outputs a constant placeholder and post-parse
+               // processing handles the option). But Wikibase forces it in $forOptions
+               // and expects the cache key to still vary on it for T85252.
+               // @deprecated since 1.30, Wikibase should use addExtraKey() or something instead.
+               if ( in_array( 'editsection', $forOptions, true ) ) {
+                       $options['editsection'] = $this->mEditSection;
+                       $defaults['editsection'] = true;
+                       $inCacheKey['editsection'] = true;
+                       ksort( $inCacheKey );
+               }
+
                // We only include used options with non-canonical values in the key
                // so adding a new option doesn't invalidate the entire parser cache.
                // The drawback to this is that changing the default value of an option
                // requires manual invalidation of existing cache entries, as mentioned
                // in the docs on the relevant methods and hooks.
-               $defaults = self::getCanonicalOverrides() + self::getDefaults();
                $values = [];
-               foreach ( self::$inCacheKey as $option => $include ) {
+               foreach ( $inCacheKey as $option => $include ) {
                        if ( $include && in_array( $option, $forOptions, true ) ) {
-                               $v = $this->optionToString( $this->options[$option] );
+                               $v = $this->optionToString( $options[$option] );
                                $d = $this->optionToString( $defaults[$option] );
                                if ( $v !== $d ) {
                                        $values[] = "$option=$v";
@@ -1300,98 +1320,6 @@ class ParserOptions {
                return $confstr;
        }
 
-       /**
-        * Generate the hash used before MediaWiki 1.30
-        * @since 1.30
-        * @deprecated since 1.30. Do not use this unless you're ParserCache.
-        * @param array $forOptions
-        * @param Title $title Used to get the content language of the page (since r97636)
-        * @return string Page rendering hash
-        */
-       public function optionsHashPre30( $forOptions, $title = null ) {
-               global $wgRenderHashAppend;
-
-               // FIXME: Once the cache key is reorganized this argument
-               // can be dropped. It was used when the math extension was
-               // part of core.
-               $confstr = '*';
-
-               // Space assigned for the stubthreshold but unused
-               // since it disables the parser cache, its value will always
-               // be 0 when this function is called by parsercache.
-               if ( in_array( 'stubthreshold', $forOptions ) ) {
-                       $confstr .= '!' . $this->options['stubthreshold'];
-               } else {
-                       $confstr .= '!*';
-               }
-
-               if ( in_array( 'dateformat', $forOptions ) ) {
-                       $confstr .= '!' . $this->getDateFormat();
-               }
-
-               if ( in_array( 'numberheadings', $forOptions ) ) {
-                       $confstr .= '!' . ( $this->options['numberheadings'] ? '1' : '' );
-               } else {
-                       $confstr .= '!*';
-               }
-
-               if ( in_array( 'userlang', $forOptions ) ) {
-                       $confstr .= '!' . $this->options['userlang']->getCode();
-               } else {
-                       $confstr .= '!*';
-               }
-
-               if ( in_array( 'thumbsize', $forOptions ) ) {
-                       $confstr .= '!' . $this->options['thumbsize'];
-               } else {
-                       $confstr .= '!*';
-               }
-
-               // add in language specific options, if any
-               // @todo FIXME: This is just a way of retrieving the url/user preferred variant
-               if ( !is_null( $title ) ) {
-                       $confstr .= $title->getPageLanguage()->getExtraHashOptions();
-               } else {
-                       global $wgContLang;
-                       $confstr .= $wgContLang->getExtraHashOptions();
-               }
-
-               $confstr .= $wgRenderHashAppend;
-
-               // @note: as of Feb 2015, core never sets the editsection flag, since it uses
-               // <mw:editsection> tags to inject editsections on the fly. However, extensions
-               // may be using it by calling ParserOption::optionUsed resp. ParserOutput::registerOption
-               // directly. At least Wikibase does at this point in time.
-               if ( !in_array( 'editsection', $forOptions ) ) {
-                       $confstr .= '!*';
-               } elseif ( !$this->options['editsection'] ) {
-                       $confstr .= '!edit=0';
-               }
-
-               if ( $this->options['printable'] && in_array( 'printable', $forOptions ) ) {
-                       $confstr .= '!printable=1';
-               }
-
-               if ( $this->options['wrapclass'] !== 'mw-parser-output' &&
-                       in_array( 'wrapclass', $forOptions )
-               ) {
-                       $confstr .= '!wrapclass=' . $this->options['wrapclass'];
-               }
-
-               if ( $this->mExtraKey != '' ) {
-                       $confstr .= $this->mExtraKey;
-               }
-
-               // Give a chance for extensions to modify the hash, if they have
-               // extra options or other effects on the parser cache.
-               Hooks::run( 'PageRenderingHash', [ &$confstr, $this->getUser(), &$forOptions ] );
-
-               // Make it a valid memcached key fragment
-               $confstr = str_replace( ' ', '_', $confstr );
-
-               return $confstr;
-       }
-
        /**
         * Test whether these options are safe to cache
         * @since 1.30