In Database::getLag(): Add some more I/O thread states.
[lhc/web/wiklou.git] / includes / OutputPage.php
index df9a4b7..a7165c4 100644 (file)
@@ -16,7 +16,7 @@ class OutputPage {
 
        var $mScriptLoaderClassList = array();
        // the most recent id of any script that is grouped in the script request
-       var $mLatestScriptRevID = 0; 
+       var $mLatestScriptRevID = 0;
 
        var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
        var $mTemplateIds = array();
@@ -97,11 +97,19 @@ class OutputPage {
                        array_push( $this->mKeywords, $text );
                }
        }
-       function addScript( $script ) { $this->mScripts .= "\t\t" . $script . "\n"; }
+       function addScript( $script ) {
+               $this->mScripts .= "\t\t" . $script . "\n";
+       }
 
-       function addExtensionStyle( $url ) {
-               $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
-               array_push( $this->mExtStyles, $linkarr );
+       /**
+        * Register and add a stylesheet from an extension directory.
+        * @param $url String 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 ) {
+               array_push( $this->mExtStyles, $url );
        }
 
        /**
@@ -109,7 +117,7 @@ class OutputPage {
         * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
         */
        function addScriptFile( $file ) {
-               global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser;
+               global $wgStylePath, $wgScript, $wgUser;
                global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgEnableScriptLoader, $wgScriptPath;
 
                if( substr( $file, 0, 1 ) == '/' ) {
@@ -121,11 +129,11 @@ class OutputPage {
                if( $wgEnableScriptLoader ){
                        if( strpos( $path, $wgScript ) !== false ){
                                $reqPath = str_replace( $wgScript . '?', '', $path );
-                               $reqArgs = split( '&', $reqPath );
+                               $reqArgs = explode( '&', $reqPath );
                                $reqSet = array();
 
                                foreach( $reqArgs as $arg ){
-                                       list( $key, $var ) = split( '=', $arg );
+                                       list( $key, $var ) = explode( '=', $arg );
                                        $reqSet[$key] = $var;
                                }
 
@@ -136,7 +144,7 @@ class OutputPage {
                                        // add the title revision to the key
                                        $t = Title::newFromText( $reqSet['title'] );
                                        // if there is no title (don't worry we just use the $wgStyleVersion var (which should be updated on relevant commits)
-                                       if( $t->exists() ){
+                                       if( $t && $t->exists() ){
                                                if( $t->getLatestRevID() > $this->mLatestScriptRevID  )
                                                        $this->mLatestScriptRevID = $t->getLatestRevID();
                                        }
@@ -154,15 +162,7 @@ class OutputPage {
                }
 
                // if the script loader did not find a way to add the script than add using addScript
-               $this->addScript(
-                       Xml::element( 'script',
-                               array(
-                                       'type' => $wgJsMimeType,
-                                       'src' => "$path?" . $this->getURIDparam(),
-                               ),
-                               '', false
-                       )
-               );
+               $this->addScript( Html::linkedScript( wfAppendQuery( $path, $this->getURIDparam() ) ) );
        }
 
        /**
@@ -171,7 +171,7 @@ class OutputPage {
         *  different page load types (edit, upload, view, etc)
         */
        function addCoreScripts2Top(){
-               global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses, $wgJsMimeType, $wgScriptPath, $wgEnableJS2system;
+               global $wgEnableScriptLoader, $wgJSAutoloadLocalClasses, $wgScriptPath, $wgEnableJS2system;
                //@@todo we should deprecate wikibits in favor of mv_embed and native jQuery functions
 
                if( $wgEnableJS2system ){
@@ -186,12 +186,7 @@ class OutputPage {
                        $so = '';
                        foreach( $core_classes as $s ){
                                if( isset( $wgJSAutoloadLocalClasses[$s] ) ){
-                                       $so.= Xml::element( 'script', array(
-                                                       'type' => $wgJsMimeType,
-                                                       'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam()
-                                               ),
-                                               '', false
-                                       );
+                                       $so .= Html::linkedScript( "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam() );
                                }
                        }
                        $this->mScripts =  $so . $this->mScripts;
@@ -203,7 +198,7 @@ class OutputPage {
         * @return Boolean: false if class wasn't found, true on success
         */
        function addScriptClass( $js_class ){
-               global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgJsMimeType,
+               global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses,
                                $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
 
                if( isset( $wgJSAutoloadClasses[$js_class] ) || isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
@@ -214,17 +209,13 @@ class OutputPage {
                        } else {
                                // do a normal load of without the script-loader:
                                $path = $wgScriptPath . '/';
-                               $path.= isset( $wgJSAutoloadClasses[$js_class] ) ? $wgJSAutoloadClasses[$js_class]:
-                                                       $wgJSAutoloadLocalClasses[$js_class];
-                               $this->addScript(
-                                       Xml::element( 'script',
-                                               array(
-                                                       'type' => $wgJsMimeType,
-                                                       'src' => "$path?$wgStyleVersion",
-                                               ),
-                                               '', false
-                                       )
-                               );
+                               if( isset( $wgJSAutoloadClasses[$js_class] ) ){
+                                       $path.= $wgJSAutoloadClasses[$js_class];
+                               }else if( isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
+                                       $path.= $wgJSAutoloadLocalClasses[$js_class];
+                               }
+                               $urlAppend = ( $wgDebugJavaScript ) ? time() : $wgStyleVersion;
+                               $this->addScript( Html::linkedScript( "$path?$urlAppend" ) );
                        }
                        return true;
                }
@@ -237,7 +228,7 @@ class OutputPage {
         * @param $forcClassAry Boolean: false by default
         */
        function getScriptLoaderJs( $forceClassAry = false ){
-               global $wgScriptPath, $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript;
+               global $wgRequest, $wgDebugJavaScript;
 
                if( !$forceClassAry ){
                        $class_list = implode( ',', $this->mScriptLoaderClassList );
@@ -255,14 +246,7 @@ class OutputPage {
 
                //generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var)
 
-
-               return Xml::element( 'script',
-                               array(
-                                       'type' => $wgJsMimeType,
-                                       'src' => "$wgScriptPath/mwScriptLoader.php?class={$class_list}{$debug_param}&".$this->getURIDparam(),
-                               ),
-                               '', false
-               );
+               return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam() );
        }
 
        function getURIDparam(){
@@ -291,8 +275,7 @@ class OutputPage {
         * @param string $script JavaScript text, no <script> tags
         */
        function addInlineScript( $script ) {
-               global $wgJsMimeType;
-               $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
+               $this->mScripts .= "\t\t" . Html::inlineScript( "\n\t\t$script\n\t\t" ) . "\n";
        }
 
        function getScript() {
@@ -749,7 +732,6 @@ class OutputPage {
                        $this->setIndexPolicy( $parserOutput->getIndexPolicy() );
                }
 
-               $this->addKeywords( $parserOutput );
                $this->mParseWarnings = $parserOutput->getWarnings();
                if ( $parserOutput->getCacheTime() == -1 ) {
                        $this->enableClientCache( false );
@@ -978,7 +960,7 @@ class OutputPage {
        }
 
        public function sendCacheControl() {
-               global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
+               global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
 
                $response = $wgRequest->response();
                if ($wgUseETag && $this->mETag)
@@ -988,8 +970,10 @@ class OutputPage {
                # maintain different caches for logged-in users and non-logged in ones
                $response->header( 'Vary: Accept-Encoding, Cookie' );
 
-               # Add an X-Vary-Options header for Squid with Wikimedia patches
-               $response->header( $this->getXVO() );
+               if ( $wgUseXVO ) {
+                       # Add an X-Vary-Options header for Squid with Wikimedia patches
+                       $response->header( $this->getXVO() );
+               }
 
                if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
                        if( $wgUseSquid && session_id() == '' &&
@@ -1042,7 +1026,7 @@ class OutputPage {
        public function output() {
                global $wgUser, $wgOutputEncoding, $wgRequest;
                global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
-               global $wgJsMimeType, $wgUseAjax, $wgAjaxWatch;
+               global $wgUseAjax, $wgAjaxWatch;
                global $wgEnableMWSuggest, $wgUniversalEditButton;
                global $wgArticle;
 
@@ -1639,7 +1623,7 @@ class OutputPage {
         * @param Title $title Title to link
         * @param string $query Query string
         */
-       public function addReturnTo( $title, $query ) {
+       public function addReturnTo( $title, $query = array() ) {
                global $wgUser;
                $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
                $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
@@ -1660,7 +1644,7 @@ class OutputPage {
                if ( $returnto == null ) {
                        $returnto = $wgRequest->getText( 'returnto' );
                }
-               
+
                if ( $returntoquery == null ) {
                        $returntoquery = $wgRequest->getText( 'returntoquery' );
                }
@@ -1681,42 +1665,6 @@ class OutputPage {
                $this->addReturnTo( $titleObj, $returntoquery );
        }
 
-       /**
-        * This function takes the title (first item of mGoodLinks), categories,
-        * existing and broken links for the page
-        * and uses the first 10 of them for META keywords
-        *
-        * @param ParserOutput &$parserOutput
-        */
-       private function addKeywords( &$parserOutput ) {
-               global $wgContLang;
-               // Get an array of keywords if there are more than one
-               // variant of the site language
-               $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText());
-               // array_values: We needn't to merge variant's code name
-               // into $this->mKeywords;
-               // array_unique: We should insert a keyword just for once
-               if( is_array( $text ))
-                       $text = array_unique( array_values( $text ));
-               $this->addKeyword( $text );
-               $count = 1;
-               $links2d =& $parserOutput->getLinks();
-               if ( !is_array( $links2d ) ) {
-                       return;
-               }
-               foreach ( $links2d as $dbkeys ) {
-                       foreach( $dbkeys as $dbkey => $unused ) {
-                               $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey );
-                               if( is_array( $dbkey ))
-                                       $dbkey = array_unique( array_values( $dbkey ));
-                               $this->addKeyword( $dbkey );
-                               if ( ++$count > 10 ) {
-                                       break 2;
-                               }
-                       }
-               }
-       }
-
        /**
         * @return string The doctype, opening <html>, and head element.
         */
@@ -1737,22 +1685,24 @@ class OutputPage {
                        $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
                }
 
-               if ( $wgHtml5 ) {
-                       $ret .= "<!doctype html>\n";
-               } else {
-                       $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
-               }
-
                if ( '' == $this->getHTMLTitle() ) {
                        $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
                }
 
                $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
-               $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
-               foreach($wgXhtmlNamespaces as $tag => $ns) {
-                       $ret .= "xmlns:{$tag}=\"{$ns}\" ";
+
+               if ( $wgHtml5 ) {
+                       $ret .= "<!doctype html>\n";
+                       $ret .= "<html lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
+               } else {
+                       $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
+                       $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
+                       foreach($wgXhtmlNamespaces as $tag => $ns) {
+                               $ret .= "xmlns:{$tag}=\"{$ns}\" ";
+                       }
+                       $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
                }
-               $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
+
                $ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
                $ret .= implode( "\n", array(
                        $this->getHeadLinks(),
@@ -1761,7 +1711,7 @@ class OutputPage {
                        $this->getHeadItems(),
                ));
                if( $sk->usercss ){
-                       $ret .= "<style type='text/css'>{$sk->usercss}</style>";
+                       $ret .= Html::inlineStyle( $sk->usercss );
                }
 
                if( $wgEnableScriptLoader )
@@ -1920,6 +1870,14 @@ class OutputPage {
         */
        public function addStyle( $style, $media='', $condition='', $dir='' ) {
                $options = array();
+               // In Opera, fullscreen mode is treated as projection mode, and it causes
+               // styles set for screen to not be loaded - thus breaking the page -  so
+               // we can just append projection to the media attribute when it's screen
+               // so the browser is happy and - with no side-effects on other browsers.
+               // Also - even though we expect the media type to be lowercase, but here
+               // we force it to lowercase to be safe.
+               if ( strtolower( $media ) == 'screen' )
+                       $media .= ',projection';
                if( $media )
                        $options['media'] = $media;
                if( $condition )
@@ -1934,7 +1892,7 @@ class OutputPage {
         * @param $style_css Mixed: inline CSS
         */
        public function addInlineStyle( $style_css ){
-               $this->mScripts .= "<style type=\"text/css\">$style_css</style>";
+               $this->mScripts .= Html::inlineStyle( $style_css );
        }
 
        /**
@@ -1968,7 +1926,7 @@ class OutputPage {
                                return '';
                        }
                } else {
-                       $media = '';
+                       $media = null;
                }
 
                if( substr( $style, 0, 1 ) == '/' ||
@@ -1980,15 +1938,7 @@ class OutputPage {
                        $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
                }
 
-               $attribs = array(
-                       'rel' => 'stylesheet',
-                       'href' => $url,
-                       'type' => 'text/css' );
-               if( $media ) {
-                       $attribs['media'] = $media;
-               }
-
-               $link = Xml::element( 'link', $attribs );
+               $link = Html::linkedStyle( $url, $media );
 
                if( isset( $options['condition'] ) ) {
                        $condition = htmlspecialchars( $options['condition'] );