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