trim trailing whitespace
[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() and ( !isset( $oldid ) or isset( $diff ) ) and
348 $wgArticle and 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 * build array of urls for personal toolbar
545 * @return array
546 * @private
547 */
548 function buildPersonalUrls() {
549 global $wgOut, $wgRequest;
550
551 $title = $wgOut->getTitle();
552 $pageurl = $title->getLocalURL();
553 wfProfileIn( __METHOD__ );
554
555 /* set up the default links for the personal toolbar */
556 $personal_urls = array();
557 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
558 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
559 $returnto = "returnto=$page";
560 if( $this->thisquery != '' ) {
561 $returnto .= "&returntoquery=$query";
562 }
563 if( $this->loggedin ) {
564 $personal_urls['userpage'] = array(
565 'text' => $this->username,
566 'href' => &$this->userpageUrlDetails['href'],
567 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
568 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
569 );
570 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
571 $personal_urls['mytalk'] = array(
572 'text' => wfMsg( 'mytalk' ),
573 'href' => &$usertalkUrlDetails['href'],
574 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
575 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
576 );
577 $href = self::makeSpecialUrl( 'Preferences' );
578 $personal_urls['preferences'] = array(
579 'text' => wfMsg( 'mypreferences' ),
580 'href' => $href,
581 'active' => ( $href == $pageurl )
582 );
583 $href = self::makeSpecialUrl( 'Watchlist' );
584 $personal_urls['watchlist'] = array(
585 'text' => wfMsg( 'mywatchlist' ),
586 'href' => $href,
587 'active' => ( $href == $pageurl )
588 );
589
590 # We need to do an explicit check for Special:Contributions, as we
591 # have to match both the title, and the target (which could come
592 # from request values or be specified in "sub page" form. The plot
593 # thickens, because $wgTitle is altered for special pages, so doesn't
594 # contain the original alias-with-subpage.
595 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
596 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
597 list( $spName, $spPar ) =
598 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
599 $active = $spName == 'Contributions'
600 && ( ( $spPar && $spPar == $this->username )
601 || $wgRequest->getText( 'target' ) == $this->username );
602 } else {
603 $active = false;
604 }
605
606 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
607 $personal_urls['mycontris'] = array(
608 'text' => wfMsg( 'mycontris' ),
609 'href' => $href,
610 'active' => $active
611 );
612 $personal_urls['logout'] = array(
613 'text' => wfMsg( 'userlogout' ),
614 'href' => self::makeSpecialUrl( 'Userlogout',
615 $title->isSpecial( 'Preferences' ) ? '' : $returnto
616 ),
617 'active' => false
618 );
619 } else {
620 global $wgUser;
621 $loginlink = $wgUser->isAllowed( 'createaccount' )
622 ? 'nav-login-createaccount'
623 : 'login';
624
625 # anonlogin & login are the same
626 $login_url = array(
627 'text' => wfMsg( $loginlink ),
628 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
629 'active' => $title->isSpecial( 'Userlogin' )
630 );
631 global $wgProto, $wgSecureLogin;
632 if( $wgProto === 'http' && $wgSecureLogin ) {
633 $title = SpecialPage::getTitleFor( 'Userlogin' );
634 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
635 $login_url['href'] = $https_url;
636 $login_url['class'] = 'link-https'; # FIXME class depends on skin
637 }
638
639 if( $this->showIPinHeader() ) {
640 $href = &$this->userpageUrlDetails['href'];
641 $personal_urls['anonuserpage'] = array(
642 'text' => $this->username,
643 'href' => $href,
644 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
645 'active' => ( $pageurl == $href )
646 );
647 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
648 $href = &$usertalkUrlDetails['href'];
649 $personal_urls['anontalk'] = array(
650 'text' => wfMsg( 'anontalk' ),
651 'href' => $href,
652 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
653 'active' => ( $pageurl == $href )
654 );
655 $personal_urls['anonlogin'] = $login_url;
656 } else {
657 $personal_urls['login'] = $login_url;
658 }
659 }
660
661 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
662 wfProfileOut( __METHOD__ );
663 return $personal_urls;
664 }
665
666 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
667 $classes = array();
668 if( $selected ) {
669 $classes[] = 'selected';
670 }
671 if( $checkEdit && !$title->isKnown() ) {
672 $classes[] = 'new';
673 $query = 'action=edit&redlink=1';
674 }
675
676 $text = wfMsg( $message );
677 if ( wfEmptyMsg( $message, $text ) ) {
678 global $wgContLang;
679 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
680 }
681
682 $result = array();
683 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
684 $title, $message, $selected, $checkEdit,
685 &$classes, &$query, &$text, &$result ) ) ) {
686 return $result;
687 }
688
689 return array(
690 'class' => implode( ' ', $classes ),
691 'text' => $text,
692 'href' => $title->getLocalUrl( $query ) );
693 }
694
695 function makeTalkUrlDetails( $name, $urlaction = '' ) {
696 $title = Title::newFromText( $name );
697 if( !is_object( $title ) ) {
698 throw new MWException( __METHOD__ . " given invalid pagename $name" );
699 }
700 $title = $title->getTalkPage();
701 self::checkTitle( $title, $name );
702 return array(
703 'href' => $title->getLocalURL( $urlaction ),
704 'exists' => $title->getArticleID() != 0,
705 );
706 }
707
708 function makeArticleUrlDetails( $name, $urlaction = '' ) {
709 $title = Title::newFromText( $name );
710 $title= $title->getSubjectPage();
711 self::checkTitle( $title, $name );
712 return array(
713 'href' => $title->getLocalURL( $urlaction ),
714 'exists' => $title->getArticleID() != 0,
715 );
716 }
717
718 /**
719 * an array of edit links by default used for the tabs
720 * @return array
721 * @private
722 */
723 function buildContentActionUrls() {
724 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
725
726 wfProfileIn( __METHOD__ );
727
728 $action = $wgRequest->getVal( 'action', 'view' );
729 $section = $wgRequest->getVal( 'section' );
730 $content_actions = array();
731
732 $prevent_active_tabs = false;
733 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
734
735 if( $this->iscontent ) {
736 $subjpage = $this->mTitle->getSubjectPage();
737 $talkpage = $this->mTitle->getTalkPage();
738
739 $nskey = $this->mTitle->getNamespaceKey();
740 $content_actions[$nskey] = $this->tabAction(
741 $subjpage,
742 $nskey,
743 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
744 '', true
745 );
746
747 $content_actions['talk'] = $this->tabAction(
748 $talkpage,
749 'talk',
750 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
751 '',
752 true
753 );
754
755 wfProfileIn( __METHOD__ . '-edit' );
756 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
757 $istalk = $this->mTitle->isTalkPage();
758 $istalkclass = $istalk?' istalk':'';
759 $content_actions['edit'] = array(
760 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
761 'text' => ( $this->mTitle->exists() || ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !wfEmptyMsg( $this->mTitle->getText() ) ) )
762 ? wfMsg( 'edit' )
763 : wfMsg( 'create' ),
764 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
765 );
766
767 // adds new section link if page is a current revision of a talk page or
768 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
769 if ( !$wgOut->forceHideNewSectionLink() ) {
770 $content_actions['addsection'] = array(
771 'class' => $section == 'new' ? 'selected' : false,
772 'text' => wfMsg( 'addsection' ),
773 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
774 );
775 }
776 }
777 } elseif ( $this->mTitle->hasSourceText() ) {
778 $content_actions['viewsource'] = array(
779 'class' => ($action == 'edit') ? 'selected' : false,
780 'text' => wfMsg( 'viewsource' ),
781 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
782 );
783 }
784 wfProfileOut( __METHOD__ . '-edit' );
785
786 wfProfileIn( __METHOD__ . '-live' );
787 if ( $this->mTitle->exists() ) {
788
789 $content_actions['history'] = array(
790 'class' => ($action == 'history') ? 'selected' : false,
791 'text' => wfMsg( 'history_short' ),
792 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
793 'rel' => 'archives',
794 );
795
796 if( $wgUser->isAllowed( 'delete' ) ) {
797 $content_actions['delete'] = array(
798 'class' => ($action == 'delete') ? 'selected' : false,
799 'text' => wfMsg( 'delete' ),
800 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
801 );
802 }
803 if ( $this->mTitle->quickUserCan( 'move' ) ) {
804 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
805 $content_actions['move'] = array(
806 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
807 'text' => wfMsg( 'move' ),
808 'href' => $moveTitle->getLocalUrl()
809 );
810 }
811
812 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
813 if( !$this->mTitle->isProtected() ){
814 $content_actions['protect'] = array(
815 'class' => ($action == 'protect') ? 'selected' : false,
816 'text' => wfMsg( 'protect' ),
817 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
818 );
819
820 } else {
821 $content_actions['unprotect'] = array(
822 'class' => ($action == 'unprotect') ? 'selected' : false,
823 'text' => wfMsg( 'unprotect' ),
824 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
825 );
826 }
827 }
828 } else {
829 //article doesn't exist or is deleted
830 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
831 $n = $this->mTitle->isDeleted();
832 if( $n ) {
833 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
834 $content_actions['undelete'] = array(
835 'class' => false,
836 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
837 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
838 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
839 );
840 }
841 }
842
843 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
844 if( !$this->mTitle->getRestrictions( 'create' ) ) {
845 $content_actions['protect'] = array(
846 'class' => ($action == 'protect') ? 'selected' : false,
847 'text' => wfMsg( 'protect' ),
848 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
849 );
850
851 } else {
852 $content_actions['unprotect'] = array(
853 'class' => ($action == 'unprotect') ? 'selected' : false,
854 'text' => wfMsg( 'unprotect' ),
855 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
856 );
857 }
858 }
859 }
860
861 wfProfileOut( __METHOD__ . '-live' );
862
863 if( $this->loggedin ) {
864 if( !$this->mTitle->userIsWatching()) {
865 $content_actions['watch'] = array(
866 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
867 'text' => wfMsg( 'watch' ),
868 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
869 );
870 } else {
871 $content_actions['unwatch'] = array(
872 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
873 'text' => wfMsg( 'unwatch' ),
874 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
875 );
876 }
877 }
878
879
880 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
881 } else {
882 /* show special page tab */
883
884 $content_actions[$this->mTitle->getNamespaceKey()] = array(
885 'class' => 'selected',
886 'text' => wfMsg('nstab-special'),
887 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
888 );
889
890 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
891 }
892
893 /* show links to different language variants */
894 global $wgDisableLangConversion;
895 $variants = $wgContLang->getVariants();
896 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
897 $preferred = $wgContLang->getPreferredVariant();
898 $vcount=0;
899 foreach( $variants as $code ) {
900 $varname = $wgContLang->getVariantname( $code );
901 if( $varname == 'disable' )
902 continue;
903 $selected = ( $code == $preferred )? 'selected' : false;
904 $content_actions['varlang-' . $vcount] = array(
905 'class' => $selected,
906 'text' => $varname,
907 'href' => $this->mTitle->getLocalURL( '', $code )
908 );
909 $vcount ++;
910 }
911 }
912
913 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
914
915 wfProfileOut( __METHOD__ );
916 return $content_actions;
917 }
918
919 /**
920 * build array of common navigation links
921 * @return array
922 * @private
923 */
924 function buildNavUrls() {
925 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
926 global $wgUploadNavigationUrl;
927
928 wfProfileIn( __METHOD__ );
929
930 $action = $wgRequest->getVal( 'action', 'view' );
931
932 $nav_urls = array();
933 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
934 if( $wgUploadNavigationUrl ) {
935 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
936 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
937 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
938 } else {
939 $nav_urls['upload'] = false;
940 }
941 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
942
943 // default permalink to being off, will override it as required below.
944 $nav_urls['permalink'] = false;
945
946 // A print stylesheet is attached to all pages, but nobody ever
947 // figures that out. :) Add a link...
948 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
949 if ( !$wgOut->isPrintable() ) {
950 $nav_urls['print'] = array(
951 'text' => wfMsg( 'printableversion' ),
952 'href' => $wgRequest->appendQuery( 'printable=yes' )
953 );
954 }
955
956 // Also add a "permalink" while we're at it
957 if ( $this->mRevisionId ) {
958 $nav_urls['permalink'] = array(
959 'text' => wfMsg( 'permalink' ),
960 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
961 );
962 }
963
964 // Copy in case this undocumented, shady hook tries to mess with internals
965 $revid = $this->mRevisionId;
966 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
967 }
968
969 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
970 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
971 $nav_urls['whatlinkshere'] = array(
972 'href' => $wlhTitle->getLocalUrl()
973 );
974 if( $this->mTitle->getArticleId() ) {
975 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
976 $nav_urls['recentchangeslinked'] = array(
977 'href' => $rclTitle->getLocalUrl()
978 );
979 } else {
980 $nav_urls['recentchangeslinked'] = false;
981 }
982 if( $wgUseTrackbacks )
983 $nav_urls['trackbacklink'] = array(
984 'href' => $wgOut->getTitle()->trackbackURL()
985 );
986 }
987
988 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
989 $rootUser = strtok( $this->mTitle->getText(), '/' );
990 $id = User::idFromName( $rootUser );
991 $ip = User::isIP( $rootUser );
992 } else {
993 $id = 0;
994 $ip = false;
995 }
996
997 if( $id || $ip ) { # both anons and non-anons have contribs list
998 $nav_urls['contributions'] = array(
999 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1000 );
1001
1002 if( $id ) {
1003 $logPage = SpecialPage::getTitleFor( 'Log' );
1004 $nav_urls['log'] = array(
1005 'href' => $logPage->getLocalUrl(
1006 array(
1007 'user' => $rootUser
1008 )
1009 )
1010 );
1011 } else {
1012 $nav_urls['log'] = false;
1013 }
1014
1015 if ( $wgUser->isAllowed( 'block' ) ) {
1016 $nav_urls['blockip'] = array(
1017 'href' => self::makeSpecialUrlSubpage( 'Blockip', $rootUser )
1018 );
1019 } else {
1020 $nav_urls['blockip'] = false;
1021 }
1022 } else {
1023 $nav_urls['contributions'] = false;
1024 $nav_urls['log'] = false;
1025 $nav_urls['blockip'] = false;
1026 }
1027 $nav_urls['emailuser'] = false;
1028 if( $this->showEmailUser( $id ) ) {
1029 $nav_urls['emailuser'] = array(
1030 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1031 );
1032 }
1033 wfProfileOut( __METHOD__ );
1034 return $nav_urls;
1035 }
1036
1037 /**
1038 * Generate strings used for xml 'id' names
1039 * @return string
1040 * @private
1041 */
1042 function getNameSpaceKey() {
1043 return $this->mTitle->getNamespaceKey();
1044 }
1045
1046 /**
1047 * @private
1048 */
1049 function setupUserJs( $allowUserJs ) {
1050 global $wgRequest, $wgJsMimeType;
1051 wfProfileIn( __METHOD__ );
1052
1053 $action = $wgRequest->getVal( 'action', 'view' );
1054
1055 if( $allowUserJs && $this->loggedin ) {
1056 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1057 # XXX: additional security check/prompt?
1058 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1059 } else {
1060 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1061 }
1062 }
1063 wfProfileOut( __METHOD__ );
1064 }
1065
1066 /**
1067 * Code for extensions to hook into to provide per-page CSS, see
1068 * extensions/PageCSS/PageCSS.php for an implementation of this.
1069 *
1070 * @private
1071 */
1072 function setupPageCss() {
1073 wfProfileIn( __METHOD__ );
1074 $out = false;
1075 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1076 wfProfileOut( __METHOD__ );
1077 return $out;
1078 }
1079
1080 public function commonPrintStylesheet() {
1081 return false;
1082 }
1083 }
1084
1085 /**
1086 * Generic wrapper for template functions, with interface
1087 * compatible with what we use of PHPTAL 0.7.
1088 * @ingroup Skins
1089 */
1090 abstract class QuickTemplate {
1091 /**
1092 * Constructor
1093 */
1094 public function QuickTemplate() {
1095 $this->data = array();
1096 $this->translator = new MediaWiki_I18N();
1097 }
1098
1099 /**
1100 * Sets the value $value to $name
1101 * @param $name
1102 * @param $value
1103 */
1104 public function set( $name, $value ) {
1105 $this->data[$name] = $value;
1106 }
1107
1108 /**
1109 * @param $name
1110 * @param $value
1111 */
1112 public function setRef( $name, &$value ) {
1113 $this->data[$name] =& $value;
1114 }
1115
1116 /**
1117 * @param $t
1118 */
1119 public function setTranslator( &$t ) {
1120 $this->translator = &$t;
1121 }
1122
1123 /**
1124 * Main function, used by classes that subclass QuickTemplate
1125 * to show the actual HTML output
1126 */
1127 abstract public function execute();
1128
1129 /**
1130 * @private
1131 */
1132 function text( $str ) {
1133 echo htmlspecialchars( $this->data[$str] );
1134 }
1135
1136 /**
1137 * @private
1138 */
1139 function jstext( $str ) {
1140 echo Xml::escapeJsString( $this->data[$str] );
1141 }
1142
1143 /**
1144 * @private
1145 */
1146 function html( $str ) {
1147 echo $this->data[$str];
1148 }
1149
1150 /**
1151 * @private
1152 */
1153 function msg( $str ) {
1154 echo htmlspecialchars( $this->translator->translate( $str ) );
1155 }
1156
1157 /**
1158 * @private
1159 */
1160 function msgHtml( $str ) {
1161 echo $this->translator->translate( $str );
1162 }
1163
1164 /**
1165 * An ugly, ugly hack.
1166 * @private
1167 */
1168 function msgWiki( $str ) {
1169 global $wgParser, $wgOut;
1170
1171 $text = $this->translator->translate( $str );
1172 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1173 $wgOut->parserOptions(), true );
1174 echo $parserOutput->getText();
1175 }
1176
1177 /**
1178 * @private
1179 */
1180 function haveData( $str ) {
1181 return isset( $this->data[$str] );
1182 }
1183
1184 /**
1185 * @private
1186 */
1187 function haveMsg( $str ) {
1188 $msg = $this->translator->translate( $str );
1189 return ( $msg != '-' ) && ( $msg != '' ); # ????
1190 }
1191 }
1192
1193 /**
1194 * New base template for a skin's template extended from QuickTemplate
1195 * this class features helper methods that provide common ways of interacting
1196 * with the data stored in the QuickTemplate
1197 */
1198 abstract class BaseTemplate extends QuickTemplate {
1199
1200 /**
1201 * Create an array of common toolbox items from the data in the quicktemplate
1202 * stored by SkinTemplate.
1203 * The resulting array is built acording to a format intended to be passed
1204 * through makeListItem to generate the html.
1205 */
1206 function getToolbox() {
1207 wfProfileIn( __METHOD__ );
1208
1209 $toolbox = array();
1210 if ( $this->data['notspecialpage'] ) {
1211 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1212 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1213 if ( $this->data['nav_urls']['recentchangeslinked'] ) {
1214 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1215 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1216 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1217 }
1218 }
1219 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) {
1220 $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink'];
1221 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1222 }
1223 if ( $this->data['feeds'] ) {
1224 $toolbox['feeds']['id'] = 'feedlinks';
1225 $toolbox['feeds']['links'] = array();
1226 foreach ( $this->data['feeds'] as $key => $feed ) {
1227 $toolbox['feeds']['links'][$key] = $feed;
1228 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1229 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1230 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1231 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1232 }
1233 }
1234 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1235 if ( $this->data['nav_urls'][$special] ) {
1236 $toolbox[$special] = $this->data['nav_urls'][$special];
1237 $toolbox[$special]['id'] = "t-$special";
1238 }
1239 }
1240 if ( !empty( $this->data['nav_urls']['print']['href'] ) ) {
1241 $toolbox['print'] = $this->data['nav_urls']['print'];
1242 $toolbox['print']['rel'] = 'alternate';
1243 $toolbox['print']['msg'] = 'printableversion';
1244 }
1245 if ( !empty( $this->data['nav_urls']['permalink']['href'] ) ) {
1246 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1247 $toolbox['permalink']['id'] = 't-permalink';
1248 } elseif ( $this->data['nav_urls']['permalink']['href'] === '' ) {
1249 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1250 unset( $toolbox['permalink']['href'] );
1251 $toolbox['ispermalink']['tooltiponly'] = true;
1252 $toolbox['ispermalink']['id'] = 't-ispermalink';
1253 $toolbox['ispermalink']['msg'] = 'permalink';
1254 }
1255 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1256 wfProfileOut( __METHOD__ );
1257 return $toolbox;
1258 }
1259
1260 /**
1261 * Makes a link, usually used by makeListItem to generate a link for an item
1262 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1263 *
1264 * $key is a string, usually a key from the list you are generating this link from
1265 * $item is an array containing some of a specific set of keys.
1266 * The text of the link will be generated either from the contents of the "text"
1267 * key in the $item array, if a "msg" key is present a message by that name will
1268 * be used, and if neither of those are set the $key will be used as a message name.
1269 * If a "href" key is not present makeLink will just output htmlescaped text.
1270 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1271 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1272 * is present it will be used to generate a tooltip and accesskey for the link.
1273 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1274 */
1275 function makeLink( $key, $item ) {
1276 if ( isset( $item['text'] ) ) {
1277 $text = $item['text'];
1278 } else {
1279 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1280 }
1281
1282 if ( !isset( $item['href'] ) ) {
1283 return htmlspecialchars( $text );
1284 }
1285
1286 $attrs = array();
1287 foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
1288 if ( isset( $item[$attr] ) ) {
1289 $attrs[$attr] = $item[$attr];
1290 }
1291 }
1292
1293 if ( isset( $item['id'] ) ) {
1294 $item['single-id'] = $item['id'];
1295 }
1296 if ( isset( $item['single-id'] ) ) {
1297 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1298 $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] );
1299 if ( $attrs['title'] === false ) {
1300 unset( $attrs['title'] );
1301 }
1302 } else {
1303 $attrs = array_merge(
1304 $attrs,
1305 $this->skin->tooltipAndAccesskeyAttribs( $item['single-id'] )
1306 );
1307 }
1308 }
1309
1310 return Html::element( 'a', $attrs, $text );
1311 }
1312
1313 /**
1314 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1315 * $key is a string, usually a key from the list you are generating this link from
1316 * $item is an array of list item data containing some of a specific set of keys.
1317 * The "id" and "class" keys will be used as attributes for the list item,
1318 * if "active" contains a value of true a "active" class will also be appended to class.
1319 * If you want something other than a <li> you can pass a tag name such as
1320 * "tag" => "span" in the $options array to change the tag used.
1321 * link/content data for the list item may come in one of two forms
1322 * A "links" key may be used, in which case it should contain an array with
1323 * a list of links to include inside the list item, see makeLink for the format
1324 * of individual links array items.
1325 * Otherwise the relevant keys from the list item $item array will be passed
1326 * to makeLink instead. Note however that "id" and "class" are used by the
1327 * list item directly so they will not be passed to makeLink
1328 * (however the link will still support a tooltip and accesskey from it)
1329 * If you need an id or class on a single link you should include a "links"
1330 * array with just one link item inside of it.
1331 */
1332 function makeListItem( $key, $item, $options = array() ) {
1333 if ( isset( $item['links'] ) ) {
1334 $html = '';
1335 foreach ( $item['links'] as $linkKey => $link ) {
1336 $html .= $this->makeLink( $linkKey, $link );
1337 }
1338 } else {
1339 $link = array();
1340 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
1341 if ( isset( $item[$k] ) ) {
1342 $link[$k] = $item[$k];
1343 }
1344 }
1345 if ( isset( $item['id'] ) ) {
1346 // The id goes on the <li> not on the <a> for single links
1347 // but makeSidebarLink still needs to know what id to use when
1348 // generating tooltips and accesskeys.
1349 $link['single-id'] = $item['id'];
1350 }
1351 $html = $this->makeLink( $key, $link );
1352 }
1353
1354 $attrs = array();
1355 foreach ( array( 'id', 'class' ) as $attr ) {
1356 if ( isset( $item[$attr] ) ) {
1357 $attrs[$attr] = $item[$attr];
1358 }
1359 }
1360 if ( isset( $item['active'] ) && $item['active'] ) {
1361 $attrs['class'] .= ' active';
1362 $attrs['class'] = trim( $attrs['class'] );
1363 }
1364 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1365 }
1366
1367 function makeSearchInput( $attrs = array() ) {
1368 $realAttrs = array(
1369 'type' => 'search',
1370 'name' => 'search',
1371 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1372 );
1373 $realAttrs = array_merge( $realAttrs, $this->skin->tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1374 return Html::element( 'input', $realAttrs );
1375 }
1376
1377 function makeSearchButton( $mode, $attrs = array() ) {
1378 switch( $mode ) {
1379 case 'go':
1380 case 'fulltext':
1381 $realAttrs = array(
1382 'type' => 'submit',
1383 'name' => $mode,
1384 'value' => $this->translator->translate( $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1385 );
1386 $realAttrs = array_merge(
1387 $realAttrs,
1388 $this->skin->tooltipAndAccesskeyAttribs( "search-$mode" ),
1389 $attrs
1390 );
1391 return Html::element( 'input', $realAttrs );
1392 case 'image':
1393 $buttonAttrs = array(
1394 'type' => 'submit',
1395 'name' => 'button',
1396 );
1397 $buttonAttrs = array_merge(
1398 $buttonAttrs,
1399 $this->skin->tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1400 $attrs
1401 );
1402 unset( $buttonAttrs['src'] );
1403 unset( $buttonAttrs['alt'] );
1404 $imgAttrs = array(
1405 'src' => $attrs['src'],
1406 'alt' => isset( $attrs['alt'] ) ? $attrs['alt'] : $this->translator->translate( 'searchbutton' ),
1407 );
1408 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1409 default:
1410 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1411 }
1412 }
1413
1414 /**
1415 * Returns an array of footerlinks trimmed down to only those footer links that
1416 * are valid.
1417 * If you pass "flat" as an option then the returned array will be a flat array
1418 * of footer icons instead of a key/value array of footerlinks arrays broken
1419 * up into categories.
1420 */
1421 function getFooterLinks( $option = null ) {
1422 $footerlinks = $this->data['footerlinks'];
1423
1424 // Reduce footer links down to only those which are being used
1425 $validFooterLinks = array();
1426 foreach( $footerlinks as $category => $links ) {
1427 $validFooterLinks[$category] = array();
1428 foreach( $links as $link ) {
1429 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1430 $validFooterLinks[$category][] = $link;
1431 }
1432 }
1433 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1434 unset( $validFooterLinks[$category] );
1435 }
1436 }
1437
1438 if ( $option == 'flat' ) {
1439 // fold footerlinks into a single array using a bit of trickery
1440 $validFooterLinks = call_user_func_array(
1441 'array_merge',
1442 array_values( $validFooterLinks )
1443 );
1444 }
1445
1446 return $validFooterLinks;
1447 }
1448
1449 /**
1450 * Returns an array of footer icons filtered down by options relevant to how
1451 * the skin wishes to display them.
1452 * If you pass "icononly" as the option all footer icons which do not have an
1453 * image icon set will be filtered out.
1454 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1455 * in the list of footer icons. This is mostly useful for skins which only
1456 * display the text from footericons instead of the images and don't want a
1457 * duplicate copyright statement because footerlinks already rendered one.
1458 */
1459 function getFooterIcons( $option = null ) {
1460 // Generate additional footer icons
1461 $footericons = $this->data['footericons'];
1462
1463 if ( $option == 'icononly' ) {
1464 // Unset any icons which don't have an image
1465 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1466 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1467 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1468 unset( $footerIconsBlock[$footerIconKey] );
1469 }
1470 }
1471 }
1472 // Redo removal of any empty blocks
1473 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1474 if ( count( $footerIconsBlock ) <= 0 ) {
1475 unset( $footericons[$footerIconsKey] );
1476 }
1477 }
1478 } elseif ( $option == 'nocopyright' ) {
1479 $footericons = $this->data['footericons'];
1480 unset( $footericons['copyright']['copyright'] );
1481 if ( count( $footericons['copyright'] ) <= 0 ) {
1482 unset( $footericons['copyright'] );
1483 }
1484 }
1485
1486 return $footericons;
1487 }
1488
1489
1490 }
1491