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