Localisation updates for core and extension messages from translatewiki.net (2010...
[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 (or file)
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return object
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 ) {
135 global $wgArticle, $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgProfiler;
144
145 wfProfileIn( __METHOD__ );
146 if ( is_object( $wgProfiler ) ) {
147 $wgProfiler->setTemplated( true );
148 }
149
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
152 $action = $wgRequest->getVal( 'action', 'view' );
153
154 wfProfileIn( __METHOD__ . '-init' );
155 $this->initPage( $out );
156
157 $this->setMembers();
158 $tpl = $this->setupTemplate( $this->template, 'skins' );
159
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator( new MediaWiki_I18N() );
162 #}
163 wfProfileOut( __METHOD__ . '-init' );
164
165 wfProfileIn( __METHOD__ . '-stuff' );
166 $this->thispage = $this->mTitle->getPrefixedDBkey();
167 $this->thisurl = $this->mTitle->getPrefixedURL();
168 $query = array();
169 if ( !$wgRequest->wasPosted() ) {
170 $query = $wgRequest->getValues();
171 unset( $query['title'] );
172 unset( $query['returnto'] );
173 unset( $query['returntoquery'] );
174 }
175 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
176 $this->loggedin = $wgUser->isLoggedIn();
177 $this->iscontent = ( $this->mTitle->getNamespace() != NS_SPECIAL );
178 $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
179 $this->username = $wgUser->getName();
180
181 if ( $wgUser->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 = $this->mTitle->getPrefixedText();
190 wfProfileOut( __METHOD__ . '-stuff' );
191
192 wfProfileIn( __METHOD__ . '-stuff-head' );
193 if ( $this->useHeadElement ) {
194 $pagecss = $this->setupPageCss();
195 if( $pagecss )
196 $out->addInlineStyle( $pagecss );
197 } else {
198 $this->setupUserCss( $out );
199
200 $tpl->set( 'pagecss', $this->setupPageCss() );
201 $tpl->setRef( 'usercss', $this->usercss );
202
203 $this->userjs = $this->userjsprev = false;
204 $this->setupUserJs( $out->isUserJsAllowed() );
205 $tpl->setRef( 'userjs', $this->userjs );
206 $tpl->setRef( 'userjsprev', $this->userjsprev );
207
208 if( $wgUseSiteJs ) {
209 $jsCache = $this->loggedin ? '&smaxage=0' : '';
210 $tpl->set( 'jsvarurl',
211 self::makeUrl( '-',
212 "action=raw$jsCache&gen=js&useskin=" .
213 urlencode( $this->getSkinName() ) ) );
214 } else {
215 $tpl->set( 'jsvarurl', false );
216 }
217
218 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
219 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
220 $tpl->set( 'html5version', $wgHtml5Version );
221 $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
222 $tpl->set( 'csslinks', $out->buildCssLinks() );
223
224 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
225 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
226 } else {
227 $tpl->set( 'trackbackhtml', null );
228 }
229 }
230 wfProfileOut( __METHOD__ . '-stuff-head' );
231
232 wfProfileIn( __METHOD__ . '-stuff2' );
233 $tpl->set( 'title', $out->getPageTitle() );
234 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
235 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
236 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
237 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
238
239 $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
240 MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
241 $this->mTitle->getNsText();
242
243 $tpl->set( 'nscanonical', $nsname );
244 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
245 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
246 $tpl->set( 'titletext', $this->mTitle->getText() );
247 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
248 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
249
250 $tpl->set( 'isarticle', $out->isArticle() );
251
252 $tpl->setRef( 'thispage', $this->thispage );
253 $subpagestr = $this->subPageSubtitle();
254 $tpl->set(
255 'subtitle', !empty( $subpagestr ) ?
256 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
257 $out->getSubtitle()
258 );
259 $undelete = $this->getUndeleteLink();
260 $tpl->set(
261 'undelete', !empty( $undelete ) ?
262 '<span class="subpages">' . $undelete . '</span>' :
263 ''
264 );
265
266 $tpl->set( 'catlinks', $this->getCategories() );
267 if( $out->isSyndicated() ) {
268 $feeds = array();
269 foreach( $out->getSyndicationLinks() as $format => $link ) {
270 $feeds[$format] = array(
271 'text' => wfMsg( "feed-$format" ),
272 'href' => $link
273 );
274 }
275 $tpl->setRef( 'feeds', $feeds );
276 } else {
277 $tpl->set( 'feeds', false );
278 }
279
280 $tpl->setRef( 'mimetype', $wgMimeType );
281 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
282 $tpl->setRef( 'charset', $wgOutputEncoding );
283 $tpl->setRef( 'wgScript', $wgScript );
284 $tpl->setRef( 'skinname', $this->skinname );
285 $tpl->set( 'skinclass', get_class( $this ) );
286 $tpl->setRef( 'stylename', $this->stylename );
287 $tpl->set( 'printable', $out->isPrintable() );
288 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
289 $tpl->setRef( 'loggedin', $this->loggedin );
290 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
291 /* XXX currently unused, might get useful later
292 $tpl->set( 'editable', ( $this->mTitle->getNamespace() != NS_SPECIAL ) );
293 $tpl->set( 'exists', $this->mTitle->getArticleID() != 0 );
294 $tpl->set( 'watch', $this->mTitle->userIsWatching() ? 'unwatch' : 'watch' );
295 $tpl->set( 'protect', count( $this->mTitle->isProtected() ) ? 'unprotect' : 'protect' );
296 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
297 */
298 $tpl->set( 'searchaction', $this->escapeSearchLink() );
299 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
300 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
301 $tpl->setRef( 'stylepath', $wgStylePath );
302 $tpl->setRef( 'articlepath', $wgArticlePath );
303 $tpl->setRef( 'scriptpath', $wgScriptPath );
304 $tpl->setRef( 'serverurl', $wgServer );
305 $tpl->setRef( 'logopath', $wgLogo );
306
307 $lang = wfUILang();
308 $tpl->set( 'lang', $lang->getCode() );
309 $tpl->set( 'dir', $lang->getDir() );
310 $tpl->set( 'rtl', $lang->isRTL() );
311
312 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
313 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
314 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
315 $tpl->setRef( 'userpage', $this->userpage );
316 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
317 $tpl->set( 'userlang', $wgLang->getCode() );
318
319 // Users can have their language set differently than the
320 // content of the wiki. For these users, tell the web browser
321 // that interface elements are in a different language.
322 $tpl->set( 'userlangattributes', '' );
323 $tpl->set( 'specialpageattributes', '' );
324
325 $lang = $wgLang->getCode();
326 $dir = $wgLang->getDir();
327 if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
328 $attrs = " lang='$lang' dir='$dir'";
329
330 $tpl->set( 'userlangattributes', $attrs );
331
332 // The content of SpecialPages should be presented in the
333 // user's language. Content of regular pages should not be touched.
334 if( $this->mTitle->isSpecialPage() ) {
335 $tpl->set( 'specialpageattributes', $attrs );
336 }
337 }
338
339 $newtalks = $this->getNewtalks();
340
341 wfProfileOut( __METHOD__ . '-stuff2' );
342
343 wfProfileIn( __METHOD__ . '-stuff3' );
344 $tpl->setRef( 'newtalk', $newtalks );
345 $tpl->setRef( 'skin', $this );
346 $tpl->set( 'logo', $this->logoText() );
347 if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
348 $wgArticle && 0 != $wgArticle->getID() ){
349 if ( !$wgDisableCounters ) {
350 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
351 if ( $viewcount ) {
352 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
353 } else {
354 $tpl->set( 'viewcount', false );
355 }
356 } else {
357 $tpl->set( 'viewcount', false );
358 }
359
360 if( $wgPageShowWatchingUsers ) {
361 $dbr = wfGetDB( DB_SLAVE );
362 $res = $dbr->select( 'watchlist',
363 array( 'COUNT(*) AS n' ),
364 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
365 __METHOD__
366 );
367 $x = $dbr->fetchObject( $res );
368 $numberofwatchingusers = $x->n;
369 if( $numberofwatchingusers > 0 ) {
370 $tpl->set( 'numberofwatchingusers',
371 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
372 $wgLang->formatNum( $numberofwatchingusers ) )
373 );
374 } else {
375 $tpl->set( 'numberofwatchingusers', false );
376 }
377 } else {
378 $tpl->set( 'numberofwatchingusers', false );
379 }
380
381 $tpl->set( 'copyright', $this->getCopyright() );
382
383 $this->credits = false;
384
385 if( $wgMaxCredits != 0 ){
386 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
387 } else {
388 $tpl->set( 'lastmod', $this->lastModified() );
389 }
390
391 $tpl->setRef( 'credits', $this->credits );
392
393 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
394 $tpl->set( 'copyright', $this->getCopyright() );
395 $tpl->set( 'viewcount', false );
396 $tpl->set( 'lastmod', false );
397 $tpl->set( 'credits', false );
398 $tpl->set( 'numberofwatchingusers', false );
399 } else {
400 $tpl->set( 'copyright', false );
401 $tpl->set( 'viewcount', false );
402 $tpl->set( 'lastmod', false );
403 $tpl->set( 'credits', false );
404 $tpl->set( 'numberofwatchingusers', false );
405 }
406 wfProfileOut( __METHOD__ . '-stuff3' );
407
408 wfProfileIn( __METHOD__ . '-stuff4' );
409 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
410 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
411 $tpl->set( 'disclaimer', $this->disclaimerLink() );
412 $tpl->set( 'privacy', $this->privacyLink() );
413 $tpl->set( 'about', $this->aboutLink() );
414
415 $tpl->set( 'footerlinks', array(
416 'info' => array(
417 'lastmod',
418 'viewcount',
419 'numberofwatchingusers',
420 'credits',
421 'copyright',
422 ),
423 'places' => array(
424 'privacy',
425 'about',
426 'disclaimer',
427 ),
428 ) );
429
430 global $wgFooterIcons;
431 $tpl->set( 'footericons', $wgFooterIcons );
432 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
433 if ( count( $footerIconsBlock ) > 0 ) {
434 foreach ( $footerIconsBlock as &$footerIcon ) {
435 if ( isset( $footerIcon['src'] ) ) {
436 if ( !isset( $footerIcon['width'] ) ) {
437 $footerIcon['width'] = 88;
438 }
439 if ( !isset( $footerIcon['height'] ) ) {
440 $footerIcon['height'] = 31;
441 }
442 }
443 }
444 } else {
445 unset( $tpl->data['footericons'][$footerIconsKey] );
446 }
447 }
448
449 if ( $wgDebugComments ) {
450 $tpl->setRef( 'debug', $out->mDebugtext );
451 } else {
452 $tpl->set( 'debug', '' );
453 }
454
455 $tpl->set( 'reporttime', wfReportTime() );
456 $tpl->set( 'sitenotice', wfGetSiteNotice() );
457 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
458
459 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
460 global $wgBetterDirectionality;
461 if ( $wgBetterDirectionality ) {
462 $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
463 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
464 }
465 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
466 $tpl->setRef( 'bodytext', $out->mBodytext );
467
468 # Language links
469 $language_urls = array();
470
471 if ( !$wgHideInterlanguageLinks ) {
472 foreach( $out->getLanguageLinks() as $l ) {
473 $tmp = explode( ':', $l, 2 );
474 $class = 'interwiki-' . $tmp[0];
475 unset( $tmp );
476 $nt = Title::newFromText( $l );
477 if ( $nt ) {
478 $language_urls[] = array(
479 'href' => $nt->getFullURL(),
480 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
481 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
482 'title' => $nt->getText(),
483 'class' => $class
484 );
485 }
486 }
487 }
488 if( count( $language_urls ) ) {
489 $tpl->setRef( 'language_urls', $language_urls );
490 } else {
491 $tpl->set( 'language_urls', false );
492 }
493 wfProfileOut( __METHOD__ . '-stuff4' );
494
495 wfProfileIn( __METHOD__ . '-stuff5' );
496 # Personal toolbar
497 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
498 $content_actions = $this->buildContentActionUrls();
499 $tpl->setRef( 'content_actions', $content_actions );
500
501 $tpl->set( 'sidebar', $this->buildSidebar() );
502 $tpl->set( 'nav_urls', $this->buildNavUrls() );
503
504 // Set the head scripts near the end, in case the above actions resulted in added scripts
505 if ( $this->useHeadElement ) {
506 $tpl->set( 'headelement', $out->headElement( $this ) );
507 } else {
508 $tpl->set( 'headscripts', $out->getScript() );
509 }
510
511 // original version by hansm
512 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
513 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
514 }
515
516 // allow extensions adding stuff after the page content.
517 // See Skin::afterContentHook() for further documentation.
518 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
519 wfProfileOut( __METHOD__ . '-stuff5' );
520
521 // execute template
522 wfProfileIn( __METHOD__ . '-execute' );
523 $res = $tpl->execute();
524 wfProfileOut( __METHOD__ . '-execute' );
525
526 // result may be an error
527 $this->printOrError( $res );
528 wfProfileOut( __METHOD__ );
529 }
530
531 /**
532 * Output the string, or print error message if it's
533 * an error object of the appropriate type.
534 * For the base class, assume strings all around.
535 *
536 * @param $str Mixed
537 * @private
538 */
539 function printOrError( $str ) {
540 echo $str;
541 }
542
543 /**
544 * Output a boolean indiciating if buildPersonalUrls should output separate
545 * login and create account links or output a combined link
546 * By default we simply return a global config setting that affects most skins
547 * This is setup as a method so that like with $wgLogo and getLogo() a skin
548 * can override this setting and always output one or the other if it has
549 * a reason it can't output one of the two modes.
550 */
551 function useCombinedLoginLink() {
552 global $wgUseCombinedLoginLink;
553 return $wgUseCombinedLoginLink;
554 }
555
556 /**
557 * build array of urls for personal toolbar
558 * @return array
559 * @private
560 */
561 function buildPersonalUrls() {
562 global $wgOut, $wgRequest;
563
564 $title = $wgOut->getTitle();
565 $pageurl = $title->getLocalURL();
566 wfProfileIn( __METHOD__ );
567
568 /* set up the default links for the personal toolbar */
569 $personal_urls = array();
570 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
571 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
572 $returnto = "returnto=$page";
573 if( $this->thisquery != '' ) {
574 $returnto .= "&returntoquery=$query";
575 }
576 if( $this->loggedin ) {
577 $personal_urls['userpage'] = array(
578 'text' => $this->username,
579 'href' => &$this->userpageUrlDetails['href'],
580 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
581 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
582 );
583 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
584 $personal_urls['mytalk'] = array(
585 'text' => wfMsg( 'mytalk' ),
586 'href' => &$usertalkUrlDetails['href'],
587 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
588 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
589 );
590 $href = self::makeSpecialUrl( 'Preferences' );
591 $personal_urls['preferences'] = array(
592 'text' => wfMsg( 'mypreferences' ),
593 'href' => $href,
594 'active' => ( $href == $pageurl )
595 );
596 $href = self::makeSpecialUrl( 'Watchlist' );
597 $personal_urls['watchlist'] = array(
598 'text' => wfMsg( 'mywatchlist' ),
599 'href' => $href,
600 'active' => ( $href == $pageurl )
601 );
602
603 # We need to do an explicit check for Special:Contributions, as we
604 # have to match both the title, and the target (which could come
605 # from request values or be specified in "sub page" form. The plot
606 # thickens, because $wgTitle is altered for special pages, so doesn't
607 # contain the original alias-with-subpage.
608 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
609 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
610 list( $spName, $spPar ) =
611 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
612 $active = $spName == 'Contributions'
613 && ( ( $spPar && $spPar == $this->username )
614 || $wgRequest->getText( 'target' ) == $this->username );
615 } else {
616 $active = false;
617 }
618
619 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
620 $personal_urls['mycontris'] = array(
621 'text' => wfMsg( 'mycontris' ),
622 'href' => $href,
623 'active' => $active
624 );
625 $personal_urls['logout'] = array(
626 'text' => wfMsg( 'userlogout' ),
627 'href' => self::makeSpecialUrl( 'Userlogout',
628 $title->isSpecial( 'Preferences' ) ? '' : $returnto
629 ),
630 'active' => false
631 );
632 } else {
633 global $wgUser;
634 $useCombinedLoginLink = $this->useCombinedLoginLink();
635 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
636 ? 'nav-login-createaccount'
637 : 'login';
638 $is_signup = $wgRequest->getText('type') == "signup";
639
640 # anonlogin & login are the same
641 $login_url = array(
642 'text' => wfMsg( $loginlink ),
643 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
644 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup )
645 );
646 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
647 $createaccount_url = array(
648 'text' => wfMsg( 'createaccount' ),
649 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
650 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
651 );
652 }
653 global $wgProto, $wgSecureLogin;
654 if( $wgProto === 'http' && $wgSecureLogin ) {
655 $title = SpecialPage::getTitleFor( 'Userlogin' );
656 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
657 $login_url['href'] = $https_url;
658 $login_url['class'] = 'link-https'; # FIXME class depends on skin
659 if ( isset($createaccount_url) ) {
660 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL("type=signup") );
661 $createaccount_url['href'] = $https_url;
662 $createaccount_url['class'] = 'link-https'; # FIXME class depends on skin
663 }
664 }
665
666
667 if( $this->showIPinHeader() ) {
668 $href = &$this->userpageUrlDetails['href'];
669 $personal_urls['anonuserpage'] = array(
670 'text' => $this->username,
671 'href' => $href,
672 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
673 'active' => ( $pageurl == $href )
674 );
675 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
676 $href = &$usertalkUrlDetails['href'];
677 $personal_urls['anontalk'] = array(
678 'text' => wfMsg( 'anontalk' ),
679 'href' => $href,
680 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
681 'active' => ( $pageurl == $href )
682 );
683 $personal_urls['anonlogin'] = $login_url;
684 if ( isset($createaccount_url) ) {
685 $personal_urls['createaccount'] = $createaccount_url;
686 }
687 } else {
688 $personal_urls['login'] = $login_url;
689 }
690 }
691
692 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
693 wfProfileOut( __METHOD__ );
694 return $personal_urls;
695 }
696
697 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
698 $classes = array();
699 if( $selected ) {
700 $classes[] = 'selected';
701 }
702 if( $checkEdit && !$title->isKnown() ) {
703 $classes[] = 'new';
704 $query = 'action=edit&redlink=1';
705 }
706
707 $text = wfMsg( $message );
708 if ( wfEmptyMsg( $message, $text ) ) {
709 global $wgContLang;
710 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
711 }
712
713 $result = array();
714 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
715 $title, $message, $selected, $checkEdit,
716 &$classes, &$query, &$text, &$result ) ) ) {
717 return $result;
718 }
719
720 return array(
721 'class' => implode( ' ', $classes ),
722 'text' => $text,
723 'href' => $title->getLocalUrl( $query ) );
724 }
725
726 function makeTalkUrlDetails( $name, $urlaction = '' ) {
727 $title = Title::newFromText( $name );
728 if( !is_object( $title ) ) {
729 throw new MWException( __METHOD__ . " given invalid pagename $name" );
730 }
731 $title = $title->getTalkPage();
732 self::checkTitle( $title, $name );
733 return array(
734 'href' => $title->getLocalURL( $urlaction ),
735 'exists' => $title->getArticleID() != 0,
736 );
737 }
738
739 function makeArticleUrlDetails( $name, $urlaction = '' ) {
740 $title = Title::newFromText( $name );
741 $title= $title->getSubjectPage();
742 self::checkTitle( $title, $name );
743 return array(
744 'href' => $title->getLocalURL( $urlaction ),
745 'exists' => $title->getArticleID() != 0,
746 );
747 }
748
749 /**
750 * an array of edit links by default used for the tabs
751 * @return array
752 * @private
753 */
754 function buildContentActionUrls() {
755 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
756
757 wfProfileIn( __METHOD__ );
758
759 $action = $wgRequest->getVal( 'action', 'view' );
760 $section = $wgRequest->getVal( 'section' );
761 $content_actions = array();
762 $userCanRead = $this->mTitle->userCanRead();
763
764 $prevent_active_tabs = false;
765 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
766
767 if( $this->iscontent ) {
768 $subjpage = $this->mTitle->getSubjectPage();
769 $talkpage = $this->mTitle->getTalkPage();
770
771 $nskey = $this->mTitle->getNamespaceKey();
772 $content_actions[$nskey] = $this->tabAction(
773 $subjpage,
774 $nskey,
775 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
776 '', $userCanRead
777 );
778
779 $content_actions['talk'] = $this->tabAction(
780 $talkpage,
781 'talk',
782 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
783 '',
784 $userCanRead
785 );
786
787 wfProfileIn( __METHOD__ . '-edit' );
788 if ( $userCanRead && $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
789 $istalk = $this->mTitle->isTalkPage();
790 $istalkclass = $istalk?' istalk':'';
791 $content_actions['edit'] = array(
792 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
793 'text' => ( $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) )
794 ? wfMsg( 'edit' )
795 : wfMsg( 'create' ),
796 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
797 );
798
799 // adds new section link if page is a current revision of a talk page or
800 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
801 if ( !$wgOut->forceHideNewSectionLink() ) {
802 $content_actions['addsection'] = array(
803 'class' => $section == 'new' ? 'selected' : false,
804 'text' => wfMsg( 'addsection' ),
805 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
806 );
807 }
808 }
809 } elseif ( $this->mTitle->hasSourceText() && $userCanRead ) {
810 $content_actions['viewsource'] = array(
811 'class' => ($action == 'edit') ? 'selected' : false,
812 'text' => wfMsg( 'viewsource' ),
813 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
814 );
815 }
816 wfProfileOut( __METHOD__ . '-edit' );
817
818 wfProfileIn( __METHOD__ . '-live' );
819 if ( $this->mTitle->exists() && $userCanRead ) {
820
821 $content_actions['history'] = array(
822 'class' => ($action == 'history') ? 'selected' : false,
823 'text' => wfMsg( 'history_short' ),
824 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
825 'rel' => 'archives',
826 );
827
828 if( $wgUser->isAllowed( 'delete' ) ) {
829 $content_actions['delete'] = array(
830 'class' => ($action == 'delete') ? 'selected' : false,
831 'text' => wfMsg( 'delete' ),
832 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
833 );
834 }
835 if ( $this->mTitle->quickUserCan( 'move' ) ) {
836 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
837 $content_actions['move'] = array(
838 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
839 'text' => wfMsg( 'move' ),
840 'href' => $moveTitle->getLocalUrl()
841 );
842 }
843
844 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
845 if( !$this->mTitle->isProtected() ){
846 $content_actions['protect'] = array(
847 'class' => ($action == 'protect') ? 'selected' : false,
848 'text' => wfMsg( 'protect' ),
849 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
850 );
851
852 } else {
853 $content_actions['unprotect'] = array(
854 'class' => ($action == 'unprotect') ? 'selected' : false,
855 'text' => wfMsg( 'unprotect' ),
856 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
857 );
858 }
859 }
860 } else {
861 //article doesn't exist or is deleted
862 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
863 $n = $this->mTitle->isDeleted();
864 if( $n ) {
865 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
866 $content_actions['undelete'] = array(
867 'class' => false,
868 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
869 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
870 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
871 );
872 }
873 }
874
875 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
876 if( !$this->mTitle->getRestrictions( 'create' ) ) {
877 $content_actions['protect'] = array(
878 'class' => ($action == 'protect') ? 'selected' : false,
879 'text' => wfMsg( 'protect' ),
880 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
881 );
882
883 } else {
884 $content_actions['unprotect'] = array(
885 'class' => ($action == 'unprotect') ? 'selected' : false,
886 'text' => wfMsg( 'unprotect' ),
887 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
888 );
889 }
890 }
891 }
892
893 wfProfileOut( __METHOD__ . '-live' );
894
895 if( $this->loggedin ) {
896 if( !$this->mTitle->userIsWatching()) {
897 $content_actions['watch'] = array(
898 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
899 'text' => wfMsg( 'watch' ),
900 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
901 );
902 } else {
903 $content_actions['unwatch'] = array(
904 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
905 'text' => wfMsg( 'unwatch' ),
906 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
907 );
908 }
909 }
910
911
912 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
913 } else {
914 /* show special page tab */
915
916 $content_actions[$this->mTitle->getNamespaceKey()] = array(
917 'class' => 'selected',
918 'text' => wfMsg('nstab-special'),
919 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
920 );
921
922 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
923 }
924
925 /* show links to different language variants */
926 global $wgDisableLangConversion;
927 $variants = $wgContLang->getVariants();
928 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
929 $preferred = $wgContLang->getPreferredVariant();
930 $vcount=0;
931 foreach( $variants as $code ) {
932 $varname = $wgContLang->getVariantname( $code );
933 if( $varname == 'disable' )
934 continue;
935 $selected = ( $code == $preferred )? 'selected' : false;
936 $content_actions['varlang-' . $vcount] = array(
937 'class' => $selected,
938 'text' => $varname,
939 'href' => $this->mTitle->getLocalURL( '', $code )
940 );
941 $vcount ++;
942 }
943 }
944
945 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
946
947 wfProfileOut( __METHOD__ );
948 return $content_actions;
949 }
950
951 /**
952 * build array of common navigation links
953 * @return array
954 * @private
955 */
956 function buildNavUrls() {
957 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
958 global $wgUploadNavigationUrl;
959
960 wfProfileIn( __METHOD__ );
961
962 $action = $wgRequest->getVal( 'action', 'view' );
963
964 $nav_urls = array();
965 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
966 if( $wgUploadNavigationUrl ) {
967 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
968 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
969 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
970 } else {
971 $nav_urls['upload'] = false;
972 }
973 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
974
975 // default permalink to being off, will override it as required below.
976 $nav_urls['permalink'] = false;
977
978 // A print stylesheet is attached to all pages, but nobody ever
979 // figures that out. :) Add a link...
980 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
981 if ( !$wgOut->isPrintable() ) {
982 $nav_urls['print'] = array(
983 'text' => wfMsg( 'printableversion' ),
984 'href' => $wgRequest->appendQuery( 'printable=yes' )
985 );
986 }
987
988 // Also add a "permalink" while we're at it
989 if ( $this->mRevisionId ) {
990 $nav_urls['permalink'] = array(
991 'text' => wfMsg( 'permalink' ),
992 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
993 );
994 }
995
996 // Copy in case this undocumented, shady hook tries to mess with internals
997 $revid = $this->mRevisionId;
998 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
999 }
1000
1001 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
1002 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
1003 $nav_urls['whatlinkshere'] = array(
1004 'href' => $wlhTitle->getLocalUrl()
1005 );
1006 if( $this->mTitle->getArticleId() ) {
1007 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
1008 $nav_urls['recentchangeslinked'] = array(
1009 'href' => $rclTitle->getLocalUrl()
1010 );
1011 } else {
1012 $nav_urls['recentchangeslinked'] = false;
1013 }
1014 if( $wgUseTrackbacks )
1015 $nav_urls['trackbacklink'] = array(
1016 'href' => $wgOut->getTitle()->trackbackURL()
1017 );
1018 }
1019
1020 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
1021 $rootUser = strtok( $this->mTitle->getText(), '/' );
1022 $id = User::idFromName( $rootUser );
1023 $ip = User::isIP( $rootUser );
1024 } else {
1025 $id = 0;
1026 $ip = false;
1027 }
1028
1029 if( $id || $ip ) { # both anons and non-anons have contribs list
1030 $nav_urls['contributions'] = array(
1031 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1032 );
1033
1034 if( $id ) {
1035 $logPage = SpecialPage::getTitleFor( 'Log' );
1036 $nav_urls['log'] = array(
1037 'href' => $logPage->getLocalUrl(
1038 array(
1039 'user' => $rootUser
1040 )
1041 )
1042 );
1043 } else {
1044 $nav_urls['log'] = false;
1045 }
1046
1047 if ( $wgUser->isAllowed( 'block' ) ) {
1048 $nav_urls['blockip'] = array(
1049 'href' => self::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1050 );
1051 } else {
1052 $nav_urls['blockip'] = false;
1053 }
1054 } else {
1055 $nav_urls['contributions'] = false;
1056 $nav_urls['log'] = false;
1057 $nav_urls['blockip'] = false;
1058 }
1059 $nav_urls['emailuser'] = false;
1060 if( $this->showEmailUser( $id ) ) {
1061 $nav_urls['emailuser'] = array(
1062 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1063 );
1064 }
1065 wfProfileOut( __METHOD__ );
1066 return $nav_urls;
1067 }
1068
1069 /**
1070 * Generate strings used for xml 'id' names
1071 * @return string
1072 * @private
1073 */
1074 function getNameSpaceKey() {
1075 return $this->mTitle->getNamespaceKey();
1076 }
1077
1078 /**
1079 * @private
1080 */
1081 function setupUserJs( $allowUserJs ) {
1082 global $wgRequest, $wgJsMimeType;
1083 wfProfileIn( __METHOD__ );
1084
1085 $action = $wgRequest->getVal( 'action', 'view' );
1086
1087 if( $allowUserJs && $this->loggedin ) {
1088 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1089 # XXX: additional security check/prompt?
1090 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1091 } else {
1092 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1093 }
1094 }
1095 wfProfileOut( __METHOD__ );
1096 }
1097
1098 /**
1099 * Code for extensions to hook into to provide per-page CSS, see
1100 * extensions/PageCSS/PageCSS.php for an implementation of this.
1101 *
1102 * @private
1103 */
1104 function setupPageCss() {
1105 wfProfileIn( __METHOD__ );
1106 $out = false;
1107 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1108 wfProfileOut( __METHOD__ );
1109 return $out;
1110 }
1111
1112 public function commonPrintStylesheet() {
1113 return false;
1114 }
1115 }
1116
1117 /**
1118 * Generic wrapper for template functions, with interface
1119 * compatible with what we use of PHPTAL 0.7.
1120 * @ingroup Skins
1121 */
1122 abstract class QuickTemplate {
1123 /**
1124 * Constructor
1125 */
1126 public function QuickTemplate() {
1127 $this->data = array();
1128 $this->translator = new MediaWiki_I18N();
1129 }
1130
1131 /**
1132 * Sets the value $value to $name
1133 * @param $name
1134 * @param $value
1135 */
1136 public function set( $name, $value ) {
1137 $this->data[$name] = $value;
1138 }
1139
1140 /**
1141 * @param $name
1142 * @param $value
1143 */
1144 public function setRef( $name, &$value ) {
1145 $this->data[$name] =& $value;
1146 }
1147
1148 /**
1149 * @param $t
1150 */
1151 public function setTranslator( &$t ) {
1152 $this->translator = &$t;
1153 }
1154
1155 /**
1156 * Main function, used by classes that subclass QuickTemplate
1157 * to show the actual HTML output
1158 */
1159 abstract public function execute();
1160
1161 /**
1162 * @private
1163 */
1164 function text( $str ) {
1165 echo htmlspecialchars( $this->data[$str] );
1166 }
1167
1168 /**
1169 * @private
1170 */
1171 function jstext( $str ) {
1172 echo Xml::escapeJsString( $this->data[$str] );
1173 }
1174
1175 /**
1176 * @private
1177 */
1178 function html( $str ) {
1179 echo $this->data[$str];
1180 }
1181
1182 /**
1183 * @private
1184 */
1185 function msg( $str ) {
1186 echo htmlspecialchars( $this->translator->translate( $str ) );
1187 }
1188
1189 /**
1190 * @private
1191 */
1192 function msgHtml( $str ) {
1193 echo $this->translator->translate( $str );
1194 }
1195
1196 /**
1197 * An ugly, ugly hack.
1198 * @private
1199 */
1200 function msgWiki( $str ) {
1201 global $wgParser, $wgOut;
1202
1203 $text = $this->translator->translate( $str );
1204 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1205 $wgOut->parserOptions(), true );
1206 echo $parserOutput->getText();
1207 }
1208
1209 /**
1210 * @private
1211 */
1212 function haveData( $str ) {
1213 return isset( $this->data[$str] );
1214 }
1215
1216 /**
1217 * @private
1218 */
1219 function haveMsg( $str ) {
1220 $msg = $this->translator->translate( $str );
1221 return ( $msg != '-' ) && ( $msg != '' ); # ????
1222 }
1223 }
1224
1225 /**
1226 * New base template for a skin's template extended from QuickTemplate
1227 * this class features helper methods that provide common ways of interacting
1228 * with the data stored in the QuickTemplate
1229 */
1230 abstract class BaseTemplate extends QuickTemplate {
1231
1232 /**
1233 * Create an array of common toolbox items from the data in the quicktemplate
1234 * stored by SkinTemplate.
1235 * The resulting array is built acording to a format intended to be passed
1236 * through makeListItem to generate the html.
1237 */
1238 function getToolbox() {
1239 wfProfileIn( __METHOD__ );
1240
1241 $toolbox = array();
1242 if ( $this->data['notspecialpage'] ) {
1243 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1244 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1245 if ( $this->data['nav_urls']['recentchangeslinked'] ) {
1246 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1247 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1248 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1249 }
1250 }
1251 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) {
1252 $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink'];
1253 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1254 }
1255 if ( $this->data['feeds'] ) {
1256 $toolbox['feeds']['id'] = 'feedlinks';
1257 $toolbox['feeds']['links'] = array();
1258 foreach ( $this->data['feeds'] as $key => $feed ) {
1259 $toolbox['feeds']['links'][$key] = $feed;
1260 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1261 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1262 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1263 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1264 }
1265 }
1266 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1267 if ( $this->data['nav_urls'][$special] ) {
1268 $toolbox[$special] = $this->data['nav_urls'][$special];
1269 $toolbox[$special]['id'] = "t-$special";
1270 }
1271 }
1272 if ( !empty( $this->data['nav_urls']['print']['href'] ) ) {
1273 $toolbox['print'] = $this->data['nav_urls']['print'];
1274 $toolbox['print']['rel'] = 'alternate';
1275 $toolbox['print']['msg'] = 'printableversion';
1276 }
1277 if ( !empty( $this->data['nav_urls']['permalink']['href'] ) ) {
1278 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1279 $toolbox['permalink']['id'] = 't-permalink';
1280 } elseif ( $this->data['nav_urls']['permalink']['href'] === '' ) {
1281 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1282 unset( $toolbox['permalink']['href'] );
1283 $toolbox['ispermalink']['tooltiponly'] = true;
1284 $toolbox['ispermalink']['id'] = 't-ispermalink';
1285 $toolbox['ispermalink']['msg'] = 'permalink';
1286 }
1287 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1288 wfProfileOut( __METHOD__ );
1289 return $toolbox;
1290 }
1291
1292 /**
1293 * Create an array of personal tools items from the data in the quicktemplate
1294 * stored by SkinTemplate.
1295 * The resulting array is built acording to a format intended to be passed
1296 * through makeListItem to generate the html.
1297 * This is in reality the same list as already stored in personal_urls
1298 * however it is reformatted so that you can just pass the individual items
1299 * to makeListItem instead of hardcoding the element creation boilerplate.
1300 */
1301 function getPersonalTools() {
1302 $personal_tools = array();
1303 foreach( $this->data['personal_urls'] as $key => $ptool ) {
1304 # The class on a personal_urls item is meant to go on the <a> instead
1305 # of the <li> so we have to use a single item "links" array instead
1306 # of using most of the personal_url's keys directly
1307 $personal_tools[$key] = array();
1308 $personal_tools[$key]["links"][] = array();
1309 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1310 if ( isset($ptool["active"]) ) {
1311 $personal_tools[$key]["active"] = $ptool["active"];
1312 }
1313 foreach ( array("href", "class", "text") as $k ) {
1314 if ( isset($ptool[$k]) )
1315 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1316 }
1317 }
1318 return $personal_tools;
1319 }
1320
1321 /**
1322 * Makes a link, usually used by makeListItem to generate a link for an item
1323 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1324 *
1325 * $key is a string, usually a key from the list you are generating this link from
1326 * $item is an array containing some of a specific set of keys.
1327 * The text of the link will be generated either from the contents of the "text"
1328 * key in the $item array, if a "msg" key is present a message by that name will
1329 * be used, and if neither of those are set the $key will be used as a message name.
1330 * If a "href" key is not present makeLink will just output htmlescaped text.
1331 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1332 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1333 * is present it will be used to generate a tooltip and accesskey for the link.
1334 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1335 */
1336 function makeLink( $key, $item ) {
1337 if ( isset( $item['text'] ) ) {
1338 $text = $item['text'];
1339 } else {
1340 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1341 }
1342
1343 if ( !isset( $item['href'] ) ) {
1344 return htmlspecialchars( $text );
1345 }
1346
1347 $attrs = array();
1348 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1349 if ( isset( $item[$attr] ) ) {
1350 $attrs[$attr] = $item[$attr];
1351 }
1352 }
1353
1354 if ( isset( $item['id'] ) ) {
1355 $item['single-id'] = $item['id'];
1356 }
1357 if ( isset( $item['single-id'] ) ) {
1358 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1359 $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] );
1360 if ( $attrs['title'] === false ) {
1361 unset( $attrs['title'] );
1362 }
1363 } else {
1364 $attrs = array_merge(
1365 $attrs,
1366 $this->skin->tooltipAndAccesskeyAttribs( $item['single-id'] )
1367 );
1368 }
1369 }
1370
1371 return Html::element( 'a', $attrs, $text );
1372 }
1373
1374 /**
1375 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1376 * $key is a string, usually a key from the list you are generating this link from
1377 * $item is an array of list item data containing some of a specific set of keys.
1378 * The "id" and "class" keys will be used as attributes for the list item,
1379 * if "active" contains a value of true a "active" class will also be appended to class.
1380 * If you want something other than a <li> you can pass a tag name such as
1381 * "tag" => "span" in the $options array to change the tag used.
1382 * link/content data for the list item may come in one of two forms
1383 * A "links" key may be used, in which case it should contain an array with
1384 * a list of links to include inside the list item, see makeLink for the format
1385 * of individual links array items.
1386 * Otherwise the relevant keys from the list item $item array will be passed
1387 * to makeLink instead. Note however that "id" and "class" are used by the
1388 * list item directly so they will not be passed to makeLink
1389 * (however the link will still support a tooltip and accesskey from it)
1390 * If you need an id or class on a single link you should include a "links"
1391 * array with just one link item inside of it.
1392 */
1393 function makeListItem( $key, $item, $options = array() ) {
1394 if ( isset( $item['links'] ) ) {
1395 $html = '';
1396 foreach ( $item['links'] as $linkKey => $link ) {
1397 $html .= $this->makeLink( $linkKey, $link );
1398 }
1399 } else {
1400 $link = array();
1401 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1402 if ( isset( $item[$k] ) ) {
1403 $link[$k] = $item[$k];
1404 }
1405 }
1406 if ( isset( $item['id'] ) ) {
1407 // The id goes on the <li> not on the <a> for single links
1408 // but makeSidebarLink still needs to know what id to use when
1409 // generating tooltips and accesskeys.
1410 $link['single-id'] = $item['id'];
1411 }
1412 $html = $this->makeLink( $key, $link );
1413 }
1414
1415 $attrs = array();
1416 foreach ( array( 'id', 'class' ) as $attr ) {
1417 if ( isset( $item[$attr] ) ) {
1418 $attrs[$attr] = $item[$attr];
1419 }
1420 }
1421 if ( isset( $item['active'] ) && $item['active'] ) {
1422 if ( !isset( $attrs['class'] ) ) {
1423 $attrs['class'] = '';
1424 }
1425 $attrs['class'] .= ' active';
1426 $attrs['class'] = trim( $attrs['class'] );
1427 }
1428 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1429 }
1430
1431 function makeSearchInput( $attrs = array() ) {
1432 $realAttrs = array(
1433 'type' => 'search',
1434 'name' => 'search',
1435 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1436 );
1437 $realAttrs = array_merge( $realAttrs, $this->skin->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1438 return Html::element( 'input', $realAttrs );
1439 }
1440
1441 function makeSearchButton( $mode, $attrs = array() ) {
1442 switch( $mode ) {
1443 case 'go':
1444 case 'fulltext':
1445 $realAttrs = array(
1446 'type' => 'submit',
1447 'name' => $mode,
1448 'value' => $this->translator->translate( $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1449 );
1450 $realAttrs = array_merge(
1451 $realAttrs,
1452 $this->skin->tooltipAndAccesskeyAttribs( "search-$mode" ),
1453 $attrs
1454 );
1455 return Html::element( 'input', $realAttrs );
1456 case 'image':
1457 $buttonAttrs = array(
1458 'type' => 'submit',
1459 'name' => 'button',
1460 );
1461 $buttonAttrs = array_merge(
1462 $buttonAttrs,
1463 $this->skin->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1464 $attrs
1465 );
1466 unset( $buttonAttrs['src'] );
1467 unset( $buttonAttrs['alt'] );
1468 $imgAttrs = array(
1469 'src' => $attrs['src'],
1470 'alt' => isset( $attrs['alt'] ) ? $attrs['alt'] : $this->translator->translate( 'searchbutton' ),
1471 );
1472 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1473 default:
1474 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1475 }
1476 }
1477
1478 /**
1479 * Returns an array of footerlinks trimmed down to only those footer links that
1480 * are valid.
1481 * If you pass "flat" as an option then the returned array will be a flat array
1482 * of footer icons instead of a key/value array of footerlinks arrays broken
1483 * up into categories.
1484 */
1485 function getFooterLinks( $option = null ) {
1486 $footerlinks = $this->data['footerlinks'];
1487
1488 // Reduce footer links down to only those which are being used
1489 $validFooterLinks = array();
1490 foreach( $footerlinks as $category => $links ) {
1491 $validFooterLinks[$category] = array();
1492 foreach( $links as $link ) {
1493 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1494 $validFooterLinks[$category][] = $link;
1495 }
1496 }
1497 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1498 unset( $validFooterLinks[$category] );
1499 }
1500 }
1501
1502 if ( $option == 'flat' ) {
1503 // fold footerlinks into a single array using a bit of trickery
1504 $validFooterLinks = call_user_func_array(
1505 'array_merge',
1506 array_values( $validFooterLinks )
1507 );
1508 }
1509
1510 return $validFooterLinks;
1511 }
1512
1513 /**
1514 * Returns an array of footer icons filtered down by options relevant to how
1515 * the skin wishes to display them.
1516 * If you pass "icononly" as the option all footer icons which do not have an
1517 * image icon set will be filtered out.
1518 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1519 * in the list of footer icons. This is mostly useful for skins which only
1520 * display the text from footericons instead of the images and don't want a
1521 * duplicate copyright statement because footerlinks already rendered one.
1522 */
1523 function getFooterIcons( $option = null ) {
1524 // Generate additional footer icons
1525 $footericons = $this->data['footericons'];
1526
1527 if ( $option == 'icononly' ) {
1528 // Unset any icons which don't have an image
1529 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1530 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1531 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1532 unset( $footerIconsBlock[$footerIconKey] );
1533 }
1534 }
1535 }
1536 // Redo removal of any empty blocks
1537 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1538 if ( count( $footerIconsBlock ) <= 0 ) {
1539 unset( $footericons[$footerIconsKey] );
1540 }
1541 }
1542 } elseif ( $option == 'nocopyright' ) {
1543 $footericons = $this->data['footericons'];
1544 unset( $footericons['copyright']['copyright'] );
1545 if ( count( $footericons['copyright'] ) <= 0 ) {
1546 unset( $footericons['copyright'] );
1547 }
1548 }
1549
1550 return $footericons;
1551 }
1552
1553
1554 }
1555