Make the instantiation tests actually work.
[lhc/web/wiklou.git] / includes / OutputPage.php
index a4cbecc..cf92eaf 100644 (file)
@@ -47,6 +47,11 @@ class OutputPage {
         */
        var $styles = array();
 
+       /**
+        * Whether to load jQuery core.
+        */
+       protected $mJQueryDone = false;
+
        private $mIndexPolicy = 'index';
        private $mFollowPolicy = 'follow';
        private $mVaryHeader = array( 'Accept-Encoding' => array('list-contains=gzip'),
@@ -117,21 +122,13 @@ class OutputPage {
         * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
         */
        function addScriptFile( $file ) {
-               global $wgStylePath, $wgStyleVersion, $wgJsMimeType;
+               global $wgStylePath, $wgStyleVersion;
                if( substr( $file, 0, 1 ) == '/' ) {
                        $path = $file;
                } else {
                        $path =  "{$wgStylePath}/common/{$file}";
                }
-               $this->addScript( 
-                       Xml::element( 'script', 
-                               array(
-                                       'type' => $wgJsMimeType,
-                                       'src' => "$path?$wgStyleVersion",
-                               ),
-                               '', false
-                       )
-               );
+               $this->addScript( Html::linkedScript( "$path?$wgStyleVersion" ) );
        }
 
        /**
@@ -384,10 +381,17 @@ class OutputPage {
        public function isArticle() { return $this->mIsarticle; }
        public function setPrintable() { $this->mPrintable = true; }
        public function isPrintable() { return $this->mPrintable; }
-       public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
        public function disable() { $this->mDoNothing = true; }
        public function isDisabled() { return $this->mDoNothing; }
 
+       /**
+        * Add or remove feed links in the page header
+        * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
+        * for the new version
+        * @see addFeedLink()
+        *
+        * @param $show Boolean: true: add default feeds, false: remove all feeds
+        */
        public function setSyndicated( $show = true ) {
                if ( $show ) {
                        $this->setFeedAppendQuery( false );
@@ -396,8 +400,17 @@ class OutputPage {
                }
        }
 
+       /**
+        * Add default feeds to the page header
+        * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
+        * for the new version
+        * @see addFeedLink()
+        *
+        * @param $val String: query to append to feed links or false to output
+        *        default links
+        */
        public function setFeedAppendQuery( $val ) {
-               global $wgFeedClasses, $wgAdvertisedFeedTypes;
+               global $wgAdvertisedFeedTypes;
 
                $this->mFeedLinks = array();
 
@@ -410,11 +423,23 @@ class OutputPage {
                }
        }
 
+       /**
+        * Add a feed link to the page header
+        *
+        * @param $format String: feed type, should be a key of $wgFeedClasses
+        * @param $href String: URL
+        */
        public function addFeedLink( $format, $href ) {
                $this->mFeedLinks[$format] = $href;
        }
 
-       public function isSyndicated() { return count($this->mFeedLinks); }
+       /**
+        * Should we output feed links for this page?
+        * @return Boolean
+        */
+       public function isSyndicated() { return count($this->mFeedLinks) > 0; }
+
+       public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
 
        public function setArticleRelated( $v ) {
                $this->mIsArticleRelated = $v;
@@ -1725,10 +1750,14 @@ class OutputPage {
                                $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
                        } else {
                                $userpage = $wgUser->getUserPage();
-                               $userjs = Skin::makeUrl(
-                                       $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
-                                       'action=raw&ctype=' . $wgJsMimeType );
-                               $this->addScriptFile( $userjs );
+                               $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 );
+                               }
                        }
                }
 
@@ -1816,7 +1845,7 @@ class OutputPage {
                        # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
                        # If so, use it instead.
 
-                       global $wgOverrideSiteFeed, $wgSitename, $wgFeedClasses, $wgAdvertisedFeedTypes;
+                       global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
                        $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
 
                        if ( $wgOverrideSiteFeed ) {
@@ -2099,4 +2128,30 @@ class OutputPage {
                }
                $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
        }
+
+       /**
+        * Include jQuery core. Use this to avoid loading it multiple times
+        * before we get a usable script loader. 
+        *
+        * @param array $modules List of jQuery modules which should be loaded
+        *
+        * Returns the list of modules which were not loaded.
+        */
+       public function includeJQuery( $modules = array() ) {
+               global $wgScriptPath, $wgStyleVersion, $wgJsMimeType;
+
+               $supportedModules = array( 'ui' );
+               $unsupported = array_diff( $modules, $supportedModules );
+
+               $params = array(
+                       'type' => $wgJsMimeType,
+                       'src' => "$wgScriptPath/skins/common/jquery.min.js?$wgStyleVersion",
+               );
+               if ( !$this->mJQueryDone ) {
+                       $this->mJQueryDone = true;
+                       $this->mScripts = Html::element( 'script', $params ) . "\n" . $this->mScripts;
+               }
+               return $unsupported;
+       }
+
 }