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