Revert r107066, see CR comments for full rationale. Basically this moves the previewe...
[lhc/web/wiklou.git] / includes / OutputPage.php
index feae2c1..05b3bf0 100644 (file)
@@ -197,6 +197,7 @@ class OutputPage extends ContextSource {
 
        /// should be private. To include the variable {{REVISIONID}}
        var $mRevisionId = null;
+       private $mRevisionTimestamp = null;
 
        var $mFileVersion = null;
 
@@ -1207,9 +1208,11 @@ class OutputPage extends ContextSource {
         * Return whether user JavaScript is allowed for this page
         * @deprecated since 1.18 Load modules with ResourceLoader, and origin and
         *     trustworthiness is identified and enforced automagically.
+        *     Will be removed in 1.20.
         * @return Boolean
         */
        public function isUserJsAllowed() {
+               wfDeprecated( __METHOD__, '1.18' );
                return $this->getAllowedModules( ResourceLoaderModule::TYPE_SCRIPTS ) >= ResourceLoaderModule::ORIGIN_USER_INDIVIDUAL;
        }
 
@@ -1339,6 +1342,27 @@ class OutputPage extends ContextSource {
                return $this->mRevisionId;
        }
 
+       /**
+        * Set the timestamp of the revision which will be displayed. This is used
+        * to avoid a extra DB call in Skin::lastModified().
+        *
+        * @param $revid Mixed: string, or null
+        * @return Mixed: previous value
+        */
+       public function setRevisionTimestamp( $timestmap ) {
+               return wfSetVar( $this->mRevisionTimestamp, $timestmap );
+       }
+
+       /**
+        * Get the timestamp of displayed revision.
+        * This will be null if not filled by setRevisionTimestamp().
+        *
+        * @return String or null
+        */
+       public function getRevisionTimestamp() {
+               return $this->mRevisionTimestamp;
+       }
+
        /**
         * Set the displayed file version
         *
@@ -1896,27 +1920,34 @@ class OutputPage extends ContextSource {
                if ( $this->mRedirect != '' ) {
                        # Standards require redirect URLs to be absolute
                        $this->mRedirect = wfExpandUrl( $this->mRedirect, PROTO_CURRENT );
-                       if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) {
-                               if( !$wgDebugRedirects ) {
-                                       $message = HttpStatus::getMessage( $this->mRedirectCode );
-                                       $response->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
+
+                       $redirect = $this->mRedirect;
+                       $code = $this->mRedirectCode;
+
+                       if( wfRunHooks( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) {
+                               if( $code == '301' || $code == '303' ) {
+                                       if( !$wgDebugRedirects ) {
+                                               $message = HttpStatus::getMessage( $code );
+                                               $response->header( "HTTP/1.1 $code $message" );
+                                       }
+                                       $this->mLastModified = wfTimestamp( TS_RFC2822 );
+                               }
+                               if ( $wgVaryOnXFP ) {
+                                       $this->addVaryHeader( 'X-Forwarded-Proto' );
+                               }
+                               $this->sendCacheControl();
+
+                               $response->header( "Content-Type: text/html; charset=utf-8" );
+                               if( $wgDebugRedirects ) {
+                                       $url = htmlspecialchars( $redirect );
+                                       print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
+                                       print "<p>Location: <a href=\"$url\">$url</a></p>\n";
+                                       print "</body>\n</html>\n";
+                               } else {
+                                       $response->header( 'Location: ' . $redirect );
                                }
-                               $this->mLastModified = wfTimestamp( TS_RFC2822 );
-                       }
-                       if ( $wgVaryOnXFP ) {
-                               $this->addVaryHeader( 'X-Forwarded-Proto' );
-                       }
-                       $this->sendCacheControl();
-
-                       $response->header( "Content-Type: text/html; charset=utf-8" );
-                       if( $wgDebugRedirects ) {
-                               $url = htmlspecialchars( $this->mRedirect );
-                               print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
-                               print "<p>Location: <a href=\"$url\">$url</a></p>\n";
-                               print "</body>\n</html>\n";
-                       } else {
-                               $response->header( 'Location: ' . $this->mRedirect );
                        }
+
                        wfProfileOut( __METHOD__ );
                        return;
                } elseif ( $this->mStatusCode ) {
@@ -2090,7 +2121,7 @@ class OutputPage extends ContextSource {
 
                        # Don't return to a page the user can't read otherwise
                        # we'll end up in a pointless loop
-                       if ( $displayReturnto && $displayReturnto->userCanRead() ) {
+                       if ( $displayReturnto && $displayReturnto->userCan( 'read', $this->getUser() ) ) {
                                $this->returnToMain( null, $displayReturnto );
                        }
                } else {
@@ -2219,17 +2250,15 @@ class OutputPage extends ContextSource {
                        $params = array(
                                'id'   => 'wpTextbox1',
                                'name' => 'wpTextbox1',
-                               'cols' => $this->getUser()->getOption( 'cols' ),
                                'rows' => $this->getUser()->getOption( 'rows' ),
                                'readonly' => 'readonly',
-                               'lang' => $pageLang->getCode(),
+                               'lang' => $pageLang->getHtmlCode(),
                                'dir' => $pageLang->getDir(),
                        );
                        $this->addHTML( Html::element( 'textarea', $params, $source ) );
 
                        // Show templates used by this article
-                       $page = WikiPage::factory( $this->getTitle() );
-                       $templates = Linker::formatTemplates( $page->getUsedTemplates() );
+                       $templates = Linker::formatTemplates( $this->getTitle()->getTemplateLinksFrom() );
                        $this->addHTML( "<div class='templatesUsed'>
 $templates
 </div>
@@ -2359,7 +2388,7 @@ $templates
                        $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
                }
 
-               $ret = Html::htmlHeader( array( 'lang' => $this->getLanguage()->getCode(), 'dir' => $userdir, 'class' => 'client-nojs' ) );
+               $ret = Html::htmlHeader( array( 'lang' => $this->getLanguage()->getHtmlCode(), 'dir' => $userdir, 'class' => 'client-nojs' ) );
 
                if ( $this->getHTMLTitle() == '' ) {
                        $this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() ) );
@@ -2547,7 +2576,9 @@ $templates
                                continue;
                        }
 
-                       // Support inlining of private modules if configured as such
+                       // Support inlining of private modules if configured as such. Note that these
+                       // modules should be loaded from getHeadScripts() before the first loader call.
+                       // Otherwise other modules can't properly use them as dependencies (bug 30914)
                        if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
                                if ( $only == ResourceLoaderModule::TYPE_STYLES ) {
                                        $links .= Html::inlineStyle(
@@ -2633,6 +2664,10 @@ $templates
                        )
                );
 
+               // Load embeddable private modules before any loader links
+               $embedScripts = array( 'user.options', 'user.tokens' );
+               $scripts .= $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
+
                // Script and Messages "only" requests marked for top inclusion
                // Messages should go first
                $scripts .= $this->makeResourceLoaderLink( $this->getModuleMessages( true, 'top' ), ResourceLoaderModule::TYPE_MESSAGES );
@@ -2680,7 +2715,7 @@ $templates
                // Legacy Scripts
                $scripts .= "\n" . $this->mScripts;
 
-               $userScripts = array( 'user.options', 'user.tokens' );
+               $userScripts = array();
 
                // Add site JS if enabled
                if ( $wgUseSiteJs ) {
@@ -2717,9 +2752,9 @@ $templates
         * Add one or more variables to be set in mw.config in JavaScript.
         *
         * @param $key {String|Array} Key or array of key/value pars.
-        * @param $value {Mixed} Value of the configuration variable.
+        * @param $value {Mixed} [optional] Value of the configuration variable.
         */
-       public function addJsConfigVars( $keys, $value ) {
+       public function addJsConfigVars( $keys, $value = null ) {
                if ( is_array( $keys ) ) {
                        foreach ( $keys as $key => $value ) {
                                $this->mJsConfigVars[$key] = $value;
@@ -2734,13 +2769,16 @@ $templates
        /**
         * Get an array containing the variables to be set in mw.config in JavaScript.
         *
+        * DO NOT CALL THIS FROM OUTSIDE OF THIS CLASS OR Skin::makeGlobalVariablesScript().
+        * This is only public until that function is removed. You have been warned.
+        *
         * Do not add things here which can be evaluated in ResourceLoaderStartupScript
         * - in other words, page-independent/site-wide variables (without state).
         * You will only be adding bloat to the html page and causing page caches to
         * have to be purged on configuration changes.
         * @return array
         */
-       protected function getJSVars() {
+       public function getJSVars() {
                global $wgUseAjax, $wgEnableMWSuggest;
 
                $title = $this->getTitle();
@@ -2987,7 +3025,7 @@ $templates
                                                $tags[] = Html::element( 'link', array(
                                                        'rel' => 'alternate',
                                                        'hreflang' => $_v,
-                                                       'href' => $this->getTitle()->getLocalURL( '', $_v ) )
+                                                       'href' => $this->getTitle()->getLocalURL( array( 'variant' => $_v ) ) )
                                                );
                                        }
                                } else {
@@ -3053,10 +3091,11 @@ $templates
                                        );
                                }
                        } elseif ( !$this->getTitle()->isSpecial( 'Recentchanges' ) ) {
+                               $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
                                foreach ( $wgAdvertisedFeedTypes as $format ) {
                                        $tags[] = $this->feedLink(
                                                $format,
-                                               $this->getTitle()->getLocalURL( "feed={$format}" ),
+                                               $rctitle->getLocalURL( "feed={$format}" ),
                                                $this->msg( "site-{$format}-feed", $wgSitename )->text() # For grep: 'site-rss-feed', 'site-atom-feed'.
                                        );
                                }