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