Merge "Adjust datetime in email confirmation email"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 726fec1..fea667e 100644 (file)
@@ -233,8 +233,8 @@ class OutputPage extends ContextSource {
        private $mParseWarnings = array();
 
        /** @var int Cache stuff. Looks like mEnableClientCache */
-       protected $mSquidMaxage = 0;
-       /** @var int Upper limit on mSquidMaxage */
+       protected $mCdnMaxage = 0;
+       /** @var int Upper limit on mCdnMaxage */
        protected $mCdnMaxageLimit = INF;
 
        /**
@@ -456,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
         */
@@ -466,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)
@@ -506,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
         */
@@ -691,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
         */
@@ -1025,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 );
        }
 
@@ -1339,6 +1354,8 @@ class OutputPage extends ContextSource {
                        array( &$this, $categories, &$this->mCategoryLinks ) )
                ) {
                        foreach ( $categories as $category => $type ) {
+                               // array keys will cast numeric category names to ints, so cast back to string
+                               $category = (string)$category;
                                $origcategory = $category;
                                $title = Title::makeTitleSafe( NS_CATEGORY, $category );
                                if ( !$title ) {
@@ -1748,6 +1765,7 @@ class OutputPage extends ContextSource {
         * @param ParserOutput $parserOutput
         */
        public function addParserOutputNoText( $parserOutput ) {
+               wfDeprecated( __METHOD__, '1.24' );
                $this->addParserOutputMetadata( $parserOutput );
        }
 
@@ -1925,24 +1943,32 @@ class OutputPage extends ContextSource {
                return Parser::stripOuterParagraph( $parsed );
        }
 
+       /**
+        * @param $maxage
+        * @deprecated since 1.27 Use setCdnMaxage() instead
+        */
+       public function setSquidMaxage( $maxage ) {
+               $this->setCdnMaxage( $maxage );
+       }
+
        /**
         * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
         *
-        * @param int $maxage Maximum cache time on the Squid, in seconds.
+        * @param int $maxage Maximum cache time on the CDN, in seconds.
         */
-       public function setSquidMaxage( $maxage ) {
-               $this->mSquidMaxage = min( $maxage, $this->mCdnMaxageLimit );
+       public function setCdnMaxage( $maxage ) {
+               $this->mCdnMaxage = min( $maxage, $this->mCdnMaxageLimit );
        }
 
        /**
         * Lower the value of the "s-maxage" part of the "Cache-control" HTTP header
         *
-        * @param int $maxage Maximum cache time on the Squid, in seconds
+        * @param int $maxage Maximum cache time on the CDN, in seconds
         * @since 1.27
         */
        public function lowerCdnMaxage( $maxage ) {
                $this->mCdnMaxageLimit = min( $maxage, $this->mCdnMaxageLimit );
-               $this->setSquidMaxage( $this->mSquidMaxage );
+               $this->setCdnMaxage( $this->mCdnMaxage );
        }
 
        /**
@@ -2163,27 +2189,27 @@ class OutputPage extends ContextSource {
                if ( $this->mEnableClientCache ) {
                        if (
                                $config->get( 'UseSquid' ) && session_id() == '' && !$this->isPrintable() &&
-                               $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies()
+                               $this->mCdnMaxage != 0 && !$this->haveCacheVaryCookies()
                        ) {
                                if ( $config->get( 'UseESI' ) ) {
                                        # We'll purge the proxy cache explicitly, but require end user agents
                                        # to revalidate against the proxy on each visit.
-                                       # Surrogate-Control controls our Squid, Cache-Control downstream caches
+                                       # Surrogate-Control controls our CDN, Cache-Control downstream caches
                                        wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", 'log' );
                                        # start with a shorter timeout for initial testing
                                        # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
                                        $response->header( 'Surrogate-Control: max-age=' . $config->get( 'SquidMaxage' )
-                                               . '+' . $this->mSquidMaxage . ', content="ESI/1.0"' );
+                                               . '+' . $this->mCdnMaxage . ', content="ESI/1.0"' );
                                        $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
                                } else {
                                        # We'll purge the proxy cache for anons explicitly, but require end user agents
                                        # to revalidate against the proxy on each visit.
-                                       # IMPORTANT! The Squid needs to replace the Cache-Control header with
+                                       # IMPORTANT! The CDN needs to replace the Cache-Control header with
                                        # Cache-Control: s-maxage=0, must-revalidate, max-age=0
                                        wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", 'log' );
                                        # start with a shorter timeout for initial testing
                                        # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
-                                       $response->header( 'Cache-Control: s-maxage=' . $this->mSquidMaxage
+                                       $response->header( 'Cache-Control: s-maxage=' . $this->mCdnMaxage
                                                . ', must-revalidate, max-age=0' );
                                }
                        } else {
@@ -2328,6 +2354,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.18
         */
        function blockedPage() {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new UserBlockedError( $this->getUser()->mBlock );
        }
 
@@ -2412,7 +2439,7 @@ class OutputPage extends ContextSource {
                        # not especially useful as a returnto parameter. Use the title
                        # from the request instead, if there was one.
                        $request = $this->getRequest();
-                       $returnto = Title::newFromURL( $request->getVal( 'title', '' ) );
+                       $returnto = Title::newFromText( $request->getVal( 'title', '' ) );
                        if ( $action == 'edit' ) {
                                $msg = 'whitelistedittext';
                                $displayReturnto = $returnto;
@@ -2479,6 +2506,7 @@ class OutputPage extends ContextSource {
         * @throws PermissionsError
         */
        public function permissionRequired( $permission ) {
+               wfDeprecated( __METHOD__, '1.18' );
                throw new PermissionsError( $permission );
        }
 
@@ -2488,6 +2516,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.19; throw the exception directly
         */
        public function loginToUse() {
+               wfDeprecated( __METHOD__, '1.19' );
                throw new PermissionsError( 'read' );
        }
 
@@ -2882,7 +2911,7 @@ class OutputPage extends ContextSource {
                                // on-wiki like user pages, or user preferences; we need to find the highest
                                // timestamp of these user-changeable modules so we can ensure cache misses on change
                                // This should NOT be done for the site group (bug 27564) because anons get that too
-                               // and we shouldn't be putting timestamps in Squid-cached HTML
+                               // and we shouldn't be putting timestamps in CDN-cached HTML
                                $version = null;
                                if ( $group === 'user' ) {
                                        $query['version'] = $resourceLoader->getCombinedVersion( $context, array_keys( $grpModules ) );
@@ -3290,7 +3319,11 @@ class OutputPage extends ContextSource {
         */
        public function userCanPreview() {
                $request = $this->getRequest();
-               if ( $request->getVal( 'action' ) !== 'submit' || !$request->wasPosted() ) {
+               if (
+                       $request->getVal( 'action' ) !== 'submit' ||
+                       !$request->getCheck( 'wpPreview' ) ||
+                       !$request->wasPosted()
+               ) {
                        return false;
                }
 
@@ -3601,7 +3634,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.
@@ -3626,6 +3659,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
         */
@@ -3940,6 +3975,7 @@ class OutputPage extends ContextSource {
         * @deprecated since 1.17
         */
        public function includeJQuery( array $modules = array() ) {
+               wfDeprecated( __METHOD__, '1.17' );
                return array();
        }