Cleanup for r39054 "Bug 15079, 'Add class="ns-talk" / "ns-subject" to <body>', also...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
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 /**
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
23 *
24 * @private
25 * @ingroup Skins
26 */
27 class MediaWiki_I18N {
28 var $_context = array();
29
30 function set($varName, $value) {
31 $this->_context[$varName] = $value;
32 }
33
34 function translate($value) {
35 wfProfileIn( __METHOD__ );
36
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
39
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace($src, $varValue, $value);
49 }
50 wfProfileOut( __METHOD__ );
51 return $value;
52 }
53 }
54
55 /**
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
60 *
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
64 *
65 * @ingroup Skins
66 */
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
70 */
71
72 /**
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
75 */
76 var $skinname;
77
78 /**
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
81 */
82 var $stylename;
83
84 /**
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
87 */
88 var $template;
89
90 /**
91 * An array of stylesheet filenames (relative from skins path), with options
92 * for CSS media, IE conditions, and RTL/LTR direction.
93 * For internal use; add settings in the skin via $this->addStyle()
94 */
95 var $styles = array();
96
97 /**#@-*/
98
99 /**
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
103 *
104 * @param OutputPage $out
105 */
106 function initPage( &$out ) {
107 parent::initPage( $out );
108 $this->skinname = 'monobook';
109 $this->stylename = 'monobook';
110 $this->template = 'QuickTemplate';
111
112 $this->addStyle( 'common/shared.css', 'screen' );
113 $this->addStyle( 'common/commonPrint.css', 'print' );
114 }
115
116 /**
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
120 *
121 * @param string $callback (or file)
122 * @param string $repository subdirectory where we keep template files
123 * @param string $cache_dir
124 * @return object
125 * @private
126 */
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
129 }
130
131 /**
132 * initialize various variables and generate the template
133 *
134 * @param OutputPage $out
135 * @public
136 */
137 function outputPage( &$out ) {
138 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
139 global $wgScript, $wgStylePath, $wgContLanguageCode;
140 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
141 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
142 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
143 global $wgMaxCredits, $wgShowCreditsIfMax;
144 global $wgPageShowWatchingUsers;
145 global $wgUseTrackbacks, $wgUseSiteJs;
146 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
147
148 wfProfileIn( __METHOD__ );
149
150 $oldid = $wgRequest->getVal( 'oldid' );
151 $diff = $wgRequest->getVal( 'diff' );
152
153 wfProfileIn( __METHOD__."-init" );
154 $this->initPage( $out );
155
156 $this->mTitle =& $wgTitle;
157 $this->mUser =& $wgUser;
158
159 $tpl = $this->setupTemplate( $this->template, 'skins' );
160
161 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
162 $tpl->setTranslator(new MediaWiki_I18N());
163 #}
164 wfProfileOut( __METHOD__."-init" );
165
166 wfProfileIn( __METHOD__."-stuff" );
167 $this->thispage = $this->mTitle->getPrefixedDbKey();
168 $this->thisurl = $this->mTitle->getPrefixedURL();
169 $this->loggedin = $wgUser->isLoggedIn();
170 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
171 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
172 $this->username = $wgUser->getName();
173 $userPage = $wgUser->getUserPage();
174 $this->userpage = $userPage->getPrefixedText();
175
176 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
177 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
178 } else {
179 # This won't be used in the standard skins, but we define it to preserve the interface
180 # To save time, we check for existence
181 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
182 }
183
184 $this->usercss = $this->userjs = $this->userjsprev = false;
185 $this->setupUserCss( $out->getExtStyle() );
186 $this->setupUserJs( $out->isUserJsAllowed() );
187 $this->titletxt = $this->mTitle->getPrefixedText();
188 wfProfileOut( __METHOD__."-stuff" );
189
190 wfProfileIn( __METHOD__."-stuff2" );
191 $tpl->set( 'title', $wgOut->getPageTitle() );
192 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
193 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
194 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
195 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
196
197 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
198 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
199 $this->mTitle->getNsText();
200
201 $tpl->set( 'nscanonical', $nsname );
202 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
203 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
204 $tpl->set( 'titletext', $this->mTitle->getText() );
205 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
206 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
207
208 $tpl->set( 'isarticle', $wgOut->isArticle() );
209
210 $tpl->setRef( "thispage", $this->thispage );
211 $subpagestr = $this->subPageSubtitle();
212 $tpl->set(
213 'subtitle', !empty($subpagestr)?
214 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
215 $out->getSubtitle()
216 );
217 $undelete = $this->getUndeleteLink();
218 $tpl->set(
219 "undelete", !empty($undelete)?
220 '<span class="subpages">'.$undelete.'</span>':
221 ''
222 );
223
224 $tpl->set( 'catlinks', $this->getCategories());
225 if( $wgOut->isSyndicated() ) {
226 $feeds = array();
227 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
228 $feeds[$format] = array(
229 'text' => wfMsg( "feed-$format" ),
230 'href' => $link );
231 }
232 $tpl->setRef( 'feeds', $feeds );
233 } else {
234 $tpl->set( 'feeds', false );
235 }
236 if ($wgUseTrackbacks && $out->isArticleRelated()) {
237 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
238 } else {
239 $tpl->set( 'trackbackhtml', null );
240 }
241
242 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
243 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
244 $tpl->setRef( 'mimetype', $wgMimeType );
245 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
246 $tpl->setRef( 'charset', $wgOutputEncoding );
247 $tpl->set( 'headlinks', $out->getHeadLinks() );
248 $tpl->set('headscripts', $out->getScript() );
249 $tpl->setRef( 'wgScript', $wgScript );
250 $tpl->setRef( 'skinname', $this->skinname );
251 $tpl->set( 'skinclass', get_class( $this ) );
252 $tpl->setRef( 'stylename', $this->stylename );
253 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
254 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
255 $tpl->set( 'csslinks', $this->buildCssLinks() );
256 $tpl->setRef( 'loggedin', $this->loggedin );
257 $tpl->set( 'nsclass', $this->getNamespaceClasses( $this->mTitle ) );
258 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
259 /* XXX currently unused, might get useful later
260 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
261 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
262 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
263 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
264 $tpl->set( "helppage", wfMsg('helppage'));
265 */
266 $tpl->set( 'searchaction', $this->escapeSearchLink() );
267 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
268 $tpl->setRef( 'stylepath', $wgStylePath );
269 $tpl->setRef( 'articlepath', $wgArticlePath );
270 $tpl->setRef( 'scriptpath', $wgScriptPath );
271 $tpl->setRef( 'serverurl', $wgServer );
272 $tpl->setRef( 'logopath', $wgLogo );
273 $tpl->setRef( "lang", $wgContLanguageCode );
274 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
275 $tpl->set( 'rtl', $wgContLang->isRTL() );
276 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
277 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
278 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
279 $tpl->setRef( 'userpage', $this->userpage);
280 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
281 $tpl->set( 'userlang', $wgLang->getCode() );
282 $tpl->set( 'pagecss', $this->setupPageCss() );
283 $tpl->setRef( 'usercss', $this->usercss);
284 $tpl->setRef( 'userjs', $this->userjs);
285 $tpl->setRef( 'userjsprev', $this->userjsprev);
286 if( $wgUseSiteJs ) {
287 $jsCache = $this->loggedin ? '&smaxage=0' : '';
288 $tpl->set( 'jsvarurl',
289 self::makeUrl('-',
290 "action=raw$jsCache&gen=js&useskin=" .
291 urlencode( $this->getSkinName() ) ) );
292 } else {
293 $tpl->set('jsvarurl', false);
294 }
295 $newtalks = $wgUser->getNewMessageLinks();
296
297 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
298 $usertitle = $this->mUser->getUserPage();
299 $usertalktitle = $usertitle->getTalkPage();
300 if( !$usertalktitle->equals( $this->mTitle ) ) {
301 $ntl = wfMsg( 'youhavenewmessages',
302 $this->makeKnownLinkObj(
303 $usertalktitle,
304 wfMsgHtml( 'newmessageslink' ),
305 'redirect=no'
306 ),
307 $this->makeKnownLinkObj(
308 $usertalktitle,
309 wfMsgHtml( 'newmessagesdifflink' ),
310 'diff=cur'
311 )
312 );
313 # Disable Cache
314 $wgOut->setSquidMaxage(0);
315 }
316 } else if (count($newtalks)) {
317 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
318 $msgs = array();
319 foreach ($newtalks as $newtalk) {
320 $msgs[] = wfElement("a",
321 array('href' => $newtalk["link"]), $newtalk["wiki"]);
322 }
323 $parts = implode($sep, $msgs);
324 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
325 $wgOut->setSquidMaxage(0);
326 } else {
327 $ntl = '';
328 }
329 wfProfileOut( __METHOD__."-stuff2" );
330
331 wfProfileIn( __METHOD__."-stuff3" );
332 $tpl->setRef( 'newtalk', $ntl );
333 $tpl->setRef( 'skin', $this );
334 $tpl->set( 'logo', $this->logoText() );
335 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
336 $wgArticle and 0 != $wgArticle->getID() )
337 {
338 if ( !$wgDisableCounters ) {
339 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
340 if ( $viewcount ) {
341 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
342 } else {
343 $tpl->set('viewcount', false);
344 }
345 } else {
346 $tpl->set('viewcount', false);
347 }
348
349 if ($wgPageShowWatchingUsers) {
350 $dbr = wfGetDB( DB_SLAVE );
351 $watchlist = $dbr->tableName( 'watchlist' );
352 $sql = "SELECT COUNT(*) AS n FROM $watchlist
353 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
354 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
355 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
356 $x = $dbr->fetchObject( $res );
357 $numberofwatchingusers = $x->n;
358 if ($numberofwatchingusers > 0) {
359 $tpl->set('numberofwatchingusers',
360 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
361 $wgLang->formatNum($numberofwatchingusers))
362 );
363 } else {
364 $tpl->set('numberofwatchingusers', false);
365 }
366 } else {
367 $tpl->set('numberofwatchingusers', false);
368 }
369
370 $tpl->set('copyright',$this->getCopyright());
371
372 $this->credits = false;
373
374 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
375 require_once("Credits.php");
376 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
377 } else {
378 $tpl->set('lastmod', $this->lastModified());
379 }
380
381 $tpl->setRef( 'credits', $this->credits );
382
383 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
384 $tpl->set('copyright', $this->getCopyright());
385 $tpl->set('viewcount', false);
386 $tpl->set('lastmod', false);
387 $tpl->set('credits', false);
388 $tpl->set('numberofwatchingusers', false);
389 } else {
390 $tpl->set('copyright', false);
391 $tpl->set('viewcount', false);
392 $tpl->set('lastmod', false);
393 $tpl->set('credits', false);
394 $tpl->set('numberofwatchingusers', false);
395 }
396 wfProfileOut( __METHOD__."-stuff3" );
397
398 wfProfileIn( __METHOD__."-stuff4" );
399 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
400 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
401 $tpl->set( 'disclaimer', $this->disclaimerLink() );
402 $tpl->set( 'privacy', $this->privacyLink() );
403 $tpl->set( 'about', $this->aboutLink() );
404
405 $tpl->setRef( 'debug', $out->mDebugtext );
406 $tpl->set( 'reporttime', wfReportTime() );
407 $tpl->set( 'sitenotice', wfGetSiteNotice() );
408 $tpl->set( 'bottomscripts', $this->bottomScripts() );
409
410 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
411 $out->mBodytext .= $printfooter ;
412 $tpl->setRef( 'bodytext', $out->mBodytext );
413
414 # Language links
415 $language_urls = array();
416
417 if ( !$wgHideInterlanguageLinks ) {
418 foreach( $wgOut->getLanguageLinks() as $l ) {
419 $tmp = explode( ':', $l, 2 );
420 $class = 'interwiki-' . $tmp[0];
421 unset($tmp);
422 $nt = Title::newFromText( $l );
423 $language_urls[] = array(
424 'href' => $nt->getFullURL(),
425 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
426 'class' => $class
427 );
428 }
429 }
430 if(count($language_urls)) {
431 $tpl->setRef( 'language_urls', $language_urls);
432 } else {
433 $tpl->set('language_urls', false);
434 }
435 wfProfileOut( __METHOD__."-stuff4" );
436
437 # Personal toolbar
438 $tpl->set('personal_urls', $this->buildPersonalUrls());
439 $content_actions = $this->buildContentActionUrls();
440 $tpl->setRef('content_actions', $content_actions);
441
442 // XXX: attach this from javascript, same with section editing
443 if($this->iseditable && $wgUser->getOption("editondblclick") )
444 {
445 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
446 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
447 } else {
448 $tpl->set('body_ondblclick', false);
449 }
450 $tpl->set( 'body_onload', false );
451 $tpl->set( 'sidebar', $this->buildSidebar() );
452 $tpl->set( 'nav_urls', $this->buildNavUrls() );
453
454 // original version by hansm
455 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
456 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
457 }
458
459 // allow extensions adding stuff after the page content.
460 // See Skin::afterContentHook() for further documentation.
461 $tpl->set ('dataAfterContent', $this->afterContentHook());
462
463 // execute template
464 wfProfileIn( __METHOD__."-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( __METHOD__."-execute" );
467
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( __METHOD__ );
471 }
472
473 /**
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
477 *
478 * @param mixed $str
479 * @private
480 */
481 function printOrError( $str ) {
482 echo $str;
483 }
484
485 /**
486 * build array of urls for personal toolbar
487 * @return array
488 * @private
489 */
490 function buildPersonalUrls() {
491 global $wgTitle, $wgRequest;
492
493 $pageurl = $wgTitle->getLocalURL();
494 wfProfileIn( __METHOD__ );
495
496 /* set up the default links for the personal toolbar */
497 $personal_urls = array();
498 if ($this->loggedin) {
499 $personal_urls['userpage'] = array(
500 'text' => $this->username,
501 'href' => &$this->userpageUrlDetails['href'],
502 'class' => $this->userpageUrlDetails['exists']?false:'new',
503 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
504 );
505 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
506 $personal_urls['mytalk'] = array(
507 'text' => wfMsg('mytalk'),
508 'href' => &$usertalkUrlDetails['href'],
509 'class' => $usertalkUrlDetails['exists']?false:'new',
510 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
511 );
512 $href = self::makeSpecialUrl( 'Preferences' );
513 $personal_urls['preferences'] = array(
514 'text' => wfMsg( 'mypreferences' ),
515 'href' => $href,
516 'active' => ( $href == $pageurl )
517 );
518 $href = self::makeSpecialUrl( 'Watchlist' );
519 $personal_urls['watchlist'] = array(
520 'text' => wfMsg( 'mywatchlist' ),
521 'href' => $href,
522 'active' => ( $href == $pageurl )
523 );
524
525 # We need to do an explicit check for Special:Contributions, as we
526 # have to match both the title, and the target (which could come
527 # from request values or be specified in "sub page" form. The plot
528 # thickens, because $wgTitle is altered for special pages, so doesn't
529 # contain the original alias-with-subpage.
530 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
531 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
532 list( $spName, $spPar ) =
533 SpecialPage::resolveAliasWithSubpage( $title->getText() );
534 $active = $spName == 'Contributions'
535 && ( ( $spPar && $spPar == $this->username )
536 || $wgRequest->getText( 'target' ) == $this->username );
537 } else {
538 $active = false;
539 }
540
541 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
542 $personal_urls['mycontris'] = array(
543 'text' => wfMsg( 'mycontris' ),
544 'href' => $href,
545 'active' => $active
546 );
547 $personal_urls['logout'] = array(
548 'text' => wfMsg( 'userlogout' ),
549 'href' => self::makeSpecialUrl( 'Userlogout',
550 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
551 ),
552 'active' => false
553 );
554 } else {
555 global $wgUser;
556 $loginlink = $wgUser->isAllowed( 'createaccount' )
557 ? 'nav-login-createaccount'
558 : 'login';
559 if( $this->showIPinHeader() ) {
560 $href = &$this->userpageUrlDetails['href'];
561 $personal_urls['anonuserpage'] = array(
562 'text' => $this->username,
563 'href' => $href,
564 'class' => $this->userpageUrlDetails['exists']?false:'new',
565 'active' => ( $pageurl == $href )
566 );
567 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
568 $href = &$usertalkUrlDetails['href'];
569 $personal_urls['anontalk'] = array(
570 'text' => wfMsg('anontalk'),
571 'href' => $href,
572 'class' => $usertalkUrlDetails['exists']?false:'new',
573 'active' => ( $pageurl == $href )
574 );
575 $personal_urls['anonlogin'] = array(
576 'text' => wfMsg( $loginlink ),
577 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
578 'active' => $wgTitle->isSpecial( 'Userlogin' )
579 );
580 } else {
581
582 $personal_urls['login'] = array(
583 'text' => wfMsg( $loginlink ),
584 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
585 'active' => $wgTitle->isSpecial( 'Userlogin' )
586 );
587 }
588 }
589
590 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
591 wfProfileOut( __METHOD__ );
592 return $personal_urls;
593 }
594
595 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
596 $classes = array();
597 if( $selected ) {
598 $classes[] = 'selected';
599 }
600 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
601 $classes[] = 'new';
602 $query = 'action=edit';
603 }
604
605 $text = wfMsg( $message );
606 if ( wfEmptyMsg( $message, $text ) ) {
607 global $wgContLang;
608 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
609 }
610
611 $result = array();
612 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
613 $title, $message, $selected, $checkEdit,
614 &$classes, &$query, &$text, &$result)) ) {
615 return $result;
616 }
617
618 return array(
619 'class' => implode( ' ', $classes ),
620 'text' => $text,
621 'href' => $title->getLocalUrl( $query ) );
622 }
623
624 function makeTalkUrlDetails( $name, $urlaction = '' ) {
625 $title = Title::newFromText( $name );
626 if( !is_object($title) ) {
627 throw new MWException( __METHOD__." given invalid pagename $name" );
628 }
629 $title = $title->getTalkPage();
630 self::checkTitle( $title, $name );
631 return array(
632 'href' => $title->getLocalURL( $urlaction ),
633 'exists' => $title->getArticleID() != 0 ? true : false
634 );
635 }
636
637 function makeArticleUrlDetails( $name, $urlaction = '' ) {
638 $title = Title::newFromText( $name );
639 $title= $title->getSubjectPage();
640 self::checkTitle( $title, $name );
641 return array(
642 'href' => $title->getLocalURL( $urlaction ),
643 'exists' => $title->getArticleID() != 0 ? true : false
644 );
645 }
646
647 /**
648 * an array of edit links by default used for the tabs
649 * @return array
650 * @private
651 */
652 function buildContentActionUrls () {
653 global $wgContLang, $wgLang, $wgOut;
654 wfProfileIn( __METHOD__ );
655
656 global $wgUser, $wgRequest;
657 $action = $wgRequest->getText( 'action' );
658 $section = $wgRequest->getText( 'section' );
659 $content_actions = array();
660
661 $prevent_active_tabs = false ;
662 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
663
664 if( $this->iscontent ) {
665 $subjpage = $this->mTitle->getSubjectPage();
666 $talkpage = $this->mTitle->getTalkPage();
667
668 $nskey = $this->mTitle->getNamespaceKey();
669 $content_actions[$nskey] = $this->tabAction(
670 $subjpage,
671 $nskey,
672 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
673 '', true);
674
675 $content_actions['talk'] = $this->tabAction(
676 $talkpage,
677 'talk',
678 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
679 '',
680 true);
681
682 wfProfileIn( __METHOD__."-edit" );
683 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
684 $istalk = $this->mTitle->isTalkPage();
685 $istalkclass = $istalk?' istalk':'';
686 $content_actions['edit'] = array(
687 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
688 'text' => $this->mTitle->exists()
689 ? wfMsg( 'edit' )
690 : wfMsg( 'create' ),
691 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
692 );
693
694 if ( $istalk || $wgOut->showNewSectionLink() ) {
695 $content_actions['addsection'] = array(
696 'class' => $section == 'new'?'selected':false,
697 'text' => wfMsg('addsection'),
698 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
699 );
700 }
701 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
702 $content_actions['viewsource'] = array(
703 'class' => ($action == 'edit') ? 'selected' : false,
704 'text' => wfMsg('viewsource'),
705 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
706 );
707 }
708 wfProfileOut( __METHOD__."-edit" );
709
710 wfProfileIn( __METHOD__."-live" );
711 if ( $this->mTitle->getArticleId() ) {
712
713 $content_actions['history'] = array(
714 'class' => ($action == 'history') ? 'selected' : false,
715 'text' => wfMsg('history_short'),
716 'href' => $this->mTitle->getLocalUrl( 'action=history')
717 );
718
719 if($wgUser->isAllowed('delete')){
720 $content_actions['delete'] = array(
721 'class' => ($action == 'delete') ? 'selected' : false,
722 'text' => wfMsg('delete'),
723 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
724 );
725 }
726 if ( $this->mTitle->quickUserCan( 'move' ) ) {
727 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
728 $content_actions['move'] = array(
729 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
730 'text' => wfMsg('move'),
731 'href' => $moveTitle->getLocalUrl()
732 );
733 }
734
735 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
736 if(!$this->mTitle->isProtected()){
737 $content_actions['protect'] = array(
738 'class' => ($action == 'protect') ? 'selected' : false,
739 'text' => wfMsg('protect'),
740 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
741 );
742
743 } else {
744 $content_actions['unprotect'] = array(
745 'class' => ($action == 'unprotect') ? 'selected' : false,
746 'text' => wfMsg('unprotect'),
747 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
748 );
749 }
750 }
751 } else {
752 //article doesn't exist or is deleted
753 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
754 if( $n = $this->mTitle->isDeleted() ) {
755 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
756 $content_actions['undelete'] = array(
757 'class' => false,
758 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
759 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
760 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
761 );
762 }
763 }
764
765 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
766 if( !$this->mTitle->getRestrictions( 'create' ) ) {
767 $content_actions['protect'] = array(
768 'class' => ($action == 'protect') ? 'selected' : false,
769 'text' => wfMsg('protect'),
770 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
771 );
772
773 } else {
774 $content_actions['unprotect'] = array(
775 'class' => ($action == 'unprotect') ? 'selected' : false,
776 'text' => wfMsg('unprotect'),
777 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
778 );
779 }
780 }
781 }
782
783 wfProfileOut( __METHOD__."-live" );
784
785 if( $this->loggedin ) {
786 if( !$this->mTitle->userIsWatching()) {
787 $content_actions['watch'] = array(
788 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
789 'text' => wfMsg('watch'),
790 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
791 );
792 } else {
793 $content_actions['unwatch'] = array(
794 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
795 'text' => wfMsg('unwatch'),
796 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
797 );
798 }
799 }
800
801
802 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
803 } else {
804 /* show special page tab */
805
806 $content_actions[$this->mTitle->getNamespaceKey()] = array(
807 'class' => 'selected',
808 'text' => wfMsg('nstab-special'),
809 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
810 );
811
812 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
813 }
814
815 /* show links to different language variants */
816 global $wgDisableLangConversion;
817 $variants = $wgContLang->getVariants();
818 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
819 $preferred = $wgContLang->getPreferredVariant();
820 $vcount=0;
821 foreach( $variants as $code ) {
822 $varname = $wgContLang->getVariantname( $code );
823 if( $varname == 'disable' )
824 continue;
825 $selected = ( $code == $preferred )? 'selected' : false;
826 $content_actions['varlang-' . $vcount] = array(
827 'class' => $selected,
828 'text' => $varname,
829 'href' => $this->mTitle->getLocalURL('',$code)
830 );
831 $vcount ++;
832 }
833 }
834
835 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
836
837 wfProfileOut( __METHOD__ );
838 return $content_actions;
839 }
840
841
842
843 /**
844 * build array of common navigation links
845 * @return array
846 * @private
847 */
848 function buildNavUrls () {
849 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
850 global $wgEnableUploads, $wgUploadNavigationUrl;
851
852 wfProfileIn( __METHOD__ );
853
854 $action = $wgRequest->getText( 'action' );
855
856 $nav_urls = array();
857 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
858 if( $wgEnableUploads ) {
859 if ($wgUploadNavigationUrl) {
860 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
861 } else {
862 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
863 }
864 } else {
865 if ($wgUploadNavigationUrl)
866 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
867 else
868 $nav_urls['upload'] = false;
869 }
870 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
871
872 // default permalink to being off, will override it as required below.
873 $nav_urls['permalink'] = false;
874
875 // A print stylesheet is attached to all pages, but nobody ever
876 // figures that out. :) Add a link...
877 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
878 $nav_urls['print'] = array(
879 'text' => wfMsg( 'printableversion' ),
880 'href' => $wgRequest->appendQuery( 'printable=yes' )
881 );
882
883 // Also add a "permalink" while we're at it
884 if ( $this->mRevisionId ) {
885 $nav_urls['permalink'] = array(
886 'text' => wfMsg( 'permalink' ),
887 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
888 );
889 }
890
891 // Copy in case this undocumented, shady hook tries to mess with internals
892 $revid = $this->mRevisionId;
893 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
894 }
895
896 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
897 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
898 $nav_urls['whatlinkshere'] = array(
899 'href' => $wlhTitle->getLocalUrl()
900 );
901 if( $this->mTitle->getArticleId() ) {
902 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
903 $nav_urls['recentchangeslinked'] = array(
904 'href' => $rclTitle->getLocalUrl()
905 );
906 } else {
907 $nav_urls['recentchangeslinked'] = false;
908 }
909 if ($wgUseTrackbacks)
910 $nav_urls['trackbacklink'] = array(
911 'href' => $wgTitle->trackbackURL()
912 );
913 }
914
915 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
916 $id = User::idFromName($this->mTitle->getText());
917 $ip = User::isIP($this->mTitle->getText());
918 } else {
919 $id = 0;
920 $ip = false;
921 }
922
923 if($id || $ip) { # both anons and non-anons have contribs list
924 $nav_urls['contributions'] = array(
925 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
926 );
927
928 if( $id ) {
929 $logPage = SpecialPage::getTitleFor( 'Log' );
930 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
931 . $this->mTitle->getPartialUrl() ) );
932 } else {
933 $nav_urls['log'] = false;
934 }
935
936 if ( $wgUser->isAllowed( 'block' ) ) {
937 $nav_urls['blockip'] = array(
938 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
939 );
940 } else {
941 $nav_urls['blockip'] = false;
942 }
943 } else {
944 $nav_urls['contributions'] = false;
945 $nav_urls['log'] = false;
946 $nav_urls['blockip'] = false;
947 }
948 $nav_urls['emailuser'] = false;
949 if( $this->showEmailUser( $id ) ) {
950 $nav_urls['emailuser'] = array(
951 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
952 );
953 }
954 wfProfileOut( __METHOD__ );
955 return $nav_urls;
956 }
957
958 /**
959 * Generate strings used for xml 'id' names
960 * @return string
961 * @private
962 */
963 function getNameSpaceKey () {
964 return $this->mTitle->getNamespaceKey();
965 }
966
967 /**
968 * @private
969 */
970 function setupUserCss( $extCSS = array() ) {
971 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
972
973 wfProfileIn( __METHOD__ );
974
975 $siteargs = array(
976 'action' => 'raw',
977 'maxage' => $wgSquidMaxage,
978 );
979 if( $this->loggedin ) {
980 // Ensure that logged-in users' generated CSS isn't clobbered
981 // by anons' publicly cacheable generated CSS.
982 $siteargs['smaxage'] = '0';
983 $siteargs['ts'] = $wgUser->mTouched;
984 }
985
986 // Add any extension CSS
987 foreach( $extCSS as $tag ) {
988 $this->addStyle( $tag['href'] );
989 }
990
991 // If we use the site's dynamic CSS, throw that in, too
992 // Per-site custom styles
993 if ( $wgUseSiteCss ) {
994 $query = wfArrayToCGI( array(
995 'usemsgcache' => 'yes',
996 'ctype' => 'text/css',
997 'smaxage' => $wgSquidMaxage
998 ) + $siteargs );
999 $this->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
1000 $this->addStyle( self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ),
1001 'screen' );
1002 }
1003
1004 // Per-user styles based on preferences
1005 $siteargs['gen'] = 'css';
1006 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' )
1007 $siteargs['useskin'] = $us;
1008 $this->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ), 'screen' );
1009
1010 // Per-user custom style pages
1011 if ( $wgAllowUserCss && $this->loggedin ) {
1012 $action = $wgRequest->getVal('action');
1013
1014 # if we're previewing the CSS page, use it
1015 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
1016 $previewCss = $wgRequest->getText('wpTextbox1');
1017
1018 /// @fixme properly escape the cdata!
1019 $this->usercss = "/*<![CDATA[*/\n" .
1020 $previewCss .
1021 "/*]]>*/";
1022 } else {
1023 $this->addStyle( self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
1024 'action=raw&ctype=text/css'), 'screen' );
1025 }
1026 }
1027
1028 wfProfileOut( __METHOD__ );
1029 }
1030
1031 /**
1032 * @private
1033 */
1034 function setupUserJs( $allowUserJs ) {
1035 wfProfileIn( __METHOD__ );
1036
1037 global $wgRequest, $wgJsMimeType;
1038 $action = $wgRequest->getText('action');
1039
1040 if( $allowUserJs && $this->loggedin ) {
1041 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1042 # XXX: additional security check/prompt?
1043 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1044 } else {
1045 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
1046 }
1047 }
1048 wfProfileOut( __METHOD__ );
1049 }
1050
1051 /**
1052 * Code for extensions to hook into to provide per-page CSS, see
1053 * extensions/PageCSS/PageCSS.php for an implementation of this.
1054 *
1055 * @private
1056 */
1057 function setupPageCss() {
1058 wfProfileIn( __METHOD__ );
1059 $out = false;
1060 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1061
1062 wfProfileOut( __METHOD__ );
1063 return $out;
1064 }
1065
1066 /**
1067 * returns css with user-specific options
1068 */
1069 public function getUserStylesheet() {
1070 wfProfileIn( __METHOD__ );
1071
1072 $s = "/* generated user stylesheet */\n";
1073 $s .= $this->reallyDoGetUserStyles();
1074 wfProfileOut( __METHOD__ );
1075 return $s;
1076 }
1077
1078 /**
1079 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1080 * nated together. For some bizarre reason, it does *not* return any
1081 * custom user JS from subpages. Huh?
1082 *
1083 * There's absolutely no reason to have separate Monobook/Common JSes.
1084 * Any JS that cares can just check the skin variable generated at the
1085 * top. For now Monobook.js will be maintained, but it should be consi-
1086 * dered deprecated.
1087 *
1088 * @return string
1089 */
1090 public function getUserJs() {
1091 wfProfileIn( __METHOD__ );
1092
1093 $s = parent::getUserJs();
1094 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js */\n";
1095
1096 // avoid inclusion of non defined user JavaScript (with custom skins only)
1097 // by checking for default message content
1098 $msgKey = ucfirst($this->skinname).'.js';
1099 $userJS = wfMsgForContent($msgKey);
1100 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1101 $s .= $userJS;
1102 }
1103
1104 wfProfileOut( __METHOD__ );
1105 return $s;
1106 }
1107
1108 /**
1109 * Add a local or specified stylesheet, with the given media options.
1110 * Meant primarily for internal use...
1111 *
1112 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1113 * @param $conditional -- for IE conditional comments, specifying an IE version
1114 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1115 */
1116 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1117 $options = array();
1118 if( $media )
1119 $options['media'] = $media;
1120 if( $condition )
1121 $options['condition'] = $condition;
1122 if( $dir )
1123 $options['dir'] = $dir;
1124 $this->styles[$style] = $options;
1125 }
1126
1127 /**
1128 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1129 * These will be applied to various media & IE conditionals.
1130 */
1131 protected function buildCssLinks() {
1132 $links = array();
1133 foreach( $this->styles as $file => $options ) {
1134 $link = $this->styleLink( $file, $options );
1135 if( $link )
1136 $links[] = $link;
1137 }
1138
1139 return implode( "\n\t\t", $links );
1140 }
1141
1142 protected function styleLink( $style, $options ) {
1143 global $wgRequest;
1144
1145 if( isset( $options['dir'] ) ) {
1146 global $wgContLang;
1147 $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
1148 if( $siteDir != $options['dir'] )
1149 return '';
1150 }
1151
1152 if( isset( $options['media'] ) ) {
1153 $media = $this->transformCssMedia( $options['media'] );
1154 if( is_null( $media ) ) {
1155 return '';
1156 }
1157 } else {
1158 $media = '';
1159 }
1160
1161 if( substr( $style, 0, 1 ) == '/' ||
1162 substr( $style, 0, 5 ) == 'http:' ||
1163 substr( $style, 0, 6 ) == 'https:' ) {
1164 $url = $style;
1165 } else {
1166 global $wgStylePath, $wgStyleVersion;
1167 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1168 }
1169
1170 $attribs = array(
1171 'rel' => 'stylesheet',
1172 'href' => $url,
1173 'type' => 'text/css' );
1174 if( $media ) {
1175 $attribs['media'] = $media;
1176 }
1177
1178 $link = Xml::element( 'link', $attribs );
1179
1180 if( isset( $options['condition'] ) ) {
1181 $condition = htmlspecialchars( $options['condition'] );
1182 $link = "<!--[if $condition]>$link<![endif]-->";
1183 }
1184 return $link;
1185 }
1186
1187 function transformCssMedia( $media ) {
1188 global $wgRequest, $wgHandheldForIPhone;
1189
1190 // Switch in on-screen display for media testing
1191 $switches = array(
1192 'printable' => 'print',
1193 'handheld' => 'handheld',
1194 );
1195 foreach( $switches as $switch => $targetMedia ) {
1196 if( $wgRequest->getBool( $switch ) ) {
1197 if( $media == $targetMedia ) {
1198 $media = '';
1199 } elseif( $media == 'screen' ) {
1200 return null;
1201 }
1202 }
1203 }
1204
1205 // Expand longer media queries as iPhone doesn't grok 'handheld'
1206 if( $wgHandheldForIPhone ) {
1207 $mediaAliases = array(
1208 'screen' => 'screen and (min-device-width: 481px)',
1209 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1210 );
1211
1212 if( isset( $mediaAliases[$media] ) ) {
1213 $media = $mediaAliases[$media];
1214 }
1215 }
1216
1217 return $media;
1218 }
1219
1220 }
1221
1222 /**
1223 * Generic wrapper for template functions, with interface
1224 * compatible with what we use of PHPTAL 0.7.
1225 * @ingroup Skins
1226 */
1227 class QuickTemplate {
1228 /**
1229 * @public
1230 */
1231 function QuickTemplate() {
1232 $this->data = array();
1233 $this->translator = new MediaWiki_I18N();
1234 }
1235
1236 /**
1237 * @public
1238 */
1239 function set( $name, $value ) {
1240 $this->data[$name] = $value;
1241 }
1242
1243 /**
1244 * @public
1245 */
1246 function setRef($name, &$value) {
1247 $this->data[$name] =& $value;
1248 }
1249
1250 /**
1251 * @public
1252 */
1253 function setTranslator( &$t ) {
1254 $this->translator = &$t;
1255 }
1256
1257 /**
1258 * @public
1259 */
1260 function execute() {
1261 echo "Override this function.";
1262 }
1263
1264
1265 /**
1266 * @private
1267 */
1268 function text( $str ) {
1269 echo htmlspecialchars( $this->data[$str] );
1270 }
1271
1272 /**
1273 * @private
1274 */
1275 function jstext( $str ) {
1276 echo Xml::escapeJsString( $this->data[$str] );
1277 }
1278
1279 /**
1280 * @private
1281 */
1282 function html( $str ) {
1283 echo $this->data[$str];
1284 }
1285
1286 /**
1287 * @private
1288 */
1289 function msg( $str ) {
1290 echo htmlspecialchars( $this->translator->translate( $str ) );
1291 }
1292
1293 /**
1294 * @private
1295 */
1296 function msgHtml( $str ) {
1297 echo $this->translator->translate( $str );
1298 }
1299
1300 /**
1301 * An ugly, ugly hack.
1302 * @private
1303 */
1304 function msgWiki( $str ) {
1305 global $wgParser, $wgTitle, $wgOut;
1306
1307 $text = $this->translator->translate( $str );
1308 $parserOutput = $wgParser->parse( $text, $wgTitle,
1309 $wgOut->parserOptions(), true );
1310 echo $parserOutput->getText();
1311 }
1312
1313 /**
1314 * @private
1315 */
1316 function haveData( $str ) {
1317 return isset( $this->data[$str] );
1318 }
1319
1320 /**
1321 * @private
1322 */
1323 function haveMsg( $str ) {
1324 $msg = $this->translator->translate( $str );
1325 return ($msg != '-') && ($msg != ''); # ????
1326 }
1327 }