8ada94cd536881cc3bb955c94ab8da684288aa93
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, $wgRequest;
44 $action = $wgRequest->getText( 'action' );
45 $oldid = $wgRequest->getVal( 'oldid' );
46 $diff = $wgRequest->getVal( 'diff' );
49 $tpl = new PHPTAL($this->template
. '.pt', 'templates');
50 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
52 $tpl->setTranslator(new MediaWiki_I18N());
55 $title = $wgTitle->getPrefixedText();
56 $tpl->setRef( "title", &$title ); // ?
57 $thispage = $wgTitle->getPrefixedDbKey();
58 $tpl->setRef( "thispage", &$thispage );
59 $tpl->set( "subtitle", $out->getSubtitle() );
60 $tpl->setRef( 'charset', $wgOutputEncoding);
61 $tpl->setRef( 'skinname', $this->skinname
);
63 $loggedin = $wgUser->getID() != 0;
64 $tpl->setRef( "loggedin", &$loggedin );
65 $tpl->set( "editable", ($wgTitle->getNamespace
!= Namespace::getSpecial() ) );
66 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
67 $tpl->set( "watch", $wgTitle->userIsWatching() ?
"unwatch" : "watch" );
68 $tpl->set( "protect", count($wgTitle->getRestrictions()) ?
"unprotect" : "protect" );
69 $tpl->set( "helppage", wfMsg('helppage'));
70 $tpl->setRef( "searchaction", &$wgScriptPath );
71 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
72 $tpl->setRef( "lang", &$wgLanguageCode );
73 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
75 $username = $wgUser->getName();
76 $tpl->setRef( "username", &$username );
77 $userpage = $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
78 $tpl->setRef( "userpage", &$userpage);
79 $tpl->set( "sysop", $wgUser->isSysop() );
80 if( $wgUser->getNewtalk() ) {
81 $ntl = wfMsg( "newmessages",
83 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
84 . ":" . $wgUser->getName(),
85 wfMsg("newmessageslink") )
90 $tpl->setRef( "newtalk", &$ntl );
91 $tpl->setRef( "skin", &$this);
92 $tpl->set( "logo", $this->logoText() );
93 $tpl->set( "pagestats", $this->pageStats() );
94 $tpl->set( "disclaimer", $this->disclaimerLink() );
95 $tpl->set( "about", $this->aboutLink() );
97 $tpl->setRef( "debug", &$out->mDebugtext
);
98 $tpl->set( "reporttime", $out->reportTime() );
100 $tpl->setRef( "bodytext", &$out->mBodytext
);
102 $language_urls = array();
103 foreach( $wgOut->getLanguageLinks() as $l ) {
104 $nt = Title
::newFromText( $l );
105 $language_urls[] = array('href' => $nt->getFullURL(),
106 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
107 'class' => $wgLang->isRTL() ?
'rtl' : 'ltr');
109 if(count($language_urls) != 0 ) {
110 $tpl->setRef( 'language_urls', &$language_urls);
112 $tpl->set('language_urls', false);
115 /* set up the default links for the personal toolbar */
116 $personal_urls = array();
118 $personal_urls['userpage'] = array('text' => $username,
119 'href' => $this->makeUrl($userpage),
120 'ttip' => wfMsg('tooltip-userpage'),
121 'akey' => wfMsg('accesskey-userpage'));
122 $personal_urls['mytalk'] = array('text' => wfMsg('mytalk'),
123 'href' => $this->makeTalkUrl($userpage),
124 'ttip' => wfMsg('tooltip-mytalk'),
125 'akey' => wfMsg('accesskey-mytalk'));
126 $personal_urls['preferences'] = array('text' => wfMsg('preferences'),
127 'href' => $this->makeSpecialUrl('Preferences'),
128 'ttip' => wfMsg('tooltip-preferences'),
129 'akey' => wfMsg('accesskey-preferences'));
130 $personal_urls['watchlist'] = array('text' => wfMsg('watchlist'),
131 'href' => $this->makeSpecialUrl('Watchlist'),
132 'ttip' => wfMsg('tooltip-watchlist'),
133 'akey' => wfMsg('accesskey-watchlist'));
134 $personal_urls['mycontris'] = array('text' => wfMsg('mycontris'),
135 'href' => $this->makeSpecialUrl('Contributions','target=' . $username),
136 'ttip' => wfMsg('tooltip-mycontris'),
137 'akey' => wfMsg('accesskey-mycontris'));
138 $personal_urls['logout'] = array('text' => wfMsg('userlogout'),
139 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . thispage
),
140 'ttip' => wfMsg('tooltip-logout'),
141 'akey' => wfMsg('accesskey-logout'));
143 $personal_urls['login'] = array('text' => wfMsg('userlogin'),
144 'href' => $this->makeSpecialUrl('Userlogin'),
145 'ttip' => wfMsg('tooltip-login'),
146 'akey' => wfMsg('accesskey-login'));
148 $tpl->setRef('personal_urls', &$personal_urls);
150 /* set up the content actions */
151 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
153 $content_actions = array();
154 /*$content_actions['view'] = array('class' => ($action == 'view' and !Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',*/
160 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ?
'selected' : '',
161 'text' => wfMsg('article'),
162 'href' => $this->makeArticleUrl($wgTitle->getPrefixedDbKey()),
163 'ttip' => wfMsg('tooltip-article'),
164 'akey' => wfMsg('accesskey-article'));
166 $content_actions['talk'] = array('class' => (Namespace::isTalk( $wgTitle->getNamespace()) ?
'selected' : ''),
167 'text' => wfMsg('talk'),
168 'href' => $this->makeTalkUrl($title),
169 'ttip' => wfMsg('tooltip-talk'),
170 'akey' => wfMsg('accesskey-talk'));
172 if ( $wgTitle->userCanEdit() ) {
173 if ( $oldid && ! isset( $diff ) ) {
174 $oid = "&oldid={$oldid}";
176 $content_actions['edit'] = array('class' => ($action == 'edit' or $action == 'submit') ?
'selected' : '',
177 'text' => wfMsg('edit'),
178 'href' => $this->makeUrl($thispage, 'action=edit'.$oid),
179 'ttip' => wfMsg('tooltip-edit'),
180 'akey' => wfMsg('accesskey-edit'));
182 if ( $oldid && ! isset( $diff ) ) {
183 $oid = "&oldid={$oldid}";
185 $content_actions['edit'] = array('class' => ($action == 'edit') ?
'selected' : '',
186 'text' => wfMsg('viewsource'),
187 'href' => $this->makeUrl($thispage, 'action=edit'.$oid),
188 'ttip' => wfMsg('tooltip-edit'),
189 'akey' => wfMsg('accesskey-edit'));
192 if ( $wgTitle->getArticleId() ) {
194 $content_actions['history'] = array('class' => ($action == 'history') ?
'selected' : '',
195 'text' => wfMsg('history_short'),
196 'href' => $this->makeUrl($thispage, 'action=history'),
197 'ttip' => wfMsg('tooltip-history'),
198 'akey' => wfMsg('accesskey-history'));
201 $content_actions['revert'] = array('class' => ($action == 'revert') ? 'selected' : '',
202 'i18n_key' => 'revert',
203 'href' => $this->makeUrl($wgTitle->getPrefixedDbKey(), 'action=revert'),
204 'akey' => wfMsg('accesskeyrevert'));
206 if( $wgUser->getNewtalk() ) {
207 $content_actions['rollback'] = array('class' => ($action == 'rollback') ?
'selected' : '',
208 'text' => wfMsg('rollback_short'),
209 'href' => $this->makeUrl($thispage, 'action=rollback'),
210 'ttip' => wfMsg('tooltip-rollback'),
211 'akey' => wfMsg('accesskey-rollback'));
213 if($wgUser->isSysop()){
214 if(!$wgTitle->isProtected()){
215 $content_actions['protect'] = array('class' => ($action == 'protect') ?
'selected' : '',
216 'text' => wfMsg('protect'),
217 'href' => $this->makeUrl($thispage, 'action=protect'),
218 'ttip' => wfMsg('tooltip-protect'),
219 'akey' => wfMsg('accesskey-protect'));
222 $content_actions['unprotect'] = array('class' => ($action == 'unprotect') ?
'selected' : '',
223 'text' => wfMsg('unprotect'),
224 'href' => $this->makeUrl($thispage, 'action=unprotect'),
225 'ttip' => wfMsg('tooltip-protect'),
226 'akey' => wfMsg('accesskey-protect'));
228 $content_actions['delete'] = array('class' => ($action == 'delete') ?
'selected' : '',
229 'text' => wfMsg('delete'),
230 'href' => $this->makeUrl($thispage, 'action=delete'),
231 'ttip' => wfMsg('tooltip-delete'),
232 'akey' => wfMsg('accesskey-delete'));
234 if ( $wgUser->getID() != 0 ) {
235 if ( $wgTitle->userCanEdit()) {
236 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace
== Namespace::getSpecial()) ?
'selected' : '',
237 'text' => wfMsg('move'),
238 'href' => $this->makeSpecialUrl('Movepage', 'target='.$thispage),
239 'ttip' => wfMsg('tooltip-move'),
240 'akey' => wfMsg('accesskey-move'));
242 $content_actions['move'] = array('class' => 'inactive',
243 'text' => wfMsg('move'),
251 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
252 if( !$wgTitle->userIsWatching()) {
253 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : '',
254 'text' => wfMsg('watch'),
255 'href' => $this->makeUrl($thispage, 'action=watch'),
256 'ttip' => wfMsg('tooltip-watch'),
257 'akey' => wfMsg('accesskey-watch'));
259 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : '',
260 'text' => wfMsg('unwatch'),
261 'href' => $this->makeUrl($thispage, 'action=unwatch'),
262 'ttip' => wfMsg('tooltip-unwatch'),
263 'akey' => wfMsg('accesskey-unwatch'));
268 /* show special page actions */
270 $content_actions['article'] = array('class' => 'selected',
271 'text' => wfMsg('specialpage'),
272 'href' => 'javascript:void()',
273 'ttip' => wfMsg('tooltip-specialpage'),
276 /*if ($wgTitle->getDbKey() == 'Movepage') {
277 $content_actions['move'] = array('class' => 'selected',
278 'i18n_key' => 'move',
283 $tpl->setRef('content_actions', &$content_actions);
286 /* prepare an array of common navigation links */
289 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
290 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
291 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
292 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.$thispage));
293 $nav_urls['currentevents'] = array('href' => $this->makeI18nUrl('currentevents'));
294 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.$thispage));
295 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
296 $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
297 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
298 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
299 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
300 $tpl->setRef( "nav_urls", &$nav_urls );
304 $res = $tpl->execute();
305 // result may be an error
306 if (PEAR
::isError($res)) {
307 echo $res->toString(), "\n";
316 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
317 $title = Title
::makeTitle( NS_SPECIAL
, $name );
318 return $title->getLocalURL( $urlaction );
320 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
321 $title = Title
::newFromText( $name );
322 $title = $title->getTalkPage();
323 return $title->getLocalURL( $urlaction );
325 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
326 $title = Title
::newFromText( $name );
327 #$title->setNamespace(0);
328 #$title = Title::makeTitle( Namespace::getSubject( $wgTitle->getNamespace() ), $wgTitle->getDbKey() );
329 $title= $title->getSubjectPage();
330 return $title->getLocalURL( $urlaction );
332 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
333 $title = Title
::newFromText( wfMsg($name) );
334 if(!is_object($title)) {
335 $title = Title
::newFromText( $name );
337 return $title->getLocalURL( $urlaction );
339 /*static*/ function makeUrl ( $name, $urlaction='' ) {
340 $title = Title
::newFromText( $name );
341 return $title->getLocalURL( $urlaction );
346 class SkinDaVinci
extends SkinPHPTal
{
347 function initPage() {
348 SkinPHPTal
::initPage();
349 $this->skinname
= "davinci";
350 $this->template
= "xhtml_slim";
354 class SkinMono
extends SkinPHPTal
{
355 function initPage() {
356 SkinPHPTal
::initPage();
357 $this->skinname
= "mono";
358 $this->template
= "xhtml_slim";