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