39dbe70edd8190b20292e55820e082e79709581c
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, $action;
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
); // ?
88 $taction = $this->getPageTitleActionText();
89 $taction = !empty($taction)?
' - '.$taction:'';
90 } else { $taction = ''; }
91 $tpl->set( "pagetitle", wfMsg( "pagetitle", $this->titletxt
.$taction ) );
92 $tpl->setRef( "thispage", &$this->thispage
);
93 $tpl->set( "subtitle", $out->getSubtitle() );
94 $tpl->set( 'catlinks', getCategories());
95 $tpl->setRef( 'mimetype', &$wgMimeType );
96 $tpl->setRef( 'charset', &$wgOutputEncoding );
97 $tpl->set( 'headlinks', $out->getHeadLinks() );
98 $tpl->setRef( 'skinname', &$this->skinname
);
99 $tpl->setRef( "loggedin", &$this->loggedin
);
100 /* XXX currently unused, might get useful later
101 $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
102 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
103 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
104 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
105 $tpl->set( "helppage", wfMsg('helppage'));
106 $tpl->set( "sysop", $wgUser->isSysop() );
108 $tpl->setRef( "searchaction", &$wgScript );
109 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
110 $tpl->setRef( "logopath", &$wgLogo );
111 $tpl->setRef( "lang", &$wgLanguageCode );
112 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
113 $tpl->setRef( "username", &$this->username
);
114 $tpl->setRef( "userpage", &$this->userpage
);
115 if( $wgUser->getNewtalk() ) {
116 $usertitle = Title
::newFromText( $this->userpage
);
117 $usertalktitle = $usertitle->getTalkPage();
118 if($usertalktitle->getPrefixedDbKey() != $this->thispage
){
120 $ntl = wfMsg( "newmessages",
121 $this->makeKnownLink(
122 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
123 . ":" . $this->username
,
124 wfMsg("newmessageslink") )
131 $tpl->setRef( "newtalk", &$ntl );
132 $tpl->setRef( "skin", &$this);
133 $tpl->set( "logo", $this->logoText() );
134 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
135 if ( !$wgDisableCounters ) {
136 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
138 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
141 $tpl->set('lastmod', $this->lastModified());
142 $tpl->set('copyright',$this->getCopyright());
144 $tpl->set( "copyrightico", $this->getCopyrightIcon() );
145 $tpl->set( "poweredbyico", $this->getPoweredBy() );
146 $tpl->set( "disclaimer", $this->disclaimerLink() );
147 $tpl->set( "about", $this->aboutLink() );
149 $tpl->setRef( "debug", &$out->mDebugtext
);
150 $tpl->set( "reporttime", $out->reportTime() );
152 $tpl->setRef( "bodytext", &$out->mBodytext
);
154 $language_urls = array();
155 foreach( $wgOut->getLanguageLinks() as $l ) {
156 $nt = Title
::newFromText( $l );
157 $language_urls[] = array('href' => $nt->getFullURL(),
158 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
159 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
161 if(count($language_urls)) {
162 $tpl->setRef( 'language_urls', &$language_urls);
164 $tpl->set('language_urls', false);
166 $tpl->set('personal_urls', $this->buildPersonalUrls());
167 $content_actions = $this->buildContentActionUrls();
168 $tpl->setRef('content_actions', &$content_actions);
169 // XXX: attach this from javascript, same with section editing
170 if(isset($content_actions['edit']['href']) &&
171 !(isset($content_actions['edit']['class']) && $content_actions['edit']['class'] != '') &&
172 $wgUser->getOption("editondblclick") )
174 $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
176 $tpl->set('body-ondblclick', '');
178 $tpl->set( "nav_urls", $this->buildNavUrls() );
181 $res = $tpl->execute();
182 // result may be an error
183 if (PEAR
::isError($res)) {
184 echo $res->toString(), "\n";
191 # build array of urls for personal toolbar
192 function buildPersonalUrls() {
193 /* set up the default links for the personal toolbar */
194 global $wgShowIPinHeader;
195 $personal_urls = array();
196 if ($this->loggedin
) {
197 $personal_urls['userpage'] = array(
198 'text' => $this->username
,
199 'href' => $this->makeUrl($this->userpage
),
200 'ttip' => wfMsg('tooltip-userpage'),
201 'akey' => wfMsg('accesskey-userpage')
203 $personal_urls['mytalk'] = array(
204 'text' => wfMsg('mytalk'),
205 'href' => $this->makeTalkUrl($this->userpage
),
206 'ttip' => wfMsg('tooltip-mytalk'),
207 'akey' => wfMsg('accesskey-mytalk')
209 $personal_urls['preferences'] = array(
210 'text' => wfMsg('preferences'),
211 'href' => $this->makeSpecialUrl('Preferences'),
212 'ttip' => wfMsg('tooltip-preferences'),
213 'akey' => wfMsg('accesskey-preferences')
215 $personal_urls['watchlist'] = array(
216 'text' => wfMsg('watchlist'),
217 'href' => $this->makeSpecialUrl('Watchlist'),
218 'ttip' => wfMsg('tooltip-watchlist'),
219 'akey' => wfMsg('accesskey-watchlist')
221 $personal_urls['mycontris'] = array(
222 'text' => wfMsg('mycontris'),
223 'href' => $this->makeSpecialUrl('Contributions','target=' . $this->username
),
224 'ttip' => wfMsg('tooltip-mycontris'),
225 'akey' => wfMsg('accesskey-mycontris')
227 $personal_urls['logout'] = array(
228 'text' => wfMsg('userlogout'),
229 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . $this->thisurle
),
230 'ttip' => wfMsg('tooltip-logout'),
231 'akey' => wfMsg('accesskey-logout')
234 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
235 $personal_urls['anonuserpage'] = array(
236 'text' => $this->username
,
237 'href' => $this->makeUrl($this->userpage
),
238 'ttip' => wfMsg('tooltip-anonuserpage'),
239 'akey' => wfMsg('accesskey-anonuserpage')
241 $personal_urls['anontalk'] = array(
242 'text' => wfMsg('anontalk'),
243 'href' => $this->makeTalkUrl($this->userpage
),
244 'ttip' => wfMsg('tooltip-anontalk'),
245 'akey' => wfMsg('accesskey-anontalk')
247 $personal_urls['anonlogin'] = array(
248 'text' => wfMsg('userlogin'),
249 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
250 'ttip' => wfMsg('tooltip-login'),
251 'akey' => wfMsg('accesskey-login')
255 $personal_urls['login'] = array(
256 'text' => wfMsg('userlogin'),
257 'href' => $this->makeSpecialUrl('Userlogin', 'return='.$this->thisurle
),
258 'ttip' => wfMsg('tooltip-login'),
259 'akey' => wfMsg('accesskey-login')
264 return $personal_urls;
267 # an array of edit links by default used for the tabs
268 function buildContentActionUrls () {
269 global $wgTitle, $wgUser, $wgRequest;
270 $action = $wgRequest->getText( 'action' );
271 $oldid = $wgRequest->getVal( 'oldid' );
272 $diff = $wgRequest->getVal( 'diff' );
273 $content_actions = array();
275 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
278 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
279 'text' => wfMsg('article'),
280 'href' => $this->makeArticleUrl($this->thispage
),
281 'ttip' => wfMsg('tooltip-article'),
282 'akey' => wfMsg('accesskey-article'));
284 /* set up the classes for the talk link */
285 $talk_class = (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : '');
286 $talktitle = Title
::newFromText( $this->titletxt
);
287 $talktitle = $talktitle->getTalkPage();
288 $this->checkTitle(&$talktitle, &$this->titletxt
);
289 if($talktitle->getArticleId() != 0) {
290 $content_actions['talk'] = array(
291 'class' => $talk_class,
292 'text' => wfMsg('talk'),
293 'href' => $this->makeTalkUrl($this->titletxt
),
294 'ttip' => wfMsg('tooltip-talk'),
295 'akey' => wfMsg('accesskey-talk')
298 $content_actions['talk'] = array(
299 'class' => $talk_class.' new',
300 'text' => wfMsg('talk'),
301 'href' => $this->makeTalkUrl($this->titletxt
,'action=edit'),
302 'ttip' => wfMsg('tooltip-talk'),
303 'akey' => wfMsg('accesskey-talk')
307 if ( $wgTitle->userCanEdit() ) {
308 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
309 $content_actions['edit'] = array(
310 'class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
311 'text' => wfMsg('edit'),
312 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
313 'ttip' => wfMsg('tooltip-edit'),
314 'akey' => wfMsg('accesskey-edit')
317 $oid = ( $oldid && ! isset( $diff ) ) ?
"&oldid={$oldid}" : '';
318 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
319 'text' => wfMsg('viewsource'),
320 'href' => $this->makeUrl($this->thispage
, 'action=edit'.$oid),
321 'ttip' => wfMsg('tooltip-viewsource'),
322 'akey' => wfMsg('accesskey-viewsource'));
325 if ( $wgTitle->getArticleId() ) {
327 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
328 'text' => wfMsg('history_short'),
329 'href' => $this->makeUrl($this->thispage
, 'action=history'),
330 'ttip' => wfMsg('tooltip-history'),
331 'akey' => wfMsg('accesskey-history'));
333 # XXX: is there a rollback action anywhere or is it planned?
334 # Don't recall where i got this from...
335 /*if( $wgUser->getNewtalk() ) {
336 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
337 'text' => wfMsg('rollback_short'),
338 'href' => $this->makeUrl($this->thispage, 'action=rollback'),
339 'ttip' => wfMsg('tooltip-rollback'),
340 'akey' => wfMsg('accesskey-rollback'));
343 if($wgUser->isSysop()){
344 if(!$wgTitle->isProtected()){
345 $content_actions['protect'] = array(
346 'class' => ($action == 'protect') ?
'selected' : '',
347 'text' => wfMsg('protect'),
348 'href' => $this->makeUrl($this->thispage
, 'action=protect'),
349 'ttip' => wfMsg('tooltip-protect'),
350 'akey' => wfMsg('accesskey-protect')
354 $content_actions['unprotect'] = array(
355 'class' => ($action == 'unprotect') ?
'selected' : '',
356 'text' => wfMsg('unprotect'),
357 'href' => $this->makeUrl($this->thispage
, 'action=unprotect'),
358 'ttip' => wfMsg('tooltip-protect'),
359 'akey' => wfMsg('accesskey-protect')
362 $content_actions['delete'] = array(
363 'class' => ($action == 'delete') ?
'selected' : '',
364 'text' => wfMsg('delete'),
365 'href' => $this->makeUrl($this->thispage
, 'action=delete'),
366 'ttip' => wfMsg('tooltip-delete'),
367 'akey' => wfMsg('accesskey-delete')
370 if ( $wgUser->getID() != 0 ) {
371 if ( $wgTitle->userCanEdit()) {
372 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
373 'text' => wfMsg('move'),
374 'href' => $this->makeSpecialUrl('Movepage', 'target='.$this->thispage
),
375 'ttip' => wfMsg('tooltip-move'),
376 'akey' => wfMsg('accesskey-move'));
378 $content_actions['move'] = array('class' => 'inactive',
379 'text' => wfMsg('move'),
381 'ttip' => wfMsg('tooltip-nomove'),
387 //article doesn't exist or is deleted
388 if($wgUser->isSysop()){
389 if( $n = $wgTitle->isDeleted() ) {
390 $content_actions['delete'] = array(
392 'text' => wfMsg( "undelete_short", $n ),
393 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage
),
394 'ttip' => wfMsg('tooltip-undelete', $n),
395 'akey' => wfMsg('accesskey-undelete')
401 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
402 if( !$wgTitle->userIsWatching()) {
403 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
404 'text' => wfMsg('watch'),
405 'href' => $this->makeUrl($this->thispage
, 'action=watch'),
406 'ttip' => wfMsg('tooltip-watch'),
407 'akey' => wfMsg('accesskey-watch'));
409 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
410 'text' => wfMsg('unwatch'),
411 'href' => $this->makeUrl($this->thispage
, 'action=unwatch'),
412 'ttip' => wfMsg('tooltip-unwatch'),
413 'akey' => wfMsg('accesskey-unwatch'));
418 /* show special page tab */
420 $content_actions['article'] = array('class' => 'selected',
421 'text' => wfMsg('specialpage'),
423 'ttip' => wfMsg('tooltip-specialpage'),
427 return $content_actions;
430 # build array of common navigation links
431 function buildNavUrls () {
432 global $wgTitle, $wgUser, $wgRequest;
433 global $wgSiteSupportPage;
435 $action = $wgRequest->getText( 'action' );
436 $oldid = $wgRequest->getVal( 'oldid' );
437 $diff = $wgRequest->getVal( 'diff' );
438 // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
440 $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
441 $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
442 $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
443 $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.$this->thispage
)));
444 $nav_urls['currentevents'] = (wfMsg('currentevents') != '') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : '';
445 $nav_urls['portal'] = (wfMsg('portal') != '') ?
array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : '';
446 $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.$this->thispage
)));
447 $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
448 // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
449 $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
450 $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
451 $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
452 $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
455 $id=User
::idFromName($wgTitle->getText());
456 $ip=User
::isIP($wgTitle->getText());
458 if($id ||
$ip) { # both anons and non-anons have contri list
459 $nav_urls['contributions'] = array(
460 'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
463 if ( 0 != $wgUser->getID() ) { # show only to signed in users
464 if($id) { # can only email non-anons
465 $nav_urls['emailuser'] = array(
466 'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
475 function getPageTitleActionText () {
479 return wfMsg('edit');
481 return wfMsg('history_short');
483 return wfMsg('unprotect');
485 return wfMsg('unprotect');
487 return wfMsg('delete');
489 return wfMsg('watch');
491 return wfMsg('unwatch');
496 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
497 $title = Title
::makeTitle( NS_SPECIAL
, $name );
498 $this->checkTitle(&$title, &$name);
499 return $title->getLocalURL( $urlaction );
501 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
502 $title = Title
::newFromText( $name );
503 $title = $title->getTalkPage();
504 $this->checkTitle(&$title, &$name);
505 return $title->getLocalURL( $urlaction );
507 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
508 $title = Title
::newFromText( $name );
509 $title= $title->getSubjectPage();
510 $this->checkTitle(&$title, &$name);
511 return $title->getLocalURL( $urlaction );
513 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
514 $title = Title
::newFromText( wfMsg($name) );
515 $this->checkTitle(&$title, &$name);
516 return $title->getLocalURL( $urlaction );
518 /*static*/ function makeUrl ( $name, $urlaction='' ) {
519 $title = Title
::newFromText( $name );
520 $this->checkTitle(&$title, &$name);
521 return $title->getLocalURL( $urlaction );
524 # make sure we have some title to operate on, mind the '&'
525 /*static*/ function checkTitle ( &$title, &$name ) {
526 if(!is_object($title)) {
527 $title = Title
::newFromText( $name );
528 if(!is_object($title)) {
529 $title = Title
::newFromText( '<error: link target missing>' );
537 class SkinDaVinci
extends SkinPHPTal
{
538 function initPage( &$out ) {
539 SkinPHPTal
::initPage( $out );
540 $this->skinname
= "davinci";
544 class SkinMono
extends SkinPHPTal
{
545 function initPage( &$out ) {
546 SkinPHPTal
::initPage( $out );
547 $this->skinname
= "mono";
551 class SkinMonoBook
extends SkinPHPTal
{
552 function initPage( &$out ) {
553 SkinPHPTal
::initPage( $out );
554 $this->skinname
= "monobook";