OutputPage: documentation for (semi-)deprecated methods
[lhc/web/wiklou.git] / includes / OutputPage.php
index 03ae8c9..81724c5 100644 (file)
@@ -50,7 +50,7 @@ class OutputPage extends ContextSource {
 
        /**
         * @var array Additional stylesheets. Looks like this is for extensions.
-        *   Might be replaced by resource loader.
+        *   Might be replaced by ResourceLoader.
         */
        protected $mExtStyles = array();
 
@@ -132,7 +132,7 @@ class OutputPage extends ContextSource {
        private $mLanguageLinks = array();
 
        /**
-        * Used for JavaScript (pre resource loader)
+        * Used for JavaScript (predates ResourceLoader)
         * @todo We should split JS / CSS.
         * mScripts content is inserted as is in "<head>" by Skin. This might
         * contain either a link to a stylesheet or inline CSS.
@@ -151,8 +151,6 @@ class OutputPage extends ContextSource {
        /** @var array Array of elements in "<head>". Parser might add its own headers! */
        protected $mHeadItems = array();
 
-       // @todo FIXME: Next 5 variables probably come from the resource loader
-
        /** @var array */
        protected $mModules = array();
 
@@ -224,7 +222,7 @@ class OutputPage extends ContextSource {
        /**
         * @var bool Comes from the parser. This was probably made to load CSS/JS
         * only if we had "<gallery>". Used directly in CategoryPage.php.
-        * Looks like resource loader can replace this.
+        * Looks like ResourceLoader can replace this.
         */
        public $mNoGallery = false;
 
@@ -236,7 +234,7 @@ class OutputPage extends ContextSource {
 
        /** @var int Cache stuff. Looks like mEnableClientCache */
        protected $mSquidMaxage = 0;
-       /** @var in Upper limit on mSquidMaxage */
+       /** @var int Upper limit on mSquidMaxage */
        protected $mCdnMaxageLimit = INF;
 
        /**
@@ -273,7 +271,7 @@ class OutputPage extends ContextSource {
        private $mIndexPolicy = 'index';
        private $mFollowPolicy = 'follow';
        private $mVaryHeader = array(
-               'Accept-Encoding' => array( 'list-contains=gzip' ),
+               'Accept-Encoding' => array( 'match=gzip' ),
        );
 
        /**
@@ -458,6 +456,8 @@ class OutputPage extends ContextSource {
 
        /**
         * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
+        * Internal use only. Use OutputPage::addModules() or OutputPage::addJsConfigVars()
+        * if possible.
         *
         * @param string $script Raw HTML
         */
@@ -468,26 +468,31 @@ class OutputPage extends ContextSource {
        /**
         * Register and add a stylesheet from an extension directory.
         *
+        * @deprecated since 1.27 use addModuleStyles() or addStyle() instead
         * @param string $url Path to sheet.  Provide either a full url (beginning
         *             with 'http', etc) or a relative path from the document root
         *             (beginning with '/').  Otherwise it behaves identically to
         *             addStyle() and draws from the /skins folder.
         */
        public function addExtensionStyle( $url ) {
+               wfDeprecated( __METHOD__, '1.27' );
                array_push( $this->mExtStyles, $url );
        }
 
        /**
         * Get all styles added by extensions
         *
+        * @deprecated since 1.27
         * @return array
         */
        function getExtStyle() {
+               wfDeprecated( __METHOD__, '1.27' );
                return $this->mExtStyles;
        }
 
        /**
         * Add a JavaScript file out of skins/common, or a given relative path.
+        * Internal use only. Use OutputPage::addModules() if possible.
         *
         * @param string $file Filename in skins/common or complete on-server path
         *              (/foo/bar.js)
@@ -508,6 +513,7 @@ class OutputPage extends ContextSource {
 
        /**
         * Add a self-contained script tag with the given contents
+        * Internal use only. Use OutputPage::addModules() if possible.
         *
         * @param string $script JavaScript text, no "<script>" tags
         */
@@ -568,8 +574,8 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add one or more modules recognized by the resource loader. Modules added
-        * through this function will be loaded by the resource loader when the
+        * Add one or more modules recognized by ResourceLoader. Modules added
+        * through this function will be loaded by ResourceLoader when the
         * page loads.
         *
         * @param string|array $modules Module name (string) or array of module names
@@ -591,8 +597,8 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add only JS of one or more modules recognized by the resource loader. Module
-        * scripts added through this function will be loaded by the resource loader when
+        * Add only JS of one or more modules recognized by ResourceLoader. Module
+        * scripts added through this function will be loaded by ResourceLoader when
         * the page loads.
         *
         * @param string|array $modules Module name (string) or array of module names
@@ -610,25 +616,11 @@ class OutputPage extends ContextSource {
         * @return array Array of module names
         */
        public function getModuleStyles( $filter = false, $position = null ) {
-               // T97420
-               $resourceLoader = $this->getResourceLoader();
-
-               foreach ( $this->mModuleStyles as $val ) {
-                       $module = $resourceLoader->getModule( $val );
-
-                       if ( $module instanceof ResourceLoaderModule && $module->isPositionDefault() ) {
-                               $warning = __METHOD__ . ': style module should define its position explicitly: ' .
-                                       $val . ' ' . get_class( $module );
-                               wfDebugLog( 'resourceloader', $warning );
-                               wfLogWarning( $warning );
-                       }
-               }
-
                return $this->getModules( $filter, $position, 'mModuleStyles' );
        }
 
        /**
-        * Add only CSS of one or more modules recognized by the resource loader.
+        * Add only CSS of one or more modules recognized by ResourceLoader.
         *
         * Module styles added through this function will be added using standard link CSS
         * tags, rather than as a combined Javascript and CSS package. Thus, they will
@@ -707,6 +699,12 @@ class OutputPage extends ContextSource {
        /**
         * Add or replace an header item to the output
         *
+        * Whenever possible, use more specific options like ResourceLoader modules,
+        * OutputPage::addLink(), OutputPage::addMetaLink() and OutputPage::addFeedLink()
+        * Fallback options for those are: OutputPage::addStyle, OutputPage::addScript(),
+        * OutputPage::addInlineScript() and OutputPage::addInlineStyle()
+        * This would be your very LAST fallback.
+        *
         * @param string $name Item name
         * @param string $value Raw HTML
         */
@@ -1041,6 +1039,7 @@ class OutputPage extends ContextSource {
         * @param string|Message $str String or Message to add to the subtitle
         */
        public function appendSubtitle( $str ) {
+               wfDeprecated( __METHOD__, '1.19' );
                $this->addSubtitle( $str );
        }
 
@@ -1764,6 +1763,7 @@ class OutputPage extends ContextSource {
         * @param ParserOutput $parserOutput
         */
        public function addParserOutputNoText( $parserOutput ) {
+               wfDeprecated( __METHOD__, '1.24' );
                $this->addParserOutputMetadata( $parserOutput );
        }
 
@@ -1957,7 +1957,7 @@ class OutputPage extends ContextSource {
         * @since 1.27
         */
        public function lowerCdnMaxage( $maxage ) {
-               $this->mCdnMaxageLimit = $this->min( $maxage, $this->mCdnMaxageLimit );
+               $this->mCdnMaxageLimit = min( $maxage, $this->mCdnMaxageLimit );
                $this->setSquidMaxage( $this->mSquidMaxage );
        }
 
@@ -2002,14 +2002,9 @@ class OutputPage extends ContextSource {
         * @return bool
         */
        function haveCacheVaryCookies() {
-               $cookieHeader = $this->getRequest()->getHeader( 'cookie' );
-               if ( $cookieHeader === false ) {
-                       return false;
-               }
-               $cvCookies = $this->getCacheVaryCookies();
-               foreach ( $cvCookies as $cookieName ) {
-                       # Check for a simple string match, like the way squid does it
-                       if ( strpos( $cookieHeader, $cookieName ) !== false ) {
+               $request = $this->getRequest();
+               foreach ( $this->getCacheVaryCookies() as $cookieName ) {
+                       if ( $request->getCookie( $cookieName, '', '' ) !== '' ) {
                                wfDebug( __METHOD__ . ": found $cookieName\n" );
                                return true;
                        }
@@ -2022,11 +2017,9 @@ class OutputPage extends ContextSource {
         * Add an HTTP header that will influence on the cache
         *
         * @param string $header Header name
-        * @param string[]|null $option Options for X-Vary-Options. Possible options are:
-        *  - "string-contains=$XXX" varies on whether the header value as a string
-        *    contains $XXX as a substring.
-        *  - "list-contains=$XXX" varies on whether the header value as a
-        *    comma-separated list contains $XXX as one of the list items.
+        * @param string[]|null $option Options for the Key header. See
+        * https://datatracker.ietf.org/doc/draft-fielding-http-key/
+        * for the list of valid options.
         */
        public function addVaryHeader( $header, array $option = null ) {
                if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
@@ -2049,16 +2042,16 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Get a complete X-Vary-Options header
+        * Get a complete Key header
         *
         * @return string
         */
-       public function getXVO() {
+       public function getKeyHeader() {
                $cvCookies = $this->getCacheVaryCookies();
 
                $cookiesOption = array();
                foreach ( $cvCookies as $cookieName ) {
-                       $cookiesOption[] = 'string-contains=' . $cookieName;
+                       $cookiesOption[] = 'param=' . $cookieName;
                }
                $this->addVaryHeader( 'Cookie', $cookiesOption );
 
@@ -2070,13 +2063,13 @@ class OutputPage extends ContextSource {
                        }
                        $headers[] = $newheader;
                }
-               $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
+               $key = 'Key: ' . implode( ',', $headers );
 
-               return $xvo;
+               return $key;
        }
 
        /**
-        * bug 21672: Add Accept-Language to Vary and XVO headers
+        * T23672: Add Accept-Language to Vary and Key headers
         * if there's no 'variant' parameter existed in GET.
         *
         * For example:
@@ -2097,14 +2090,14 @@ class OutputPage extends ContextSource {
                                if ( $variant === $lang->getCode() ) {
                                        continue;
                                } else {
-                                       $aloption[] = 'string-contains=' . $variant;
+                                       $aloption[] = 'substr=' . $variant;
 
                                        // IE and some other browsers use BCP 47 standards in
                                        // their Accept-Language header, like "zh-CN" or "zh-Hant".
                                        // We should handle these too.
                                        $variantBCP47 = wfBCP47( $variant );
                                        if ( $variantBCP47 !== $variant ) {
-                                               $aloption[] = 'string-contains=' . $variantBCP47;
+                                               $aloption[] = 'substr=' . $variantBCP47;
                                        }
                                }
                        }
@@ -2179,9 +2172,8 @@ class OutputPage extends ContextSource {
                # maintain different caches for logged-in users and non-logged in ones
                $response->header( $this->getVaryHeader() );
 
-               if ( $config->get( 'UseXVO' ) ) {
-                       # Add an X-Vary-Options header for Squid with Wikimedia patches
-                       $response->header( $this->getXVO() );
+               if ( $config->get( 'UseKeyHeader' ) ) {
+                       $response->header( $this->getKeyHeader() );
                }
 
                if ( $this->mEnableClientCache ) {
@@ -2352,6 +2344,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.18
         */
        function blockedPage() {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new UserBlockedError( $this->getUser()->mBlock );
        }
 
@@ -2503,6 +2496,7 @@ class OutputPage extends ContextSource {
         * @throws PermissionsError
         */
        public function permissionRequired( $permission ) {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new PermissionsError( $permission );
        }
 
@@ -2512,6 +2506,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.19; throw the exception directly
         */
        public function loginToUse() {
+               wfDeprecated( __METHOD__, '1.19' );
                throw new PermissionsError( 'read' );
        }
 
@@ -3082,10 +3077,6 @@ class OutputPage extends ContextSource {
                        ResourceLoaderModule::TYPE_SCRIPTS
                );
 
-               $links[] = $this->makeResourceLoaderLink( $this->getModuleStyles( true, 'bottom' ),
-                       ResourceLoaderModule::TYPE_STYLES
-               );
-
                // Modules requests - let the client calculate dependencies and batch requests as it likes
                // Only load modules that have marked themselves for loading at the bottom
                $modules = $this->getModules( true, 'bottom' );
@@ -3151,9 +3142,6 @@ class OutputPage extends ContextSource {
         * @return string
         */
        function getBottomScripts() {
-               // In case the skin wants to add bottom CSS
-               $this->getSkin()->setupSkinUserCss( $this );
-
                return $this->getScriptsForBottomQueue();
        }
 
@@ -3320,22 +3308,31 @@ class OutputPage extends ContextSource {
         * @return bool
         */
        public function userCanPreview() {
-               if ( $this->getRequest()->getVal( 'action' ) != 'submit'
-                       || !$this->getRequest()->wasPosted()
-                       || !$this->getUser()->matchEditToken(
-                               $this->getRequest()->getVal( 'wpEditToken' ) )
-               ) {
+               $request = $this->getRequest();
+               if ( $request->getVal( 'action' ) !== 'submit' || !$request->wasPosted() ) {
                        return false;
                }
-               if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
+
+               $user = $this->getUser();
+               if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
                        return false;
                }
-               if ( !$this->getTitle()->isSubpageOf( $this->getUser()->getUserPage() ) ) {
+
+               $title = $this->getTitle();
+               if ( !$title->isJsSubpage() && !$title->isCssSubpage() ) {
+                       return false;
+               }
+               if ( !$title->isSubpageOf( $user->getUserPage() ) ) {
                        // Don't execute another user's CSS or JS on preview (T85855)
                        return false;
                }
 
-               return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
+               $errors = $title->getUserPermissionsErrors( 'edit', $user );
+               if ( count( $errors ) !== 0 ) {
+                       return false;
+               }
+
+               return true;
        }
 
        /**
@@ -3623,7 +3620,7 @@ class OutputPage extends ContextSource {
 
        /**
         * Add a local or specified stylesheet, with the given media options.
-        * Meant primarily for internal use...
+        * Internal use only. Use OutputPage::addModuleStyles() if possible.
         *
         * @param string $style URL to the file
         * @param string $media To specify a media type, 'screen', 'printable', 'handheld' or any.
@@ -3648,6 +3645,8 @@ class OutputPage extends ContextSource {
 
        /**
         * Adds inline CSS styles
+        * Internal use only. Use OutputPage::addModuleStyles() if possible.
+        *
         * @param mixed $style_css Inline CSS
         * @param string $flip Set to 'flip' to flip the CSS if needed
         */
@@ -3683,7 +3682,7 @@ class OutputPage extends ContextSource {
                $otherTags = array(); // Tags to append after the normal <link> tags
                $resourceLoader = $this->getResourceLoader();
 
-               $moduleStyles = $this->getModuleStyles( true, 'top' );
+               $moduleStyles = $this->getModuleStyles();
 
                // Per-site custom styles
                $moduleStyles[] = 'site';
@@ -3855,18 +3854,19 @@ class OutputPage extends ContextSource {
                                if ( $media == $targetMedia ) {
                                        $media = '';
                                } elseif ( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
-                                       // This regex will not attempt to understand a comma-separated media_query_list
-                                       //
-                                       // Example supported values for $media:
-                                       // 'screen', 'only screen', 'screen and (min-width: 982px)' ),
-                                       // Example NOT supported value for $media:
-                                       // '3d-glasses, screen, print and resolution > 90dpi'
-                                       //
-                                       // If it's a print request, we never want any kind of screen stylesheets
-                                       // If it's a handheld request (currently the only other choice with a switch),
-                                       // we don't want simple 'screen' but we might want screen queries that
-                                       // have a max-width or something, so we'll pass all others on and let the
-                                       // client do the query.
+                                       /* This regex will not attempt to understand a comma-separated media_query_list
+                                        *
+                                        * Example supported values for $media:
+                                        * 'screen', 'only screen', 'screen and (min-width: 982px)' ),
+                                        * Example NOT supported value for $media:
+                                        * '3d-glasses, screen, print and resolution > 90dpi'
+                                        *
+                                        * If it's a print request, we never want any kind of screen stylesheets
+                                        * If it's a handheld request (currently the only other choice with a switch),
+                                        * we don't want simple 'screen' but we might want screen queries that
+                                        * have a max-width or something, so we'll pass all others on and let the
+                                        * client do the query.
+                                        */
                                        if ( $targetMedia == 'print' || $media == 'screen' ) {
                                                return null;
                                        }
@@ -3961,6 +3961,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.17
         */
        public function includeJQuery( array $modules = array() ) {
+               wfDeprecated( __METHOD__, '1.17' );
                return array();
        }