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