* added redundand join condition for index usage as per comment on CR r88008
[lhc/web/wiklou.git] / includes / OutputPage.php
index 0164ad3..a45a3ad 100644 (file)
@@ -440,22 +440,6 @@ class OutputPage extends ContextSource {
                $this->mModules = array_merge( $this->mModules, (array)$modules );
        }
 
-       /**
-        * Remove one or more modules recognized by the resource loader.
-        *
-        * @param $modules Mixed: module name (string) or array of module names
-        */
-       public function removeModules( $modules ) {
-               $this->mModules = array_diff( $this->mModules, (array)$modules );
-       }
-
-       /**
-        * Removes all modules for resource loader.
-        */
-       public function resetModules() {
-               $this->mModules = array();
-       }
-
        /**
         * Get the list of module JS to include on this page
         *
@@ -1481,13 +1465,6 @@ class OutputPage extends ContextSource {
         * @return String: HTML
         */
        public function parse( $text, $linestart = true, $interface = false, $language = null ) {
-               // Check one for one common cause for parser state resetting
-               $callers = wfGetAllCallers( 10 );
-               if ( strpos( $callers, 'Parser::extensionSubstitution' ) !== false ) {
-                       throw new MWException( "wfMsg* function with parsing cannot be used " .
-                               "inside a tag hook. Should use parser->recursiveTagParse() instead" );
-               }
-
                global $wgParser;
 
                if( is_null( $this->getTitle() ) ) {
@@ -1835,7 +1812,7 @@ class OutputPage extends ContextSource {
 
                if ( $this->mRedirect != '' ) {
                        # Standards require redirect URLs to be absolute
-                       $this->mRedirect = wfExpandUrl( $this->mRedirect );
+                       $this->mRedirect = wfExpandUrl( $this->mRedirect, PROTO_CURRENT );
                        if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) {
                                if( !$wgDebugRedirects ) {
                                        $message = HttpStatus::getMessage( $this->mRedirectCode );
@@ -1887,7 +1864,7 @@ class OutputPage extends ContextSource {
                        wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
 
                        wfProfileIn( 'Output-skin' );
-                       $sk->outputPage( $this );
+                       $sk->outputPage();
                        wfProfileOut( 'Output-skin' );
                }
 
@@ -1916,9 +1893,12 @@ class OutputPage extends ContextSource {
        /**
         * Output a standard error page
         *
+        * showErrorPage( 'titlemsg', 'pagetextmsg', array( 'param1', 'param2' ) );
+        * showErrorPage( 'titlemsg', $messageObject );
+        *
         * @param $title String: message key for page title
-        * @param $msg String: message key for page text
-        * @param $params Array: message parameters
+        * @param $msg Mixed: message key (string) for page text, or a Message object
+        * @param $params Array: message parameters; ignored if $msg is a Message object
         */
        public function showErrorPage( $title, $msg, $params = array() ) {
                if ( $this->getTitle() ) {
@@ -1932,7 +1912,11 @@ class OutputPage extends ContextSource {
                $this->mRedirect = '';
                $this->mBodytext = '';
 
-               $this->addWikiMsgArray( $msg, $params );
+               if ( $msg instanceof Message ){
+                       $this->addHTML( $msg->parse() );
+               } else {
+                       $this->addWikiMsgArray( $msg, $params );
+               }
 
                $this->returnToMain();
        }
@@ -2071,6 +2055,8 @@ class OutputPage extends ContextSource {
         * @param $action    String: action that was denied or null if unknown
         */
        public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
+               global $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
+
                $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
@@ -2100,12 +2086,15 @@ class OutputPage extends ContextSource {
                if( is_string( $source ) ) {
                        $this->addWikiMsg( 'viewsourcetext' );
 
+                       $pageLang = $this->getTitle()->getPageLanguage();
                        $params = array(
                                'id'   => 'wpTextbox1',
                                'name' => 'wpTextbox1',
                                'cols' => $this->getUser()->getOption( 'cols' ),
                                'rows' => $this->getUser()->getOption( 'rows' ),
-                               'readonly' => 'readonly'
+                               'readonly' => 'readonly',
+                               'lang' => $pageLang->getCode(),
+                               'dir' => $pageLang->getDir(),
                        );
                        $this->addHTML( Html::element( 'textarea', $params, $source ) );
 
@@ -2116,6 +2105,13 @@ class OutputPage extends ContextSource {
 $templates
 </div>
 " );
+                       if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
+                               $distantTemplates = Linker::formatDistantTemplates( $article->getUsedDistantTemplates() );
+                               $this->addHTML( "<div class='distantTemplatesUsed'>
+$distantTemplates
+</div>
+" );
+                       }
                }
 
                # If the title doesn't exist, it's fairly pointless to print a return
@@ -2246,7 +2242,7 @@ $templates
                        $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
                }
 
-               $ret = Html::htmlHeader( array( 'lang' => $this->getLang()->getCode(), 'dir' => $userdir ) );
+               $ret = Html::htmlHeader( array( 'lang' => $this->getLang()->getCode(), 'dir' => $userdir, 'class' => 'client-nojs' ) );
 
                if ( $this->getHTMLTitle() == '' ) {
                        $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
@@ -2325,7 +2321,7 @@ $templates
                        }
 
                        if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
-                               $this->addModules( 'mediawiki.page.mwsuggest' );
+                               $this->addModules( 'mediawiki.legacy.mwsuggest' );
                        }
                }
 
@@ -2363,21 +2359,20 @@ $templates
 
        /**
         * TODO: Document
-        * @param $modules Array/string with the module name
+        * @param $modules Array/string with the module name(s)
         * @param $only String ResourceLoaderModule TYPE_ class constant
         * @param $useESI boolean
+        * @param $extraQuery Array with extra query parameters to add to each request. array( param => value )
         * @return string html <script> and <style> tags
         */
-       protected function makeResourceLoaderLink( $modules, $only, $useESI = false ) {
+       protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array() ) {
                global $wgLoadScript, $wgResourceLoaderUseESI,
                        $wgResourceLoaderInlinePrivateModules;
-               // Lazy-load ResourceLoader
-               // TODO: Should this be a static function of ResourceLoader instead?
                $baseQuery = array(
                        'lang' => $this->getContext()->getLang()->getCode(),
                        'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false',
                        'skin' => $this->getSkin()->getSkinName(),
-               );
+               ) + $extraQuery;
                if ( $only !== ResourceLoaderModule::TYPE_COMBINED ) {
                        $baseQuery['only'] = $only;
                }
@@ -2595,11 +2590,15 @@ $templates
                if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
                        if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview() ) {
                                # XXX: additional security check/prompt?
+                               // We're on a preview of a JS subpage
+                               // Exclude this page from the user module in case it's in there (bug 26283)
+                               $scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS, false,
+                                       array( 'excludepage' => $this->getTitle()->getPrefixedDBkey() )
+                               );
+                               // Load the previewed JS
                                $scripts .= Html::inlineScript( "\n" . $this->getRequest()->getText( 'wpTextbox1' ) . "\n" ) . "\n";
                        } else {
-                               # @todo FIXME: This means that User:Me/Common.js doesn't load when previewing
-                               # User:Me/Vector.js, and vice versa (bug 26283)
-
+                               // Include the user module normally
                                // We can't do $userScripts[] = 'user'; because the user module would end up
                                // being wrapped in a closure, so load it raw like 'site'
                                $scripts .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_SCRIPTS );
@@ -2659,7 +2658,7 @@ $templates
                }
 
                // Allow extensions to add their custom variables to the global JS variables
-               wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
+               wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars, &$this ) );
 
                return $vars;
        }
@@ -2820,7 +2819,7 @@ $templates
                                'type' => 'application/rsd+xml',
                                // Output a protocol-relative URL here if $wgServer is protocol-relative
                                // Whether RSD accepts relative or protocol-relative URLs is completely undocumented, though
-                               'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ), PROT_RELATIVE ),
+                               'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ), PROTO_RELATIVE ),
                        ) );
                }
 
