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