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