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