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 "PHPTAL.php";
31 class MediaWiki_I18N
extends PHPTAL_I18N
33 var $_context = array();
35 function set($varName, $value)
37 $this->_context
[$varName] = $value;
40 function translate($value)
42 $value = wfMsg( $value );
44 // interpolate variables
45 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
46 list($src, $var) = $m;
47 $varValue = $this->_context
[$var];
48 $value = str_replace($src, $varValue, $value);
54 class SkinPHPTal
extends Skin
{
57 function initPage( &$out ) {
58 parent
::initPage( $out );
59 $this->skinname
= "davinci";
60 $this->template
= "xhtml_slim";
63 function outputPage( &$out ) {
64 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
65 global $wgScript, $wgStylePath, $wgLanguageCode, $wgUseNewInterlanguage;
66 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
67 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
69 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
71 $this->thispage
= $wgTitle->getPrefixedDbKey();
72 $this->thisurl
= $wgTitle->getPrefixedURL();
73 $this->thisurle
= urlencode($this->thisurl
);
74 $this->loggedin
= $wgUser->getID() != 0;
75 $this->username
= $wgUser->getName();
76 $this->userpage
= $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
77 $this->titletxt
= $wgTitle->getPrefixedText();
79 $this->initPage( $out );
80 $tpl = new PHPTAL($this->template
. '.pt', 'templates');
82 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
83 $tpl->setTranslator(new MediaWiki_I18N());
86 $tpl->set( "title", $wgOut->getPageTitle() );
87 $tpl->set( "pagetitle", $wgOut->getHTMLTitle() );
89 $tpl->setRef( "thispage", &$this->thispage
);
90 $tpl->set( "subtitle", $out->getSubtitle() );
91 $tpl->set( 'catlinks', getCategories());
92 if( $wgOut->isSyndicated() ) {
94 foreach( $wgFeedClasses as $format => $class ) {
95 $feeds[$format] = array(
97 'href' => $wgRequest->appendQuery( "feed=$format" ),
98 'ttip' => wfMsg('tooltip-'.$format)
101 $tpl->setRef( 'feeds', &$feeds );
103 $tpl->setRef( 'mimetype', &$wgMimeType );
104 $tpl->setRef( 'charset', &$wgOutputEncoding );
105 $tpl->set( 'headlinks', $out->getHeadLinks() );
106 $tpl->setRef( 'skinname', &$this->skinname
);
107 $tpl->setRef( "loggedin", &$this->loggedin
);
108 /* XXX currently unused, might get useful later
109 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
110 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
111 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
112 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
113 $tpl->set( "helppage", wfMsg('helppage'));
114 $tpl->set( "sysop", $wgUser->isSysop() );
116 $tpl->set( "searchaction", $this->escapeSearchLink() );
117 $tpl->setRef( "stylepath", &$wgStylePath );
118 $tpl->setRef( "logopath", &$wgLogo );
119 $tpl->setRef( "lang", &$wgLanguageCode );
120 $tpl->set( "dir", $wgLang->isRTL() ?
"rtl" : "ltr" );
121 $tpl->set( "rtl", $wgLang->isRTL() );
122 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
123 $tpl->setRef( "username", &$this->username
);
124 $tpl->setRef( "userpage", &$this->userpage
);
125 if( $wgUser->getNewtalk() ) {
126 $usertitle = Title
::newFromText( $this->userpage
);
127 $usertalktitle = $usertitle->getTalkPage();
128 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
130 $ntl = wfMsg( "newmessages",
131 $this->makeKnownLink(
132 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
133 . ":" . $this->username
,
134 wfMsg("newmessageslink") )
141 $tpl->setRef( "newtalk", &$ntl );
142 $tpl->setRef( "skin", &$this);
143 $tpl->set( "logo", $this->logoText() );
144 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
145 if ( !$wgDisableCounters ) {
146 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
148 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
151 $tpl->set('lastmod', $this->lastModified());
152 $tpl->set('copyright',$this->getCopyright());
154 $tpl->set( "copyrightico", $this->getCopyrightIcon() );
155 $tpl->set( "poweredbyico", $this->getPoweredBy() );
156 $tpl->set( "disclaimer", $this->disclaimerLink() );
157 $tpl->set( "about", $this->aboutLink() );
159 $tpl->setRef( "debug", &$out->mDebugtext
);
160 $tpl->set( "reporttime", $out->reportTime() );
162 $tpl->setRef( "bodytext", &$out->mBodytext
);
164 $language_urls = array();
165 foreach( $wgOut->getLanguageLinks() as $l ) {
166 $nt = Title
::newFromText( $l );
167 $language_urls[] = array('href' => $nt->getFullURL(),
168 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
169 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
171 if(count($language_urls)) {
172 $tpl->setRef( 'language_urls', &$language_urls);
174 $tpl->set('language_urls', false);
176 $tpl->set('personal_urls', $this->buildPersonalUrls());
177 $content_actions = $this->buildContentActionUrls();
178 $tpl->setRef('content_actions', &$content_actions);
179 // XXX: attach this from javascript, same with section editing
180 if(isset($content_actions['edit']['href']) &&
181 !(isset($content_actions['edit']['class']) && $content_actions['edit']['class'] != '') &&
182 $wgUser->getOption("editondblclick") )
184 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
186 $tpl->set('body-ondblclick', '');
188 $tpl->set( "nav_urls", $this->buildNavUrls() );
191 $res = $tpl->execute();
192 // result may be an error
193 if (PEAR
::isError($res)) {
194 echo $res->toString(), "\n";
201 # build array of urls for personal toolbar
202 function buildPersonalUrls() {
203 /* set up the default links for the personal toolbar */
204 global $wgShowIPinHeader;
205 $personal_urls = array();
206 if ($this->loggedin
) {
207 $personal_urls['userpage'] = array(
208 'text' => $this->username
,
209 'href' => $this->makeUrl($this->userpage
),
210 'ttip' => wfMsg('tooltip-userpage'),
211 'akey' => wfMsg('accesskey-userpage')
213 $personal_urls['mytalk'] = array(
214 'text' => wfMsg('mytalk'),
215 'href' => $this->makeTalkUrl($this->userpage
),
216 'ttip' => wfMsg('tooltip-mytalk'),
217 'akey' => wfMsg('accesskey-mytalk')
219 $personal_urls['preferences'] = array(
220 'text' => wfMsg('preferences'),
221 'href' => $this->makeSpecialUrl('Preferences'),
222 'ttip' => wfMsg('tooltip-preferences'),
223 'akey' => wfMsg('accesskey-preferences')
225 $personal_urls['watchlist'] = array(
226 'text' => wfMsg('watchlist'),
227 'href' => $this->makeSpecialUrl('Watchlist'),
228 'ttip' => wfMsg('tooltip-watchlist'),
229 'akey' => wfMsg('accesskey-watchlist')
231 $personal_urls['mycontris'] = array(
232 'text' => wfMsg('mycontris'),
233 'href' => $this->makeSpecialUrl('Contributions','target=' . $this->username
),
234 'ttip' => wfMsg('tooltip-mycontris'),
235 'akey' => wfMsg('accesskey-mycontris')
237 $personal_urls['logout'] = array(
238 'text' => wfMsg('userlogout'),
239 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . $this->thisurle
),
240 'ttip' => wfMsg('tooltip-logout'),
241 'akey' => wfMsg('accesskey-logout')
244 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
245 $personal_urls['anonuserpage'] = array(
246 'text' => $this->username
,
247 'href' => $this->makeUrl($this->userpage
),
248 'ttip' => wfMsg('tooltip-anonuserpage'),
249 'akey' => wfMsg('accesskey-anonuserpage')
251 $personal_urls['anontalk'] = array(
252 'text' => wfMsg('anontalk'),
253 'href' => $this->makeTalkUrl($this->userpage
),
254 'ttip' => wfMsg('tooltip-anontalk'),
255 'akey' => wfMsg('accesskey-anontalk')
257 $personal_urls['anonlogin'] = array(
258 'text' => wfMsg('userlogin'),
259 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
260 'ttip' => wfMsg('tooltip-login'),
261 'akey' => wfMsg('accesskey-login')
265 $personal_urls['login'] = array(
266 'text' => wfMsg('userlogin'),
267 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
268 'ttip' => wfMsg('tooltip-login'),
269 'akey' => wfMsg('accesskey-login')
274 return $personal_urls;
277 # an array of edit links by default used for the tabs
278 function buildContentActionUrls () {
279 global $wgTitle, $wgUser, $wgRequest;
280 $action = $wgRequest->getText( 'action' );
281 $oldid = $wgRequest->getVal( 'oldid' );
282 $diff = $wgRequest->getVal( 'diff' );
283 $content_actions = array();
285 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
288 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
289 'text' => wfMsg('article'),
290 'href' => $this->makeArticleUrl($this->thispage
),
291 'ttip' => wfMsg('tooltip-article'),
292 'akey' => wfMsg('accesskey-article'));
294 /* set up the classes for the talk link */
295 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : '');
296 $talktitle = Title
::newFromText( $this->titletxt
);
297 $talktitle = $talktitle->getTalkPage();
298 $this->checkTitle(&$talktitle, &$this->titletxt
);
299 if($talktitle->getArticleId() != 0) {
300 $content_actions['talk'] = array(
301 'class' => $talk_class,
302 'text' => wfMsg('talk'),
303 'href' => $this->makeTalkUrl($this->titletxt
),
304 'ttip' => wfMsg('tooltip-talk'),
305 'akey' => wfMsg('accesskey-talk')
308 $content_actions['talk'] = array(
309 'class' => $talk_class?
$talk_class.' new':'new',
310 'text' => wfMsg('talk'),
311 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit'),
312 'ttip' => wfMsg('tooltip-talk'),
313 'akey' => wfMsg('accesskey-talk')
317 if ( $wgTitle->userCanEdit() ) {
318 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
319 $content_actions['edit'] = array(
320 'class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
321 'text' => wfMsg('edit'),
322 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
323 'ttip' => wfMsg('tooltip-edit'),
324 'akey' => wfMsg('accesskey-edit')
327 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
328 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
329 'text' => wfMsg('viewsource'),
330 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
331 'ttip' => wfMsg('tooltip-viewsource'),
332 'akey' => wfMsg('accesskey-viewsource'));
335 if ( $wgTitle->getArticleId() ) {
337 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
338 'text' => wfMsg('history_short'),
339 'href' => $this->makeUrl($this->thispage
, 'action=history'),
340 'ttip' => wfMsg('tooltip-history'),
341 'akey' => wfMsg('accesskey-history'));
343 # XXX: is there a rollback action anywhere or is it planned?
344 # Don't recall where i got this from...
345 /*if( $wgUser->getNewtalk() ) {
346 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
347 'text' => wfMsg('rollback_short'),
348 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
349 'ttip' => wfMsg('tooltip-rollback'),
350 'akey' => wfMsg('accesskey-rollback'));
353 if($wgUser->isSysop()){
354 if(!$wgTitle->isProtected()){
355 $content_actions['protect'] = array(
356 'class' => ($action == 'protect') ?
'selected' : '',
357 'text' => wfMsg('protect'),
358 'href' => $this->makeUrl($this->thispage
, 'action=protect'),
359 'ttip' => wfMsg('tooltip-protect'),
360 'akey' => wfMsg('accesskey-protect')
364 $content_actions['unprotect'] = array(
365 'class' => ($action == 'unprotect') ?
'selected' : '',
366 'text' => wfMsg('unprotect'),
367 'href' => $this->makeUrl($this->thispage
, 'action=unprotect'),
368 'ttip' => wfMsg('tooltip-protect'),
369 'akey' => wfMsg('accesskey-protect')
372 $content_actions['delete'] = array(
373 'class' => ($action == 'delete') ?
'selected' : '',
374 'text' => wfMsg('delete'),
375 'href' => $this->makeUrl($this->thispage
, 'action=delete'),
376 'ttip' => wfMsg('tooltip-delete'),
377 'akey' => wfMsg('accesskey-delete')
380 if ( $wgUser->getID() != 0 ) {
381 if ( $wgTitle->userCanEdit()) {
382 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
383 'text' => wfMsg('move'),
384 'href' => $this->makeSpecialUrl('Movepage', 'target='.$this->thispage
),
385 'ttip' => wfMsg('tooltip-move'),
386 'akey' => wfMsg('accesskey-move'));
388 $content_actions['move'] = array('class' => 'inactive',
389 'text' => wfMsg('move'),
391 'ttip' => wfMsg('tooltip-nomove'),
397 //article doesn't exist or is deleted
398 if($wgUser->isSysop()){
399 if( $n = $wgTitle->isDeleted() ) {
400 $content_actions['delete'] = array(
402 'text' => wfMsg( "undelete_short", $n ),
403 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
),
404 'ttip' => wfMsg('tooltip-undelete', $n),
405 'akey' => wfMsg('accesskey-undelete')
411 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
412 if( !$wgTitle->userIsWatching()) {
413 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
414 'text' => wfMsg('watch'),
415 'href' => $this->makeUrl($this->thispage
, 'action=watch'),
416 'ttip' => wfMsg('tooltip-watch'),
417 'akey' => wfMsg('accesskey-watch'));
419 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
420 'text' => wfMsg('unwatch'),
421 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'),
422 'ttip' => wfMsg('tooltip-unwatch'),
423 'akey' => wfMsg('accesskey-unwatch'));
428 /* show special page tab */
430 $content_actions['article'] = array('class' => 'selected',
431 'text' => wfMsg('specialpage'),
433 'ttip' => wfMsg('tooltip-specialpage'),
437 return $content_actions;
440 # build array of common navigation links
441 function buildNavUrls () {
442 global $wgTitle, $wgUser, $wgRequest;
443 global $wgSiteSupportPage;
445 $action = $wgRequest->getText( 'action' );
446 $oldid = $wgRequest->getVal( 'oldid' );
447 $diff = $wgRequest->getVal( 'diff' );
448 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
450 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
451 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
452 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
453 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.$this->thispage
)));
454 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : '';
455 $nav_urls['portal'] = (wfMsg('portal') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : '';
456 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.$this->thispage
)));
457 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
458 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
459 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
460 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
461 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
462 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
465 $id=User
::idFromName($wgTitle->getText());
466 $ip=User
::isIP($wgTitle->getText());
468 if($id ||
$ip) { # both anons and non-anons have contri list
469 $nav_urls['contributions'] = array(
470 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
473 if ( 0 != $wgUser->getID() ) { # show only to signed in users
474 if($id) { # can only email non-anons
475 $nav_urls['emailuser'] = array(
476 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
485 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
486 $title = Title
::makeTitle( NS_SPECIAL
, $name );
487 $this->checkTitle(&$title, &$name);
488 return $title->getLocalURL( $urlaction );
490 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
491 $title = Title
::newFromText( $name );
492 $title = $title->getTalkPage();
493 $this->checkTitle(&$title, &$name);
494 return $title->getLocalURL( $urlaction );
496 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
497 $title = Title
::newFromText( $name );
498 $title= $title->getSubjectPage();
499 $this->checkTitle(&$title, &$name);
500 return $title->getLocalURL( $urlaction );
502 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
503 $title = Title
::newFromText( wfMsg($name) );
504 $this->checkTitle(&$title, &$name);
505 return $title->getLocalURL( $urlaction );
507 /*static*/ function makeUrl ( $name, $urlaction='' ) {
508 $title = Title
::newFromText( $name );
509 $this->checkTitle(&$title, &$name);
510 return $title->getLocalURL( $urlaction );
513 # make sure we have some title to operate on, mind the '&'
514 /*static*/ function checkTitle ( &$title, &$name ) {
515 if(!is_object($title)) {
516 $title = Title
::newFromText( $name );
517 if(!is_object($title)) {
518 $title = Title
::newFromText( '<error: link target missing>' );
526 class SkinDaVinci
extends SkinPHPTal
{
527 function initPage( &$out ) {
528 SkinPHPTal
::initPage( $out );
529 $this->skinname
= "davinci";
533 class SkinMono
extends SkinPHPTal
{
534 function initPage( &$out ) {
535 SkinPHPTal
::initPage( $out );
536 $this->skinname
= "mono";
540 class SkinMonoBook
extends SkinPHPTal
{
541 function initPage( &$out ) {
542 SkinPHPTal
::initPage( $out );
543 $this->skinname
= "monobook";