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