@@ -2842,8 +2841,8 @@ $templates
                        } else {
                                $tags[] = Html::element( 'link', array(
                                        'rel' => 'canonical',
-                                       'href' => wfExpandUrl( $this->getTitle()->getFullURL(), PROTO_HTTP ) )
-                               );
+                                       'href' => $this->getTitle()->getCanonicalUrl()
+                               ) );
                        }
                }
 
@@ -2979,6 +2978,7 @@ $templates
                // Add ResourceLoader styles
                // Split the styles into four groups
                $styles = array( 'other' => array(), 'user' => array(), 'site' => array(), 'private' => array(), 'noscript' => array() );
+               $otherTags = ''; // Tags to append after the normal <link> tags
                $resourceLoader = $this->getResourceLoader();
 
                $moduleStyles = $this->getModuleStyles();
@@ -2995,9 +2995,15 @@ $templates
                // Per-user custom styles
                if ( $wgAllowUserCss ) {
                        if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview() ) {
-                               // @todo FIXME: Properly escape the cdata!
-                               $this->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
+                               // We're on a preview of a CSS subpage
+                               // Exclude this page from the user module in case it's in there (bug 26283)
+                               $otherTags .= $this->makeResourceLoaderLink( 'user', ResourceLoaderModule::TYPE_STYLES, false,
+                                       array( 'excludepage' => $this->getTitle()->getPrefixedDBkey() )
+                               );
+                               // Load the previewed CSS
+                               $otherTags .= Html::inlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
                        } else {
+                               // Load the user styles normally
                                $moduleStyles[] = 'user';
                        }
                }
@@ -3033,6 +3039,9 @@ $templates
                                        ResourceLoaderModule::TYPE_STYLES
                        );
                }
+
+               // Add stuff in $otherTags (previewed user CSS if applicable)
+               $ret .= $otherTags;
                return $ret;
        }