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