2 # And turn on $wgUsePHPTal so this file gets included
4 # Set your include_path so the PHPTal dir is available
6 require_once "PHPTAL.php";
8 class MediaWiki_I18N
extends PHPTAL_I18N
10 var $_context = array();
12 function set($varName, $value)
14 $this->_context
[$varName] = $value;
17 function translate($value)
19 $value = wfMsg( $value );
21 // interpolate variables
22 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
23 list($src, $var) = $m;
24 $varValue = $this->_context
[$var];
25 $value = str_replace($src, $varValue, $value);
31 class SkinPHPTal
extends Skin
{
35 $this->skinname
= "davinci";
36 $this->template
= "xhtml_slim";
39 function outputPage( &$out ) {
40 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
41 global $wgScriptPath, $wgStyleSheetPath, $wgLanguageCode, $wgUseNewInterlanguage;
42 global $wgOutputEncoding, $wgUseDatabaseMessages, $action, $oldid, $diff;
45 $tpl = new PHPTAL($this->template
. '.pt', 'templates');
46 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
48 $tpl->setTranslator(new MediaWiki_I18N());
51 $title = $wgTitle->getPrefixedText();
52 $tpl->setRef( "title", &$title ); // ?
53 $thispage = $wgTitle->getPrefixedDbKey();
54 $tpl->setRef( "thispage", &$thispage );
55 $tpl->set( "subtitle", $out->getSubtitle() );
56 $tpl->setRef( 'charset', $wgOutputEncoding);
57 $tpl->setRef( 'skinname', $this->skinname
);
59 $loggedin = $wgUser->getID() != 0;
60 $tpl->setRef( "loggedin", &$loggedin );
61 $tpl->set( "editable", ($wgTitle->getNamespace
!= Namespace::getSpecial() ) );
62 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
63 $tpl->set( "watch", $wgTitle->userIsWatching() ?
"unwatch" : "watch" );
64 $tpl->set( "protect", count($wgTitle->getRestrictions()) ?
"unprotect" : "protect" );
65 $tpl->set( "helppage", wfMsg('helppage'));
66 $tpl->setRef( "searchaction", &$wgScriptPath );
67 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
68 $tpl->setRef( "lang", &$wgLanguageCode );
69 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
71 $username = $wgUser->getName();
72 $tpl->setRef( "username", &$username );
73 $userpage = $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
74 $tpl->setRef( "userpage", &$userpage);
75 $tpl->set( "sysop", $wgUser->isSysop() );
76 if( $wgUser->getNewtalk() ) {
77 $ntl = wfMsg( "newmessages",
79 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
80 . ":" . $wgUser->getName(),
81 wfMsg("newmessageslink") )
86 $tpl->setRef( "newtalk", &$ntl );
87 $tpl->setRef( "skin", &$this);
88 $tpl->set( "logo", $this->logoText() );
89 $tpl->set( "pagestats", $this->pageStats() );
90 $tpl->set( "disclaimer", $this->disclaimerLink() );
91 $tpl->set( "about", $this->aboutLink() );
93 $tpl->setRef( "debug", &$out->mDebugtext
);
94 $tpl->set( "reporttime", $out->reportTime() );
96 $tpl->setRef( "bodytext", &$out->mBodytext
);
98 $language_urls = array();
99 foreach( $wgOut->getLanguageLinks() as $l ) {
100 $nt = Title
::newFromText( $l );
101 $language_urls[] = array('href' => $nt->getFullURL(),
102 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
103 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
105 if(count($language_urls) != 0 ) {
106 $tpl->setRef( 'language_urls', &$language_urls);
108 $tpl->set('language_urls', false);
111 /* set up the default links for the personal toolbar */
112 $personal_urls = array();
114 $personal_urls['userpage'] = array('text' => $username,
115 'href' => $this->makeUrl($userpage),
116 'ttip' => wfMsg('tooltip-userpage'),
117 'akey' => wfMsg('accesskey-userpage'));
118 $personal_urls['mytalk'] = array('text' => wfMsg('mytalk'),
119 'href' => $this->makeTalkUrl($userpage),
120 'ttip' => wfMsg('tooltip-mytalk'),
121 'akey' => wfMsg('accesskey-mytalk'));
122 $personal_urls['preferences'] = array('text' => wfMsg('preferences'),
123 'href' => $this->makeSpecialUrl('Preferences'),
124 'ttip' => wfMsg('tooltip-preferences'),
125 'akey' => wfMsg('accesskey-preferences'));
126 $personal_urls['watchlist'] = array('text' => wfMsg('watchlist'),
127 'href' => $this->makeSpecialUrl('Watchlist'),
128 'ttip' => wfMsg('tooltip-watchlist'),
129 'akey' => wfMsg('accesskey-watchlist'));
130 $personal_urls['mycontris'] = array('text' => wfMsg('mycontris'),
131 'href' => $this->makeSpecialUrl('Contributions','target=' . $username),
132 'ttip' => wfMsg('tooltip-mycontris'),
133 'akey' => wfMsg('accesskey-mycontris'));
134 $personal_urls['logout'] = array('text' => wfMsg('userlogout'),
135 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . thispage
),
136 'ttip' => wfMsg('tooltip-logout'),
137 'akey' => wfMsg('accesskey-logout'));
139 $personal_urls['login'] = array('text' => wfMsg('userlogin'),
140 'href' => $this->makeSpecialUrl('Userlogin'),
141 'ttip' => wfMsg('tooltip-login'),
142 'akey' => wfMsg('accesskey-login'));
144 $tpl->setRef('personal_urls', &$personal_urls);
146 /* set up the content actions */
147 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
149 $content_actions = array();
150 /*$content_actions['view'] = array('class' => ($action == 'view' and !Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',*/
156 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
157 'text' => wfMsg('article'),
158 'href' => $this->makeArticleUrl($wgTitle->getPrefixedDbKey()),
159 'ttip' => wfMsg('tooltip-article'),
160 'akey' => wfMsg('accesskey-article'));
162 $content_actions['talk'] = array('class' => (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : ''),
163 'text' => wfMsg('talk'),
164 'href' => $this->makeTalkUrl($title),
165 'ttip' => wfMsg('tooltip-talk'),
166 'akey' => wfMsg('accesskey-talk'));
168 if ( $wgTitle->userCanEdit() ) {
169 if ( $oldid && ! isset( $diff ) ) {
170 $oid = "&oldid={$oldid}";
172 $content_actions['edit'] = array('class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
173 'text' => wfMsg('edit'),
174 'href' => $this->makeUrl($thispage, 'action=edit'.$oid),
175 'ttip' => wfMsg('tooltip-edit'),
176 'akey' => wfMsg('accesskey-edit'));
178 if ( $oldid && ! isset( $diff ) ) {
179 $oid = "&oldid={$oldid}";
181 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
182 'text' => wfMsg('viewsource'),
183 'href' => $this->makeUrl($thispage, 'action=edit'.$oid),
184 'ttip' => wfMsg('tooltip-edit'),
185 'akey' => wfMsg('accesskey-edit'));
188 if ( $wgTitle->getArticleId() ) {
190 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
191 'text' => wfMsg('history_short'),
192 'href' => $this->makeUrl($thispage, 'action=history'),
193 'ttip' => wfMsg('tooltip-history'),
194 'akey' => wfMsg('accesskey-history'));
197 $content_actions['revert'] = array('class' => ($action == 'revert') ? 'selected' : '',
198 'i18n_key' => 'revert',
199 'href' => $this->makeUrl($wgTitle->getPrefixedDbKey(), 'action=revert'),
200 'akey' => wfMsg('accesskeyrevert'));
202 if( $wgUser->getNewtalk() ) {
203 $content_actions['rollback'] = array('class' => ($action == 'rollback') ?
'selected' : '',
204 'text' => wfMsg('rollback_short'),
205 'href' => $this->makeUrl($thispage, 'action=rollback'),
206 'ttip' => wfMsg('tooltip-rollback'),
207 'akey' => wfMsg('accesskey-rollback'));
209 if($wgUser->isSysop()){
210 if(!$wgTitle->isProtected()){
211 $content_actions['protect'] = array('class' => ($action == 'protect') ?
'selected' : '',
212 'text' => wfMsg('protect'),
213 'href' => $this->makeUrl($thispage, 'action=protect'),
214 'ttip' => wfMsg('tooltip-protect'),
215 'akey' => wfMsg('accesskey-protect'));
218 $content_actions['unprotect'] = array('class' => ($action == 'unprotect') ?
'selected' : '',
219 'text' => wfMsg('unprotect'),
220 'href' => $this->makeUrl($thispage, 'action=unprotect'),
221 'ttip' => wfMsg('tooltip-protect'),
222 'akey' => wfMsg('accesskey-protect'));
224 $content_actions['delete'] = array('class' => ($action == 'delete') ?
'selected' : '',
225 'text' => wfMsg('delete'),
226 'href' => $this->makeUrl($thispage, 'action=delete'),
227 'ttip' => wfMsg('tooltip-delete'),
228 'akey' => wfMsg('accesskey-delete'));
230 if ( $wgUser->getID() != 0 ) {
231 if ( $wgTitle->userCanEdit()) {
232 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
233 'text' => wfMsg('move'),
234 'href' => $this->makeSpecialUrl('Movepage', 'target='.$thispage),
235 'ttip' => wfMsg('tooltip-move'),
236 'akey' => wfMsg('accesskey-move'));
238 $content_actions['move'] = array('class' => 'inactive',
239 'text' => wfMsg('move'),
247 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
248 if( !$wgTitle->userIsWatching()) {
249 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
250 'text' => wfMsg('watch'),
251 'href' => $this->makeUrl($thispage, 'action=watch'),
252 'ttip' => wfMsg('tooltip-watch'),
253 'akey' => wfMsg('accesskey-watch'));
255 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
256 'text' => wfMsg('unwatch'),
257 'href' => $this->makeUrl($thispage, 'action=unwatch'),
258 'ttip' => wfMsg('tooltip-unwatch'),
259 'akey' => wfMsg('accesskey-unwatch'));
264 /* show special page actions */
266 $content_actions['article'] = array('class' => 'selected',
267 'text' => wfMsg('specialpage'),
268 'href' => 'javascript:void()',
269 'ttip' => wfMsg('tooltip-specialpage'),
272 /*if ($wgTitle->getDbKey() == 'Movepage') {
273 $content_actions['move'] = array('class' => 'selected',
274 'i18n_key' => 'move',
279 $tpl->setRef('content_actions', &$content_actions);
282 /* prepare an array of common navigation links */
285 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
286 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
287 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
288 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.$thispage));
289 $nav_urls['currentevents'] = array('href' => $this->makeI18nUrl('currentevents'));
290 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.$thispage));
291 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
292 $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
293 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
294 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
295 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
296 $tpl->setRef( "nav_urls", &$nav_urls );
300 $res = $tpl->execute();
301 // result may be an error
302 if (PEAR
::isError($res)) {
303 echo $res->toString(), "\n";
312 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
313 $title = Title
::makeTitle( NS_SPECIAL
, $name );
314 return $title->getLocalURL( $urlaction );
316 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
317 $title = Title
::newFromText( $name );
318 $title = $title->getTalkPage();
319 return $title->getLocalURL( $urlaction );
321 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
322 $title = Title
::newFromText( $name );
323 #$title->setNamespace(0);
324 #$title = Title::makeTitle( Namespace::getSubject( $wgTitle->getNamespace() ), $wgTitle->getDbKey() );
325 $title= $title->getSubjectPage();
326 return $title->getLocalURL( $urlaction );
328 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
329 $title = Title
::newFromText( wfMsg($name) );
330 if(!is_object($title)) {
331 $title = Title
::newFromText( $name );
333 return $title->getLocalURL( $urlaction );
335 /*static*/ function makeUrl ( $name, $urlaction='' ) {
336 $title = Title
::newFromText( $name );
337 return $title->getLocalURL( $urlaction );
342 class SkinDaVinci
extends SkinPHPTal
{
343 function initPage() {
344 SkinPHPTal
::initPage();
345 $this->skinname
= "davinci";
346 $this->template
= "xhtml_slim";
350 class SkinMono
extends SkinPHPTal
{
351 function initPage() {
352 SkinPHPTal
::initPage();
353 $this->skinname
= "mono";
354 $this->template
= "xhtml_slim";