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