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