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