Clean up <html> generation slightly
[lhc/web/wiklou.git] / includes / OutputPage.php
index a378905..4a2b819 100644 (file)
@@ -186,12 +186,12 @@ class OutputPage {
         */
        public function addScriptFile( $file ) {
                global $wgStylePath, $wgStyleVersion;
-               if( substr( $file, 0, 1 ) == '/' || substr( $file, 0, 7 ) == 'http://' ) {
+               if( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
                        $path = $file;
                } else {
                        $path =  "{$wgStylePath}/common/{$file}";
                }
-               $this->addScript( Html::linkedScript( "$path?$wgStyleVersion" ) );
+               $this->addScript( Html::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) );
        }
 
        /**
@@ -472,7 +472,7 @@ class OutputPage {
        }
 
        /**
-        * Return the "page title", i.e. the content of the <h1> tag.
+        * Return the "page title", i.e. the content of the \<h1\> tag.
         *
         * @return String
         */
@@ -1401,7 +1401,6 @@ class OutputPage {
                        $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
                        $response->header( 'Pragma: no-cache' );
                }
-               wfRunHooks('CacheHeadersAfterSet', array( $this ) );
        }
 
        /**
@@ -2018,12 +2017,15 @@ class OutputPage {
         *
         * @param $title Title to link
         * @param $query String: query string
+        * @param $text String text of the link (input is not escaped)
         */
-       public function addReturnTo( $title, $query = array() ) {
+       public function addReturnTo( $title, $query=array(), $text=null ) {
                global $wgUser;
                $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
-               $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
-                       $title, null, array(), $query ) );
+               $link = wfMsgHtml( 
+                       'returnto', 
+                       $wgUser->getSkin()->link( $title, $text, array(), $query )
+               );
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
@@ -2086,11 +2088,12 @@ class OutputPage {
                }
 
                if ( $this->getHTMLTitle() == '' ) {
-                       $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
+                       $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
                }
 
                $dir = $wgContLang->getDir();
 
+               $htmlAttribs = array( 'lang' => $wgContLanguageCode, 'dir' => $dir );
                if ( $wgHtml5 ) {
                        if ( $wgWellFormedXml ) {
                                # Unknown elements and attributes are okay in XML, but unknown
@@ -2105,34 +2108,42 @@ class OutputPage {
                                # Much saner.
                                $ret .= "<!doctype html>\n";
                        }
-                       $ret .= "<html lang=\"$wgContLanguageCode\" dir=\"$dir\" ";
-                       if ( $wgHtml5Version ) $ret .= " version=\"$wgHtml5Version\" ";
-                       $ret .= ">\n";
+                       if ( $wgHtml5Version ) {
+                               $htmlAttribs['version'] = $wgHtml5Version;
+                       }
                } else {
                        $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
-                       $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
-                       foreach($wgXhtmlNamespaces as $tag => $ns) {
-                               $ret .= "xmlns:{$tag}=\"{$ns}\" ";
+                       $htmlAttribs['xmlns'] = $wgXhtmlDefaultNamespace;
+                       foreach ( $wgXhtmlNamespaces as $tag => $ns ) {
+                               $htmlAttribs["xmlns:$tag"] = $ns;
                        }
-                       $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
                }
+               $ret .= Html::element( 'html', $htmlAttribs ) . "\n";
 
-               $ret .= "<head>\n";
+               $openHead = Html::openElement( 'head' );
+               if ( $openHead ) {
+                       # Don't bother with the newline if $head == ''
+                       $ret .= "$openHead\n";
+               }
                $ret .= "<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
                $ret .= implode( "\n", array(
                        $this->getHeadLinks(),
                        $this->buildCssLinks(),
                        $this->getHeadScripts( $sk ),
                        $this->getHeadItems(),
-               ));
-               if( $sk->usercss ){
+               ) );
+               if ( $sk->usercss ) {
                        $ret .= Html::inlineStyle( $sk->usercss );
                }
 
-               if ($wgUseTrackbacks && $this->isArticleRelated())
+               if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
                        $ret .= $this->getTitle()->trackbackRDF();
+               }
 
-               $ret .= "</head>\n";
+               $closeHead = Html::closeElement( 'head' );
+               if ( $closeHead ) {
+                       $ret .= "$closeHead\n";
+               }
 
                $bodyAttrs = array();
 
@@ -2200,13 +2211,16 @@ class OutputPage {
                                $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
                        } else {
                                $userpage = $wgUser->getUserPage();
-                               $scriptpage = Title::makeTitleSafe(
-                                       NS_USER,
-                                       $userpage->getDBkey() . '/' . $sk->getSkinName() . '.js'
-                               );
-                               if ( $scriptpage && $scriptpage->exists() ) {
-                                       $userjs = Skin::makeUrl( $scriptpage->getPrefixedText(), 'action=raw&ctype=' . $wgJsMimeType );
-                                       $this->addScriptFile( $userjs );
+                               $names = array( 'common', $sk->getSkinName() );
+                               foreach( $names as $name ) {
+                                       $scriptpage = Title::makeTitleSafe(
+                                               NS_USER,
+                                               $userpage->getDBkey() . '/' . $name . '.js'
+                                       );
+                                       if ( $scriptpage && $scriptpage->exists() ) {
+                                               $userjs = $scriptpage->getLocalURL( 'action=raw&ctype=' . $wgJsMimeType );
+                                               $this->addScriptFile( $userjs );
+                                       }
                                }
                        }
                }
@@ -2581,20 +2595,18 @@ class OutputPage {
         *
         * @param $modules Array: list of jQuery modules which should be loaded
         * @return Array: the list of modules which were not loaded.
+        * @since 1.16
         */
        public function includeJQuery( $modules = array() ) {
-               global $wgScriptPath, $wgStyleVersion, $wgJsMimeType;
+               global $wgStylePath, $wgStyleVersion;
 
                $supportedModules = array( /** TODO: add things here */ );
                $unsupported = array_diff( $modules, $supportedModules );
 
-               $params = array(
-                       'type' => $wgJsMimeType,
-                       'src' => "$wgScriptPath/skins/common/jquery.min.js?$wgStyleVersion",
-               );
+               $url = "$wgStylePath/common/jquery.min.js?$wgStyleVersion";
                if ( !$this->mJQueryDone ) {
                        $this->mJQueryDone = true;
-                       $this->mScripts = Html::element( 'script', $params ) . "\n" . $this->mScripts;
+                       $this->mScripts = Html::linkedScript( $url ) . "\n" . $this->mScripts;
                }
                return $unsupported;
        }