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) {
36 $this->_context
[$varName] = $value;
39 function translate($value) {
40 $value = wfMsg( $value );
41 // interpolate variables
42 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
43 list($src, $var) = $m;
44 $varValue = @$this->_context
[$var];
45 $value = str_replace($src, $varValue, $value);
51 class SkinPHPTal
extends Skin
{
54 function initPage( &$out ) {
55 parent
::initPage( $out );
56 $this->skinname
= "davinci";
57 $this->template
= "xhtml_slim";
60 function outputPage( &$out ) {
61 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
62 global $wgScript, $wgStylePath, $wgLanguageCode, $wgUseNewInterlanguage;
63 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
64 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses;
66 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
68 $this->thispage
= $wgTitle->getPrefixedDbKey();
69 $this->thisurl
= $wgTitle->getPrefixedURL();
70 $this->thisurle
= urlencode($this->thisurl
);
71 $this->loggedin
= $wgUser->getID() != 0;
72 $this->username
= $wgUser->getName();
73 $this->userpage
= $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
74 $this->userpageurl
= $this->makeUrl($this->userpage
);
75 $this->userpageurle
= htmlspecialchars($this->userpageurl
);
76 $this->titletxt
= $wgTitle->getPrefixedText();
78 $this->initPage( $out );
79 $tpl = new PHPTAL($this->template
. '.pt', 'templates');
81 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
82 $tpl->setTranslator(new MediaWiki_I18N());
85 $tpl->set( "title", $wgOut->getPageTitle() );
86 $tpl->set( "pagetitle", $wgOut->getHTMLTitle() );
88 $tpl->setRef( "thispage", &$this->thispage
);
89 $subpagestr = $this->subPageSubtitle();
91 "subtitle", !empty($subpagestr)?
92 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
95 $tpl->set( 'catlinks', $this->getCategories());
96 if( $wgOut->isSyndicated() ) {
98 foreach( $wgFeedClasses as $format => $class ) {
99 $feeds[$format] = array(
101 'href' => $wgRequest->appendQuery( "feed=$format" ),
102 'ttip' => wfMsg('tooltip-'.$format)
105 $tpl->setRef( 'feeds', &$feeds );
107 $tpl->setRef( 'mimetype', &$wgMimeType );
108 $tpl->setRef( 'charset', &$wgOutputEncoding );
109 $tpl->set( 'headlinks', $out->getHeadLinks() );
110 $tpl->setRef( 'skinname', &$this->skinname
);
111 $tpl->setRef( "loggedin", &$this->loggedin
);
112 /* XXX currently unused, might get useful later
113 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
114 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
115 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
116 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
117 $tpl->set( "helppage", wfMsg('helppage'));
118 $tpl->set( "sysop", $wgUser->isSysop() );
120 $tpl->set( "searchaction", $this->escapeSearchLink() );
121 $tpl->setRef( "stylepath", &$wgStylePath );
122 $tpl->setRef( "logopath", &$wgLogo );
123 $tpl->setRef( "lang", &$wgLanguageCode );
124 $tpl->set( "dir", $wgLang->isRTL() ?
"rtl" : "ltr" );
125 $tpl->set( "rtl", $wgLang->isRTL() );
126 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
127 $tpl->setRef( "username", &$this->username
);
128 $tpl->setRef( "userpage", &$this->userpage
);
129 $tpl->setRef( "userpageurl", &$this->userpageurl
);
130 $tpl->setRef( "userpageurle", &$this->userpageurle
);
131 if( $wgUser->getNewtalk() ) {
132 $usertitle = Title
::newFromText( $this->userpage
);
133 $usertalktitle = $usertitle->getTalkPage();
134 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
136 $ntl = wfMsg( "newmessages",
137 $this->makeKnownLink(
138 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
139 . ":" . $this->username
,
140 wfMsg("newmessageslink") )
147 $tpl->setRef( "newtalk", &$ntl );
148 $tpl->setRef( "skin", &$this);
149 $tpl->set( "logo", $this->logoText() );
150 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
151 if ( !$wgDisableCounters ) {
152 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
154 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
157 $tpl->set('lastmod', $this->lastModified());
158 $tpl->set('copyright',$this->getCopyright());
160 $tpl->set( "copyrightico", $this->getCopyrightIcon() );
161 $tpl->set( "poweredbyico", $this->getPoweredBy() );
162 $tpl->set( "disclaimer", $this->disclaimerLink() );
163 $tpl->set( "about", $this->aboutLink() );
165 $tpl->setRef( "debug", &$out->mDebugtext
);
166 $tpl->set( "reporttime", $out->reportTime() );
168 $tpl->setRef( "bodytext", &$out->mBodytext
);
170 $language_urls = array();
171 foreach( $wgOut->getLanguageLinks() as $l ) {
172 $nt = Title
::newFromText( $l );
173 $language_urls[] = array('href' => $nt->getFullURL(),
174 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
175 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
177 if(count($language_urls)) {
178 $tpl->setRef( 'language_urls', &$language_urls);
180 $tpl->set('language_urls', false);
182 $tpl->set('personal_urls', $this->buildPersonalUrls());
183 $content_actions = $this->buildContentActionUrls();
184 $tpl->setRef('content_actions', &$content_actions);
185 // XXX: attach this from javascript, same with section editing
186 if(isset($content_actions['edit']['href']) &&
187 !(isset($content_actions['edit']['class']) && $content_actions['edit']['class'] != '') &&
188 $wgUser->getOption("editondblclick") )
190 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
192 $tpl->set('body-ondblclick', '');
194 $tpl->set( "nav_urls", $this->buildNavUrls() );
197 $res = $tpl->execute();
198 // result may be an error
199 if (PEAR
::isError($res)) {
200 echo $res->toString(), "\n";
207 # build array of urls for personal toolbar
208 function buildPersonalUrls() {
209 /* set up the default links for the personal toolbar */
210 global $wgShowIPinHeader;
211 $personal_urls = array();
212 if ($this->loggedin
) {
213 $personal_urls['userpage'] = array(
214 'text' => $this->username
,
215 'href' => &$this->userpageurl
,
216 'ttip' => wfMsg('tooltip-userpage'),
217 'akey' => wfMsg('accesskey-userpage')
219 $personal_urls['mytalk'] = array(
220 'text' => wfMsg('mytalk'),
221 'href' => $this->makeTalkUrl($this->userpage
),
222 'ttip' => wfMsg('tooltip-mytalk'),
223 'akey' => wfMsg('accesskey-mytalk')
225 $personal_urls['preferences'] = array(
226 'text' => wfMsg('preferences'),
227 'href' => $this->makeSpecialUrl('Preferences'),
228 'ttip' => wfMsg('tooltip-preferences'),
229 'akey' => wfMsg('accesskey-preferences')
231 $personal_urls['watchlist'] = array(
232 'text' => wfMsg('watchlist'),
233 'href' => $this->makeSpecialUrl('Watchlist'),
234 'ttip' => wfMsg('tooltip-watchlist'),
235 'akey' => wfMsg('accesskey-watchlist')
237 $personal_urls['mycontris'] = array(
238 'text' => wfMsg('mycontris'),
239 'href' => $this->makeSpecialUrl('Contributions','target=' . $this->username
),
240 'ttip' => wfMsg('tooltip-mycontris'),
241 'akey' => wfMsg('accesskey-mycontris')
243 $personal_urls['logout'] = array(
244 'text' => wfMsg('userlogout'),
245 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . $this->thisurle
),
246 'ttip' => wfMsg('tooltip-logout'),
247 'akey' => wfMsg('accesskey-logout')
250 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
251 $personal_urls['anonuserpage'] = array(
252 'text' => $this->username
,
253 'href' => $this->makeUrl($this->userpage
),
254 'ttip' => wfMsg('tooltip-anonuserpage'),
255 'akey' => wfMsg('accesskey-anonuserpage')
257 $personal_urls['anontalk'] = array(
258 'text' => wfMsg('anontalk'),
259 'href' => $this->makeTalkUrl($this->userpage
),
260 'ttip' => wfMsg('tooltip-anontalk'),
261 'akey' => wfMsg('accesskey-anontalk')
263 $personal_urls['anonlogin'] = array(
264 'text' => wfMsg('userlogin'),
265 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
266 'ttip' => wfMsg('tooltip-login'),
267 'akey' => wfMsg('accesskey-login')
271 $personal_urls['login'] = array(
272 'text' => wfMsg('userlogin'),
273 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
274 'ttip' => wfMsg('tooltip-login'),
275 'akey' => wfMsg('accesskey-login')
280 return $personal_urls;
283 # an array of edit links by default used for the tabs
284 function buildContentActionUrls () {
285 global $wgTitle, $wgUser, $wgRequest;
286 $action = $wgRequest->getText( 'action' );
287 $oldid = $wgRequest->getVal( 'oldid' );
288 $diff = $wgRequest->getVal( 'diff' );
289 $content_actions = array();
291 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
294 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
295 'text' => wfMsg('article'),
296 'href' => $this->makeArticleUrl($this->thispage
),
297 'ttip' => wfMsg('tooltip-article'),
298 'akey' => wfMsg('accesskey-article'));
300 /* set up the classes for the talk link */
301 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : '');
302 $talktitle = Title
::newFromText( $this->titletxt
);
303 $talktitle = $talktitle->getTalkPage();
304 $this->checkTitle(&$talktitle, &$this->titletxt
);
305 if($talktitle->getArticleId() != 0) {
306 $content_actions['talk'] = array(
307 'class' => $talk_class,
308 'text' => wfMsg('talk'),
309 'href' => $this->makeTalkUrl($this->titletxt
),
310 'ttip' => wfMsg('tooltip-talk'),
311 'akey' => wfMsg('accesskey-talk')
314 $content_actions['talk'] = array(
315 'class' => $talk_class?
$talk_class.' new':'new',
316 'text' => wfMsg('talk'),
317 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit'),
318 'ttip' => wfMsg('tooltip-talk'),
319 'akey' => wfMsg('accesskey-talk')
323 if ( $wgTitle->userCanEdit() ) {
324 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
325 $content_actions['edit'] = array(
326 'class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
327 'text' => wfMsg('edit'),
328 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
329 'ttip' => wfMsg('tooltip-edit'),
330 'akey' => wfMsg('accesskey-edit')
333 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
334 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
335 'text' => wfMsg('viewsource'),
336 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
337 'ttip' => wfMsg('tooltip-viewsource'),
338 'akey' => wfMsg('accesskey-viewsource'));
341 if ( $wgTitle->getArticleId() ) {
343 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
344 'text' => wfMsg('history_short'),
345 'href' => $this->makeUrl($this->thispage
, 'action=history'),
346 'ttip' => wfMsg('tooltip-history'),
347 'akey' => wfMsg('accesskey-history'));
349 # XXX: is there a rollback action anywhere or is it planned?
350 # Don't recall where i got this from...
351 /*if( $wgUser->getNewtalk() ) {
352 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
353 'text' => wfMsg('rollback_short'),
354 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
355 'ttip' => wfMsg('tooltip-rollback'),
356 'akey' => wfMsg('accesskey-rollback'));
359 if($wgUser->isSysop()){
360 if(!$wgTitle->isProtected()){
361 $content_actions['protect'] = array(
362 'class' => ($action == 'protect') ?
'selected' : '',
363 'text' => wfMsg('protect'),
364 'href' => $this->makeUrl($this->thispage
, 'action=protect'),
365 'ttip' => wfMsg('tooltip-protect'),
366 'akey' => wfMsg('accesskey-protect')
370 $content_actions['unprotect'] = array(
371 'class' => ($action == 'unprotect') ?
'selected' : '',
372 'text' => wfMsg('unprotect'),
373 'href' => $this->makeUrl($this->thispage
, 'action=unprotect'),
374 'ttip' => wfMsg('tooltip-protect'),
375 'akey' => wfMsg('accesskey-protect')
378 $content_actions['delete'] = array(
379 'class' => ($action == 'delete') ?
'selected' : '',
380 'text' => wfMsg('delete'),
381 'href' => $this->makeUrl($this->thispage
, 'action=delete'),
382 'ttip' => wfMsg('tooltip-delete'),
383 'akey' => wfMsg('accesskey-delete')
386 if ( $wgUser->getID() != 0 ) {
387 if ( $wgTitle->userCanEdit()) {
388 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
389 'text' => wfMsg('move'),
390 'href' => $this->makeSpecialUrl('Movepage', 'target='.$this->thispage
),
391 'ttip' => wfMsg('tooltip-move'),
392 'akey' => wfMsg('accesskey-move'));
394 $content_actions['move'] = array('class' => 'inactive',
395 'text' => wfMsg('move'),
397 'ttip' => wfMsg('tooltip-nomove'),
403 //article doesn't exist or is deleted
404 if($wgUser->isSysop()){
405 if( $n = $wgTitle->isDeleted() ) {
406 $content_actions['delete'] = array(
408 'text' => wfMsg( "undelete_short", $n ),
409 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
),
410 'ttip' => wfMsg('tooltip-undelete', $n),
411 'akey' => wfMsg('accesskey-undelete')
417 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
418 if( !$wgTitle->userIsWatching()) {
419 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
420 'text' => wfMsg('watch'),
421 'href' => $this->makeUrl($this->thispage
, 'action=watch'),
422 'ttip' => wfMsg('tooltip-watch'),
423 'akey' => wfMsg('accesskey-watch'));
425 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
426 'text' => wfMsg('unwatch'),
427 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'),
428 'ttip' => wfMsg('tooltip-unwatch'),
429 'akey' => wfMsg('accesskey-unwatch'));
434 /* show special page tab */
436 $content_actions['article'] = array('class' => 'selected',
437 'text' => wfMsg('specialpage'),
439 'ttip' => wfMsg('tooltip-specialpage'),
443 return $content_actions;
446 # build array of common navigation links
447 function buildNavUrls () {
448 global $wgTitle, $wgUser, $wgRequest;
449 global $wgSiteSupportPage;
451 $action = $wgRequest->getText( 'action' );
452 $oldid = $wgRequest->getVal( 'oldid' );
453 $diff = $wgRequest->getVal( 'diff' );
454 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
456 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
457 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
458 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
459 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.$this->thispage
)));
460 $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : '';
461 $nav_urls['portal'] = (wfMsg('portal') != '-') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : '';
462 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.$this->thispage
)));
463 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
464 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
465 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
466 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
467 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
468 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
471 $id=User
::idFromName($wgTitle->getText());
472 $ip=User
::isIP($wgTitle->getText());
474 if($id ||
$ip) { # both anons and non-anons have contri list
475 $nav_urls['contributions'] = array(
476 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
479 if ( 0 != $wgUser->getID() ) { # show only to signed in users
480 if($id) { # can only email non-anons
481 $nav_urls['emailuser'] = array(
482 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
491 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
492 $title = Title
::makeTitle( NS_SPECIAL
, $name );
493 $this->checkTitle(&$title, &$name);
494 return $title->getLocalURL( $urlaction );
496 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
497 $title = Title
::newFromText( $name );
498 $title = $title->getTalkPage();
499 $this->checkTitle(&$title, &$name);
500 return $title->getLocalURL( $urlaction );
502 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
503 $title = Title
::newFromText( $name );
504 $title= $title->getSubjectPage();
505 $this->checkTitle(&$title, &$name);
506 return $title->getLocalURL( $urlaction );
508 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
509 $title = Title
::newFromText( wfMsg($name) );
510 $this->checkTitle(&$title, &$name);
511 return $title->getLocalURL( $urlaction );
513 /*static*/ function makeUrl ( $name, $urlaction='' ) {
514 $title = Title
::newFromText( $name );
515 $this->checkTitle(&$title, &$name);
516 return $title->getLocalURL( $urlaction );
519 # make sure we have some title to operate on, mind the '&'
520 /*static*/ function checkTitle ( &$title, &$name ) {
521 if(!is_object($title)) {
522 $title = Title
::newFromText( $name );
523 if(!is_object($title)) {
524 $title = Title
::newFromText( '<error: link target missing>' );
532 class SkinDaVinci
extends SkinPHPTal
{
533 function initPage( &$out ) {
534 SkinPHPTal
::initPage( $out );
535 $this->skinname
= "davinci";
539 class SkinMono
extends SkinPHPTal
{
540 function initPage( &$out ) {
541 SkinPHPTal
::initPage( $out );
542 $this->skinname
= "mono";
546 class SkinMonoBook
extends SkinPHPTal
{
547 function initPage( &$out ) {
548 SkinPHPTal
::initPage( $out );
549 $this->skinname
= "monobook";