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