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, $wgStyleSheetPath, $wgLanguageCode, $wgUseNewInterlanguage;
66 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
67 global $wgDisableCounters, $wgLogo;
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->setRef( "title", &$this->titletxt
); // ?
87 $taction = $this->getPageTitleActionText();
88 $taction = !empty($taction)?
' - '.$taction:'';
89 $tpl->set( "pagetitle", wfMsg( "pagetitle", $this->titletxt
.$taction ) );
90 $tpl->setRef( "thispage", &$this->thispage
);
91 $tpl->set( "subtitle", $out->getSubtitle() );
92 $tpl->set( 'catlinks', getCategories());
93 $tpl->setRef( 'mimetype', &$wgMimeType );
94 $tpl->setRef( 'charset', &$wgOutputEncoding );
95 $tpl->set( 'headlinks', $out->getHeadLinks() );
96 $tpl->setRef( 'skinname', &$this->skinname
);
97 $tpl->setRef( "loggedin", &$this->loggedin
);
98 /* XXX currently unused, might get useful later
99 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
100 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
101 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
102 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
103 $tpl->set( "helppage", wfMsg('helppage'));
104 $tpl->set( "sysop", $wgUser->isSysop() );
106 $tpl->setRef( "searchaction", &$wgScript );
107 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
108 $tpl->setRef( "logopath", &$wgLogo );
109 $tpl->setRef( "lang", &$wgLanguageCode );
110 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
111 $tpl->setRef( "username", &$this->username
);
112 $tpl->setRef( "userpage", &$this->userpage
);
113 if( $wgUser->getNewtalk() ) {
114 $usertitle = Title
::newFromText( $this->userpage
);
115 $usertalktitle = $usertitle->getTalkPage();
116 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
118 $ntl = wfMsg( "newmessages",
119 $this->makeKnownLink(
120 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
121 . ":" . $this->username
,
122 wfMsg("newmessageslink") )
129 $tpl->setRef( "newtalk", &$ntl );
130 $tpl->setRef( "skin", &$this);
131 $tpl->set( "logo", $this->logoText() );
132 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
133 if ( !$wgDisableCounters ) {
134 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
136 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
139 $tpl->set('lastmod', $this->lastModified());
140 $tpl->set('copyright',$this->getCopyright());
142 $tpl->set( "copyrightico", $this->getCopyrightIcon() );
143 $tpl->set( "poweredbyico", $this->getPoweredBy() );
144 $tpl->set( "disclaimer", $this->disclaimerLink() );
145 $tpl->set( "about", $this->aboutLink() );
147 $tpl->setRef( "debug", &$out->mDebugtext
);
148 $tpl->set( "reporttime", $out->reportTime() );
150 $tpl->setRef( "bodytext", &$out->mBodytext
);
152 $language_urls = array();
153 foreach( $wgOut->getLanguageLinks() as $l ) {
154 $nt = Title
::newFromText( $l );
155 $language_urls[] = array('href' => $nt->getFullURL(),
156 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
157 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
159 if(count($language_urls)) {
160 $tpl->setRef( 'language_urls', &$language_urls);
162 $tpl->set('language_urls', false);
164 $tpl->set('personal_urls', $this->buildPersonalUrls());
165 $content_actions = $this->buildContentActionUrls();
166 $tpl->setRef('content_actions', &$content_actions);
167 // XXX: attach this from javascript, same with section editing
168 if(isset($content_actions['edit']['href']) &&
169 !(isset($content_actions['edit']['class']) && $content_actions['edit']['class'] != '') &&
170 $wgUser->getOption("editondblclick") )
172 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
174 $tpl->set('body-ondblclick', '');
176 $tpl->set( "nav_urls", $this->buildNavUrls() );
179 $res = $tpl->execute();
180 // result may be an error
181 if (PEAR
::isError($res)) {
182 echo $res->toString(), "\n";
189 # build array of urls for personal toolbar
190 function buildPersonalUrls() {
191 /* set up the default links for the personal toolbar */
192 global $wgShowIPinHeader;
193 $personal_urls = array();
194 if ($this->loggedin
) {
195 $personal_urls['userpage'] = array(
196 'text' => $this->username
,
197 'href' => $this->makeUrl($this->userpage
),
198 'ttip' => wfMsg('tooltip-userpage'),
199 'akey' => wfMsg('accesskey-userpage')
201 $personal_urls['mytalk'] = array(
202 'text' => wfMsg('mytalk'),
203 'href' => $this->makeTalkUrl($this->userpage
),
204 'ttip' => wfMsg('tooltip-mytalk'),
205 'akey' => wfMsg('accesskey-mytalk')
207 $personal_urls['preferences'] = array(
208 'text' => wfMsg('preferences'),
209 'href' => $this->makeSpecialUrl('Preferences'),
210 'ttip' => wfMsg('tooltip-preferences'),
211 'akey' => wfMsg('accesskey-preferences')
213 $personal_urls['watchlist'] = array(
214 'text' => wfMsg('watchlist'),
215 'href' => $this->makeSpecialUrl('Watchlist'),
216 'ttip' => wfMsg('tooltip-watchlist'),
217 'akey' => wfMsg('accesskey-watchlist')
219 $personal_urls['mycontris'] = array(
220 'text' => wfMsg('mycontris'),
221 'href' => $this->makeSpecialUrl('Contributions','target=' . $this->username
),
222 'ttip' => wfMsg('tooltip-mycontris'),
223 'akey' => wfMsg('accesskey-mycontris')
225 $personal_urls['logout'] = array(
226 'text' => wfMsg('userlogout'),
227 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . $this->thisurle
),
228 'ttip' => wfMsg('tooltip-logout'),
229 'akey' => wfMsg('accesskey-logout')
232 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
233 $personal_urls['anonuserpage'] = array(
234 'text' => $this->username
,
235 'href' => $this->makeUrl($this->userpage
),
236 'ttip' => wfMsg('tooltip-anonuserpage'),
237 'akey' => wfMsg('accesskey-anonuserpage')
239 $personal_urls['anontalk'] = array(
240 'text' => wfMsg('anontalk'),
241 'href' => $this->makeTalkUrl($this->userpage
),
242 'ttip' => wfMsg('tooltip-anontalk'),
243 'akey' => wfMsg('accesskey-anontalk')
245 $personal_urls['anonlogin'] = array(
246 'text' => wfMsg('userlogin'),
247 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
248 'ttip' => wfMsg('tooltip-login'),
249 'akey' => wfMsg('accesskey-login')
253 $personal_urls['login'] = array(
254 'text' => wfMsg('userlogin'),
255 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
256 'ttip' => wfMsg('tooltip-login'),
257 'akey' => wfMsg('accesskey-login')
262 return $personal_urls;
265 # an array of edit links by default used for the tabs
266 function buildContentActionUrls () {
267 global $wgTitle, $wgUser, $wgRequest;
268 $action = $wgRequest->getText( 'action' );
269 $oldid = $wgRequest->getVal( 'oldid' );
270 $diff = $wgRequest->getVal( 'diff' );
271 $content_actions = array();
273 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
276 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
277 'text' => wfMsg('article'),
278 'href' => $this->makeArticleUrl($this->thispage
),
279 'ttip' => wfMsg('tooltip-article'),
280 'akey' => wfMsg('accesskey-article'));
282 /* set up the classes for the talk link */
283 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : '');
284 $talktitle = Title
::newFromText( $this->titletxt
);
285 $talktitle = $talktitle->getTalkPage();
286 $this->checkTitle(&$talktitle, &$this->titletxt
);
287 if($talktitle->getArticleId() != 0) {
288 $content_actions['talk'] = array(
289 'class' => $talk_class,
290 'text' => wfMsg('talk'),
291 'href' => $this->makeTalkUrl($this->titletxt
),
292 'ttip' => wfMsg('tooltip-talk'),
293 'akey' => wfMsg('accesskey-talk')
296 $content_actions['talk'] = array(
297 'class' => $talk_class.' new',
298 'text' => wfMsg('talk'),
299 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit'),
300 'ttip' => wfMsg('tooltip-talk'),
301 'akey' => wfMsg('accesskey-talk')
305 if ( $wgTitle->userCanEdit() ) {
306 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
307 $content_actions['edit'] = array(
308 'class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
309 'text' => wfMsg('edit'),
310 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
311 'ttip' => wfMsg('tooltip-edit'),
312 'akey' => wfMsg('accesskey-edit')
315 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
316 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
317 'text' => wfMsg('viewsource'),
318 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
319 'ttip' => wfMsg('tooltip-viewsource'),
320 'akey' => wfMsg('accesskey-viewsource'));
323 if ( $wgTitle->getArticleId() ) {
325 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
326 'text' => wfMsg('history_short'),
327 'href' => $this->makeUrl($this->thispage
, 'action=history'),
328 'ttip' => wfMsg('tooltip-history'),
329 'akey' => wfMsg('accesskey-history'));
331 # XXX: is there a rollback action anywhere or is it planned?
332 # Don't recall where i got this from...
333 /*if( $wgUser->getNewtalk() ) {
334 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
335 'text' => wfMsg('rollback_short'),
336 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
337 'ttip' => wfMsg('tooltip-rollback'),
338 'akey' => wfMsg('accesskey-rollback'));
341 if($wgUser->isSysop()){
342 if(!$wgTitle->isProtected()){
343 $content_actions['protect'] = array(
344 'class' => ($action == 'protect') ?
'selected' : '',
345 'text' => wfMsg('protect'),
346 'href' => $this->makeUrl($this->thispage
, 'action=protect'),
347 'ttip' => wfMsg('tooltip-protect'),
348 'akey' => wfMsg('accesskey-protect')
352 $content_actions['unprotect'] = array(
353 'class' => ($action == 'unprotect') ?
'selected' : '',
354 'text' => wfMsg('unprotect'),
355 'href' => $this->makeUrl($this->thispage
, 'action=unprotect'),
356 'ttip' => wfMsg('tooltip-protect'),
357 'akey' => wfMsg('accesskey-protect')
360 $content_actions['delete'] = array(
361 'class' => ($action == 'delete') ?
'selected' : '',
362 'text' => wfMsg('delete'),
363 'href' => $this->makeUrl($this->thispage
, 'action=delete'),
364 'ttip' => wfMsg('tooltip-delete'),
365 'akey' => wfMsg('accesskey-delete')
368 if ( $wgUser->getID() != 0 ) {
369 if ( $wgTitle->userCanEdit()) {
370 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
371 'text' => wfMsg('move'),
372 'href' => $this->makeSpecialUrl('Movepage', 'target='.$this->thispage
),
373 'ttip' => wfMsg('tooltip-move'),
374 'akey' => wfMsg('accesskey-move'));
376 $content_actions['move'] = array('class' => 'inactive',
377 'text' => wfMsg('move'),
379 'ttip' => wfMsg('tooltip-nomove'),
385 //article doesn't exist or is deleted
386 if($wgUser->isSysop()){
387 if( $n = $wgTitle->isDeleted() ) {
388 $content_actions['delete'] = array(
390 'text' => wfMsg( "undelete_short", $n ),
391 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
),
392 'ttip' => wfMsg('tooltip-undelete', $n),
393 'akey' => wfMsg('accesskey-undelete')
399 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
400 if( !$wgTitle->userIsWatching()) {
401 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
402 'text' => wfMsg('watch'),
403 'href' => $this->makeUrl($this->thispage
, 'action=watch'),
404 'ttip' => wfMsg('tooltip-watch'),
405 'akey' => wfMsg('accesskey-watch'));
407 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
408 'text' => wfMsg('unwatch'),
409 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'),
410 'ttip' => wfMsg('tooltip-unwatch'),
411 'akey' => wfMsg('accesskey-unwatch'));
416 /* show special page tab */
418 $content_actions['article'] = array('class' => 'selected',
419 'text' => wfMsg('specialpage'),
421 'ttip' => wfMsg('tooltip-specialpage'),
425 return $content_actions;
428 # build array of common navigation links
429 function buildNavUrls () {
430 global $wgTitle, $wgUser, $wgRequest;
431 global $wgSiteSupportPage;
433 $action = $wgRequest->getText( 'action' );
434 $oldid = $wgRequest->getVal( 'oldid' );
435 $diff = $wgRequest->getVal( 'diff' );
436 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
438 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
439 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
440 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
441 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.$this->thispage
)));
442 $nav_urls['currentevents'] = (wfMsg('currentevents') != '') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : '';
443 $nav_urls['portal'] = (wfMsg('portal') != '') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : '';
444 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.$this->thispage
)));
445 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
446 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
447 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
448 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
449 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
450 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
453 $id=User
::idFromName($wgTitle->getText());
454 $ip=User
::isIP($wgTitle->getText());
456 if($id ||
$ip) { # both anons and non-anons have contri list
457 $nav_urls['contributions'] = array(
458 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
461 if ( 0 != $wgUser->getID() ) { # show only to signed in users
462 if($id) { # can only email non-anons
463 $nav_urls['emailuser'] = array(
464 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
473 function getPageTitleActionText () {
477 return wfMsg('edit');
479 return wfMsg('history_short');
481 return wfMsg('unprotect');
483 return wfMsg('unprotect');
485 return wfMsg('delete');
487 return wfMsg('watch');
489 return wfMsg('unwatch');
494 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
495 $title = Title
::makeTitle( NS_SPECIAL
, $name );
496 $this->checkTitle(&$title, &$name);
497 return $title->getLocalURL( $urlaction );
499 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
500 $title = Title
::newFromText( $name );
501 $title = $title->getTalkPage();
502 $this->checkTitle(&$title, &$name);
503 return $title->getLocalURL( $urlaction );
505 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
506 $title = Title
::newFromText( $name );
507 $title= $title->getSubjectPage();
508 $this->checkTitle(&$title, &$name);
509 return $title->getLocalURL( $urlaction );
511 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
512 $title = Title
::newFromText( wfMsg($name) );
513 $this->checkTitle(&$title, &$name);
514 return $title->getLocalURL( $urlaction );
516 /*static*/ function makeUrl ( $name, $urlaction='' ) {
517 $title = Title
::newFromText( $name );
518 $this->checkTitle(&$title, &$name);
519 return $title->getLocalURL( $urlaction );
522 # make sure we have some title to operate on, mind the '&'
523 /*static*/ function checkTitle ( &$title, &$name ) {
524 if(!is_object($title)) {
525 $title = Title
::newFromText( $name );
526 if(!is_object($title)) {
527 $title = Title
::newFromText( '<error: link target missing>' );
535 class SkinDaVinci
extends SkinPHPTal
{
536 function initPage( &$out ) {
537 SkinPHPTal
::initPage( $out );
538 $this->skinname
= "davinci";
542 class SkinMono
extends SkinPHPTal
{
543 function initPage( &$out ) {
544 SkinPHPTal
::initPage( $out );
545 $this->skinname
= "mono";
549 class SkinMonoBook
extends SkinPHPTal
{
550 function initPage( &$out ) {
551 SkinPHPTal
::initPage( $out );
552 $this->skinname
= "monobook";