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