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