[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/skins/ -> SkinTemplate.php (source)

   1  <?php
   2  /**
   3   * Base class for template-based skins.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   */
  22  
  23  /**
  24   * Wrapper object for MediaWiki's localization functions,
  25   * to be passed to the template engine.
  26   *
  27   * @private
  28   * @ingroup Skins
  29   */
  30  class MediaWikiI18N {
  31      private $context = array();
  32  
  33  	function set( $varName, $value ) {
  34          $this->context[$varName] = $value;
  35      }
  36  
  37  	function translate( $value ) {
  38          wfProfileIn( __METHOD__ );
  39  
  40          // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
  41          $value = preg_replace( '/^string:/', '', $value );
  42  
  43          $value = wfMessage( $value )->text();
  44          // interpolate variables
  45          $m = array();
  46          while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
  47              list( $src, $var ) = $m;
  48              wfSuppressWarnings();
  49              $varValue = $this->context[$var];
  50              wfRestoreWarnings();
  51              $value = str_replace( $src, $varValue, $value );
  52          }
  53          wfProfileOut( __METHOD__ );
  54          return $value;
  55      }
  56  }
  57  
  58  /**
  59   * Template-filler skin base class
  60   * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
  61   * Based on Brion's smarty skin
  62   * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
  63   *
  64   * @todo Needs some serious refactoring into functions that correspond
  65   * to the computations individual esi snippets need. Most importantly no body
  66   * parsing for most of those of course.
  67   *
  68   * @ingroup Skins
  69   */
  70  class SkinTemplate extends Skin {
  71      /**
  72       * @var string Name of our skin, it probably needs to be all lower case.
  73       *   Child classes should override the default.
  74       */
  75      public $skinname = 'monobook';
  76  
  77      /**
  78       * @var string For QuickTemplate, the name of the subclass which will
  79       *   actually fill the template.  Child classes should override the default.
  80       */
  81      public $template = 'QuickTemplate';
  82  
  83      /**
  84       * Add specific styles for this skin
  85       *
  86       * @param OutputPage $out
  87       */
  88  	function setupSkinUserCss( OutputPage $out ) {
  89          $out->addModuleStyles( array(
  90              'mediawiki.legacy.shared',
  91              'mediawiki.legacy.commonPrint',
  92              'mediawiki.ui.button'
  93          ) );
  94      }
  95  
  96      /**
  97       * Create the template engine object; we feed it a bunch of data
  98       * and eventually it spits out some HTML. Should have interface
  99       * roughly equivalent to PHPTAL 0.7.
 100       *
 101       * @param string $classname
 102       * @param bool|string $repository Subdirectory where we keep template files
 103       * @param bool|string $cache_dir
 104       * @return QuickTemplate
 105       * @private
 106       */
 107  	function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
 108          return new $classname( $this->getConfig() );
 109      }
 110  
 111      /**
 112       * Generates array of language links for the current page
 113       *
 114       * @return array
 115       */
 116  	public function getLanguages() {
 117          global $wgHideInterlanguageLinks;
 118          if ( $wgHideInterlanguageLinks ) {
 119              return array();
 120          }
 121  
 122          $userLang = $this->getLanguage();
 123          $languageLinks = array();
 124  
 125          foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
 126              $languageLinkParts = explode( ':', $languageLinkText, 2 );
 127              $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
 128              unset( $languageLinkParts );
 129  
 130              $languageLinkTitle = Title::newFromText( $languageLinkText );
 131              if ( $languageLinkTitle ) {
 132                  $ilInterwikiCode = $languageLinkTitle->getInterwiki();
 133                  $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
 134  
 135                  if ( strval( $ilLangName ) === '' ) {
 136                      $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
 137                      if ( !$ilDisplayTextMsg->isDisabled() ) {
 138                          // Use custom MW message for the display text
 139                          $ilLangName = $ilDisplayTextMsg->text();
 140                      } else {
 141                          // Last resort: fallback to the language link target
 142                          $ilLangName = $languageLinkText;
 143                      }
 144                  } else {
 145                      // Use the language autonym as display text
 146                      $ilLangName = $this->formatLanguageName( $ilLangName );
 147                  }
 148  
 149                  // CLDR extension or similar is required to localize the language name;
 150                  // otherwise we'll end up with the autonym again.
 151                  $ilLangLocalName = Language::fetchLanguageName(
 152                      $ilInterwikiCode,
 153                      $userLang->getCode()
 154                  );
 155  
 156                  $languageLinkTitleText = $languageLinkTitle->getText();
 157                  if ( $ilLangLocalName === '' ) {
 158                      $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
 159                      if ( !$ilFriendlySiteName->isDisabled() ) {
 160                          if ( $languageLinkTitleText === '' ) {
 161                              $ilTitle = wfMessage(
 162                                  'interlanguage-link-title-nonlangonly',
 163                                  $ilFriendlySiteName->text()
 164                              )->text();
 165                          } else {
 166                              $ilTitle = wfMessage(
 167                                  'interlanguage-link-title-nonlang',
 168                                  $languageLinkTitleText,
 169                                  $ilFriendlySiteName->text()
 170                              )->text();
 171                          }
 172                      } else {
 173                          // we have nothing friendly to put in the title, so fall back to
 174                          // displaying the interlanguage link itself in the title text
 175                          // (similar to what is done in page content)
 176                          $ilTitle = $languageLinkTitle->getInterwiki() .
 177                              ":$languageLinkTitleText";
 178                      }
 179                  } elseif ( $languageLinkTitleText === '' ) {
 180                      $ilTitle = wfMessage(
 181                          'interlanguage-link-title-langonly',
 182                          $ilLangLocalName
 183                      )->text();
 184                  } else {
 185                      $ilTitle = wfMessage(
 186                          'interlanguage-link-title',
 187                          $languageLinkTitleText,
 188                          $ilLangLocalName
 189                      )->text();
 190                  }
 191  
 192                  $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
 193                  $languageLink = array(
 194                      'href' => $languageLinkTitle->getFullURL(),
 195                      'text' => $ilLangName,
 196                      'title' => $ilTitle,
 197                      'class' => $class,
 198                      'lang' => $ilInterwikiCodeBCP47,
 199                      'hreflang' => $ilInterwikiCodeBCP47,
 200                  );
 201                  wfRunHooks(
 202                      'SkinTemplateGetLanguageLink',
 203                      array( &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() )
 204                  );
 205                  $languageLinks[] = $languageLink;
 206              }
 207          }
 208  
 209          return $languageLinks;
 210      }
 211  
 212  	protected function setupTemplateForOutput() {
 213          wfProfileIn( __METHOD__ );
 214  
 215          $request = $this->getRequest();
 216          $user = $this->getUser();
 217          $title = $this->getTitle();
 218  
 219          wfProfileIn( __METHOD__ . '-init' );
 220          $tpl = $this->setupTemplate( $this->template, 'skins' );
 221          wfProfileOut( __METHOD__ . '-init' );
 222  
 223          wfProfileIn( __METHOD__ . '-stuff' );
 224          $this->thispage = $title->getPrefixedDBkey();
 225          $this->titletxt = $title->getPrefixedText();
 226          $this->userpage = $user->getUserPage()->getPrefixedText();
 227          $query = array();
 228          if ( !$request->wasPosted() ) {
 229              $query = $request->getValues();
 230              unset( $query['title'] );
 231              unset( $query['returnto'] );
 232              unset( $query['returntoquery'] );
 233          }
 234          $this->thisquery = wfArrayToCgi( $query );
 235          $this->loggedin = $user->isLoggedIn();
 236          $this->username = $user->getName();
 237  
 238          if ( $this->loggedin || $this->showIPinHeader() ) {
 239              $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
 240          } else {
 241              # This won't be used in the standard skins, but we define it to preserve the interface
 242              # To save time, we check for existence
 243              $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
 244          }
 245  
 246          wfProfileOut( __METHOD__ . '-stuff' );
 247  
 248          wfProfileOut( __METHOD__ );
 249  
 250          return $tpl;
 251      }
 252  
 253      /**
 254       * initialize various variables and generate the template
 255       *
 256       * @param OutputPage $out
 257       */
 258  	function outputPage( OutputPage $out = null ) {
 259          wfProfileIn( __METHOD__ );
 260          Profiler::instance()->setTemplated( true );
 261  
 262          $oldContext = null;
 263          if ( $out !== null ) {
 264              // @todo Add wfDeprecated in 1.20
 265              $oldContext = $this->getContext();
 266              $this->setContext( $out->getContext() );
 267          }
 268  
 269          $out = $this->getOutput();
 270  
 271          wfProfileIn( __METHOD__ . '-init' );
 272          $this->initPage( $out );
 273          wfProfileOut( __METHOD__ . '-init' );
 274          $tpl = $this->prepareQuickTemplate( $out );
 275          // execute template
 276          wfProfileIn( __METHOD__ . '-execute' );
 277          $res = $tpl->execute();
 278          wfProfileOut( __METHOD__ . '-execute' );
 279  
 280          // result may be an error
 281          $this->printOrError( $res );
 282  
 283          if ( $oldContext ) {
 284              $this->setContext( $oldContext );
 285          }
 286  
 287          wfProfileOut( __METHOD__ );
 288      }
 289  
 290      /**
 291       * initialize various variables and generate the template
 292       *
 293       * @since 1.23
 294       * @return QuickTemplate The template to be executed by outputPage
 295       */
 296  	protected function prepareQuickTemplate() {
 297          global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
 298              $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
 299              $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
 300              $wgScriptPath, $wgServer;
 301  
 302          wfProfileIn( __METHOD__ );
 303  
 304          $title = $this->getTitle();
 305          $request = $this->getRequest();
 306          $out = $this->getOutput();
 307          $tpl = $this->setupTemplateForOutput();
 308  
 309          wfProfileIn( __METHOD__ . '-stuff2' );
 310          $tpl->set( 'title', $out->getPageTitle() );
 311          $tpl->set( 'pagetitle', $out->getHTMLTitle() );
 312          $tpl->set( 'displaytitle', $out->mPageLinkTitle );
 313  
 314          $tpl->setRef( 'thispage', $this->thispage );
 315          $tpl->setRef( 'titleprefixeddbkey', $this->thispage );
 316          $tpl->set( 'titletext', $title->getText() );
 317          $tpl->set( 'articleid', $title->getArticleID() );
 318  
 319          $tpl->set( 'isarticle', $out->isArticle() );
 320  
 321          $subpagestr = $this->subPageSubtitle();
 322          if ( $subpagestr !== '' ) {
 323              $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
 324          }
 325          $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
 326  
 327          $undelete = $this->getUndeleteLink();
 328          if ( $undelete === '' ) {
 329              $tpl->set( 'undelete', '' );
 330          } else {
 331              $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
 332          }
 333  
 334          $tpl->set( 'catlinks', $this->getCategories() );
 335          if ( $out->isSyndicated() ) {
 336              $feeds = array();
 337              foreach ( $out->getSyndicationLinks() as $format => $link ) {
 338                  $feeds[$format] = array(
 339                      // Messages: feed-atom, feed-rss
 340                      'text' => $this->msg( "feed-$format" )->text(),
 341                      'href' => $link
 342                  );
 343              }
 344              $tpl->setRef( 'feeds', $feeds );
 345          } else {
 346              $tpl->set( 'feeds', false );
 347          }
 348  
 349          $tpl->setRef( 'mimetype', $wgMimeType );
 350          $tpl->setRef( 'jsmimetype', $wgJsMimeType );
 351          $tpl->set( 'charset', 'UTF-8' );
 352          $tpl->setRef( 'wgScript', $wgScript );
 353          $tpl->setRef( 'skinname', $this->skinname );
 354          $tpl->set( 'skinclass', get_class( $this ) );
 355          $tpl->setRef( 'skin', $this );
 356          $tpl->setRef( 'stylename', $this->stylename );
 357          $tpl->set( 'printable', $out->isPrintable() );
 358          $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
 359          $tpl->setRef( 'loggedin', $this->loggedin );
 360          $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
 361          $tpl->set( 'searchaction', $this->escapeSearchLink() );
 362          $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
 363          $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
 364          $tpl->setRef( 'stylepath', $wgStylePath );
 365          $tpl->setRef( 'articlepath', $wgArticlePath );
 366          $tpl->setRef( 'scriptpath', $wgScriptPath );
 367          $tpl->setRef( 'serverurl', $wgServer );
 368          $tpl->setRef( 'logopath', $wgLogo );
 369          $tpl->setRef( 'sitename', $wgSitename );
 370  
 371          $userLang = $this->getLanguage();
 372          $userLangCode = $userLang->getHtmlCode();
 373          $userLangDir = $userLang->getDir();
 374  
 375          $tpl->set( 'lang', $userLangCode );
 376          $tpl->set( 'dir', $userLangDir );
 377          $tpl->set( 'rtl', $userLang->isRTL() );
 378  
 379          $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
 380          $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
 381          $tpl->set( 'username', $this->loggedin ? $this->username : null );
 382          $tpl->setRef( 'userpage', $this->userpage );
 383          $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
 384          $tpl->set( 'userlang', $userLangCode );
 385  
 386          // Users can have their language set differently than the
 387          // content of the wiki. For these users, tell the web browser
 388          // that interface elements are in a different language.
 389          $tpl->set( 'userlangattributes', '' );
 390          $tpl->set( 'specialpageattributes', '' ); # obsolete
 391          // Used by VectorBeta to insert HTML before content but after the
 392          // heading for the page title. Defaults to empty string.
 393          $tpl->set( 'prebodyhtml', '' );
 394  
 395          if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
 396              $escUserlang = htmlspecialchars( $userLangCode );
 397              $escUserdir = htmlspecialchars( $userLangDir );
 398              // Attributes must be in double quotes because htmlspecialchars() doesn't
 399              // escape single quotes
 400              $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
 401              $tpl->set( 'userlangattributes', $attrs );
 402          }
 403  
 404          wfProfileOut( __METHOD__ . '-stuff2' );
 405  
 406          wfProfileIn( __METHOD__ . '-stuff3' );
 407          $tpl->set( 'newtalk', $this->getNewtalks() );
 408          $tpl->set( 'logo', $this->logoText() );
 409  
 410          $tpl->set( 'copyright', false );
 411          $tpl->set( 'viewcount', false );
 412          $tpl->set( 'lastmod', false );
 413          $tpl->set( 'credits', false );
 414          $tpl->set( 'numberofwatchingusers', false );
 415          if ( $out->isArticle() && $title->exists() ) {
 416              if ( $this->isRevisionCurrent() ) {
 417                  if ( !$wgDisableCounters ) {
 418                      $viewcount = $this->getWikiPage()->getCount();
 419                      if ( $viewcount ) {
 420                          $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
 421                      }
 422                  }
 423  
 424                  if ( $wgPageShowWatchingUsers ) {
 425                      $dbr = wfGetDB( DB_SLAVE );
 426                      $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
 427                          array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
 428                          __METHOD__
 429                      );
 430                      if ( $num > 0 ) {
 431                          $tpl->set( 'numberofwatchingusers',
 432                              $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
 433                          );
 434                      }
 435                  }
 436  
 437                  if ( $wgMaxCredits != 0 ) {
 438                      $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
 439                          $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
 440                  } else {
 441                      $tpl->set( 'lastmod', $this->lastModified() );
 442                  }
 443              }
 444              $tpl->set( 'copyright', $this->getCopyright() );
 445          }
 446          wfProfileOut( __METHOD__ . '-stuff3' );
 447  
 448          wfProfileIn( __METHOD__ . '-stuff4' );
 449          $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
 450          $tpl->set( 'poweredbyico', $this->getPoweredBy() );
 451          $tpl->set( 'disclaimer', $this->disclaimerLink() );
 452          $tpl->set( 'privacy', $this->privacyLink() );
 453          $tpl->set( 'about', $this->aboutLink() );
 454  
 455          $tpl->set( 'footerlinks', array(
 456              'info' => array(
 457                  'lastmod',
 458                  'viewcount',
 459                  'numberofwatchingusers',
 460                  'credits',
 461                  'copyright',
 462              ),
 463              'places' => array(
 464                  'privacy',
 465                  'about',
 466                  'disclaimer',
 467              ),
 468          ) );
 469  
 470          global $wgFooterIcons;
 471          $tpl->set( 'footericons', $wgFooterIcons );
 472          foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
 473              if ( count( $footerIconsBlock ) > 0 ) {
 474                  foreach ( $footerIconsBlock as &$footerIcon ) {
 475                      if ( isset( $footerIcon['src'] ) ) {
 476                          if ( !isset( $footerIcon['width'] ) ) {
 477                              $footerIcon['width'] = 88;
 478                          }
 479                          if ( !isset( $footerIcon['height'] ) ) {
 480                              $footerIcon['height'] = 31;
 481                          }
 482                      }
 483                  }
 484              } else {
 485                  unset( $tpl->data['footericons'][$footerIconsKey] );
 486              }
 487          }
 488  
 489          $tpl->set( 'sitenotice', $this->getSiteNotice() );
 490          $tpl->set( 'bottomscripts', $this->bottomScripts() );
 491          $tpl->set( 'printfooter', $this->printSource() );
 492  
 493          # An ID that includes the actual body text; without categories, contentSub, ...
 494          $realBodyAttribs = array( 'id' => 'mw-content-text' );
 495  
 496          # Add a mw-content-ltr/rtl class to be able to style based on text direction
 497          # when the content is different from the UI language, i.e.:
 498          # not for special pages or file pages AND only when viewing AND if the page exists
 499          # (or is in MW namespace, because that has default content)
 500          if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
 501              Action::getActionName( $this ) === 'view' &&
 502              ( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) {
 503              $pageLang = $title->getPageViewLanguage();
 504              $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
 505              $realBodyAttribs['dir'] = $pageLang->getDir();
 506              $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
 507          }
 508  
 509          $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
 510          $tpl->setRef( 'bodytext', $out->mBodytext );
 511  
 512          $language_urls = $this->getLanguages();
 513          if ( count( $language_urls ) ) {
 514              $tpl->setRef( 'language_urls', $language_urls );
 515          } else {
 516              $tpl->set( 'language_urls', false );
 517          }
 518          wfProfileOut( __METHOD__ . '-stuff4' );
 519  
 520          wfProfileIn( __METHOD__ . '-stuff5' );
 521          # Personal toolbar
 522          $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
 523          $content_navigation = $this->buildContentNavigationUrls();
 524          $content_actions = $this->buildContentActionUrls( $content_navigation );
 525          $tpl->setRef( 'content_navigation', $content_navigation );
 526          $tpl->setRef( 'content_actions', $content_actions );
 527  
 528          $tpl->set( 'sidebar', $this->buildSidebar() );
 529          $tpl->set( 'nav_urls', $this->buildNavUrls() );
 530  
 531          // Set the head scripts near the end, in case the above actions resulted in added scripts
 532          $tpl->set( 'headelement', $out->headElement( $this ) );
 533  
 534          $tpl->set( 'debug', '' );
 535          $tpl->set( 'debughtml', $this->generateDebugHTML() );
 536          $tpl->set( 'reporttime', wfReportTime() );
 537  
 538          // original version by hansm
 539          if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
 540              wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
 541          }
 542  
 543          // Set the bodytext to another key so that skins can just output it on it's own
 544          // and output printfooter and debughtml separately
 545          $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
 546  
 547          // Append printfooter and debughtml onto bodytext so that skins that
 548          // were already using bodytext before they were split out don't suddenly
 549          // start not outputting information.
 550          $tpl->data['bodytext'] .= Html::rawElement(
 551              'div',
 552              array( 'class' => 'printfooter' ),
 553              "\n{$tpl->data['printfooter']}"
 554          ) . "\n";
 555          $tpl->data['bodytext'] .= $tpl->data['debughtml'];
 556  
 557          // allow extensions adding stuff after the page content.
 558          // See Skin::afterContentHook() for further documentation.
 559          $tpl->set( 'dataAfterContent', $this->afterContentHook() );
 560          wfProfileOut( __METHOD__ . '-stuff5' );
 561  
 562          wfProfileOut( __METHOD__ );
 563          return $tpl;
 564      }
 565  
 566      /**
 567       * Get the HTML for the p-personal list
 568       * @return string
 569       */
 570  	public function getPersonalToolsList() {
 571          $tpl = $this->setupTemplateForOutput();
 572          $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
 573          $html = '';
 574          foreach ( $tpl->getPersonalTools() as $key => $item ) {
 575              $html .= $tpl->makeListItem( $key, $item );
 576          }
 577          return $html;
 578      }
 579  
 580      /**
 581       * Format language name for use in sidebar interlanguage links list.
 582       * By default it is capitalized.
 583       *
 584       * @param string $name Language name, e.g. "English" or "español"
 585       * @return string
 586       * @private
 587       */
 588  	function formatLanguageName( $name ) {
 589          return $this->getLanguage()->ucfirst( $name );
 590      }
 591  
 592      /**
 593       * Output the string, or print error message if it's
 594       * an error object of the appropriate type.
 595       * For the base class, assume strings all around.
 596       *
 597       * @param string $str
 598       * @private
 599       */
 600  	function printOrError( $str ) {
 601          echo $str;
 602      }
 603  
 604      /**
 605       * Output a boolean indicating if buildPersonalUrls should output separate
 606       * login and create account links or output a combined link
 607       * By default we simply return a global config setting that affects most skins
 608       * This is setup as a method so that like with $wgLogo and getLogo() a skin
 609       * can override this setting and always output one or the other if it has
 610       * a reason it can't output one of the two modes.
 611       * @return bool
 612       */
 613  	function useCombinedLoginLink() {
 614          global $wgUseCombinedLoginLink;
 615          return $wgUseCombinedLoginLink;
 616      }
 617  
 618      /**
 619       * build array of urls for personal toolbar
 620       * @return array
 621       */
 622  	protected function buildPersonalUrls() {
 623          $title = $this->getTitle();
 624          $request = $this->getRequest();
 625          $pageurl = $title->getLocalURL();
 626          wfProfileIn( __METHOD__ );
 627  
 628          /* set up the default links for the personal toolbar */
 629          $personal_urls = array();
 630  
 631          # Due to bug 32276, if a user does not have read permissions,
 632          # $this->getTitle() will just give Special:Badtitle, which is
 633          # not especially useful as a returnto parameter. Use the title
 634          # from the request instead, if there was one.
 635          if ( $this->getUser()->isAllowed( 'read' ) ) {
 636              $page = $this->getTitle();
 637          } else {
 638              $page = Title::newFromText( $request->getVal( 'title', '' ) );
 639          }
 640          $page = $request->getVal( 'returnto', $page );
 641          $a = array();
 642          if ( strval( $page ) !== '' ) {
 643              $a['returnto'] = $page;
 644              $query = $request->getVal( 'returntoquery', $this->thisquery );
 645              if ( $query != '' ) {
 646                  $a['returntoquery'] = $query;
 647              }
 648          }
 649  
 650          $returnto = wfArrayToCgi( $a );
 651          if ( $this->loggedin ) {
 652              $personal_urls['userpage'] = array(
 653                  'text' => $this->username,
 654                  'href' => &$this->userpageUrlDetails['href'],
 655                  'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
 656                  'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
 657                  'dir' => 'auto'
 658              );
 659              $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
 660              $personal_urls['mytalk'] = array(
 661                  'text' => $this->msg( 'mytalk' )->text(),
 662                  'href' => &$usertalkUrlDetails['href'],
 663                  'class' => $usertalkUrlDetails['exists'] ? false : 'new',
 664                  'active' => ( $usertalkUrlDetails['href'] == $pageurl )
 665              );
 666              $href = self::makeSpecialUrl( 'Preferences' );
 667              $personal_urls['preferences'] = array(
 668                  'text' => $this->msg( 'mypreferences' )->text(),
 669                  'href' => $href,
 670                  'active' => ( $href == $pageurl )
 671              );
 672  
 673              if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
 674                  $href = self::makeSpecialUrl( 'Watchlist' );
 675                  $personal_urls['watchlist'] = array(
 676                      'text' => $this->msg( 'mywatchlist' )->text(),
 677                      'href' => $href,
 678                      'active' => ( $href == $pageurl )
 679                  );
 680              }
 681  
 682              # We need to do an explicit check for Special:Contributions, as we
 683              # have to match both the title, and the target, which could come
 684              # from request values (Special:Contributions?target=Jimbo_Wales)
 685              # or be specified in "sub page" form
 686              # (Special:Contributions/Jimbo_Wales). The plot
 687              # thickens, because the Title object is altered for special pages,
 688              # so it doesn't contain the original alias-with-subpage.
 689              $origTitle = Title::newFromText( $request->getText( 'title' ) );
 690              if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
 691                  list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
 692                  $active = $spName == 'Contributions'
 693                      && ( ( $spPar && $spPar == $this->username )
 694                          || $request->getText( 'target' ) == $this->username );
 695              } else {
 696                  $active = false;
 697              }
 698  
 699              $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
 700              $personal_urls['mycontris'] = array(
 701                  'text' => $this->msg( 'mycontris' )->text(),
 702                  'href' => $href,
 703                  'active' => $active
 704              );
 705              $personal_urls['logout'] = array(
 706                  'text' => $this->msg( 'pt-userlogout' )->text(),
 707                  'href' => self::makeSpecialUrl( 'Userlogout',
 708                      // userlogout link must always contain an & character, otherwise we might not be able
 709                      // to detect a buggy precaching proxy (bug 17790)
 710                      $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
 711                  ),
 712                  'active' => false
 713              );
 714          } else {
 715              $useCombinedLoginLink = $this->useCombinedLoginLink();
 716              $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
 717                  ? 'nav-login-createaccount'
 718                  : 'pt-login';
 719              $is_signup = $request->getText( 'type' ) == 'signup';
 720  
 721              $login_url = array(
 722                  'text' => $this->msg( $loginlink )->text(),
 723                  'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
 724                  'active' => $title->isSpecial( 'Userlogin' )
 725                      && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
 726              );
 727              $createaccount_url = array(
 728                  'text' => $this->msg( 'pt-createaccount' )->text(),
 729                  'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
 730                  'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
 731              );
 732  
 733              if ( $this->showIPinHeader() ) {
 734                  $href = &$this->userpageUrlDetails['href'];
 735                  $personal_urls['anonuserpage'] = array(
 736                      'text' => $this->username,
 737                      'href' => $href,
 738                      'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
 739                      'active' => ( $pageurl == $href )
 740                  );
 741                  $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
 742                  $href = &$usertalkUrlDetails['href'];
 743                  $personal_urls['anontalk'] = array(
 744                      'text' => $this->msg( 'anontalk' )->text(),
 745                      'href' => $href,
 746                      'class' => $usertalkUrlDetails['exists'] ? false : 'new',
 747                      'active' => ( $pageurl == $href )
 748                  );
 749              }
 750  
 751              if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
 752                  $personal_urls['createaccount'] = $createaccount_url;
 753              }
 754  
 755              $personal_urls['login'] = $login_url;
 756          }
 757  
 758          wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
 759          wfProfileOut( __METHOD__ );
 760          return $personal_urls;
 761      }
 762  
 763      /**
 764       * Builds an array with tab definition
 765       *
 766       * @param Title $title Page Where the tab links to
 767       * @param string|array $message Message key or an array of message keys (will fall back)
 768       * @param bool $selected Display the tab as selected
 769       * @param string $query Query string attached to tab URL
 770       * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
 771       *
 772       * @return array
 773       */
 774  	function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
 775          $classes = array();
 776          if ( $selected ) {
 777              $classes[] = 'selected';
 778          }
 779          if ( $checkEdit && !$title->isKnown() ) {
 780              $classes[] = 'new';
 781              if ( $query !== '' ) {
 782                  $query = 'action=edit&redlink=1&' . $query;
 783              } else {
 784                  $query = 'action=edit&redlink=1';
 785              }
 786          }
 787  
 788          // wfMessageFallback will nicely accept $message as an array of fallbacks
 789          // or just a single key
 790          $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
 791          if ( is_array( $message ) ) {
 792              // for hook compatibility just keep the last message name
 793              $message = end( $message );
 794          }
 795          if ( $msg->exists() ) {
 796              $text = $msg->text();
 797          } else {
 798              global $wgContLang;
 799              $text = $wgContLang->getFormattedNsText(
 800                  MWNamespace::getSubject( $title->getNamespace() ) );
 801          }
 802  
 803          $result = array();
 804          if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
 805                  $title, $message, $selected, $checkEdit,
 806                  &$classes, &$query, &$text, &$result ) ) ) {
 807              return $result;
 808          }
 809  
 810          return array(
 811              'class' => implode( ' ', $classes ),
 812              'text' => $text,
 813              'href' => $title->getLocalURL( $query ),
 814              'primary' => true );
 815      }
 816  
 817  	function makeTalkUrlDetails( $name, $urlaction = '' ) {
 818          $title = Title::newFromText( $name );
 819          if ( !is_object( $title ) ) {
 820              throw new MWException( __METHOD__ . " given invalid pagename $name" );
 821          }
 822          $title = $title->getTalkPage();
 823          self::checkTitle( $title, $name );
 824          return array(
 825              'href' => $title->getLocalURL( $urlaction ),
 826              'exists' => $title->getArticleID() != 0,
 827          );
 828      }
 829  
 830  	function makeArticleUrlDetails( $name, $urlaction = '' ) {
 831          $title = Title::newFromText( $name );
 832          $title = $title->getSubjectPage();
 833          self::checkTitle( $title, $name );
 834          return array(
 835              'href' => $title->getLocalURL( $urlaction ),
 836              'exists' => $title->getArticleID() != 0,
 837          );
 838      }
 839  
 840      /**
 841       * a structured array of links usually used for the tabs in a skin
 842       *
 843       * There are 4 standard sections
 844       * namespaces: Used for namespace tabs like special, page, and talk namespaces
 845       * views: Used for primary page views like read, edit, history
 846       * actions: Used for most extra page actions like deletion, protection, etc...
 847       * variants: Used to list the language variants for the page
 848       *
 849       * Each section's value is a key/value array of links for that section.
 850       * The links themselves have these common keys:
 851       * - class: The css classes to apply to the tab
 852       * - text: The text to display on the tab
 853       * - href: The href for the tab to point to
 854       * - rel: An optional rel= for the tab's link
 855       * - redundant: If true the tab will be dropped in skins using content_actions
 856       *   this is useful for tabs like "Read" which only have meaning in skins that
 857       *   take special meaning from the grouped structure of content_navigation
 858       *
 859       * Views also have an extra key which can be used:
 860       * - primary: If this is not true skins like vector may try to hide the tab
 861       *            when the user has limited space in their browser window
 862       *
 863       * content_navigation using code also expects these ids to be present on the
 864       * links, however these are usually automatically generated by SkinTemplate
 865       * itself and are not necessary when using a hook. The only things these may
 866       * matter to are people modifying content_navigation after it's initial creation:
 867       * - id: A "preferred" id, most skins are best off outputting this preferred
 868       *   id for best compatibility.
 869       * - tooltiponly: This is set to true for some tabs in cases where the system
 870       *   believes that the accesskey should not be added to the tab.
 871       *
 872       * @return array
 873       */
 874  	protected function buildContentNavigationUrls() {
 875          global $wgDisableLangConversion;
 876  
 877          wfProfileIn( __METHOD__ );
 878  
 879          // Display tabs for the relevant title rather than always the title itself
 880          $title = $this->getRelevantTitle();
 881          $onPage = $title->equals( $this->getTitle() );
 882  
 883          $out = $this->getOutput();
 884          $request = $this->getRequest();
 885          $user = $this->getUser();
 886  
 887          $content_navigation = array(
 888              'namespaces' => array(),
 889              'views' => array(),
 890              'actions' => array(),
 891              'variants' => array()
 892          );
 893  
 894          // parameters
 895          $action = $request->getVal( 'action', 'view' );
 896  
 897          $userCanRead = $title->quickUserCan( 'read', $user );
 898  
 899          $preventActiveTabs = false;
 900          wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
 901  
 902          // Checks if page is some kind of content
 903          if ( $title->canExist() ) {
 904              // Gets page objects for the related namespaces
 905              $subjectPage = $title->getSubjectPage();
 906              $talkPage = $title->getTalkPage();
 907  
 908              // Determines if this is a talk page
 909              $isTalk = $title->isTalkPage();
 910  
 911              // Generates XML IDs from namespace names
 912              $subjectId = $title->getNamespaceKey( '' );
 913  
 914              if ( $subjectId == 'main' ) {
 915                  $talkId = 'talk';
 916              } else {
 917                  $talkId = "{$subjectId}_talk";
 918              }
 919  
 920              $skname = $this->skinname;
 921  
 922              // Adds namespace links
 923              $subjectMsg = array( "nstab-$subjectId" );
 924              if ( $subjectPage->isMainPage() ) {
 925                  array_unshift( $subjectMsg, 'mainpage-nstab' );
 926              }
 927              $content_navigation['namespaces'][$subjectId] = $this->tabAction(
 928                  $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
 929              );
 930              $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
 931              $content_navigation['namespaces'][$talkId] = $this->tabAction(
 932                  $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
 933              );
 934              $content_navigation['namespaces'][$talkId]['context'] = 'talk';
 935  
 936              if ( $userCanRead ) {
 937                  $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
 938                      $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
 939  
 940                  // Adds view view link
 941                  if ( $title->exists() || $isForeignFile ) {
 942                      $content_navigation['views']['view'] = $this->tabAction(
 943                          $isTalk ? $talkPage : $subjectPage,
 944                          array( "$skname-view-view", 'view' ),
 945                          ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
 946                      );
 947                      // signal to hide this from simple content_actions
 948                      $content_navigation['views']['view']['redundant'] = true;
 949                  }
 950  
 951                  // If it is a non-local file, show a link to the file in its own repository
 952                  if ( $isForeignFile ) {
 953                      $file = $this->getWikiPage()->getFile();
 954                      $content_navigation['views']['view-foreign'] = array(
 955                          'class' => '',
 956                          'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
 957                              setContext( $this->getContext() )->
 958                              params( $file->getRepo()->getDisplayName() )->text(),
 959                          'href' => $file->getDescriptionUrl(),
 960                          'primary' => false,
 961                      );
 962                  }
 963  
 964                  wfProfileIn( __METHOD__ . '-edit' );
 965  
 966                  // Checks if user can edit the current page if it exists or create it otherwise
 967                  if ( $title->quickUserCan( 'edit', $user )
 968                      && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
 969                  ) {
 970                      // Builds CSS class for talk page links
 971                      $isTalkClass = $isTalk ? ' istalk' : '';
 972                      // Whether the user is editing the page
 973                      $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
 974                      // Whether to show the "Add a new section" tab
 975                      // Checks if this is a current rev of talk page and is not forced to be hidden
 976                      $showNewSection = !$out->forceHideNewSectionLink()
 977                          && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
 978                      $section = $request->getVal( 'section' );
 979  
 980                      if ( $title->exists()
 981                          || ( $title->getNamespace() == NS_MEDIAWIKI
 982                              && $title->getDefaultMessageText() !== false
 983                          )
 984                      ) {
 985                          $msgKey = $isForeignFile ? 'edit-local' : 'edit';
 986                      } else {
 987                          $msgKey = $isForeignFile ? 'create-local' : 'create';
 988                      }
 989                      $content_navigation['views']['edit'] = array(
 990                          'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
 991                              ? 'selected'
 992                              : ''
 993                          ) . $isTalkClass,
 994                          'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
 995                              ->setContext( $this->getContext() )->text(),
 996                          'href' => $title->getLocalURL( $this->editUrlOptions() ),
 997                          'primary' => !$isForeignFile, // don't collapse this in vector
 998                      );
 999  
1000                      // section link
1001                      if ( $showNewSection ) {
1002                          // Adds new section link
1003                          //$content_navigation['actions']['addsection']
1004                          $content_navigation['views']['addsection'] = array(
1005                              'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
1006                              'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1007                                  ->setContext( $this->getContext() )->text(),
1008                              'href' => $title->getLocalURL( 'action=edit&section=new' )
1009                          );
1010                      }
1011                  // Checks if the page has some kind of viewable content
1012                  } elseif ( $title->hasSourceText() ) {
1013                      // Adds view source view link
1014                      $content_navigation['views']['viewsource'] = array(
1015                          'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
1016                          'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1017                              ->setContext( $this->getContext() )->text(),
1018                          'href' => $title->getLocalURL( $this->editUrlOptions() ),
1019                          'primary' => true, // don't collapse this in vector
1020                      );
1021                  }
1022                  wfProfileOut( __METHOD__ . '-edit' );
1023  
1024                  wfProfileIn( __METHOD__ . '-live' );
1025                  // Checks if the page exists
1026                  if ( $title->exists() ) {
1027                      // Adds history view link
1028                      $content_navigation['views']['history'] = array(
1029                          'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
1030                          'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1031                              ->setContext( $this->getContext() )->text(),
1032                          'href' => $title->getLocalURL( 'action=history' ),
1033                          'rel' => 'archives',
1034                      );
1035  
1036                      if ( $title->quickUserCan( 'delete', $user ) ) {
1037                          $content_navigation['actions']['delete'] = array(
1038                              'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
1039                              'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1040                                  ->setContext( $this->getContext() )->text(),
1041                              'href' => $title->getLocalURL( 'action=delete' )
1042                          );
1043                      }
1044  
1045                      if ( $title->quickUserCan( 'move', $user ) ) {
1046                          $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1047                          $content_navigation['actions']['move'] = array(
1048                              'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
1049                              'text' => wfMessageFallback( "$skname-action-move", 'move' )
1050                                  ->setContext( $this->getContext() )->text(),
1051                              'href' => $moveTitle->getLocalURL()
1052                          );
1053                      }
1054                  } else {
1055                      // article doesn't exist or is deleted
1056                      if ( $user->isAllowed( 'deletedhistory' ) ) {
1057                          $n = $title->isDeleted();
1058                          if ( $n ) {
1059                              $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
1060                              // If the user can't undelete but can view deleted
1061                              // history show them a "View .. deleted" tab instead.
1062                              $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
1063                              $content_navigation['actions']['undelete'] = array(
1064                                  'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
1065                                  'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1066                                      ->setContext( $this->getContext() )->numParams( $n )->text(),
1067                                  'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1068                              );
1069                          }
1070                      }
1071                  }
1072  
1073                  if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1074                      MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1075                  ) {
1076                      $mode = $title->isProtected() ? 'unprotect' : 'protect';
1077                      $content_navigation['actions'][$mode] = array(
1078                          'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1079                          'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1080                              ->setContext( $this->getContext() )->text(),
1081                          'href' => $title->getLocalURL( "action=$mode" )
1082                      );
1083                  }
1084  
1085                  wfProfileOut( __METHOD__ . '-live' );
1086  
1087                  // Checks if the user is logged in
1088                  if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1089                      /**
1090                       * The following actions use messages which, if made particular to
1091                       * the any specific skins, would break the Ajax code which makes this
1092                       * action happen entirely inline. OutputPage::getJSVars
1093                       * defines a set of messages in a javascript object - and these
1094                       * messages are assumed to be global for all skins. Without making
1095                       * a change to that procedure these messages will have to remain as
1096                       * the global versions.
1097                       */
1098                      $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1099                      $token = WatchAction::getWatchToken( $title, $user, $mode );
1100                      $content_navigation['actions'][$mode] = array(
1101                          'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1102                          // uses 'watch' or 'unwatch' message
1103                          'text' => $this->msg( $mode )->text(),
1104                          'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1105                      );
1106                  }
1107              }
1108  
1109              wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1110  
1111              if ( $userCanRead && !$wgDisableLangConversion ) {
1112                  $pageLang = $title->getPageLanguage();
1113                  // Gets list of language variants
1114                  $variants = $pageLang->getVariants();
1115                  // Checks that language conversion is enabled and variants exist
1116                  // And if it is not in the special namespace
1117                  if ( count( $variants ) > 1 ) {
1118                      // Gets preferred variant (note that user preference is
1119                      // only possible for wiki content language variant)
1120                      $preferred = $pageLang->getPreferredVariant();
1121                      if ( Action::getActionName( $this ) === 'view' ) {
1122                          $params = $request->getQueryValues();
1123                          unset( $params['title'] );
1124                      } else {
1125                          $params = array();
1126                      }
1127                      // Loops over each variant
1128                      foreach ( $variants as $code ) {
1129                          // Gets variant name from language code
1130                          $varname = $pageLang->getVariantname( $code );
1131                          // Appends variant link
1132                          $content_navigation['variants'][] = array(
1133                              'class' => ( $code == $preferred ) ? 'selected' : false,
1134                              'text' => $varname,
1135                              'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1136                              'lang' => wfBCP47( $code ),
1137                              'hreflang' => wfBCP47( $code ),
1138                          );
1139                      }
1140                  }
1141              }
1142          } else {
1143              // If it's not content, it's got to be a special page
1144              $content_navigation['namespaces']['special'] = array(
1145                  'class' => 'selected',
1146                  'text' => $this->msg( 'nstab-special' )->text(),
1147                  'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1148                  'context' => 'subject'
1149              );
1150  
1151              wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1152                  array( &$this, &$content_navigation ) );
1153          }
1154  
1155          // Equiv to SkinTemplateContentActions
1156          wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1157  
1158          // Setup xml ids and tooltip info
1159          foreach ( $content_navigation as $section => &$links ) {
1160              foreach ( $links as $key => &$link ) {
1161                  $xmlID = $key;
1162                  if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1163                      $xmlID = 'ca-nstab-' . $xmlID;
1164                  } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1165                      $xmlID = 'ca-talk';
1166                  } elseif ( $section == 'variants' ) {
1167                      $xmlID = 'ca-varlang-' . $xmlID;
1168                  } else {
1169                      $xmlID = 'ca-' . $xmlID;
1170                  }
1171                  $link['id'] = $xmlID;
1172              }
1173          }
1174  
1175          # We don't want to give the watch tab an accesskey if the
1176          # page is being edited, because that conflicts with the
1177          # accesskey on the watch checkbox.  We also don't want to
1178          # give the edit tab an accesskey, because that's fairly
1179          # superfluous and conflicts with an accesskey (Ctrl-E) often
1180          # used for editing in Safari.
1181          if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1182              if ( isset( $content_navigation['views']['edit'] ) ) {
1183                  $content_navigation['views']['edit']['tooltiponly'] = true;
1184              }
1185              if ( isset( $content_navigation['actions']['watch'] ) ) {
1186                  $content_navigation['actions']['watch']['tooltiponly'] = true;
1187              }
1188              if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1189                  $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1190              }
1191          }
1192  
1193          wfProfileOut( __METHOD__ );
1194  
1195          return $content_navigation;
1196      }
1197  
1198      /**
1199       * an array of edit links by default used for the tabs
1200       * @param array $content_navigation
1201       * @return array
1202       */
1203  	private function buildContentActionUrls( $content_navigation ) {
1204  
1205          wfProfileIn( __METHOD__ );
1206  
1207          // content_actions has been replaced with content_navigation for backwards
1208          // compatibility and also for skins that just want simple tabs content_actions
1209          // is now built by flattening the content_navigation arrays into one
1210  
1211          $content_actions = array();
1212  
1213          foreach ( $content_navigation as $links ) {
1214              foreach ( $links as $key => $value ) {
1215                  if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1216                      // Redundant tabs are dropped from content_actions
1217                      continue;
1218                  }
1219  
1220                  // content_actions used to have ids built using the "ca-$key" pattern
1221                  // so the xmlID based id is much closer to the actual $key that we want
1222                  // for that reason we'll just strip out the ca- if present and use
1223                  // the latter potion of the "id" as the $key
1224                  if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1225                      $key = substr( $value['id'], 3 );
1226                  }
1227  
1228                  if ( isset( $content_actions[$key] ) ) {
1229                      wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
1230                          "content_navigation into content_actions.\n" );
1231                      continue;
1232                  }
1233  
1234                  $content_actions[$key] = $value;
1235              }
1236          }
1237  
1238          wfProfileOut( __METHOD__ );
1239  
1240          return $content_actions;
1241      }
1242  
1243      /**
1244       * build array of common navigation links
1245       * @return array
1246       */
1247  	protected function buildNavUrls() {
1248          global $wgUploadNavigationUrl;
1249  
1250          wfProfileIn( __METHOD__ );
1251  
1252          $out = $this->getOutput();
1253          $request = $this->getRequest();
1254  
1255          $nav_urls = array();
1256          $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1257          if ( $wgUploadNavigationUrl ) {
1258              $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1259          } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1260              $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1261          } else {
1262              $nav_urls['upload'] = false;
1263          }
1264          $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1265  
1266          $nav_urls['print'] = false;
1267          $nav_urls['permalink'] = false;
1268          $nav_urls['info'] = false;
1269          $nav_urls['whatlinkshere'] = false;
1270          $nav_urls['recentchangeslinked'] = false;
1271          $nav_urls['contributions'] = false;
1272          $nav_urls['log'] = false;
1273          $nav_urls['blockip'] = false;
1274          $nav_urls['emailuser'] = false;
1275          $nav_urls['userrights'] = false;
1276  
1277          // A print stylesheet is attached to all pages, but nobody ever
1278          // figures that out. :)  Add a link...
1279          if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1280              $nav_urls['print'] = array(
1281                  'text' => $this->msg( 'printableversion' )->text(),
1282                  'href' => $this->getTitle()->getLocalURL(
1283                      $request->appendQueryValue( 'printable', 'yes', true ) )
1284              );
1285          }
1286  
1287          if ( $out->isArticle() ) {
1288              // Also add a "permalink" while we're at it
1289              $revid = $this->getRevisionId();
1290              if ( $revid ) {
1291                  $nav_urls['permalink'] = array(
1292                      'text' => $this->msg( 'permalink' )->text(),
1293                      'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1294                  );
1295              }
1296  
1297              // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1298              wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1299                  array( &$this, &$nav_urls, &$revid, &$revid ) );
1300          }
1301  
1302          if ( $out->isArticleRelated() ) {
1303              $nav_urls['whatlinkshere'] = array(
1304                  'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1305              );
1306  
1307              $nav_urls['info'] = array(
1308                  'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1309                  'href' => $this->getTitle()->getLocalURL( "action=info" )
1310              );
1311  
1312              if ( $this->getTitle()->getArticleID() ) {
1313                  $nav_urls['recentchangeslinked'] = array(
1314                      'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1315                  );
1316              }
1317          }
1318  
1319          $user = $this->getRelevantUser();
1320          if ( $user ) {
1321              $rootUser = $user->getName();
1322  
1323              $nav_urls['contributions'] = array(
1324                  'text' => $this->msg( 'contributions', $rootUser )->text(),
1325                  'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1326              );
1327  
1328              $nav_urls['log'] = array(
1329                  'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1330              );
1331  
1332              if ( $this->getUser()->isAllowed( 'block' ) ) {
1333                  $nav_urls['blockip'] = array(
1334                      'text' => $this->msg( 'blockip', $rootUser )->text(),
1335                      'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1336                  );
1337              }
1338  
1339              if ( $this->showEmailUser( $user ) ) {
1340                  $nav_urls['emailuser'] = array(
1341                      'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1342                  );
1343              }
1344  
1345              if ( !$user->isAnon() ) {
1346                  $sur = new UserrightsPage;
1347                  $sur->setContext( $this->getContext() );
1348                  if ( $sur->userCanExecute( $this->getUser() ) ) {
1349                      $nav_urls['userrights'] = array(
1350                          'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1351                      );
1352                  }
1353              }
1354          }
1355  
1356          wfProfileOut( __METHOD__ );
1357          return $nav_urls;
1358      }
1359  
1360      /**
1361       * Generate strings used for xml 'id' names
1362       * @return string
1363       */
1364  	protected function getNameSpaceKey() {
1365          return $this->getTitle()->getNamespaceKey();
1366      }
1367  }
1368  
1369  /**
1370   * Generic wrapper for template functions, with interface
1371   * compatible with what we use of PHPTAL 0.7.
1372   * @ingroup Skins
1373   */
1374  abstract class QuickTemplate {
1375  
1376      /** @var Config $config */
1377      protected $config;
1378  
1379      /**
1380       * @param Config $config
1381       */
1382  	function __construct( Config $config = null ) {
1383          $this->data = array();
1384          $this->translator = new MediaWikiI18N();
1385          if ( $config === null ) {
1386              wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
1387              $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
1388          }
1389          $this->config = $config;
1390      }
1391  
1392      /**
1393       * Sets the value $value to $name
1394       * @param string $name
1395       * @param mixed $value
1396       */
1397  	public function set( $name, $value ) {
1398          $this->data[$name] = $value;
1399      }
1400  
1401      /**
1402       * Gets the template data requested
1403       * @since 1.22
1404       * @param string $name Key for the data
1405       * @param mixed $default Optional default (or null)
1406       * @return mixed The value of the data requested or the deafult
1407       */
1408  	public function get( $name, $default = null ) {
1409          if ( isset( $this->data[$name] ) ) {
1410              return $this->data[$name];
1411          } else {
1412              return $default;
1413          }
1414      }
1415  
1416      /**
1417       * @param string $name
1418       * @param mixed $value
1419       */
1420  	public function setRef( $name, &$value ) {
1421          $this->data[$name] =& $value;
1422      }
1423  
1424      /**
1425       * @param MediaWikiI18N $t
1426       */
1427  	public function setTranslator( &$t ) {
1428          $this->translator = &$t;
1429      }
1430  
1431      /**
1432       * Main function, used by classes that subclass QuickTemplate
1433       * to show the actual HTML output
1434       */
1435      abstract public function execute();
1436  
1437      /**
1438       * @private
1439       * @param string $str
1440       * @return string
1441       */
1442  	function text( $str ) {
1443          echo htmlspecialchars( $this->data[$str] );
1444      }
1445  
1446      /**
1447       * @private
1448       * @param string $str
1449       * @return string
1450       */
1451  	function html( $str ) {
1452          echo $this->data[$str];
1453      }
1454  
1455      /**
1456       * @private
1457       * @param string $str
1458       * @return string
1459       */
1460  	function msg( $str ) {
1461          echo htmlspecialchars( $this->translator->translate( $str ) );
1462      }
1463  
1464      /**
1465       * @private
1466       * @param string $str
1467       * @return string
1468       */
1469  	function msgHtml( $str ) {
1470          echo $this->translator->translate( $str );
1471      }
1472  
1473      /**
1474       * An ugly, ugly hack.
1475       * @private
1476       * @param string $str
1477       * @return string
1478       */
1479  	function msgWiki( $str ) {
1480          global $wgOut;
1481  
1482          $text = $this->translator->translate( $str );
1483          echo $wgOut->parse( $text );
1484      }
1485  
1486      /**
1487       * @private
1488       * @param string $str
1489       * @return bool
1490       */
1491  	function haveData( $str ) {
1492          return isset( $this->data[$str] );
1493      }
1494  
1495      /**
1496       * @private
1497       *
1498       * @param string $str
1499       * @return bool
1500       */
1501  	function haveMsg( $str ) {
1502          $msg = $this->translator->translate( $str );
1503          return ( $msg != '-' ) && ( $msg != '' ); # ????
1504      }
1505  
1506      /**
1507       * Get the Skin object related to this object
1508       *
1509       * @return Skin
1510       */
1511  	public function getSkin() {
1512          return $this->data['skin'];
1513      }
1514  
1515      /**
1516       * Fetch the output of a QuickTemplate and return it
1517       *
1518       * @since 1.23
1519       * @return string
1520       */
1521  	public function getHTML() {
1522          ob_start();
1523          $this->execute();
1524          $html = ob_get_contents();
1525          ob_end_clean();
1526          return $html;
1527      }
1528  }
1529  
1530  /**
1531   * New base template for a skin's template extended from QuickTemplate
1532   * this class features helper methods that provide common ways of interacting
1533   * with the data stored in the QuickTemplate
1534   */
1535  abstract class BaseTemplate extends QuickTemplate {
1536  
1537      /**
1538       * Get a Message object with its context set
1539       *
1540       * @param string $name Message name
1541       * @return Message
1542       */
1543  	public function getMsg( $name ) {
1544          return $this->getSkin()->msg( $name );
1545      }
1546  
1547  	function msg( $str ) {
1548          echo $this->getMsg( $str )->escaped();
1549      }
1550  
1551  	function msgHtml( $str ) {
1552          echo $this->getMsg( $str )->text();
1553      }
1554  
1555  	function msgWiki( $str ) {
1556          echo $this->getMsg( $str )->parseAsBlock();
1557      }
1558  
1559      /**
1560       * Create an array of common toolbox items from the data in the quicktemplate
1561       * stored by SkinTemplate.
1562       * The resulting array is built according to a format intended to be passed
1563       * through makeListItem to generate the html.
1564       * @return array
1565       */
1566  	function getToolbox() {
1567          wfProfileIn( __METHOD__ );
1568  
1569          $toolbox = array();
1570          if ( isset( $this->data['nav_urls']['whatlinkshere'] )
1571              && $this->data['nav_urls']['whatlinkshere']
1572          ) {
1573              $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1574              $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1575          }
1576          if ( isset( $this->data['nav_urls']['recentchangeslinked'] )
1577              && $this->data['nav_urls']['recentchangeslinked']
1578          ) {
1579              $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1580              $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1581              $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1582          }
1583          if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
1584              $toolbox['feeds']['id'] = 'feedlinks';
1585              $toolbox['feeds']['links'] = array();
1586              foreach ( $this->data['feeds'] as $key => $feed ) {
1587                  $toolbox['feeds']['links'][$key] = $feed;
1588                  $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1589                  $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1590                  $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1591                  $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1592              }
1593          }
1594          foreach ( array( 'contributions', 'log', 'blockip', 'emailuser',
1595              'userrights', 'upload', 'specialpages' ) as $special
1596          ) {
1597              if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
1598                  $toolbox[$special] = $this->data['nav_urls'][$special];
1599                  $toolbox[$special]['id'] = "t-$special";
1600              }
1601          }
1602          if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
1603              $toolbox['print'] = $this->data['nav_urls']['print'];
1604              $toolbox['print']['id'] = 't-print';
1605              $toolbox['print']['rel'] = 'alternate';
1606              $toolbox['print']['msg'] = 'printableversion';
1607          }
1608          if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
1609              $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1610              if ( $toolbox['permalink']['href'] === '' ) {
1611                  unset( $toolbox['permalink']['href'] );
1612                  $toolbox['ispermalink']['tooltiponly'] = true;
1613                  $toolbox['ispermalink']['id'] = 't-ispermalink';
1614                  $toolbox['ispermalink']['msg'] = 'permalink';
1615              } else {
1616                  $toolbox['permalink']['id'] = 't-permalink';
1617              }
1618          }
1619          if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
1620              $toolbox['info'] = $this->data['nav_urls']['info'];
1621              $toolbox['info']['id'] = 't-info';
1622          }
1623  
1624          wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1625          wfProfileOut( __METHOD__ );
1626          return $toolbox;
1627      }
1628  
1629      /**
1630       * Create an array of personal tools items from the data in the quicktemplate
1631       * stored by SkinTemplate.
1632       * The resulting array is built according to a format intended to be passed
1633       * through makeListItem to generate the html.
1634       * This is in reality the same list as already stored in personal_urls
1635       * however it is reformatted so that you can just pass the individual items
1636       * to makeListItem instead of hardcoding the element creation boilerplate.
1637       * @return array
1638       */
1639  	function getPersonalTools() {
1640          $personal_tools = array();
1641          foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1642              # The class on a personal_urls item is meant to go on the <a> instead
1643              # of the <li> so we have to use a single item "links" array instead
1644              # of using most of the personal_url's keys directly.
1645              $ptool = array(
1646                  'links' => array(
1647                      array( 'single-id' => "pt-$key" ),
1648                  ),
1649                  'id' => "pt-$key",
1650              );
1651              if ( isset( $plink['active'] ) ) {
1652                  $ptool['active'] = $plink['active'];
1653              }
1654              foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
1655                  if ( isset( $plink[$k] ) ) {
1656                      $ptool['links'][0][$k] = $plink[$k];
1657                  }
1658              }
1659              $personal_tools[$key] = $ptool;
1660          }
1661          return $personal_tools;
1662      }
1663  
1664  	function getSidebar( $options = array() ) {
1665          // Force the rendering of the following portals
1666          $sidebar = $this->data['sidebar'];
1667          if ( !isset( $sidebar['SEARCH'] ) ) {
1668              $sidebar['SEARCH'] = true;
1669          }
1670          if ( !isset( $sidebar['TOOLBOX'] ) ) {
1671              $sidebar['TOOLBOX'] = true;
1672          }
1673          if ( !isset( $sidebar['LANGUAGES'] ) ) {
1674              $sidebar['LANGUAGES'] = true;
1675          }
1676  
1677          if ( !isset( $options['search'] ) || $options['search'] !== true ) {
1678              unset( $sidebar['SEARCH'] );
1679          }
1680          if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1681              unset( $sidebar['TOOLBOX'] );
1682          }
1683          if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1684              unset( $sidebar['LANGUAGES'] );
1685          }
1686  
1687          $boxes = array();
1688          foreach ( $sidebar as $boxName => $content ) {
1689              if ( $content === false ) {
1690                  continue;
1691              }
1692              switch ( $boxName ) {
1693              case 'SEARCH':
1694                  // Search is a special case, skins should custom implement this
1695                  $boxes[$boxName] = array(
1696                      'id' => 'p-search',
1697                      'header' => $this->getMsg( 'search' )->text(),
1698                      'generated' => false,
1699                      'content' => true,
1700                  );
1701                  break;
1702              case 'TOOLBOX':
1703                  $msgObj = $this->getMsg( 'toolbox' );
1704                  $boxes[$boxName] = array(
1705                      'id' => 'p-tb',
1706                      'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
1707                      'generated' => false,
1708                      'content' => $this->getToolbox(),
1709                  );
1710                  break;
1711              case 'LANGUAGES':
1712                  if ( $this->data['language_urls'] ) {
1713                      $msgObj = $this->getMsg( 'otherlanguages' );
1714                      $boxes[$boxName] = array(
1715                          'id' => 'p-lang',
1716                          'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
1717                          'generated' => false,
1718                          'content' => $this->data['language_urls'],
1719                      );
1720                  }
1721                  break;
1722              default:
1723                  $msgObj = $this->getMsg( $boxName );
1724                  $boxes[$boxName] = array(
1725                      'id' => "p-$boxName",
1726                      'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
1727                      'generated' => true,
1728                      'content' => $content,
1729                  );
1730                  break;
1731              }
1732          }
1733  
1734          // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1735          $hookContents = null;
1736          if ( isset( $boxes['TOOLBOX'] ) ) {
1737              ob_start();
1738              // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1739              // can abort and avoid outputting double toolbox links
1740              wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1741              $hookContents = ob_get_contents();
1742              ob_end_clean();
1743              if ( !trim( $hookContents ) ) {
1744                  $hookContents = null;
1745              }
1746          }
1747          // END hack
1748  
1749          if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1750              foreach ( $boxes as $boxName => $box ) {
1751                  if ( is_array( $box['content'] ) ) {
1752                      $content = '<ul>';
1753                      foreach ( $box['content'] as $key => $val ) {
1754                          $content .= "\n    " . $this->makeListItem( $key, $val );
1755                      }
1756                      // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1757                      if ( $hookContents ) {
1758                          $content .= "\n    $hookContents";
1759                      }
1760                      // END hack
1761                      $content .= "\n</ul>\n";
1762                      $boxes[$boxName]['content'] = $content;
1763                  }
1764              }
1765          } else {
1766              if ( $hookContents ) {
1767                  $boxes['TOOLBOXEND'] = array(
1768                      'id' => 'p-toolboxend',
1769                      'header' => $boxes['TOOLBOX']['header'],
1770                      'generated' => false,
1771                      'content' => "<ul>{$hookContents}</ul>",
1772                  );
1773                  // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1774                  $boxes2 = array();
1775                  foreach ( $boxes as $key => $box ) {
1776                      if ( $key === 'TOOLBOXEND' ) {
1777                          continue;
1778                      }
1779                      $boxes2[$key] = $box;
1780                      if ( $key === 'TOOLBOX' ) {
1781                          $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1782                      }
1783                  }
1784                  $boxes = $boxes2;
1785                  // END hack
1786              }
1787          }
1788  
1789          return $boxes;
1790      }
1791  
1792      /**
1793       * @param string $name
1794       */
1795  	protected function renderAfterPortlet( $name ) {
1796          $content = '';
1797          wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
1798  
1799          if ( $content !== '' ) {
1800              echo "<div class='after-portlet after-portlet-$name'>$content</div>";
1801          }
1802  
1803      }
1804  
1805      /**
1806       * Makes a link, usually used by makeListItem to generate a link for an item
1807       * in a list used in navigation lists, portlets, portals, sidebars, etc...
1808       *
1809       * @param string $key Usually a key from the list you are generating this
1810       * link from.
1811       * @param array $item Contains some of a specific set of keys.
1812       *
1813       * The text of the link will be generated either from the contents of the
1814       * "text" key in the $item array, if a "msg" key is present a message by
1815       * that name will be used, and if neither of those are set the $key will be
1816       * used as a message name.
1817       *
1818       * If a "href" key is not present makeLink will just output htmlescaped text.
1819       * The "href", "id", "class", "rel", and "type" keys are used as attributes
1820       * for the link if present.
1821       *
1822       * If an "id" or "single-id" (if you don't want the actual id to be output
1823       * on the link) is present it will be used to generate a tooltip and
1824       * accesskey for the link.
1825       *
1826       * The keys "context" and "primary" are ignored; these keys are used
1827       * internally by skins and are not supposed to be included in the HTML
1828       * output.
1829       *
1830       * If you don't want an accesskey, set $item['tooltiponly'] = true;
1831       *
1832       * @param array $options Can be used to affect the output of a link.
1833       * Possible options are:
1834       *   - 'text-wrapper' key to specify a list of elements to wrap the text of
1835       *   a link in. This should be an array of arrays containing a 'tag' and
1836       *   optionally an 'attributes' key. If you only have one element you don't
1837       *   need to wrap it in another array. eg: To use <a><span>...</span></a>
1838       *   in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1839       *   for your options.
1840       *   - 'link-class' key can be used to specify additional classes to apply
1841       *   to all links.
1842       *   - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1843       *   if there is no link. eg: If you specify 'link-fallback' => 'span' than
1844       *   any non-link will output a "<span>" instead of just text.
1845       *
1846       * @return string
1847       */
1848  	function makeLink( $key, $item, $options = array() ) {
1849          if ( isset( $item['text'] ) ) {
1850              $text = $item['text'];
1851          } else {
1852              $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1853          }
1854  
1855          $html = htmlspecialchars( $text );
1856  
1857          if ( isset( $options['text-wrapper'] ) ) {
1858              $wrapper = $options['text-wrapper'];
1859              if ( isset( $wrapper['tag'] ) ) {
1860                  $wrapper = array( $wrapper );
1861              }
1862              while ( count( $wrapper ) > 0 ) {
1863                  $element = array_pop( $wrapper );
1864                  $html = Html::rawElement( $element['tag'], isset( $element['attributes'] )
1865                      ? $element['attributes']
1866                      : null, $html );
1867              }
1868          }
1869  
1870          if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
1871              $attrs = $item;
1872              foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1873                  unset( $attrs[$k] );
1874              }
1875  
1876              if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1877                  $item['single-id'] = $item['id'];
1878              }
1879              if ( isset( $item['single-id'] ) ) {
1880                  if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1881                      $title = Linker::titleAttrib( $item['single-id'] );
1882                      if ( $title !== false ) {
1883                          $attrs['title'] = $title;
1884                      }
1885                  } else {
1886                      $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
1887                      if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1888                          $attrs['title'] = $tip['title'];
1889                      }
1890                      if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1891                          $attrs['accesskey'] = $tip['accesskey'];
1892                      }
1893                  }
1894              }
1895              if ( isset( $options['link-class'] ) ) {
1896                  if ( isset( $attrs['class'] ) ) {
1897                      $attrs['class'] .= " {$options['link-class']}";
1898                  } else {
1899                      $attrs['class'] = $options['link-class'];
1900                  }
1901              }
1902              $html = Html::rawElement( isset( $attrs['href'] )
1903                  ? 'a'
1904                  : $options['link-fallback'], $attrs, $html );
1905          }
1906  
1907          return $html;
1908      }
1909  
1910      /**
1911       * Generates a list item for a navigation, portlet, portal, sidebar... list
1912       *
1913       * @param string $key Usually a key from the list you are generating this link from.
1914       * @param array $item Array of list item data containing some of a specific set of keys.
1915       * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
1916       * if "active" contains a value of true a "active" class will also be appended to class.
1917       *
1918       * @param array $options
1919       *
1920       * If you want something other than a "<li>" you can pass a tag name such as
1921       * "tag" => "span" in the $options array to change the tag used.
1922       * link/content data for the list item may come in one of two forms
1923       * A "links" key may be used, in which case it should contain an array with
1924       * a list of links to include inside the list item, see makeLink for the
1925       * format of individual links array items.
1926       *
1927       * Otherwise the relevant keys from the list item $item array will be passed
1928       * to makeLink instead. Note however that "id" and "class" are used by the
1929       * list item directly so they will not be passed to makeLink
1930       * (however the link will still support a tooltip and accesskey from it)
1931       * If you need an id or class on a single link you should include a "links"
1932       * array with just one link item inside of it. If you want to add a title
1933       * to the list item itself, you can set "itemtitle" to the value.
1934       * $options is also passed on to makeLink calls
1935       *
1936       * @return string
1937       */
1938  	function makeListItem( $key, $item, $options = array() ) {
1939          if ( isset( $item['links'] ) ) {
1940              $links = array();
1941              foreach ( $item['links'] as $linkKey => $link ) {
1942                  $links[] = $this->makeLink( $linkKey, $link, $options );
1943              }
1944              $html = implode( ' ', $links );
1945          } else {
1946              $link = $item;
1947              // These keys are used by makeListItem and shouldn't be passed on to the link
1948              foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
1949                  unset( $link[$k] );
1950              }
1951              if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1952                  // The id goes on the <li> not on the <a> for single links
1953                  // but makeSidebarLink still needs to know what id to use when
1954                  // generating tooltips and accesskeys.
1955                  $link['single-id'] = $item['id'];
1956              }
1957              $html = $this->makeLink( $key, $link, $options );
1958          }
1959  
1960          $attrs = array();
1961          foreach ( array( 'id', 'class' ) as $attr ) {
1962              if ( isset( $item[$attr] ) ) {
1963                  $attrs[$attr] = $item[$attr];
1964              }
1965          }
1966          if ( isset( $item['active'] ) && $item['active'] ) {
1967              if ( !isset( $attrs['class'] ) ) {
1968                  $attrs['class'] = '';
1969              }
1970              $attrs['class'] .= ' active';
1971              $attrs['class'] = trim( $attrs['class'] );
1972          }
1973          if ( isset( $item['itemtitle'] ) ) {
1974              $attrs['title'] = $item['itemtitle'];
1975          }
1976          return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1977      }
1978  
1979  	function makeSearchInput( $attrs = array() ) {
1980          $realAttrs = array(
1981              'type' => 'search',
1982              'name' => 'search',
1983              'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1984              'value' => $this->get( 'search', '' ),
1985          );
1986          $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1987          return Html::element( 'input', $realAttrs );
1988      }
1989  
1990  	function makeSearchButton( $mode, $attrs = array() ) {
1991          switch ( $mode ) {
1992              case 'go':
1993              case 'fulltext':
1994                  $realAttrs = array(
1995                      'type' => 'submit',
1996                      'name' => $mode,
1997                      'value' => $this->translator->translate(
1998                          $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1999                  );
2000                  $realAttrs = array_merge(
2001                      $realAttrs,
2002                      Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
2003                      $attrs
2004                  );
2005                  return Html::element( 'input', $realAttrs );
2006              case 'image':
2007                  $buttonAttrs = array(
2008                      'type' => 'submit',
2009                      'name' => 'button',
2010                  );
2011                  $buttonAttrs = array_merge(
2012                      $buttonAttrs,
2013                      Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
2014                      $attrs
2015                  );
2016                  unset( $buttonAttrs['src'] );
2017                  unset( $buttonAttrs['alt'] );
2018                  unset( $buttonAttrs['width'] );
2019                  unset( $buttonAttrs['height'] );
2020                  $imgAttrs = array(
2021                      'src' => $attrs['src'],
2022                      'alt' => isset( $attrs['alt'] )
2023                          ? $attrs['alt']
2024                          : $this->translator->translate( 'searchbutton' ),
2025                      'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
2026                      'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
2027                  );
2028                  return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
2029              default:
2030                  throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
2031          }
2032      }
2033  
2034      /**
2035       * Returns an array of footerlinks trimmed down to only those footer links that
2036       * are valid.
2037       * If you pass "flat" as an option then the returned array will be a flat array
2038       * of footer icons instead of a key/value array of footerlinks arrays broken
2039       * up into categories.
2040       * @param string $option
2041       * @return array|mixed
2042       */
2043  	function getFooterLinks( $option = null ) {
2044          $footerlinks = $this->get( 'footerlinks' );
2045  
2046          // Reduce footer links down to only those which are being used
2047          $validFooterLinks = array();
2048          foreach ( $footerlinks as $category => $links ) {
2049              $validFooterLinks[$category] = array();
2050              foreach ( $links as $link ) {
2051                  if ( isset( $this->data[$link] ) && $this->data[$link] ) {
2052                      $validFooterLinks[$category][] = $link;
2053                  }
2054              }
2055              if ( count( $validFooterLinks[$category] ) <= 0 ) {
2056                  unset( $validFooterLinks[$category] );
2057              }
2058          }
2059  
2060          if ( $option == 'flat' ) {
2061              // fold footerlinks into a single array using a bit of trickery
2062              $validFooterLinks = call_user_func_array(
2063                  'array_merge',
2064                  array_values( $validFooterLinks )
2065              );
2066          }
2067  
2068          return $validFooterLinks;
2069      }
2070  
2071      /**
2072       * Returns an array of footer icons filtered down by options relevant to how
2073       * the skin wishes to display them.
2074       * If you pass "icononly" as the option all footer icons which do not have an
2075       * image icon set will be filtered out.
2076       * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2077       * in the list of footer icons. This is mostly useful for skins which only
2078       * display the text from footericons instead of the images and don't want a
2079       * duplicate copyright statement because footerlinks already rendered one.
2080       * @param string $option
2081       * @return string
2082       */
2083  	function getFooterIcons( $option = null ) {
2084          // Generate additional footer icons
2085          $footericons = $this->get( 'footericons' );
2086  
2087          if ( $option == 'icononly' ) {
2088              // Unset any icons which don't have an image
2089              foreach ( $footericons as &$footerIconsBlock ) {
2090                  foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2091                      if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2092                          unset( $footerIconsBlock[$footerIconKey] );
2093                      }
2094                  }
2095              }
2096              // Redo removal of any empty blocks
2097              foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2098                  if ( count( $footerIconsBlock ) <= 0 ) {
2099                      unset( $footericons[$footerIconsKey] );
2100                  }
2101              }
2102          } elseif ( $option == 'nocopyright' ) {
2103              unset( $footericons['copyright']['copyright'] );
2104              if ( count( $footericons['copyright'] ) <= 0 ) {
2105                  unset( $footericons['copyright'] );
2106              }
2107          }
2108  
2109          return $footericons;
2110      }
2111  
2112      /**
2113       * Output the basic end-page trail including bottomscripts, reporttime, and
2114       * debug stuff. This should be called right before outputting the closing
2115       * body and html tags.
2116       */
2117  	function printTrail() { ?>
2118  <?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?>
2119  <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
2120  <?php $this->html( 'reporttime' ) ?>
2121  <?php
2122      }
2123  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1