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