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