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