Merge "Enforce array type hinting in OutputPage.php"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 1 Aug 2014 19:08:16 +0000 (19:08 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 1 Aug 2014 19:08:16 +0000 (19:08 +0000)
1  2 
includes/OutputPage.php

diff --combined includes/OutputPage.php
@@@ -100,7 -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 = '';
         * 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 ) );
         *
         * 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 );
        }
        /**
         * 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";
        /**
         * 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.
        /**
         * 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;
         * 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();
        /**
         * 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;
        /**
         * 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;
        /**
         * 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 ) {
        /**
         * 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
         * 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 ) {
         * 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;
         * "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 ) {
        /**
         * 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();
         * 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 );
        /**
         * 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 ) {
         * 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 ) {
         * 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 ) {
        /**
         * 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 ) {
  
        /**
         * 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;
         * @param array $newLinkArray Associative array mapping language code to the page
         *                      name
         */
-       public function addLanguageLinks( $newLinkArray ) {
+       public function addLanguageLinks( array $newLinkArray ) {
                $this->mLanguageLinks += $newLinkArray;
        }
  
         * @param array $newLinkArray Associative array mapping language code to the page
         *                      name
         */
-       public function setLanguageLinks( $newLinkArray ) {
+       public function setLanguageLinks( array $newLinkArray ) {
                $this->mLanguageLinks = $newLinkArray;
        }
  
        /**
         * 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 ) {
+       public function addCategoryLinks( array $categories ) {
                global $wgContLang;
  
                if ( !is_array( $categories ) || count( $categories ) == 0 ) {
                # 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 ) {
                        foreach ( $categories as $category => $type ) {
                                $origcategory = $category;
                                $title = Title::makeTitleSafe( NS_CATEGORY, $category );
 +                              if ( !$title ) {
 +                                      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();
        /**
         * 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 );
        }
         * @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 ) );
        }
  
                $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 ) {
        /**
         * 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?
                $this->mPreventClickjacking = false;
        }
  
 +      /**
 +       * Get the prevent-clickjacking flag
 +       *
 +       * @since 1.24
 +       * @return boolean
 +       */
 +      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
        /**
         * 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 ) {
         * 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
         */
        /**
         * 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
        /**
         * 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 ) {
         * @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 {
         * @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 );
@@@ -2539,7 -2529,7 +2539,7 @@@ $template
         * @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" );
                                        && $only == ResourceLoaderModule::TYPE_SCRIPTS )
                                || ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_STYLES )
                                        && $only == ResourceLoaderModule::TYPE_STYLES )
 +                              || ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_COMBINED )
 +                                      && $only == ResourceLoaderModule::TYPE_COMBINED )
                                || ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) )
                        ) {
                                continue;
         * @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 ) {
  
                // 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(
                        /* $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 );
        }
  
        }
  
        /**
 -       * @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,
         * 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();
                        $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
         * @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 '';
         * @since 1.16
         * @deprecated since 1.17
         */
-       public function includeJQuery( $modules = array() ) {
+       public function includeJQuery( array $modules = array() ) {
                return array();
        }