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