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