2 # Generic PHPTal (http://phptal.sourceforge.net/) skin
3 # Based on Brion's smarty skin
4 # Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
6 # Todo: Needs some serious refactoring into functions that correspond
7 # to the computations individual esi snippets need. Most importantly no body
8 # parsing for most of those of course.
10 # Set this in LocalSettings to enable phptal:
11 # set_include_path(get_include_path() . ":" . $IP.'/PHPTAL-NP-0.7.0/libs');
12 # $wgUsePHPTal = true;
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write to the Free Software Foundation, Inc.,
26 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 # http://www.gnu.org/copyleft/gpl.html
29 require_once "GlobalFunctions.php";
30 require_once $IP."/PHPTAL-NP-0.7.0/libs/PHPTAL.php";
32 class MediaWiki_I18N
extends PHPTAL_I18N
34 var $_context = array();
36 function set($varName, $value) {
37 $this->_context
[$varName] = $value;
40 function translate($value) {
41 $value = wfMsg( $value );
42 // interpolate variables
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 $varValue = @$this->_context
[$var];
46 $value = str_replace($src, $varValue, $value);
52 class SkinPHPTal
extends Skin
{
55 function initPage( &$out ) {
56 parent
::initPage( $out );
57 $this->skinname
= "davinci";
58 $this->template
= "xhtml_slim";
61 function outputPage( &$out ) {
62 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
63 global $wgScript, $wgStylePath, $wgLanguageCode, $wgUseNewInterlanguage;
64 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
65 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
67 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
69 $this->initPage( $out );
70 $tpl = new PHPTAL($this->template
. '.pt', 'templates');
72 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
73 $tpl->setTranslator(new MediaWiki_I18N());
76 $this->thispage
= $wgTitle->getPrefixedDbKey();
77 $this->thisurl
= $wgTitle->getPrefixedURL();
78 $this->loggedin
= $wgUser->getID() != 0;
79 $this->iscontent
= ($wgTitle->getNamespace() != Namespace::getSpecial() );
80 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
81 $this->username
= $wgUser->getName();
82 $this->userpage
= $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
83 $this->userpageurl
= $this->makeUrl($this->userpage
);
85 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
86 if( $this->loggedin
) { $this->setupUserCssJs(); }
88 $this->titletxt
= $wgTitle->getPrefixedText();
90 $tpl->set( "title", $wgOut->getPageTitle() );
91 $tpl->set( "pagetitle", $wgOut->getHTMLTitle() );
93 $tpl->setRef( "thispage", &$this->thispage
);
94 $subpagestr = $this->subPageSubtitle();
96 "subtitle", !empty($subpagestr)?
97 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
100 $tpl->set( 'catlinks', $this->getCategories());
101 if( $wgOut->isSyndicated() ) {
103 foreach( $wgFeedClasses as $format => $class ) {
104 $feeds[$format] = array(
106 'href' => $wgRequest->appendQuery( "feed=$format" ),
107 'ttip' => wfMsg('tooltip-'.$format)
110 $tpl->setRef( 'feeds', &$feeds );
112 $tpl->setRef( 'mimetype', &$wgMimeType );
113 $tpl->setRef( 'charset', &$wgOutputEncoding );
114 $tpl->set( 'headlinks', $out->getHeadLinks() );
115 $tpl->setRef( 'skinname', &$this->skinname
);
116 $tpl->setRef( "loggedin", &$this->loggedin
);
117 /* XXX currently unused, might get useful later
118 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
119 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
120 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
121 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
122 $tpl->set( "helppage", wfMsg('helppage'));
123 $tpl->set( "sysop", $wgUser->isSysop() );
125 $tpl->set( "searchaction", $this->escapeSearchLink() );
126 $tpl->setRef( "stylepath", &$wgStylePath );
127 $tpl->setRef( "logopath", &$wgLogo );
128 $tpl->setRef( "lang", &$wgLanguageCode );
129 $tpl->set( "dir", $wgLang->isRTL() ?
"rtl" : "ltr" );
130 $tpl->set( "rtl", $wgLang->isRTL() );
131 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
132 $tpl->setRef( "username", &$this->username
);
133 $tpl->setRef( "userpage", &$this->userpage
);
134 $tpl->setRef( "userpageurl", &$this->userpageurl
);
135 $tpl->setRef( "usercss", &$this->usercss
);
136 $tpl->setRef( "userjs", &$this->userjs
);
137 $tpl->setRef( "userjsprev", &$this->userjsprev
);
138 if( $wgUser->getNewtalk() ) {
139 $usertitle = Title
::newFromText( $this->userpage
);
140 $usertalktitle = $usertitle->getTalkPage();
141 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
143 $ntl = wfMsg( "newmessages",
144 $this->makeKnownLink(
145 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
146 . ":" . $this->username
,
147 wfMsg("newmessageslink") )
154 $tpl->setRef( "newtalk", &$ntl );
155 $tpl->setRef( "skin", &$this);
156 $tpl->set( "logo", $this->logoText() );
157 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
158 if ( !$wgDisableCounters ) {
159 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
161 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
164 $tpl->set('lastmod', $this->lastModified());
165 $tpl->set('copyright',$this->getCopyright());
167 $tpl->set( "copyrightico", $this->getCopyrightIcon() );
168 $tpl->set( "poweredbyico", $this->getPoweredBy() );
169 $tpl->set( "disclaimer", $this->disclaimerLink() );
170 $tpl->set( "about", $this->aboutLink() );
172 $tpl->setRef( "debug", &$out->mDebugtext
);
173 $tpl->set( "reporttime", $out->reportTime() );
175 $tpl->setRef( "bodytext", &$out->mBodytext
);
177 $language_urls = array();
178 foreach( $wgOut->getLanguageLinks() as $l ) {
179 $nt = Title
::newFromText( $l );
180 $language_urls[] = array('href' => $nt->getFullURL(),
181 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
182 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
184 if(count($language_urls)) {
185 $tpl->setRef( 'language_urls', &$language_urls);
187 $tpl->set('language_urls', false);
189 $tpl->set('personal_urls', $this->buildPersonalUrls());
190 $content_actions = $this->buildContentActionUrls();
191 $tpl->setRef('content_actions', &$content_actions);
192 // XXX: attach this from javascript, same with section editing
193 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
195 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
197 $tpl->set('body-ondblclick', false);
199 $tpl->set( "nav_urls", $this->buildNavUrls() );
202 $res = $tpl->execute();
203 // result may be an error
204 if (PEAR
::isError($res)) {
205 echo $res->toString(), "\n";
212 # build array of urls for personal toolbar
213 function buildPersonalUrls() {
214 /* set up the default links for the personal toolbar */
215 global $wgShowIPinHeader;
216 $personal_urls = array();
217 if ($this->loggedin
) {
218 $personal_urls['userpage'] = array(
219 'text' => $this->username
,
220 'href' => &$this->userpageurl
,
221 'ttip' => wfMsg('tooltip-userpage'),
222 'akey' => wfMsg('accesskey-userpage')
224 $personal_urls['mytalk'] = array(
225 'text' => wfMsg('mytalk'),
226 'href' => $this->makeTalkUrl($this->userpage
),
227 'ttip' => wfMsg('tooltip-mytalk'),
228 'akey' => wfMsg('accesskey-mytalk')
230 $personal_urls['preferences'] = array(
231 'text' => wfMsg('preferences'),
232 'href' => $this->makeSpecialUrl('Preferences'),
233 'ttip' => wfMsg('tooltip-preferences'),
234 'akey' => wfMsg('accesskey-preferences')
236 $personal_urls['watchlist'] = array(
237 'text' => wfMsg('watchlist'),
238 'href' => $this->makeSpecialUrl('Watchlist'),
239 'ttip' => wfMsg('tooltip-watchlist'),
240 'akey' => wfMsg('accesskey-watchlist')
242 $personal_urls['mycontris'] = array(
243 'text' => wfMsg('mycontris'),
244 'href' => $this->makeSpecialUrl('Contributions','target=' . $this->username
),
245 'ttip' => wfMsg('tooltip-mycontris'),
246 'akey' => wfMsg('accesskey-mycontris')
248 $personal_urls['logout'] = array(
249 'text' => wfMsg('userlogout'),
250 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl
),
251 'ttip' => wfMsg('tooltip-logout'),
252 'akey' => wfMsg('accesskey-logout')
255 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
256 $personal_urls['anonuserpage'] = array(
257 'text' => $this->username
,
258 'href' => $this->makeUrl($this->userpage
),
259 'ttip' => wfMsg('tooltip-anonuserpage'),
260 'akey' => wfMsg('accesskey-anonuserpage')
262 $personal_urls['anontalk'] = array(
263 'text' => wfMsg('anontalk'),
264 'href' => $this->makeTalkUrl($this->userpage
),
265 'ttip' => wfMsg('tooltip-anontalk'),
266 'akey' => wfMsg('accesskey-anontalk')
268 $personal_urls['anonlogin'] = array(
269 'text' => wfMsg('userlogin'),
270 'href' => $this->makeSpecialUrl('Userlogin', 'returnto='.$this->thisurl
),
271 'ttip' => wfMsg('tooltip-login'),
272 'akey' => wfMsg('accesskey-login')
276 $personal_urls['login'] = array(
277 'text' => wfMsg('userlogin'),
278 'href' => $this->makeSpecialUrl('Userlogin', 'returnto='.$this->thisurl
),
279 'ttip' => wfMsg('tooltip-login'),
280 'akey' => wfMsg('accesskey-login')
285 return $personal_urls;
288 # an array of edit links by default used for the tabs
289 function buildContentActionUrls () {
290 global $wgTitle, $wgUser, $wgRequest;
291 $action = $wgRequest->getText( 'action' );
292 $section = $wgRequest->getText( 'section' );
293 $oldid = $wgRequest->getVal( 'oldid' );
294 $diff = $wgRequest->getVal( 'diff' );
295 $content_actions = array();
297 if( $this->iscontent
) {
299 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : false,
300 'text' => $this->getNameSpaceWord(),
301 'href' => $this->makeArticleUrl($this->thispage
),
302 'ttip' => wfMsg('tooltip-article'),
303 'akey' => wfMsg('accesskey-article'));
305 /* set up the classes for the talk link */
306 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : false);
307 $talktitle = Title
::newFromText( $this->titletxt
);
308 $talktitle = $talktitle->getTalkPage();
309 $this->checkTitle(&$talktitle, &$this->titletxt
);
310 if($talktitle->getArticleId() != 0) {
311 $content_actions['talk'] = array(
312 'class' => $talk_class,
313 'text' => wfMsg('talk'),
314 'href' => $this->makeTalkUrl($this->titletxt
),
315 'ttip' => wfMsg('tooltip-talk'),
316 'akey' => wfMsg('accesskey-talk')
319 $content_actions['talk'] = array(
320 'class' => $talk_class?
$talk_class.' new':'new',
321 'text' => wfMsg('talk'),
322 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit'),
323 'ttip' => wfMsg('tooltip-talk'),
324 'akey' => wfMsg('accesskey-talk')
328 if ( $wgTitle->userCanEdit() ) {
329 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : false;
330 $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
331 $istalkclass = $istalk?
' istalk':'';
332 $content_actions['edit'] = array(
333 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
334 'text' => wfMsg('edit'),
335 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
336 'ttip' => wfMsg('tooltip-edit'),
337 'akey' => wfMsg('accesskey-edit')
340 $content_actions['addsection'] = array(
341 'class' => $section == 'new'?
'selected':false,
342 'text' => wfMsg('addsection'),
343 'href' => $this->makeUrl($this->thispage
, 'action=edit§ion=new'),
344 'ttip' => wfMsg('tooltip-addsection'),
345 'akey' => wfMsg('accesskey-addsection')
349 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
350 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : false,
351 'text' => wfMsg('viewsource'),
352 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
353 'ttip' => wfMsg('tooltip-viewsource'),
354 'akey' => wfMsg('accesskey-viewsource'));
357 if ( $wgTitle->getArticleId() ) {
359 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : false,
360 'text' => wfMsg('history_short'),
361 'href' => $this->makeUrl($this->thispage
, 'action=history'),
362 'ttip' => wfMsg('tooltip-history'),
363 'akey' => wfMsg('accesskey-history'));
365 # XXX: is there a rollback action anywhere or is it planned?
366 # Don't recall where i got this from...
367 /*if( $wgUser->getNewtalk() ) {
368 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : false,
369 'text' => wfMsg('rollback_short'),
370 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
371 'ttip' => wfMsg('tooltip-rollback'),
372 'akey' => wfMsg('accesskey-rollback'));
375 if($wgUser->isSysop()){
376 if(!$wgTitle->isProtected()){
377 $content_actions['protect'] = array(
378 'class' => ($action == 'protect') ?
'selected' : false,
379 'text' => wfMsg('protect'),
380 'href' => $this->makeUrl($this->thispage
, 'action=protect'),
381 'ttip' => wfMsg('tooltip-protect'),
382 'akey' => wfMsg('accesskey-protect')
386 $content_actions['unprotect'] = array(
387 'class' => ($action == 'unprotect') ?
'selected' : false,
388 'text' => wfMsg('unprotect'),
389 'href' => $this->makeUrl($this->thispage
, 'action=unprotect'),
390 'ttip' => wfMsg('tooltip-protect'),
391 'akey' => wfMsg('accesskey-protect')
394 $content_actions['delete'] = array(
395 'class' => ($action == 'delete') ?
'selected' : false,
396 'text' => wfMsg('delete'),
397 'href' => $this->makeUrl($this->thispage
, 'action=delete'),
398 'ttip' => wfMsg('tooltip-delete'),
399 'akey' => wfMsg('accesskey-delete')
402 if ( $wgUser->getID() != 0 ) {
403 if ( $wgTitle->userCanEdit()) {
404 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : false,
405 'text' => wfMsg('move'),
406 'href' => $this->makeSpecialUrl('Movepage', 'target='.$this->thispage
),
407 'ttip' => wfMsg('tooltip-move'),
408 'akey' => wfMsg('accesskey-move'));
410 $content_actions['move'] = array('class' => 'inactive',
411 'text' => wfMsg('move'),
413 'ttip' => wfMsg('tooltip-nomove'),
419 //article doesn't exist or is deleted
420 if($wgUser->isSysop()){
421 if( $n = $wgTitle->isDeleted() ) {
422 $content_actions['delete'] = array(
424 'text' => wfMsg( "undelete_short", $n ),
425 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
),
426 'ttip' => wfMsg('tooltip-undelete', $n),
427 'akey' => wfMsg('accesskey-undelete')
433 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
434 if( !$wgTitle->userIsWatching()) {
435 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
436 'text' => wfMsg('watch'),
437 'href' => $this->makeUrl($this->thispage
, 'action=watch'),
438 'ttip' => wfMsg('tooltip-watch'),
439 'akey' => wfMsg('accesskey-watch'));
441 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
442 'text' => wfMsg('unwatch'),
443 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'),
444 'ttip' => wfMsg('tooltip-unwatch'),
445 'akey' => wfMsg('accesskey-unwatch'));
450 /* show special page tab */
452 $content_actions['article'] = array('class' => 'selected',
453 'text' => wfMsg('specialpage'),
455 'ttip' => wfMsg('tooltip-specialpage'),
459 return $content_actions;
462 # build array of common navigation links
463 function buildNavUrls () {
464 global $wgTitle, $wgUser, $wgRequest;
465 global $wgSiteSupportPage;
467 $action = $wgRequest->getText( 'action' );
468 $oldid = $wgRequest->getVal( 'oldid' );
469 $diff = $wgRequest->getVal( 'diff' );
470 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
472 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
473 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
474 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
475 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.$this->thispage
)));
476 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
477 $nav_urls['portal'] = (wfMsg('portal') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
478 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.$this->thispage
)));
479 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
480 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
481 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
482 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
483 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
484 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
487 $id=User
::idFromName($wgTitle->getText());
488 $ip=User
::isIP($wgTitle->getText());
490 if($id ||
$ip) { # both anons and non-anons have contri list
491 $nav_urls['contributions'] = array(
492 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
495 if ( 0 != $wgUser->getID() ) { # show only to signed in users
496 if($id) { # can only email non-anons
497 $nav_urls['emailuser'] = array(
498 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
507 function getNameSpaceWord () {
509 switch ($wgTitle->getNamespace()) {
512 return wfMsg('nstab-main');
515 return wfMsg('nstab-user');
517 return wfMsg('nstab-media');
519 return wfMsg('nstab-special');
522 return wfMsg('nstab-wp');
525 return wfMsg('nstab-image');
527 case NS_MEDIAWIKI_TALK
:
528 return wfMsg('nstab-mediawiki');
530 case NS_TEMPLATE_TALK
:
531 return wfMsg('nstab-template');
534 return wfMsg('nstab-help');
536 case NS_CATEGORY_TALK
:
537 return wfMsg('nstab-category');
539 return wfMsg('nstab-main');
542 /* private */ function setupUserCssJs () {
543 global $wgRequest, $wgTitle;
544 $action = $wgRequest->getText('action');
545 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
547 $this->usercss
= $wgRequest->getText('wpTextbox1');
549 $this->usercss
= '@import url('.
550 $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.css', 'action=raw&ctype=text/css').');';
552 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
553 # XXX: additional security check/prompt?
554 $this->userjsprev
= $wgRequest->getText('wpTextbox1');
556 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype=text/javascript');
561 class SkinDaVinci
extends SkinPHPTal
{
562 function initPage( &$out ) {
563 SkinPHPTal
::initPage( $out );
564 $this->skinname
= "davinci";
568 class SkinMono
extends SkinPHPTal
{
569 function initPage( &$out ) {
570 SkinPHPTal
::initPage( $out );
571 $this->skinname
= "mono";
575 class SkinMonoBook
extends SkinPHPTal
{
576 function initPage( &$out ) {
577 SkinPHPTal
::initPage( $out );
578 $this->skinname
= "monobook";