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