Merge "Ensure that expiry times are given as integers"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 64d2bc8..c98f34b 100644 (file)
@@ -100,7 +100,7 @@ class OutputPage extends ContextSource {
        protected $mStatusCode;
 
        /**
-        * @ var string mLastModified and mEtag are used for sending cache control.
+        * @var string Variable mLastModified and mEtag are used for sending cache control.
         *   The whole caching system should probably be moved into its own class.
         */
        protected $mLastModified = '';
@@ -311,6 +311,7 @@ class OutputPage extends ContextSource {
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
         * a OutputPage tied to that context.
+        * @param IContextSource|null $context
         */
        function __construct( IContextSource $context = null ) {
                if ( $context === null ) {
@@ -355,8 +356,8 @@ class OutputPage extends ContextSource {
         * Add a new "<meta>" tag
         * To add an http-equiv meta tag, precede the name with "http:"
         *
-        * @param string $name tag name
-        * @param string $val tag value
+        * @param string $name Tag name
+        * @param string $val Tag value
         */
        function addMeta( $name, $val ) {
                array_push( $this->mMetatags, array( $name, $val ) );
@@ -367,20 +368,20 @@ class OutputPage extends ContextSource {
         *
         * Note: use setCanonicalUrl() for rel=canonical.
         *
-        * @param array $linkarr associative array of attributes.
+        * @param array $linkarr Associative array of attributes.
         */
-       function addLink( $linkarr ) {
+       function addLink( array $linkarr ) {
                array_push( $this->mLinktags, $linkarr );
        }
 
        /**
         * Add a new \<link\> with "rel" attribute set to "meta"
         *
-        * @param array $linkarr associative array mapping attribute names to their
+        * @param array $linkarr Associative array mapping attribute names to their
         *                 values, both keys and values will be escaped, and the
         *                 "rel" attribute will be automatically added
         */
-       function addMetadataLink( $linkarr ) {
+       function addMetadataLink( array $linkarr ) {
                $linkarr['rel'] = $this->getMetadataAttribute();
                $this->addLink( $linkarr );
        }
@@ -388,6 +389,7 @@ class OutputPage extends ContextSource {
        /**
         * Set the URL to be used for the <link rel=canonical>. This should be used
         * in preference to addLink(), to avoid duplicate link tags.
+        * @param string $url
         */
        function setCanonicalUrl( $url ) {
                $this->mCanonicalUrl = $url;
@@ -412,7 +414,7 @@ class OutputPage extends ContextSource {
        /**
         * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
         *
-        * @param string $script raw HTML
+        * @param string $script Raw HTML
         */
        function addScript( $script ) {
                $this->mScripts .= $script . "\n";
@@ -421,7 +423,7 @@ class OutputPage extends ContextSource {
        /**
         * Register and add a stylesheet from an extension directory.
         *
-        * @param string $url path to sheet.  Provide either a full url (beginning
+        * @param string $url 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.
@@ -442,9 +444,9 @@ class OutputPage extends ContextSource {
        /**
         * Add a JavaScript file out of skins/common, or a given relative path.
         *
-        * @param string $file filename in skins/common or complete on-server path
+        * @param string $file Filename in skins/common or complete on-server path
         *              (/foo/bar.js)
-        * @param string $version style version of the file. Defaults to $wgStyleVersion
+        * @param string $version Style version of the file. Defaults to $wgStyleVersion
         */
        public function addScriptFile( $file, $version = null ) {
                global $wgStylePath, $wgStyleVersion;
@@ -484,11 +486,11 @@ class OutputPage extends ContextSource {
         * Filter an array of modules to remove insufficiently trustworthy members, and modules
         * which are no longer registered (eg a page is cached before an extension is disabled)
         * @param array $modules
-        * @param string|null $position if not null, only return modules with this position
+        * @param string|null $position If not null, only return modules with this position
         * @param string $type
         * @return array
         */
-       protected function filterModules( $modules, $position = null,
+       protected function filterModules( array $modules, $position = null,
                $type = ResourceLoaderModule::TYPE_COMBINED
        ) {
                $resourceLoader = $this->getResourceLoader();
@@ -647,8 +649,8 @@ class OutputPage extends ContextSource {
        /**
         * Add or replace an header item to the output
         *
-        * @param string $name item name
-        * @param string $value raw HTML
+        * @param string $name Item name
+        * @param string $value Raw HTML
         */
        public function addHeadItem( $name, $value ) {
                $this->mHeadItems[$name] = $value;
@@ -667,7 +669,7 @@ class OutputPage extends ContextSource {
        /**
         * Set the value of the ETag HTTP header, only used if $wgUseETag is true
         *
-        * @param string $tag value of "ETag" header
+        * @param string $tag Value of "ETag" header
         */
        function setETag( $tag ) {
                $this->mETag = $tag;
@@ -815,7 +817,7 @@ class OutputPage extends ContextSource {
        /**
         * Override the last modified timestamp
         *
-        * @param string $timestamp new timestamp, in a format readable by
+        * @param string $timestamp New timestamp, in a format readable by
         *        wfTimestamp()
         */
        public function setLastModified( $timestamp ) {
@@ -825,7 +827,7 @@ class OutputPage extends ContextSource {
        /**
         * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
         *
-        * @param string $policy the literal string to output as the contents of
+        * @param string $policy The literal string to output as the contents of
         *   the meta tag.  Will be parsed according to the spec and output in
         *   standardized form.
         * @return null
@@ -859,7 +861,7 @@ class OutputPage extends ContextSource {
         * Set the follow policy for the page, but leave the index policy un-
         * touched.
         *
-        * @param string $policy either 'follow' or 'nofollow'.
+        * @param string $policy Either 'follow' or 'nofollow'.
         * @return null
         */
        public function setFollowPolicy( $policy ) {
@@ -873,7 +875,7 @@ class OutputPage extends ContextSource {
         * Set the new value of the "action text", this will be added to the
         * "HTML title", separated from it with " - ".
         *
-        * @param string $text new value of the "action text"
+        * @param string $text New value of the "action text"
         */
        public function setPageTitleActionText( $text ) {
                $this->mPageTitleActionText = $text;
@@ -892,7 +894,7 @@ class OutputPage extends ContextSource {
         * "HTML title" means the contents of "<title>".
         * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
         *
-        * @param string $name
+        * @param string|Message $name
         */
        public function setHTMLTitle( $name ) {
                if ( $name instanceof Message ) {
@@ -968,7 +970,7 @@ class OutputPage extends ContextSource {
        /**
         * Replace the subtitle with $str
         *
-        * @param string|Message $str new value of the subtitle. String should be safe HTML.
+        * @param string|Message $str New value of the subtitle. String should be safe HTML.
         */
        public function setSubtitle( $str ) {
                $this->clearSubtitle();
@@ -979,7 +981,7 @@ class OutputPage extends ContextSource {
         * Add $str to the subtitle
         *
         * @deprecated since 1.19; use addSubtitle() instead
-        * @param string|Message $str to add to the subtitle
+        * @param string|Message $str String or Message to add to the subtitle
         */
        public function appendSubtitle( $str ) {
                $this->addSubtitle( $str );
@@ -988,7 +990,7 @@ class OutputPage extends ContextSource {
        /**
         * Add $str to the subtitle
         *
-        * @param string|Message $str to add to the subtitle. String should be safe HTML.
+        * @param string|Message $str String or Message to add to the subtitle. String should be safe HTML.
         */
        public function addSubtitle( $str ) {
                if ( $str instanceof Message ) {
@@ -1002,9 +1004,9 @@ class OutputPage extends ContextSource {
         * Add a subtitle containing a backlink to a page
         *
         * @param Title $title Title to link to
+        * @param array $query Array of additional parameters to include in the link
         */
-       public function addBacklinkSubtitle( Title $title ) {
-               $query = array();
+       public function addBacklinkSubtitle( Title $title, $query = array() ) {
                if ( $title->isRedirect() ) {
                        $query['redirect'] = 'no';
                }
@@ -1085,7 +1087,7 @@ class OutputPage extends ContextSource {
         * for the new version
         * @see addFeedLink()
         *
-        * @param bool $show true: add default feeds, false: remove all feeds
+        * @param bool $show True: add default feeds, false: remove all feeds
         */
        public function setSyndicated( $show = true ) {
                if ( $show ) {
@@ -1101,7 +1103,7 @@ class OutputPage extends ContextSource {
         * for the new version
         * @see addFeedLink()
         *
-        * @param string $val query to append to feed links or false to output
+        * @param string $val Query to append to feed links or false to output
         *        default links
         */
        public function setFeedAppendQuery( $val ) {
@@ -1121,7 +1123,7 @@ class OutputPage extends ContextSource {
        /**
         * Add a feed link to the page header
         *
-        * @param string $format feed type, should be a key of $wgFeedClasses
+        * @param string $format Feed type, should be a key of $wgFeedClasses
         * @param string $href URL
         */
        public function addFeedLink( $format, $href ) {
@@ -1142,7 +1144,7 @@ class OutputPage extends ContextSource {
 
        /**
         * Return URLs for each supported syndication format for this page.
-        * @return array associating format keys with URLs
+        * @return array Associating format keys with URLs
         */
        public function getSyndicationLinks() {
                return $this->mFeedLinks;
@@ -1209,7 +1211,7 @@ class OutputPage extends ContextSource {
         * @param array $newLinkArray Associative array mapping language code to the page
         *                      name
         */
-       public function addLanguageLinks( $newLinkArray ) {
+       public function addLanguageLinks( array $newLinkArray ) {
                $this->mLanguageLinks += $newLinkArray;
        }
 
@@ -1219,7 +1221,7 @@ class OutputPage extends ContextSource {
         * @param array $newLinkArray Associative array mapping language code to the page
         *                      name
         */
-       public function setLanguageLinks( $newLinkArray ) {
+       public function setLanguageLinks( array $newLinkArray ) {
                $this->mLanguageLinks = $newLinkArray;
        }
 
@@ -1235,10 +1237,10 @@ class OutputPage extends ContextSource {
        /**
         * Add an array of categories, with names in the keys
         *
-        * @param array $categories mapping category name => sort key
+        * @param array $categories Mapping category name => sort key
         */
-       public function addCategoryLinks( $categories ) {
-               global $wgContLang;
+       public function addCategoryLinks( array $categories ) {
+               global $wgContLang, $wgContentHandlerUseDB;
 
                if ( !is_array( $categories ) || count( $categories ) == 0 ) {
                        return;
@@ -1251,9 +1253,15 @@ class OutputPage extends ContextSource {
 
                # Fetch existence plus the hiddencat property
                $dbr = wfGetDB( DB_SLAVE );
+               $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len',
+                       'page_is_redirect', 'page_latest', 'pp_value' );
+
+               if ( $wgContentHandlerUseDB ) {
+                       $fields[] = 'page_content_model';
+               }
+
                $res = $dbr->select( array( 'page', 'page_props' ),
-                       array( 'page_id', 'page_namespace', 'page_title', 'page_len',
-                               'page_is_redirect', 'page_latest', 'pp_value' ),
+                       $fields,
                        $lb->constructSet( 'page', $dbr ),
                        __METHOD__,
                        array(),
@@ -1266,11 +1274,8 @@ class OutputPage extends ContextSource {
                # Add the results to the link cache
                $lb->addResultToCache( LinkCache::singleton(), $res );
 
-               # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
-               $categories = array_combine(
-                       array_keys( $categories ),
-                       array_fill( 0, count( $categories ), 'normal' )
-               );
+               # Set all the values to 'normal'.
+               $categories = array_fill_keys( array_keys( $categories ), 'normal' );
 
                # Mark hidden categories
                foreach ( $res as $row ) {
@@ -1291,10 +1296,8 @@ class OutputPage extends ContextSource {
                                        continue;
                                }
                                $wgContLang->findVariantLink( $category, $title, true );
-                               if ( $category != $origcategory ) {
-                                       if ( array_key_exists( $category, $categories ) ) {
-                                               continue;
-                                       }
+                               if ( $category != $origcategory && array_key_exists( $category, $categories ) ) {
+                                       continue;
                                }
                                $text = $wgContLang->convertHtml( $title->getText() );
                                $this->mCategories[] = $title->getText();
@@ -1306,9 +1309,9 @@ class OutputPage extends ContextSource {
        /**
         * Reset the category links (but not the category list) and add $categories
         *
-        * @param array $categories mapping category name => sort key
+        * @param array $categories Mapping category name => sort key
         */
-       public function setCategoryLinks( $categories ) {
+       public function setCategoryLinks( array $categories ) {
                $this->mCategoryLinks = array();
                $this->addCategoryLinks( $categories );
        }
@@ -1406,7 +1409,7 @@ class OutputPage extends ContextSource {
         * @param array $attribs
         * @param string $contents
         */
-       public function addElement( $element, $attribs = array(), $contents = '' ) {
+       public function addElement( $element, array $attribs = array(), $contents = '' ) {
                $this->addHTML( Html::element( $element, $attribs, $contents ) );
        }
 
@@ -1643,6 +1646,8 @@ class OutputPage extends ContextSource {
                $this->addModuleStyles( $parserOutput->getModuleStyles() );
                $this->addModuleMessages( $parserOutput->getModuleMessages() );
                $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
+               $this->mPreventClickjacking = $this->mPreventClickjacking
+                       || $parserOutput->preventClickjacking();
 
                // Template versioning...
                foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {
@@ -1855,7 +1860,7 @@ class OutputPage extends ContextSource {
        /**
         * Add an HTTP header that will influence on the cache
         *
-        * @param string $header header name
+        * @param string $header Header name
         * @param array|null $option
         * @todo FIXME: Document the $option parameter; it appears to be for
         *        X-Vary-Options but what format is acceptable?
@@ -1970,6 +1975,16 @@ class OutputPage extends ContextSource {
                $this->mPreventClickjacking = false;
        }
 
+       /**
+        * Get the prevent-clickjacking flag
+        *
+        * @since 1.24
+        * @return bool
+        */
+       public function getPreventClickjacking() {
+               return $this->mPreventClickjacking;
+       }
+
        /**
         * Get the X-Frame-Options header value (without the name part), or false
         * if there isn't one. This is used by Skin to determine whether to enable
@@ -2177,7 +2192,7 @@ class OutputPage extends ContextSource {
        /**
         * Actually output something with print.
         *
-        * @param string $ins the string to output
+        * @param string $ins The string to output
         * @deprecated since 1.22 Use echo yourself.
         */
        public function out( $ins ) {
@@ -2198,8 +2213,8 @@ class OutputPage extends ContextSource {
         * indexing, clear the current text and redirect, set the page's title
         * and optionally an custom HTML title (content of the "<title>" tag).
         *
-        * @param string|Message $pageTitle will be passed directly to setPageTitle()
-        * @param string|Message $htmlTitle will be passed directly to setHTMLTitle();
+        * @param string|Message $pageTitle Will be passed directly to setPageTitle()
+        * @param string|Message $htmlTitle Will be passed directly to setHTMLTitle();
         *                   optional, if not passed the "<title>" attribute will be
         *                   based on $pageTitle
         */
@@ -2252,10 +2267,10 @@ class OutputPage extends ContextSource {
        /**
         * Output a standard permission error page
         *
-        * @param array $errors error message keys
-        * @param string $action action that was denied or null if unknown
+        * @param array $errors Error message keys
+        * @param string $action Action that was denied or null if unknown
         */
-       public function showPermissionsErrorPage( $errors, $action = null ) {
+       public function showPermissionsErrorPage( array $errors, $action = null ) {
                // For some action (read, edit, create and upload), display a "login to do this action"
                // error if all of the following conditions are met:
                // 1. the user is not logged in
@@ -2337,7 +2352,7 @@ class OutputPage extends ContextSource {
        /**
         * Display an error page noting that a given permission bit is required.
         * @deprecated since 1.18, just throw the exception directly
-        * @param string $permission key required
+        * @param string $permission Key required
         * @throws PermissionsError
         */
        public function permissionRequired( $permission ) {
@@ -2360,7 +2375,7 @@ class OutputPage extends ContextSource {
         * @param string $action Action that was denied or null if unknown
         * @return string The wikitext error-messages, formatted into a list.
         */
-       public function formatPermissionsErrorMessage( $errors, $action = null ) {
+       public function formatPermissionsErrorMessage( array $errors, $action = null ) {
                if ( $action == null ) {
                        $text = $this->msg( 'permissionserrorstext', count( $errors ) )->plain() . "\n\n";
                } else {
@@ -2413,7 +2428,7 @@ class OutputPage extends ContextSource {
         * @throws ReadOnlyError
         */
        public function readOnlyPage( $source = null, $protected = false,
-               $reasons = array(), $action = null
+               array $reasons = array(), $action = null
        ) {
                $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
@@ -2532,7 +2547,7 @@ $templates
         * @param string $text Text of the link (input is not escaped)
         * @param array $options Options array to pass to Linker
         */
-       public function addReturnTo( $title, $query = array(), $text = null, $options = array() ) {
+       public function addReturnTo( $title, array $query = array(), $text = null, $options = array() ) {
                $link = $this->msg( 'returnto' )->rawParams(
                        Linker::link( $title, $text, array(), $query, $options ) )->escaped();
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
@@ -2790,9 +2805,7 @@ $templates
                                                );
                                        } else {
                                                $links['html'] .= Html::inlineScript(
-                                                       ResourceLoader::makeLoaderConditionalScript(
-                                                               $resourceLoader->makeModuleResponse( $context, $grpModules )
-                                                       )
+                                                       $resourceLoader->makeModuleResponse( $context, $grpModules )
                                                );
                                        }
                                        $links['html'] .= "\n";
@@ -2866,7 +2879,7 @@ $templates
         * @param array $links
         * @return string HTML
         */
-       protected static function getHtmlFromLoaderLinks( Array $links ) {
+       protected static function getHtmlFromLoaderLinks( array $links ) {
                $html = '';
                $states = array();
                foreach ( $links as $link ) {
@@ -2900,7 +2913,7 @@ $templates
 
                // Startup - this will immediately load jquery and mediawiki modules
                $links = array();
-               $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, /* $useESI =  */ true );
+               $links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
 
                // Load config before anything else
                $links[] = Html::inlineScript(
@@ -3022,14 +3035,6 @@ $templates
                        /* $useESI = */ false, /* $extraQuery = */ array(), /* $loadCall = */ $inHead
                );
 
-               $modules = array();
-               wfRunHooks( 'OutputPageScriptsForBottomQueue', array( $this, &$modules ) );
-               if ( $modules ) {
-                       $links[] = $this->makeResourceLoaderLink( $modules, ResourceLoaderModule::TYPE_COMBINED,
-                               /* $useESI = */ false, /* $extraQuery = */ array(), /* $loadCall = */ $inHead
-                       );
-               }
-
                return self::getHtmlFromLoaderLinks( $links );
        }
 
@@ -3230,7 +3235,7 @@ $templates
        }
 
        /**
-        * @return array in format "link name or number => 'link html'".
+        * @return array Array in format "link name or number => 'link html'".
         */
        public function getHeadLinksArray() {
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
@@ -3487,9 +3492,9 @@ $templates
         * Meant primarily for internal use...
         *
         * @param string $style URL to the file
-        * @param string $media to specify a media type, 'screen', 'printable', 'handheld' or any.
-        * @param string $condition for IE conditional comments, specifying an IE version
-        * @param string $dir set to 'rtl' or 'ltr' for direction-specific sheets
+        * @param string $media To specify a media type, 'screen', 'printable', 'handheld' or any.
+        * @param string $condition For IE conditional comments, specifying an IE version
+        * @param string $dir Set to 'rtl' or 'ltr' for direction-specific sheets
         */
        public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
                $options = array();
@@ -3584,7 +3589,7 @@ $templates
                        $group = $module->getGroup();
                        // Modules in groups different than the ones listed on top (see $styles assignment)
                        // will be placed in the "other" group
-                       $styles[ isset( $styles[$group] ) ? $group : 'other' ][] = $name;
+                       $styles[isset( $styles[$group] ) ? $group : 'other'][] = $name;
                }
 
                // We want site, private and user styles to override dynamically added
@@ -3643,7 +3648,7 @@ $templates
         * @param array $options Option, can contain 'condition', 'dir', 'media' keys
         * @return string HTML fragment
         */
-       protected function styleLink( $style, $options ) {
+       protected function styleLink( $style, array $options ) {
                if ( isset( $options['dir'] ) ) {
                        if ( $this->getLanguage()->getDir() != $options['dir'] ) {
                                return '';
@@ -3804,7 +3809,7 @@ $templates
         * @since 1.16
         * @deprecated since 1.17
         */
-       public function includeJQuery( $modules = array() ) {
+       public function includeJQuery( array $modules = array() ) {
                return array();
        }