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