Merge "(bug 42030) Include original URL params in variant links"
[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 Action::getActionName( $this ) === 'view' &&
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->formatLanguageName( $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 * Format language name for use in sidebar interlanguage links list.
503 * By default it is capitalized.
504 *
505 * @param $name string Language name, e.g. "English" or "español"
506 * @return string
507 * @private
508 */
509 function formatLanguageName( $name ) {
510 return $this->getLanguage()->ucfirst( $name );
511 }
512
513 /**
514 * Output the string, or print error message if it's
515 * an error object of the appropriate type.
516 * For the base class, assume strings all around.
517 *
518 * @param $str Mixed
519 * @private
520 */
521 function printOrError( $str ) {
522 echo $str;
523 }
524
525 /**
526 * Output a boolean indiciating if buildPersonalUrls should output separate
527 * login and create account links or output a combined link
528 * By default we simply return a global config setting that affects most skins
529 * This is setup as a method so that like with $wgLogo and getLogo() a skin
530 * can override this setting and always output one or the other if it has
531 * a reason it can't output one of the two modes.
532 * @return bool
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 global $wgSecureLogin;
545
546 $title = $this->getTitle();
547 $request = $this->getRequest();
548 $pageurl = $title->getLocalURL();
549 wfProfileIn( __METHOD__ );
550
551 /* set up the default links for the personal toolbar */
552 $personal_urls = array();
553
554 # Due to bug 32276, if a user does not have read permissions,
555 # $this->getTitle() will just give Special:Badtitle, which is
556 # not especially useful as a returnto parameter. Use the title
557 # from the request instead, if there was one.
558 if ( $this->getUser()->isAllowed( 'read' ) ) {
559 $page = $this->getTitle();
560 } else {
561 $page = Title::newFromText( $request->getVal( 'title', '' ) );
562 }
563 $page = $request->getVal( 'returnto', $page );
564 $a = array();
565 if ( strval( $page ) !== '' ) {
566 $a['returnto'] = $page;
567 $query = $request->getVal( 'returntoquery', $this->thisquery );
568 if( $query != '' ) {
569 $a['returntoquery'] = $query;
570 }
571 }
572
573 if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
574 $a['wpStickHTTPS'] = true;
575 }
576
577 $returnto = wfArrayToCGI( $a );
578 if( $this->loggedin ) {
579 $personal_urls['userpage'] = array(
580 'text' => $this->username,
581 'href' => &$this->userpageUrlDetails['href'],
582 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
583 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
584 'dir' => 'auto'
585 );
586 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
587 $personal_urls['mytalk'] = array(
588 'text' => $this->msg( 'mytalk' )->text(),
589 'href' => &$usertalkUrlDetails['href'],
590 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
591 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
592 );
593 $href = self::makeSpecialUrl( 'Preferences' );
594 $personal_urls['preferences'] = array(
595 'text' => $this->msg( 'mypreferences' )->text(),
596 'href' => $href,
597 'active' => ( $href == $pageurl )
598 );
599 $href = self::makeSpecialUrl( 'Watchlist' );
600 $personal_urls['watchlist'] = array(
601 'text' => $this->msg( 'mywatchlist' )->text(),
602 'href' => $href,
603 'active' => ( $href == $pageurl )
604 );
605
606 # We need to do an explicit check for Special:Contributions, as we
607 # have to match both the title, and the target, which could come
608 # from request values (Special:Contributions?target=Jimbo_Wales)
609 # or be specified in "sub page" form
610 # (Special:Contributions/Jimbo_Wales). The plot
611 # thickens, because the Title object is altered for special pages,
612 # so it doesn't contain the original alias-with-subpage.
613 $origTitle = Title::newFromText( $request->getText( 'title' ) );
614 if( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
615 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
616 $active = $spName == 'Contributions'
617 && ( ( $spPar && $spPar == $this->username )
618 || $request->getText( 'target' ) == $this->username );
619 } else {
620 $active = false;
621 }
622
623 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
624 $personal_urls['mycontris'] = array(
625 'text' => $this->msg( 'mycontris' )->text(),
626 'href' => $href,
627 'active' => $active
628 );
629 $personal_urls['logout'] = array(
630 'text' => $this->msg( 'userlogout' )->text(),
631 'href' => self::makeSpecialUrl( 'Userlogout',
632 // userlogout link must always contain an & character, otherwise we might not be able
633 // to detect a buggy precaching proxy (bug 17790)
634 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
635 ),
636 'active' => false
637 );
638 } else {
639 $useCombinedLoginLink = $this->useCombinedLoginLink();
640 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
641 ? 'nav-login-createaccount'
642 : 'login';
643 $is_signup = $request->getText( 'type' ) == 'signup';
644
645 # anonlogin & login are the same
646 $proto = $wgSecureLogin ? PROTO_HTTPS : null;
647
648 $login_id = $this->showIPinHeader() ? 'anonlogin' : 'login';
649 $login_url = array(
650 'text' => $this->msg( $loginlink )->text(),
651 'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
652 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
653 'class' => $wgSecureLogin ? 'link-https' : ''
654 );
655 $createaccount_url = array(
656 'text' => $this->msg( 'createaccount' )->text(),
657 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
658 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
659 'class' => $wgSecureLogin ? 'link-https' : ''
660 );
661
662 if( $this->showIPinHeader() ) {
663 $href = &$this->userpageUrlDetails['href'];
664 $personal_urls['anonuserpage'] = array(
665 'text' => $this->username,
666 'href' => $href,
667 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
668 'active' => ( $pageurl == $href )
669 );
670 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
671 $href = &$usertalkUrlDetails['href'];
672 $personal_urls['anontalk'] = array(
673 'text' => $this->msg( 'anontalk' )->text(),
674 'href' => $href,
675 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
676 'active' => ( $pageurl == $href )
677 );
678 }
679
680 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
681 $personal_urls['createaccount'] = $createaccount_url;
682 }
683
684 $personal_urls[$login_id] = $login_url;
685 }
686
687 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
688 wfProfileOut( __METHOD__ );
689 return $personal_urls;
690 }
691
692 /**
693 * Builds an array with tab definition
694 *
695 * @param Title $title page where the tab links to
696 * @param string|array $message message key or an array of message keys (will fall back)
697 * @param boolean $selected display the tab as selected
698 * @param string $query query string attached to tab URL
699 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
700 *
701 * @return array
702 */
703 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
704 $classes = array();
705 if( $selected ) {
706 $classes[] = 'selected';
707 }
708 if( $checkEdit && !$title->isKnown() ) {
709 $classes[] = 'new';
710 if ( $query !== '' ) {
711 $query = 'action=edit&redlink=1&' . $query;
712 } else {
713 $query = 'action=edit&redlink=1';
714 }
715 }
716
717 // wfMessageFallback will nicely accept $message as an array of fallbacks
718 // or just a single key
719 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
720 if ( is_array( $message ) ) {
721 // for hook compatibility just keep the last message name
722 $message = end( $message );
723 }
724 if ( $msg->exists() ) {
725 $text = $msg->text();
726 } else {
727 global $wgContLang;
728 $text = $wgContLang->getFormattedNsText(
729 MWNamespace::getSubject( $title->getNamespace() ) );
730 }
731
732 $result = array();
733 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
734 $title, $message, $selected, $checkEdit,
735 &$classes, &$query, &$text, &$result ) ) ) {
736 return $result;
737 }
738
739 return array(
740 'class' => implode( ' ', $classes ),
741 'text' => $text,
742 'href' => $title->getLocalUrl( $query ),
743 'primary' => true );
744 }
745
746 function makeTalkUrlDetails( $name, $urlaction = '' ) {
747 $title = Title::newFromText( $name );
748 if( !is_object( $title ) ) {
749 throw new MWException( __METHOD__ . " given invalid pagename $name" );
750 }
751 $title = $title->getTalkPage();
752 self::checkTitle( $title, $name );
753 return array(
754 'href' => $title->getLocalURL( $urlaction ),
755 'exists' => $title->getArticleID() != 0,
756 );
757 }
758
759 function makeArticleUrlDetails( $name, $urlaction = '' ) {
760 $title = Title::newFromText( $name );
761 $title= $title->getSubjectPage();
762 self::checkTitle( $title, $name );
763 return array(
764 'href' => $title->getLocalURL( $urlaction ),
765 'exists' => $title->getArticleID() != 0,
766 );
767 }
768
769 /**
770 * a structured array of links usually used for the tabs in a skin
771 *
772 * There are 4 standard sections
773 * namespaces: Used for namespace tabs like special, page, and talk namespaces
774 * views: Used for primary page views like read, edit, history
775 * actions: Used for most extra page actions like deletion, protection, etc...
776 * variants: Used to list the language variants for the page
777 *
778 * Each section's value is a key/value array of links for that section.
779 * The links themseves have these common keys:
780 * - class: The css classes to apply to the tab
781 * - text: The text to display on the tab
782 * - href: The href for the tab to point to
783 * - rel: An optional rel= for the tab's link
784 * - redundant: If true the tab will be dropped in skins using content_actions
785 * this is useful for tabs like "Read" which only have meaning in skins that
786 * take special meaning from the grouped structure of content_navigation
787 *
788 * Views also have an extra key which can be used:
789 * - primary: If this is not true skins like vector may try to hide the tab
790 * when the user has limited space in their browser window
791 *
792 * content_navigation using code also expects these ids to be present on the
793 * links, however these are usually automatically generated by SkinTemplate
794 * itself and are not necessary when using a hook. The only things these may
795 * matter to are people modifying content_navigation after it's initial creation:
796 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
797 * - tooltiponly: This is set to true for some tabs in cases where the system
798 * believes that the accesskey should not be added to the tab.
799 *
800 * @return array
801 */
802 protected function buildContentNavigationUrls() {
803 global $wgDisableLangConversion;
804
805 wfProfileIn( __METHOD__ );
806
807 // Display tabs for the relevant title rather than always the title itself
808 $title = $this->getRelevantTitle();
809 $onPage = $title->equals( $this->getTitle() );
810
811 $out = $this->getOutput();
812 $request = $this->getRequest();
813 $user = $this->getUser();
814
815 $content_navigation = array(
816 'namespaces' => array(),
817 'views' => array(),
818 'actions' => array(),
819 'variants' => array()
820 );
821
822 // parameters
823 $action = $request->getVal( 'action', 'view' );
824
825 $userCanRead = $title->quickUserCan( 'read', $user );
826
827 $preventActiveTabs = false;
828 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
829
830 // Checks if page is some kind of content
831 if( $title->canExist() ) {
832 // Gets page objects for the related namespaces
833 $subjectPage = $title->getSubjectPage();
834 $talkPage = $title->getTalkPage();
835
836 // Determines if this is a talk page
837 $isTalk = $title->isTalkPage();
838
839 // Generates XML IDs from namespace names
840 $subjectId = $title->getNamespaceKey( '' );
841
842 if ( $subjectId == 'main' ) {
843 $talkId = 'talk';
844 } else {
845 $talkId = "{$subjectId}_talk";
846 }
847
848 $skname = $this->skinname;
849
850 // Adds namespace links
851 $subjectMsg = array( "nstab-$subjectId" );
852 if ( $subjectPage->isMainPage() ) {
853 array_unshift( $subjectMsg, 'mainpage-nstab' );
854 }
855 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
856 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
857 );
858 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
859 $content_navigation['namespaces'][$talkId] = $this->tabAction(
860 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
861 );
862 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
863
864 if ( $userCanRead ) {
865 // Adds view view link
866 if ( $title->exists() ) {
867 $content_navigation['views']['view'] = $this->tabAction(
868 $isTalk ? $talkPage : $subjectPage,
869 array( "$skname-view-view", 'view' ),
870 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
871 );
872 // signal to hide this from simple content_actions
873 $content_navigation['views']['view']['redundant'] = true;
874 }
875
876 wfProfileIn( __METHOD__ . '-edit' );
877
878 // Checks if user can edit the current page if it exists or create it otherwise
879 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) {
880 // Builds CSS class for talk page links
881 $isTalkClass = $isTalk ? ' istalk' : '';
882 // Whether the user is editing the page
883 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
884 // Whether to show the "Add a new section" tab
885 // Checks if this is a current rev of talk page and is not forced to be hidden
886 $showNewSection = !$out->forceHideNewSectionLink()
887 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
888 $section = $request->getVal( 'section' );
889
890 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
891 'edit' : 'create';
892 $content_navigation['views']['edit'] = array(
893 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
894 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
895 'href' => $title->getLocalURL( $this->editUrlOptions() ),
896 'primary' => true, // don't collapse this in vector
897 );
898
899 // section link
900 if ( $showNewSection ) {
901 // Adds new section link
902 //$content_navigation['actions']['addsection']
903 $content_navigation['views']['addsection'] = array(
904 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
905 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
906 'href' => $title->getLocalURL( 'action=edit&section=new' )
907 );
908 }
909 // Checks if the page has some kind of viewable content
910 } elseif ( $title->hasSourceText() ) {
911 // Adds view source view link
912 $content_navigation['views']['viewsource'] = array(
913 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
914 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
915 'href' => $title->getLocalURL( $this->editUrlOptions() ),
916 'primary' => true, // don't collapse this in vector
917 );
918 }
919 wfProfileOut( __METHOD__ . '-edit' );
920
921 wfProfileIn( __METHOD__ . '-live' );
922 // Checks if the page exists
923 if ( $title->exists() ) {
924 // Adds history view link
925 $content_navigation['views']['history'] = array(
926 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
927 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
928 'href' => $title->getLocalURL( 'action=history' ),
929 'rel' => 'archives',
930 );
931
932 if ( $title->quickUserCan( 'delete', $user ) ) {
933 $content_navigation['actions']['delete'] = array(
934 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
935 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
936 'href' => $title->getLocalURL( 'action=delete' )
937 );
938 }
939
940 if ( $title->quickUserCan( 'move', $user ) ) {
941 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
942 $content_navigation['actions']['move'] = array(
943 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
944 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
945 'href' => $moveTitle->getLocalURL()
946 );
947 }
948 } else {
949 // article doesn't exist or is deleted
950 if ( $user->isAllowed( 'deletedhistory' ) ) {
951 $n = $title->isDeleted();
952 if ( $n ) {
953 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
954 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
955 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
956 $content_navigation['actions']['undelete'] = array(
957 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
958 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
959 ->setContext( $this->getContext() )->numParams( $n )->text(),
960 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
961 );
962 }
963 }
964 }
965
966 if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
967 $mode = $title->isProtected() ? 'unprotect' : 'protect';
968 $content_navigation['actions'][$mode] = array(
969 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
970 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
971 'href' => $title->getLocalURL( "action=$mode" )
972 );
973 }
974
975 wfProfileOut( __METHOD__ . '-live' );
976
977 // Checks if the user is logged in
978 if ( $this->loggedin ) {
979 /**
980 * The following actions use messages which, if made particular to
981 * the any specific skins, would break the Ajax code which makes this
982 * action happen entirely inline. Skin::makeGlobalVariablesScript
983 * defines a set of messages in a javascript object - and these
984 * messages are assumed to be global for all skins. Without making
985 * a change to that procedure these messages will have to remain as
986 * the global versions.
987 */
988 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
989 $token = WatchAction::getWatchToken( $title, $user, $mode );
990 $content_navigation['actions'][$mode] = array(
991 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
992 // uses 'watch' or 'unwatch' message
993 'text' => $this->msg( $mode )->text(),
994 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
995 );
996 }
997 }
998
999 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1000
1001 if ( $userCanRead && !$wgDisableLangConversion ) {
1002 $pageLang = $title->getPageLanguage();
1003 // Gets list of language variants
1004 $variants = $pageLang->getVariants();
1005 // Checks that language conversion is enabled and variants exist
1006 // And if it is not in the special namespace
1007 if ( count( $variants ) > 1 ) {
1008 // Gets preferred variant (note that user preference is
1009 // only possible for wiki content language variant)
1010 $preferred = $pageLang->getPreferredVariant();
1011 if ( Action::getActionName( $this ) === 'view' ) {
1012 $params = $request->getQueryValues();
1013 unset( $params['title'] );
1014 } else {
1015 $params = array();
1016 }
1017 // Loops over each variant
1018 foreach( $variants as $code ) {
1019 // Gets variant name from language code
1020 $varname = $pageLang->getVariantname( $code );
1021 // Checks if the variant is marked as disabled
1022 if( $varname == 'disable' ) {
1023 // Skips this variant
1024 continue;
1025 }
1026 // Appends variant link
1027 $content_navigation['variants'][] = array(
1028 'class' => ( $code == $preferred ) ? 'selected' : false,
1029 'text' => $varname,
1030 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1031 'lang' => $code,
1032 'hreflang' => $code
1033 );
1034 }
1035 }
1036 }
1037 } else {
1038 // If it's not content, it's got to be a special page
1039 $content_navigation['namespaces']['special'] = array(
1040 'class' => 'selected',
1041 'text' => $this->msg( 'nstab-special' )->text(),
1042 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1043 'context' => 'subject'
1044 );
1045
1046 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1047 array( &$this, &$content_navigation ) );
1048 }
1049
1050 // Equiv to SkinTemplateContentActions
1051 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1052
1053 // Setup xml ids and tooltip info
1054 foreach ( $content_navigation as $section => &$links ) {
1055 foreach ( $links as $key => &$link ) {
1056 $xmlID = $key;
1057 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1058 $xmlID = 'ca-nstab-' . $xmlID;
1059 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1060 $xmlID = 'ca-talk';
1061 } elseif ( $section == 'variants' ) {
1062 $xmlID = 'ca-varlang-' . $xmlID;
1063 } else {
1064 $xmlID = 'ca-' . $xmlID;
1065 }
1066 $link['id'] = $xmlID;
1067 }
1068 }
1069
1070 # We don't want to give the watch tab an accesskey if the
1071 # page is being edited, because that conflicts with the
1072 # accesskey on the watch checkbox. We also don't want to
1073 # give the edit tab an accesskey, because that's fairly su-
1074 # perfluous and conflicts with an accesskey (Ctrl-E) often
1075 # used for editing in Safari.
1076 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1077 if ( isset( $content_navigation['views']['edit'] ) ) {
1078 $content_navigation['views']['edit']['tooltiponly'] = true;
1079 }
1080 if ( isset( $content_navigation['actions']['watch'] ) ) {
1081 $content_navigation['actions']['watch']['tooltiponly'] = true;
1082 }
1083 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1084 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1085 }
1086 }
1087
1088 wfProfileOut( __METHOD__ );
1089
1090 return $content_navigation;
1091 }
1092
1093 /**
1094 * an array of edit links by default used for the tabs
1095 * @return array
1096 * @private
1097 */
1098 function buildContentActionUrls( $content_navigation ) {
1099
1100 wfProfileIn( __METHOD__ );
1101
1102 // content_actions has been replaced with content_navigation for backwards
1103 // compatibility and also for skins that just want simple tabs content_actions
1104 // is now built by flattening the content_navigation arrays into one
1105
1106 $content_actions = array();
1107
1108 foreach ( $content_navigation as $links ) {
1109
1110 foreach ( $links as $key => $value ) {
1111
1112 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1113 // Redundant tabs are dropped from content_actions
1114 continue;
1115 }
1116
1117 // content_actions used to have ids built using the "ca-$key" pattern
1118 // so the xmlID based id is much closer to the actual $key that we want
1119 // for that reason we'll just strip out the ca- if present and use
1120 // the latter potion of the "id" as the $key
1121 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1122 $key = substr( $value['id'], 3 );
1123 }
1124
1125 if ( isset( $content_actions[$key] ) ) {
1126 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1127 continue;
1128 }
1129
1130 $content_actions[$key] = $value;
1131
1132 }
1133
1134 }
1135
1136 wfProfileOut( __METHOD__ );
1137
1138 return $content_actions;
1139 }
1140
1141 /**
1142 * build array of common navigation links
1143 * @return array
1144 * @private
1145 */
1146 protected function buildNavUrls() {
1147 global $wgUploadNavigationUrl;
1148
1149 wfProfileIn( __METHOD__ );
1150
1151 $out = $this->getOutput();
1152 $request = $this->getRequest();
1153
1154 $nav_urls = array();
1155 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1156 if( $wgUploadNavigationUrl ) {
1157 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1158 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1159 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1160 } else {
1161 $nav_urls['upload'] = false;
1162 }
1163 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1164
1165 $nav_urls['print'] = false;
1166 $nav_urls['permalink'] = false;
1167 $nav_urls['info'] = false;
1168 $nav_urls['whatlinkshere'] = false;
1169 $nav_urls['recentchangeslinked'] = false;
1170 $nav_urls['contributions'] = false;
1171 $nav_urls['log'] = false;
1172 $nav_urls['blockip'] = false;
1173 $nav_urls['emailuser'] = false;
1174
1175 // A print stylesheet is attached to all pages, but nobody ever
1176 // figures that out. :) Add a link...
1177 if ( $out->isArticle() ) {
1178 if ( !$out->isPrintable() ) {
1179 $nav_urls['print'] = array(
1180 'text' => $this->msg( 'printableversion' )->text(),
1181 'href' => $this->getTitle()->getLocalURL(
1182 $request->appendQueryValue( 'printable', 'yes', true ) )
1183 );
1184 }
1185
1186 // Also add a "permalink" while we're at it
1187 $revid = $this->getRevisionId();
1188 if ( $revid ) {
1189 $nav_urls['permalink'] = array(
1190 'text' => $this->msg( 'permalink' )->text(),
1191 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1192 );
1193 }
1194
1195 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1196 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1197 array( &$this, &$nav_urls, &$revid, &$revid ) );
1198 }
1199
1200 if ( $out->isArticleRelated() ) {
1201 $nav_urls['whatlinkshere'] = array(
1202 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalUrl()
1203 );
1204
1205 $nav_urls['info'] = array(
1206 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1207 'href' => $this->getTitle()->getLocalURL( "action=info" )
1208 );
1209
1210 if ( $this->getTitle()->getArticleID() ) {
1211 $nav_urls['recentchangeslinked'] = array(
1212 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalUrl()
1213 );
1214 }
1215 }
1216
1217 $user = $this->getRelevantUser();
1218 if ( $user ) {
1219 $rootUser = $user->getName();
1220
1221 $nav_urls['contributions'] = array(
1222 'text' => $this->msg( 'contributions', $rootUser )->text(),
1223 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1224 );
1225
1226 $nav_urls['log'] = array(
1227 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1228 );
1229
1230 if ( $this->getUser()->isAllowed( 'block' ) ) {
1231 $nav_urls['blockip'] = array(
1232 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1233 );
1234 }
1235
1236 if ( $this->showEmailUser( $user ) ) {
1237 $nav_urls['emailuser'] = array(
1238 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1239 );
1240 }
1241 }
1242
1243 wfProfileOut( __METHOD__ );
1244 return $nav_urls;
1245 }
1246
1247 /**
1248 * Generate strings used for xml 'id' names
1249 * @return string
1250 * @private
1251 */
1252 function getNameSpaceKey() {
1253 return $this->getTitle()->getNamespaceKey();
1254 }
1255
1256 public function commonPrintStylesheet() {
1257 return false;
1258 }
1259 }
1260
1261 /**
1262 * Generic wrapper for template functions, with interface
1263 * compatible with what we use of PHPTAL 0.7.
1264 * @ingroup Skins
1265 */
1266 abstract class QuickTemplate {
1267 /**
1268 * Constructor
1269 */
1270 function __construct() {
1271 $this->data = array();
1272 $this->translator = new MediaWiki_I18N();
1273 }
1274
1275 /**
1276 * Sets the value $value to $name
1277 * @param $name
1278 * @param $value
1279 */
1280 public function set( $name, $value ) {
1281 $this->data[$name] = $value;
1282 }
1283
1284 /**
1285 * @param $name
1286 * @param $value
1287 */
1288 public function setRef( $name, &$value ) {
1289 $this->data[$name] =& $value;
1290 }
1291
1292 /**
1293 * @param $t
1294 */
1295 public function setTranslator( &$t ) {
1296 $this->translator = &$t;
1297 }
1298
1299 /**
1300 * Main function, used by classes that subclass QuickTemplate
1301 * to show the actual HTML output
1302 */
1303 abstract public function execute();
1304
1305 /**
1306 * @private
1307 */
1308 function text( $str ) {
1309 echo htmlspecialchars( $this->data[$str] );
1310 }
1311
1312 /**
1313 * @private
1314 */
1315 function jstext( $str ) {
1316 echo Xml::escapeJsString( $this->data[$str] );
1317 }
1318
1319 /**
1320 * @private
1321 */
1322 function html( $str ) {
1323 echo $this->data[$str];
1324 }
1325
1326 /**
1327 * @private
1328 */
1329 function msg( $str ) {
1330 echo htmlspecialchars( $this->translator->translate( $str ) );
1331 }
1332
1333 /**
1334 * @private
1335 */
1336 function msgHtml( $str ) {
1337 echo $this->translator->translate( $str );
1338 }
1339
1340 /**
1341 * An ugly, ugly hack.
1342 * @private
1343 */
1344 function msgWiki( $str ) {
1345 global $wgOut;
1346
1347 $text = $this->translator->translate( $str );
1348 echo $wgOut->parse( $text );
1349 }
1350
1351 /**
1352 * @private
1353 * @return bool
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 string 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 * @return array
1414 */
1415 function getToolbox() {
1416 wfProfileIn( __METHOD__ );
1417
1418 $toolbox = array();
1419 if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) {
1420 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1421 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1422 }
1423 if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) {
1424 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1425 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1426 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1427 }
1428 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
1429 $toolbox['feeds']['id'] = 'feedlinks';
1430 $toolbox['feeds']['links'] = array();
1431 foreach ( $this->data['feeds'] as $key => $feed ) {
1432 $toolbox['feeds']['links'][$key] = $feed;
1433 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1434 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1435 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1436 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1437 }
1438 }
1439 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1440 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
1441 $toolbox[$special] = $this->data['nav_urls'][$special];
1442 $toolbox[$special]['id'] = "t-$special";
1443 }
1444 }
1445 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
1446 $toolbox['print'] = $this->data['nav_urls']['print'];
1447 $toolbox['print']['id'] = 't-print';
1448 $toolbox['print']['rel'] = 'alternate';
1449 $toolbox['print']['msg'] = 'printableversion';
1450 }
1451 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
1452 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1453 if ( $toolbox['permalink']['href'] === '' ) {
1454 unset( $toolbox['permalink']['href'] );
1455 $toolbox['ispermalink']['tooltiponly'] = true;
1456 $toolbox['ispermalink']['id'] = 't-ispermalink';
1457 $toolbox['ispermalink']['msg'] = 'permalink';
1458 } else {
1459 $toolbox['permalink']['id'] = 't-permalink';
1460 }
1461 }
1462 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
1463 $toolbox['info'] = $this->data['nav_urls']['info'];
1464 $toolbox['info']['id'] = 't-info';
1465 }
1466
1467 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1468 wfProfileOut( __METHOD__ );
1469 return $toolbox;
1470 }
1471
1472 /**
1473 * Create an array of personal tools items from the data in the quicktemplate
1474 * stored by SkinTemplate.
1475 * The resulting array is built acording to a format intended to be passed
1476 * through makeListItem to generate the html.
1477 * This is in reality the same list as already stored in personal_urls
1478 * however it is reformatted so that you can just pass the individual items
1479 * to makeListItem instead of hardcoding the element creation boilerplate.
1480 * @return array
1481 */
1482 function getPersonalTools() {
1483 $personal_tools = array();
1484 foreach ( $this->data['personal_urls'] as $key => $plink ) {
1485 # The class on a personal_urls item is meant to go on the <a> instead
1486 # of the <li> so we have to use a single item "links" array instead
1487 # of using most of the personal_url's keys directly.
1488 $ptool = array(
1489 'links' => array(
1490 array( 'single-id' => "pt-$key" ),
1491 ),
1492 'id' => "pt-$key",
1493 );
1494 if ( isset( $plink['active'] ) ) {
1495 $ptool['active'] = $plink['active'];
1496 }
1497 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1498 if ( isset( $plink[$k] ) )
1499 $ptool['links'][0][$k] = $plink[$k];
1500 }
1501 $personal_tools[$key] = $ptool;
1502 }
1503 return $personal_tools;
1504 }
1505
1506 function getSidebar( $options = array() ) {
1507 // Force the rendering of the following portals
1508 $sidebar = $this->data['sidebar'];
1509 if ( !isset( $sidebar['SEARCH'] ) ) {
1510 $sidebar['SEARCH'] = true;
1511 }
1512 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1513 $sidebar['TOOLBOX'] = true;
1514 }
1515 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1516 $sidebar['LANGUAGES'] = true;
1517 }
1518
1519 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
1520 unset( $sidebar['SEARCH'] );
1521 }
1522 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1523 unset( $sidebar['TOOLBOX'] );
1524 }
1525 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1526 unset( $sidebar['LANGUAGES'] );
1527 }
1528
1529 $boxes = array();
1530 foreach ( $sidebar as $boxName => $content ) {
1531 if ( $content === false ) {
1532 continue;
1533 }
1534 switch ( $boxName ) {
1535 case 'SEARCH':
1536 // Search is a special case, skins should custom implement this
1537 $boxes[$boxName] = array(
1538 'id' => 'p-search',
1539 'header' => $this->getMsg( 'search' )->text(),
1540 'generated' => false,
1541 'content' => true,
1542 );
1543 break;
1544 case 'TOOLBOX':
1545 $msgObj = $this->getMsg( 'toolbox' );
1546 $boxes[$boxName] = array(
1547 'id' => 'p-tb',
1548 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
1549 'generated' => false,
1550 'content' => $this->getToolbox(),
1551 );
1552 break;
1553 case 'LANGUAGES':
1554 if ( $this->data['language_urls'] ) {
1555 $msgObj = $this->getMsg( 'otherlanguages' );
1556 $boxes[$boxName] = array(
1557 'id' => 'p-lang',
1558 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
1559 'generated' => false,
1560 'content' => $this->data['language_urls'],
1561 );
1562 }
1563 break;
1564 default:
1565 $msgObj = $this->getMsg( $boxName );
1566 $boxes[$boxName] = array(
1567 'id' => "p-$boxName",
1568 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
1569 'generated' => true,
1570 'content' => $content,
1571 );
1572 break;
1573 }
1574 }
1575
1576 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1577 $hookContents = null;
1578 if ( isset( $boxes['TOOLBOX'] ) ) {
1579 ob_start();
1580 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1581 // can abort and avoid outputting double toolbox links
1582 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1583 $hookContents = ob_get_contents();
1584 ob_end_clean();
1585 if ( !trim( $hookContents ) ) {
1586 $hookContents = null;
1587 }
1588 }
1589 // END hack
1590
1591 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1592 foreach ( $boxes as $boxName => $box ) {
1593 if ( is_array( $box['content'] ) ) {
1594 $content = '<ul>';
1595 foreach ( $box['content'] as $key => $val ) {
1596 $content .= "\n " . $this->makeListItem( $key, $val );
1597 }
1598 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1599 if ( $hookContents ) {
1600 $content .= "\n $hookContents";
1601 }
1602 // END hack
1603 $content .= "\n</ul>\n";
1604 $boxes[$boxName]['content'] = $content;
1605 }
1606 }
1607 } else {
1608 if ( $hookContents ) {
1609 $boxes['TOOLBOXEND'] = array(
1610 'id' => 'p-toolboxend',
1611 'header' => $boxes['TOOLBOX']['header'],
1612 'generated' => false,
1613 'content' => "<ul>{$hookContents}</ul>",
1614 );
1615 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1616 $boxes2 = array();
1617 foreach ( $boxes as $key => $box ) {
1618 if ( $key === 'TOOLBOXEND' ) {
1619 continue;
1620 }
1621 $boxes2[$key] = $box;
1622 if ( $key === 'TOOLBOX' ) {
1623 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1624 }
1625 }
1626 $boxes = $boxes2;
1627 // END hack
1628 }
1629 }
1630
1631 return $boxes;
1632 }
1633
1634 /**
1635 * Makes a link, usually used by makeListItem to generate a link for an item
1636 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1637 *
1638 * @param $key string usually a key from the list you are generating this
1639 * link from.
1640 * @param $item array contains some of a specific set of keys.
1641 *
1642 * The text of the link will be generated either from the contents of the
1643 * "text" key in the $item array, if a "msg" key is present a message by
1644 * that name will be used, and if neither of those are set the $key will be
1645 * used as a message name.
1646 *
1647 * If a "href" key is not present makeLink will just output htmlescaped text.
1648 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1649 * for the link if present.
1650 *
1651 * If an "id" or "single-id" (if you don't want the actual id to be output
1652 * on the link) is present it will be used to generate a tooltip and
1653 * accesskey for the link.
1654 *
1655 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1656 *
1657 * @param $options array can be used to affect the output of a link.
1658 * Possible options are:
1659 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1660 * a link in. This should be an array of arrays containing a 'tag' and
1661 * optionally an 'attributes' key. If you only have one element you don't
1662 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1663 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1664 * for your options.
1665 * - 'link-class' key can be used to specify additional classes to apply
1666 * to all links.
1667 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1668 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1669 * any non-link will output a "<span>" instead of just text.
1670 *
1671 * @return string
1672 */
1673 function makeLink( $key, $item, $options = array() ) {
1674 if ( isset( $item['text'] ) ) {
1675 $text = $item['text'];
1676 } else {
1677 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1678 }
1679
1680 $html = htmlspecialchars( $text );
1681
1682 if ( isset( $options['text-wrapper'] ) ) {
1683 $wrapper = $options['text-wrapper'];
1684 if ( isset( $wrapper['tag'] ) ) {
1685 $wrapper = array( $wrapper );
1686 }
1687 while ( count( $wrapper ) > 0 ) {
1688 $element = array_pop( $wrapper );
1689 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
1690 }
1691 }
1692
1693 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
1694 $attrs = $item;
1695 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1696 unset( $attrs[$k] );
1697 }
1698
1699 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1700 $item['single-id'] = $item['id'];
1701 }
1702 if ( isset( $item['single-id'] ) ) {
1703 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1704 $title = Linker::titleAttrib( $item['single-id'] );
1705 if ( $title !== false ) {
1706 $attrs['title'] = $title;
1707 }
1708 } else {
1709 $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
1710 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1711 $attrs['title'] = $tip['title'];
1712 }
1713 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1714 $attrs['accesskey'] = $tip['accesskey'];
1715 }
1716 }
1717 }
1718 if ( isset( $options['link-class'] ) ) {
1719 if ( isset( $attrs['class'] ) ) {
1720 $attrs['class'] .= " {$options['link-class']}";
1721 } else {
1722 $attrs['class'] = $options['link-class'];
1723 }
1724 }
1725 $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html );
1726 }
1727
1728 return $html;
1729 }
1730
1731 /**
1732 * Generates a list item for a navigation, portlet, portal, sidebar... list
1733 *
1734 * @param $key string, usually a key from the list you are generating this link from.
1735 * @param $item array, of list item data containing some of a specific set of keys.
1736 * The "id" and "class" keys will be used as attributes for the list item,
1737 * if "active" contains a value of true a "active" class will also be appended to class.
1738 *
1739 * @param $options array
1740 *
1741 * If you want something other than a "<li>" you can pass a tag name such as
1742 * "tag" => "span" in the $options array to change the tag used.
1743 * link/content data for the list item may come in one of two forms
1744 * A "links" key may be used, in which case it should contain an array with
1745 * a list of links to include inside the list item, see makeLink for the
1746 * format of individual links array items.
1747 *
1748 * Otherwise the relevant keys from the list item $item array will be passed
1749 * to makeLink instead. Note however that "id" and "class" are used by the
1750 * list item directly so they will not be passed to makeLink
1751 * (however the link will still support a tooltip and accesskey from it)
1752 * If you need an id or class on a single link you should include a "links"
1753 * array with just one link item inside of it.
1754 * $options is also passed on to makeLink calls
1755 *
1756 * @return string
1757 */
1758 function makeListItem( $key, $item, $options = array() ) {
1759 if ( isset( $item['links'] ) ) {
1760 $html = '';
1761 foreach ( $item['links'] as $linkKey => $link ) {
1762 $html .= $this->makeLink( $linkKey, $link, $options );
1763 }
1764 } else {
1765 $link = $item;
1766 // These keys are used by makeListItem and shouldn't be passed on to the link
1767 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1768 unset( $link[$k] );
1769 }
1770 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1771 // The id goes on the <li> not on the <a> for single links
1772 // but makeSidebarLink still needs to know what id to use when
1773 // generating tooltips and accesskeys.
1774 $link['single-id'] = $item['id'];
1775 }
1776 $html = $this->makeLink( $key, $link, $options );
1777 }
1778
1779 $attrs = array();
1780 foreach ( array( 'id', 'class' ) as $attr ) {
1781 if ( isset( $item[$attr] ) ) {
1782 $attrs[$attr] = $item[$attr];
1783 }
1784 }
1785 if ( isset( $item['active'] ) && $item['active'] ) {
1786 if ( !isset( $attrs['class'] ) ) {
1787 $attrs['class'] = '';
1788 }
1789 $attrs['class'] .= ' active';
1790 $attrs['class'] = trim( $attrs['class'] );
1791 }
1792 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1793 }
1794
1795 function makeSearchInput( $attrs = array() ) {
1796 $realAttrs = array(
1797 'type' => 'search',
1798 'name' => 'search',
1799 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1800 );
1801 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1802 return Html::element( 'input', $realAttrs );
1803 }
1804
1805 function makeSearchButton( $mode, $attrs = array() ) {
1806 switch( $mode ) {
1807 case 'go':
1808 case 'fulltext':
1809 $realAttrs = array(
1810 'type' => 'submit',
1811 'name' => $mode,
1812 'value' => $this->translator->translate(
1813 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1814 );
1815 $realAttrs = array_merge(
1816 $realAttrs,
1817 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1818 $attrs
1819 );
1820 return Html::element( 'input', $realAttrs );
1821 case 'image':
1822 $buttonAttrs = array(
1823 'type' => 'submit',
1824 'name' => 'button',
1825 );
1826 $buttonAttrs = array_merge(
1827 $buttonAttrs,
1828 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1829 $attrs
1830 );
1831 unset( $buttonAttrs['src'] );
1832 unset( $buttonAttrs['alt'] );
1833 unset( $buttonAttrs['width'] );
1834 unset( $buttonAttrs['height'] );
1835 $imgAttrs = array(
1836 'src' => $attrs['src'],
1837 'alt' => isset( $attrs['alt'] )
1838 ? $attrs['alt']
1839 : $this->translator->translate( 'searchbutton' ),
1840 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
1841 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
1842 );
1843 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1844 default:
1845 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1846 }
1847 }
1848
1849 /**
1850 * Returns an array of footerlinks trimmed down to only those footer links that
1851 * are valid.
1852 * If you pass "flat" as an option then the returned array will be a flat array
1853 * of footer icons instead of a key/value array of footerlinks arrays broken
1854 * up into categories.
1855 * @return array|mixed
1856 */
1857 function getFooterLinks( $option = null ) {
1858 $footerlinks = $this->data['footerlinks'];
1859
1860 // Reduce footer links down to only those which are being used
1861 $validFooterLinks = array();
1862 foreach( $footerlinks as $category => $links ) {
1863 $validFooterLinks[$category] = array();
1864 foreach( $links as $link ) {
1865 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1866 $validFooterLinks[$category][] = $link;
1867 }
1868 }
1869 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1870 unset( $validFooterLinks[$category] );
1871 }
1872 }
1873
1874 if ( $option == 'flat' ) {
1875 // fold footerlinks into a single array using a bit of trickery
1876 $validFooterLinks = call_user_func_array(
1877 'array_merge',
1878 array_values( $validFooterLinks )
1879 );
1880 }
1881
1882 return $validFooterLinks;
1883 }
1884
1885 /**
1886 * Returns an array of footer icons filtered down by options relevant to how
1887 * the skin wishes to display them.
1888 * If you pass "icononly" as the option all footer icons which do not have an
1889 * image icon set will be filtered out.
1890 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1891 * in the list of footer icons. This is mostly useful for skins which only
1892 * display the text from footericons instead of the images and don't want a
1893 * duplicate copyright statement because footerlinks already rendered one.
1894 * @return
1895 */
1896 function getFooterIcons( $option = null ) {
1897 // Generate additional footer icons
1898 $footericons = $this->data['footericons'];
1899
1900 if ( $option == 'icononly' ) {
1901 // Unset any icons which don't have an image
1902 foreach ( $footericons as &$footerIconsBlock ) {
1903 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1904 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1905 unset( $footerIconsBlock[$footerIconKey] );
1906 }
1907 }
1908 }
1909 // Redo removal of any empty blocks
1910 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1911 if ( count( $footerIconsBlock ) <= 0 ) {
1912 unset( $footericons[$footerIconsKey] );
1913 }
1914 }
1915 } elseif ( $option == 'nocopyright' ) {
1916 unset( $footericons['copyright']['copyright'] );
1917 if ( count( $footericons['copyright'] ) <= 0 ) {
1918 unset( $footericons['copyright'] );
1919 }
1920 }
1921
1922 return $footericons;
1923 }
1924
1925 /**
1926 * Output the basic end-page trail including bottomscripts, reporttime, and
1927 * debug stuff. This should be called right before outputting the closing
1928 * body and html tags.
1929 */
1930 function printTrail() { ?>
1931 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
1932 <?php $this->html( 'reporttime' ) ?>
1933 <?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() );
1934 }
1935
1936 }