API: Fix documentation for ApiBase::require*OneParameter
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index 5073913..e8fa944 100644 (file)
  * @private
  * @ingroup Skins
  */
-class MediaWiki_I18N {
-       var $_context = array();
+class MediaWikiI18N {
+       private $context = array();
 
        function set( $varName, $value ) {
-               $this->_context[$varName] = $value;
+               $this->context[$varName] = $value;
        }
 
        function translate( $value ) {
@@ -46,7 +46,7 @@ class MediaWiki_I18N {
                while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
                        list( $src, $var ) = $m;
                        wfSuppressWarnings();
-                       $varValue = $this->_context[$var];
+                       $varValue = $this->context[$var];
                        wfRestoreWarnings();
                        $value = str_replace( $src, $varValue, $value );
                }
@@ -68,40 +68,34 @@ class MediaWiki_I18N {
  * @ingroup Skins
  */
 class SkinTemplate extends Skin {
-       /**#@+
-        * @private
-        */
-
        /**
-        * Name of our skin, it probably needs to be all lower case.  Child classes
-        * should override the default.
+        * @var string Name of our skin, it probably needs to be all lower case.
+        *   Child classes should override the default.
         */
-       var $skinname = 'monobook';
+       public $skinname = 'monobook';
 
        /**
-        * Stylesheets set to use.  Subdirectory in skins/ where various stylesheets
-        * are located.  Child classes should override the default.
+        * @var string Stylesheets set to use. Subdirectory in skins/ where various
+        *   stylesheets are located.  Child classes should override the default.
         */
-       var $stylename = 'monobook';
+       public $stylename = 'monobook';
 
        /**
-        * For QuickTemplate, the name of the subclass which will actually fill the
-        * template.  Child classes should override the default.
+        * @var string For QuickTemplate, the name of the subclass which will
+        *   actually fill the template.  Child classes should override the default.
         */
-       var $template = 'QuickTemplate';
+       public $template = 'QuickTemplate';
 
        /**
-        * Whether this skin use OutputPage::headElement() to generate the "<head>"
-        * tag
+        * @var bool Whether this skin use OutputPage::headElement() to generate
+        *   the "<head>" tag.
         */
-       var $useHeadElement = false;
-
-       /**#@-*/
+       public $useHeadElement = false;
 
        /**
         * Add specific styles for this skin
         *
-        * @param $out OutputPage
+        * @param OutputPage $out
         */
        function setupSkinUserCss( OutputPage $out ) {
                $out->addModuleStyles( array(
@@ -116,9 +110,9 @@ class SkinTemplate extends Skin {
         * and eventually it spits out some HTML. Should have interface
         * roughly equivalent to PHPTAL 0.7.
         *
-        * @param $classname String
-        * @param string $repository subdirectory where we keep template files
-        * @param $cache_dir string
+        * @param string $classname
+        * @param string $repository Subdirectory where we keep template files
+        * @param string $cache_dir
         * @return QuickTemplate
         * @private
         */
@@ -187,7 +181,10 @@ class SkinTemplate extends Skin {
                                        'lang' => $ilInterwikiCodeBCP47,
                                        'hreflang' => $ilInterwikiCodeBCP47,
                                );
-                               wfRunHooks( 'SkinTemplateGetLanguageLink', array( &$languageLink, $languageLinkTitle, $this->getTitle() ) );
+                               wfRunHooks(
+                                       'SkinTemplateGetLanguageLink',
+                                       array( &$languageLink, $languageLinkTitle, $this->getTitle() )
+                               );
                                $languageLinks[] = $languageLink;
                        }
                }
@@ -239,7 +236,7 @@ class SkinTemplate extends Skin {
        /**
         * initialize various variables and generate the template
         *
-        * @param $out OutputPage
+        * @param OutputPage $out
         */
        function outputPage( OutputPage $out = null ) {
                wfProfileIn( __METHOD__ );
@@ -277,7 +274,7 @@ class SkinTemplate extends Skin {
         * initialize various variables and generate the template
         *
         * @since 1.23
-        * @return QuickTemplate the template to be executed by outputPage
+        * @return QuickTemplate The template to be executed by outputPage
         */
        protected function prepareQuickTemplate() {
                global $wgContLang, $wgScript, $wgStylePath,
@@ -402,7 +399,8 @@ class SkinTemplate extends Skin {
                // that interface elements are in a different language.
                $tpl->set( 'userlangattributes', '' );
                $tpl->set( 'specialpageattributes', '' ); # obsolete
-               // Used by VectorBeta to insert HTML before content but after the heading for the page title. Defaults to empty string.
+               // Used by VectorBeta to insert HTML before content but after the
+               // heading for the page title. Defaults to empty string.
                $tpl->set( 'prebodyhtml', '' );
 
                if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
@@ -561,9 +559,14 @@ class SkinTemplate extends Skin {
                // and output printfooter and debughtml separately
                $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
 
-               // Append printfooter and debughtml onto bodytext so that skins that were already
-               // using bodytext before they were split out don't suddenly start not outputting information
-               $tpl->data['bodytext'] .= Html::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
+               // Append printfooter and debughtml onto bodytext so that skins that
+               // were already using bodytext before they were split out don't suddenly
+               // start not outputting information.
+               $tpl->data['bodytext'] .= Html::rawElement(
+                       'div',
+                       array( 'class' => 'printfooter' ),
+                       "\n{$tpl->data['printfooter']}"
+               ) . "\n";
                $tpl->data['bodytext'] .= $tpl->data['debughtml'];
 
                // allow extensions adding stuff after the page content.
@@ -606,7 +609,7 @@ class SkinTemplate extends Skin {
         * an error object of the appropriate type.
         * For the base class, assume strings all around.
         *
-        * @param $str Mixed
+        * @param string $str
         * @private
         */
        function printOrError( $str ) {
@@ -733,7 +736,8 @@ class SkinTemplate extends Skin {
                        $login_url = array(
                                'text' => $this->msg( $loginlink )->text(),
                                'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
-                               'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
+                               'active' => $title->isSpecial( 'Userlogin' )
+                                       && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
                        );
                        $createaccount_url = array(
                                'text' => $this->msg( 'pt-createaccount' )->text(),
@@ -774,11 +778,11 @@ class SkinTemplate extends Skin {
        /**
         * Builds an array with tab definition
         *
-        * @param Title $title page where the tab links to
-        * @param string|array $message message key or an array of message keys (will fall back)
-        * @param boolean $selected display the tab as selected
-        * @param string $query query string attached to tab URL
-        * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
+        * @param Title $title page Where the tab links to
+        * @param string|array $message Message key or an array of message keys (will fall back)
+        * @param bool $selected Display the tab as selected
+        * @param string $query Query string attached to tab URL
+        * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
         *
         * @return array
         */
@@ -875,9 +879,10 @@ class SkinTemplate extends Skin {
         * links, however these are usually automatically generated by SkinTemplate
         * itself and are not necessary when using a hook. The only things these may
         * matter to are people modifying content_navigation after it's initial creation:
-        * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
+        * - id: A "preferred" id, most skins are best off outputting this preferred
+        *   id for best compatibility.
         * - tooltiponly: This is set to true for some tabs in cases where the system
-        *                believes that the accesskey should not be added to the tab.
+        *   believes that the accesskey should not be added to the tab.
         *
         * @return array
         */
@@ -944,8 +949,11 @@ class SkinTemplate extends Skin {
                        $content_navigation['namespaces'][$talkId]['context'] = 'talk';
 
                        if ( $userCanRead ) {
+                               $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
+                                       $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
+
                                // Adds view view link
-                               if ( $title->exists() ) {
+                               if ( $title->exists() || $isForeignFile ) {
                                        $content_navigation['views']['view'] = $this->tabAction(
                                                $isTalk ? $talkPage : $subjectPage,
                                                array( "$skname-view-view", 'view' ),
@@ -955,10 +963,25 @@ class SkinTemplate extends Skin {
                                        $content_navigation['views']['view']['redundant'] = true;
                                }
 
+                               // If it is a non-local file, show a link to the file in its own repository
+                               if ( $isForeignFile ) {
+                                       $file = $this->getWikiPage()->getFile();
+                                       $content_navigation['views']['view-foreign'] = array(
+                                               'class' => '',
+                                               'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
+                                                       setContext( $this->getContext() )->
+                                                       params( $file->getRepo()->getDisplayName() )->text(),
+                                               'href' => $file->getDescriptionUrl(),
+                                               'primary' => false,
+                                       );
+                               }
+
                                wfProfileIn( __METHOD__ . '-edit' );
 
                                // Checks if user can edit the current page if it exists or create it otherwise
-                               if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) {
+                               if ( $title->quickUserCan( 'edit', $user )
+                                       && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
+                               ) {
                                        // Builds CSS class for talk page links
                                        $isTalkClass = $isTalk ? ' istalk' : '';
                                        // Whether the user is editing the page
@@ -969,13 +992,24 @@ class SkinTemplate extends Skin {
                                                && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
                                        $section = $request->getVal( 'section' );
 
-                                       $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
-                                               'edit' : 'create';
+                                       if ( $title->exists()
+                                               || ( $title->getNamespace() == NS_MEDIAWIKI
+                                                       && $title->getDefaultMessageText() !== false
+                                               )
+                                       ) {
+                                               $msgKey = $isForeignFile ? 'edit-local' : 'edit';
+                                       } else {
+                                               $msgKey = $isForeignFile ? 'create-local' : 'create';
+                                       }
                                        $content_navigation['views']['edit'] = array(
-                                               'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
-                                               'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
+                                               'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
+                                                       ? 'selected'
+                                                       : ''
+                                               ) . $isTalkClass,
+                                               'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
+                                                       ->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( $this->editUrlOptions() ),
-                                               'primary' => true, // don't collapse this in vector
+                                               'primary' => !$isForeignFile, // don't collapse this in vector
                                        );
 
                                        // section link
@@ -984,7 +1018,8 @@ class SkinTemplate extends Skin {
                                                //$content_navigation['actions']['addsection']
                                                $content_navigation['views']['addsection'] = array(
                                                        'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
-                                                       'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
+                                                       'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
+                                                               ->setContext( $this->getContext() )->text(),
                                                        'href' => $title->getLocalURL( 'action=edit&section=new' )
                                                );
                                        }
@@ -993,7 +1028,8 @@ class SkinTemplate extends Skin {
                                        // Adds view source view link
                                        $content_navigation['views']['viewsource'] = array(
                                                'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
+                                               'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
+                                                       ->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( $this->editUrlOptions() ),
                                                'primary' => true, // don't collapse this in vector
                                        );
@@ -1006,7 +1042,8 @@ class SkinTemplate extends Skin {
                                        // Adds history view link
                                        $content_navigation['views']['history'] = array(
                                                'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
+                                               'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
+                                                       ->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( 'action=history' ),
                                                'rel' => 'archives',
                                        );
@@ -1014,7 +1051,8 @@ class SkinTemplate extends Skin {
                                        if ( $title->quickUserCan( 'delete', $user ) ) {
                                                $content_navigation['actions']['delete'] = array(
                                                        'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
-                                                       'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
+                                                       'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
+                                                               ->setContext( $this->getContext() )->text(),
                                                        'href' => $title->getLocalURL( 'action=delete' )
                                                );
                                        }
@@ -1023,7 +1061,8 @@ class SkinTemplate extends Skin {
                                                $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
                                                $content_navigation['actions']['move'] = array(
                                                        'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
-                                                       'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
+                                                       'text' => wfMessageFallback( "$skname-action-move", 'move' )
+                                                               ->setContext( $this->getContext() )->text(),
                                                        'href' => $moveTitle->getLocalURL()
                                                );
                                        }
@@ -1033,7 +1072,8 @@ class SkinTemplate extends Skin {
                                                $n = $title->isDeleted();
                                                if ( $n ) {
                                                        $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
-                                                       // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
+                                                       // If the user can't undelete but can view deleted
+                                                       // history show them a "View .. deleted" tab instead.
                                                        $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
                                                        $content_navigation['actions']['undelete'] = array(
                                                                'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
@@ -1051,7 +1091,8 @@ class SkinTemplate extends Skin {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
+                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )
+                                                       ->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( "action=$mode" )
                                        );
                                }
@@ -1356,13 +1397,13 @@ abstract class QuickTemplate {
         */
        function __construct() {
                $this->data = array();
-               $this->translator = new MediaWiki_I18N();
+               $this->translator = new MediaWikiI18N();
        }
 
        /**
         * Sets the value $value to $name
-        * @param $name
-        * @param $value
+        * @param string $name
+        * @param mixed $value
         */
        public function set( $name, $value ) {
                $this->data[$name] = $value;
@@ -1384,15 +1425,15 @@ abstract class QuickTemplate {
        }
 
        /**
-        * @param $name
-        * @param $value
+        * @param string $name
+        * @param mixed $value
         */
        public function setRef( $name, &$value ) {
                $this->data[$name] =& $value;
        }
 
        /**
-        * @param $t
+        * @param MediaWikiI18N $t
         */
        public function setTranslator( &$t ) {
                $this->translator = &$t;
@@ -1406,6 +1447,8 @@ abstract class QuickTemplate {
 
        /**
         * @private
+        * @param string $str
+        * @return string
         */
        function text( $str ) {
                echo htmlspecialchars( $this->data[$str] );
@@ -1413,6 +1456,8 @@ abstract class QuickTemplate {
 
        /**
         * @private
+        * @param string $str
+        * @return string
         */
        function html( $str ) {
                echo $this->data[$str];
@@ -1420,6 +1465,8 @@ abstract class QuickTemplate {
 
        /**
         * @private
+        * @param string $str
+        * @return string
         */
        function msg( $str ) {
                echo htmlspecialchars( $this->translator->translate( $str ) );
@@ -1427,6 +1474,8 @@ abstract class QuickTemplate {
 
        /**
         * @private
+        * @param string $str
+        * @return string
         */
        function msgHtml( $str ) {
                echo $this->translator->translate( $str );
@@ -1435,6 +1484,8 @@ abstract class QuickTemplate {
        /**
         * An ugly, ugly hack.
         * @private
+        * @param string $str
+        * @return string
         */
        function msgWiki( $str ) {
                global $wgOut;
@@ -1445,6 +1496,7 @@ abstract class QuickTemplate {
 
        /**
         * @private
+        * @param string $str
         * @return bool
         */
        function haveData( $str ) {
@@ -1454,6 +1506,7 @@ abstract class QuickTemplate {
        /**
         * @private
         *
+        * @param string $str
         * @return bool
         */
        function haveMsg( $str ) {
@@ -1464,7 +1517,7 @@ abstract class QuickTemplate {
        /**
         * Get the Skin object related to this object
         *
-        * @return Skin object
+        * @return Skin
         */
        public function getSkin() {
                return $this->data['skin'];
@@ -1474,7 +1527,7 @@ abstract class QuickTemplate {
         * Fetch the output of a QuickTemplate and return it
         *
         * @since 1.23
-        * @return String
+        * @return string
         */
        public function getHTML() {
                ob_start();
@@ -1495,7 +1548,7 @@ abstract class BaseTemplate extends QuickTemplate {
        /**
         * Get a Message object with its context set
         *
-        * @param string $name message name
+        * @param string $name Message name
         * @return Message
         */
        public function getMsg( $name ) {
@@ -1525,11 +1578,15 @@ abstract class BaseTemplate extends QuickTemplate {
                wfProfileIn( __METHOD__ );
 
                $toolbox = array();
-               if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) {
+               if ( isset( $this->data['nav_urls']['whatlinkshere'] )
+                       && $this->data['nav_urls']['whatlinkshere']
+               ) {
                        $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
                        $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
                }
-               if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) {
+               if ( isset( $this->data['nav_urls']['recentchangeslinked'] )
+                       && $this->data['nav_urls']['recentchangeslinked']
+               ) {
                        $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
                        $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
                        $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
@@ -1545,7 +1602,9 @@ abstract class BaseTemplate extends QuickTemplate {
                                $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
                        }
                }
-               foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
+               foreach ( array( 'contributions', 'log', 'blockip', 'emailuser',
+                       'userrights', 'upload', 'specialpages' ) as $special
+               ) {
                        if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
                                $toolbox[$special] = $this->data['nav_urls'][$special];
                                $toolbox[$special]['id'] = "t-$special";
@@ -1813,7 +1872,9 @@ abstract class BaseTemplate extends QuickTemplate {
                        }
                        while ( count( $wrapper ) > 0 ) {
                                $element = array_pop( $wrapper );
-                               $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
+                               $html = Html::rawElement( $element['tag'], isset( $element['attributes'] )
+                                       ? $element['attributes']
+                                       : null, $html );
                        }
                }
 
@@ -1849,7 +1910,9 @@ abstract class BaseTemplate extends QuickTemplate {
                                        $attrs['class'] = $options['link-class'];
                                }
                        }
-                       $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html );
+                       $html = Html::rawElement( isset( $attrs['href'] )
+                               ? 'a'
+                               : $options['link-fallback'], $attrs, $html );
                }
 
                return $html;
@@ -1858,12 +1921,12 @@ abstract class BaseTemplate extends QuickTemplate {
        /**
         * Generates a list item for a navigation, portlet, portal, sidebar... list
         *
-        * @param $key string, usually a key from the list you are generating this link from.
-        * @param $item array, of list item data containing some of a specific set of keys.
+        * @param string $key Usually a key from the list you are generating this link from.
+        * @param array $item Array of list item data containing some of a specific set of keys.
         * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
         * if "active" contains a value of true a "active" class will also be appended to class.
         *
-        * @param $options array
+        * @param array $options
         *
         * If you want something other than a "<li>" you can pass a tag name such as
         * "tag" => "span" in the $options array to change the tag used.
@@ -1885,10 +1948,11 @@ abstract class BaseTemplate extends QuickTemplate {
         */
        function makeListItem( $key, $item, $options = array() ) {
                if ( isset( $item['links'] ) ) {
-                       $html = '';
+                       $links = array();
                        foreach ( $item['links'] as $linkKey => $link ) {
-                               $html .= $this->makeLink( $linkKey, $link, $options );
+                               $links[] = $this->makeLink( $linkKey, $link, $options );
                        }
+                       $html = implode( ' ', $links );
                } else {
                        $link = $item;
                        // These keys are used by makeListItem and shouldn't be passed on to the link
@@ -2023,7 +2087,7 @@ abstract class BaseTemplate extends QuickTemplate {
         * in the list of footer icons. This is mostly useful for skins which only
         * display the text from footericons instead of the images and don't want a
         * duplicate copyright statement because footerlinks already rendered one.
-        * @return
+        * @return string
         */
        function getFooterIcons( $option = null ) {
                // Generate additional footer icons