(bug14900) Make __INDEX__ and __NOINDEX__ not override $wgArticleRobotPolicies where...
[lhc/web/wiklou.git] / includes / OutputPage.php
index 7c51381..4bb2f95 100644 (file)
@@ -98,7 +98,7 @@ class OutputPage {
                }
        }
        function addScript( $script ) {
-               $this->mScripts .= "\t\t" . $script . "\n";
+               $this->mScripts .= $script . "\n";
        }
 
        /**
@@ -109,8 +109,7 @@ class OutputPage {
         *             addStyle() and draws from the /skins folder.
         */
        public function addExtensionStyle( $url ) {
-               $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
-               array_push( $this->mExtStyles, $linkarr );
+               array_push( $this->mExtStyles, $url );
        }
 
        /**
@@ -118,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 ) == '/' ) {
@@ -163,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' => wfAppendQuery( $path, $this->getURIDparam() ),
-                               ),
-                               '', false
-                       )
-               );
+               $this->addScript( Html::linkedScript( wfAppendQuery( $path, $this->getURIDparam() ) ) );
        }
 
        /**
@@ -180,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 ){
@@ -195,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;
@@ -213,7 +199,7 @@ class OutputPage {
         */
        function addScriptClass( $js_class ){
                global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses,
-                               $wgJsMimeType, $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
+                               $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
 
                if( isset( $wgJSAutoloadClasses[$js_class] ) || isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
                        if( $wgEnableScriptLoader ){
@@ -228,16 +214,8 @@ class OutputPage {
                                }else if( isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
                                        $path.= $wgJSAutoloadLocalClasses[$js_class];
                                }
-                               $urlApend = ( $wgDebugJavaScript) ? time() : $wgStyleVersion;
-                               $this->addScript(
-                                       Xml::element( 'script',
-                                               array(
-                                                       'type' => $wgJsMimeType,
-                                                       'src' => "$path?" . $urlApend,
-                                               ),
-                                               '', false
-                                       )
-                               );
+                               $urlAppend = ( $wgDebugJavaScript ) ? time() : $wgStyleVersion;
+                               $this->addScript( Html::linkedScript( "$path?$urlAppend" ) );
                        }
                        return true;
                }
@@ -250,7 +228,7 @@ class OutputPage {
         * @param $forcClassAry Boolean: false by default
         */
        function getScriptLoaderJs( $forceClassAry = false ){
-               global $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript;
+               global $wgRequest, $wgDebugJavaScript;
 
                if( !$forceClassAry ){
                        $class_list = implode( ',', $this->mScriptLoaderClassList );
@@ -268,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' => wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&".$this->getURIDparam(),
-                               ),
-                               '', false
-               );
+               return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam() );
        }
 
        function getURIDparam(){
@@ -304,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 .= Html::inlineScript( "\n$script\n" ) . "\n";
        }
 
        function getScript() {
@@ -464,22 +434,14 @@ class OutputPage {
         * @return null
         */
        public function setRobotPolicy( $policy ) {
-               $policy = explode( ',', $policy );
-               $policy = array_map( 'trim', $policy );
-
-               # The default policy is follow, so if nothing is said explicitly, we
-               # do that.
-               if( in_array( 'nofollow', $policy ) ) {
-                       $this->mFollowPolicy = 'nofollow';
-               } else {
-                       $this->mFollowPolicy = 'follow';
-               }
+               $policy = Article::formatRobotPolicy( $policy );
 
-               if( in_array( 'noindex', $policy ) ) {
-                       $this->mIndexPolicy = 'noindex';
-               } else {
-                       $this->mIndexPolicy = 'index';
-               }
+               if( isset( $policy['index'] ) ){
+                       $this->setIndexPolicy( $policy['index'] );
+               }
+               if( isset( $policy['follow'] ) ){
+                       $this->setFollowPolicy( $policy['follow'] );
+               }
        }
 
        /**
@@ -751,17 +713,6 @@ class OutputPage {
                $this->mNewSectionLink = $parserOutput->getNewSection();
                $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
 
-               if( is_null( $wgExemptFromUserRobotsControl ) ) {
-                       $bannedNamespaces = $wgContentNamespaces;
-               } else {
-                       $bannedNamespaces = $wgExemptFromUserRobotsControl;
-               }
-               if( !in_array( $this->getTitle()->getNamespace(), $bannedNamespaces ) ) {
-                       # FIXME (bug 14900): This overrides $wgArticleRobotPolicies, and it
-                       # shouldn't
-                       $this->setIndexPolicy( $parserOutput->getIndexPolicy() );
-               }
-
                $this->mParseWarnings = $parserOutput->getWarnings();
                if ( $parserOutput->getCacheTime() == -1 ) {
                        $this->enableClientCache( false );
@@ -1056,7 +1007,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;
 
@@ -1719,7 +1670,7 @@ class OutputPage {
                        $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
                }
 
-               $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $dir = $wgContLang->getDir();
 
                if ( $wgHtml5 ) {
                        $ret .= "<!doctype html>\n";
@@ -1733,7 +1684,8 @@ class OutputPage {
                        $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
                }
 
-               $ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
+               $ret .= "<head>\n";
+               $ret .= "<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
                $ret .= implode( "\n", array(
                        $this->getHeadLinks(),
                        $this->buildCssLinks(),
@@ -1741,7 +1693,7 @@ class OutputPage {
                        $this->getHeadItems(),
                ));
                if( $sk->usercss ){
-                       $ret .= "<style type='text/css'>{$sk->usercss}</style>";
+                       $ret .= Html::inlineStyle( $sk->usercss );
                }
 
                if( $wgEnableScriptLoader )
@@ -1854,7 +1806,7 @@ class OutputPage {
                        }
                }
 
-               return implode( "\n\t", $tags ) . "\n";
+               return implode( "\n", $tags ) . "\n";
        }
 
        /**
@@ -1900,14 +1852,8 @@ 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';
+               // Even though we expect the media type to be lowercase, but here we
+               // force it to lowercase to be safe.
                if( $media )
                        $options['media'] = $media;
                if( $condition )
@@ -1922,7 +1868,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 );
        }
 
        /**
@@ -1937,7 +1883,7 @@ class OutputPage {
                                $links[] = $link;
                }
 
-               return "\t" . implode( "\n\t", $links );
+               return implode( "\n", $links );
        }
 
        protected function styleLink( $style, $options ) {
@@ -1945,7 +1891,7 @@ class OutputPage {
 
                if( isset( $options['dir'] ) ) {
                        global $wgContLang;
-                       $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+                       $siteDir = $wgContLang->getDir();
                        if( $siteDir != $options['dir'] )
                                return '';
                }
@@ -1956,7 +1902,7 @@ class OutputPage {
                                return '';
                        }
                } else {
-                       $media = '';
+                       $media = null;
                }
 
                if( substr( $style, 0, 1 ) == '/' ||
@@ -1968,15 +1914,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'] );