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