no edit options for non-existing pages
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
1 <?php
2 # And turn on $wgUsePHPTal so this file gets included
3
4 # Set your include_path so the PHPTal dir is available
5
6 require_once "PHPTAL.php";
7
8 class MediaWiki_I18N extends PHPTAL_I18N
9 {
10 var $_context = array();
11
12 function set($varName, $value)
13 {
14 $this->_context[$varName] = $value;
15 }
16
17 function translate($value)
18 {
19 $value = wfMsg( $value );
20
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);
26 }
27 return $value;
28 }
29 }
30
31 class SkinPHPTal extends Skin {
32 var $template;
33
34 function initPage() {
35 $this->skinname = "davinci";
36 }
37
38 function outputPage( &$out ) {
39 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
40 global $wgScriptPath, $wgStyleSheetPath, $wgLanguageCode, $wgUseNewInterlanguage;
41 global $wgUseDatabaseMessages, $action;
42
43 $this->initPage();
44 $tpl = new PHPTAL($this->skinname . '.pt', 'templates');
45 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
46
47 $tpl->setTranslator(new MediaWiki_I18N());
48 #}
49
50 $title = $wgTitle->getPrefixedText();
51 $tpl->setRef( "title", &$title ); // ?
52 $thispage = $wgTitle->getPrefixedDbKey();
53 $tpl->setRef( "thispage", &$thispage );
54 $tpl->set( "subtitle", $out->getSubtitle() );
55
56 $loggedin = $wgUser->getID() != 0;
57 $tpl->setRef( "loggedin", &$loggedin );
58 $tpl->set( "editable", ($wgTitle->getNamespace != Namespace::getSpecial() ) );
59 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
60 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
61 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
62 $tpl->set( "helppage", wfMsg('helppage'));
63 $tpl->setRef( "searchaction", &$wgScriptPath );
64 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
65 $tpl->setRef( "lang", &$wgLanguageCode );
66 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
67
68 $username = $wgUser->getName();
69 $tpl->setRef( "username", &$username );
70 $userpage = $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
71 $tpl->setRef( "userpage", &$userpage);
72 $tpl->set( "sysop", $wgUser->isSysop() );
73 if( $wgUser->getNewtalk() ) {
74 $ntl = wfMsg( "newmessages",
75 $this->makeKnownLink(
76 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
77 . ":" . $wgUser->getName(),
78 wfMsg("newmessageslink") )
79 );
80 } else {
81 $ntl = "";
82 }
83 $tpl->setRef( "newtalk", &$ntl );
84 $tpl->setRef( "skin", &$this);
85 $tpl->set( "logo", $this->logoText() );
86 $tpl->set( "pagestats", $this->pageStats() );
87
88 $tpl->setRef( "debug", &$out->mDebugtext );
89 $tpl->set( "reporttime", $out->reportTime() );
90
91 $tpl->setRef( "bodytext", &$out->mBodytext );
92
93 $language_urls = array();
94 foreach( $wgOut->getLanguageLinks() as $l ) {
95 $nt = Title::newFromText( $l );
96 $language_urls[] = array('href' => $nt->getFullURL(),
97 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
98 'class' => $wgLang->isRTL() ? 'rtl' : 'ltr');
99 }
100 if(count($language_urls) != 0 ) {
101 $tpl->setRef( 'language_urls', &$language_urls);
102 } else {
103 $tpl->set('language_urls', false);
104 }
105
106 /* set up the default links for the personal toolbar */
107 $personal_urls = array();
108 if ($loggedin) {
109 $personal_urls['userpage'] = array('text' => $username,
110 'href' => $this->makeUrl($userpage),
111 'ttip' => wfMsg('tooltip-userpage'),
112 'akey' => wfMsg('accesskey-userpage'));
113 $personal_urls['mytalk'] = array('text' => wfMsg('mytalk'),
114 'href' => $this->makeTalkUrl($userpage),
115 'ttip' => wfMsg('tooltip-mytalk'),
116 'akey' => wfMsg('accesskey-mytalk'));
117 $personal_urls['preferences'] = array('text' => wfMsg('preferences'),
118 'href' => $this->makeSpecialUrl('Preferences'),
119 'ttip' => wfMsg('tooltip-preferences'),
120 'akey' => wfMsg('accesskey-preferences'));
121 $personal_urls['watchlist'] = array('text' => wfMsg('watchlist'),
122 'href' => $this->makeSpecialUrl('Watchlist'),
123 'ttip' => wfMsg('tooltip-watchlist'),
124 'akey' => wfMsg('accesskey-watchlist'));
125 $personal_urls['mycontris'] = array('text' => wfMsg('mycontris'),
126 'href' => $this->makeSpecialUrl('Contributions','target=' . $username),
127 'ttip' => wfMsg('tooltip-mycontris'),
128 'akey' => wfMsg('accesskey-mycontris'));
129 $personal_urls['logout'] = array('text' => wfMsg('userlogout'),
130 'href' => $this->makeSpecialUrl('Userlogout','returnpage=' . thispage),
131 'ttip' => wfMsg('tooltip-logout'),
132 'akey' => wfMsg('accesskey-logout'));
133 } else {
134 $personal_urls['login'] = array('text' => wfMsg('userlogin'),
135 'href' => $this->makeSpecialUrl('Userlogin'),
136 'ttip' => wfMsg('tooltip-login'),
137 'akey' => wfMsg('accesskey-login'));
138 }
139 $tpl->setRef('personal_urls', &$personal_urls);
140
141 /* set up the content actions */
142 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
143
144 $content_actions = array();
145 /*$content_actions['view'] = array('class' => ($action == 'view' and !Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',*/
146
147
148 /* the edit tab */
149 if( $iscontent) {
150
151 $content_actions['article'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',
152 'text' => wfMsg('article'),
153 'href' => $this->makeArticleUrl($wgTitle->getPrefixedDbKey()),
154 'ttip' => wfMsg('tooltip-article'),
155 'akey' => wfMsg('accesskey-article'));
156
157 $content_actions['talk'] = array('class' => (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : ''),
158 'text' => wfMsg('talk'),
159 'href' => $this->makeTalkUrl($title),
160 'ttip' => wfMsg('tooltip-talk'),
161 'akey' => wfMsg('accesskey-talk'));
162
163 if ( $wgTitle->userCanEdit() ) {
164 $content_actions['edit'] = array('class' => ($action == 'edit' or $action == 'submit') ? 'selected' : '',
165 'text' => wfMsg('edit'),
166 'href' => $this->makeUrl($thispage, 'action=edit'),
167 'ttip' => wfMsg('tooltip-edit'),
168 'akey' => wfMsg('accesskey-edit'));
169 } else {
170 $content_actions['edit'] = array('class' => ($action == 'edit') ? 'selected' : '',
171 'text' => wfMsg('viewsource'),
172 'href' => $this->makeUrl($thispage, 'action=edit'),
173 'ttip' => wfMsg('tooltip-edit'),
174 'akey' => wfMsg('accesskey-edit'));
175 }
176
177 if ( $wgTitle->getArticleId() ) {
178
179 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : '',
180 'text' => wfMsg('history_short'),
181 'href' => $this->makeUrl($thispage, 'action=history'),
182 'ttip' => wfMsg('tooltip-history'),
183 'akey' => wfMsg('accesskey-history'));
184
185 /*
186 $content_actions['revert'] = array('class' => ($action == 'revert') ? 'selected' : '',
187 'i18n_key' => 'revert',
188 'href' => $this->makeUrl($wgTitle->getPrefixedDbKey(), 'action=revert'),
189 'akey' => wfMsg('accesskeyrevert'));
190 */
191 if( $wgUser->getNewtalk() ) {
192 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
193 'text' => wfMsg('rollback_short'),
194 'href' => $this->makeUrl($thispage, 'action=rollback'),
195 'ttip' => wfMsg('tooltip-rollback'),
196 'akey' => wfMsg('accesskey-rollback'));
197 }
198 if($wgUser->isSysop()){
199 if(!$wgTitle->isProtected()){
200 $content_actions['protect'] = array('class' => ($action == 'protect') ? 'selected' : '',
201 'text' => wfMsg('protect'),
202 'href' => $this->makeUrl($thispage, 'action=protect'),
203 'ttip' => wfMsg('tooltip-protect'),
204 'akey' => wfMsg('accesskey-protect'));
205
206 } else {
207 $content_actions['unprotect'] = array('class' => ($action == 'unprotect') ? 'selected' : '',
208 'text' => wfMsg('unprotect'),
209 'href' => $this->makeUrl($thispage, 'action=unprotect'),
210 'ttip' => wfMsg('tooltip-protect'),
211 'akey' => wfMsg('accesskey-protect'));
212 }
213 $content_actions['delete'] = array('class' => ($action == 'delete') ? 'selected' : '',
214 'text' => wfMsg('delete'),
215 'href' => $this->makeUrl($thispage, 'action=delete'),
216 'ttip' => wfMsg('tooltip-delete'),
217 'akey' => wfMsg('accesskey-delete'));
218 }
219 if ( $wgUser->getID() != 0 ) {
220 if ( $wgTitle->userCanEdit()) {
221 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : '',
222 'text' => wfMsg('move'),
223 'href' => $this->makeSpecialUrl('Movepage', 'target='.$thispage),
224 'ttip' => wfMsg('tooltip-move'),
225 'akey' => wfMsg('accesskey-move'));
226 } else {
227 $content_actions['move'] = array('class' => 'inactive',
228 'text' => wfMsg('move'),
229 'href' => '',
230 'akey' => '');
231
232 }
233 }
234 }
235
236 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
237 if( !$wgTitle->userIsWatching()) {
238 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : '',
239 'text' => wfMsg('watch'),
240 'href' => $this->makeUrl($thispage, 'action=watch'),
241 'ttip' => wfMsg('tooltip-watch'),
242 'akey' => wfMsg('accesskey-watch'));
243 } else {
244 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : '',
245 'text' => wfMsg('unwatch'),
246 'href' => $this->makeUrl($thispage, 'action=unwatch'),
247 'ttip' => wfMsg('tooltip-unwatch'),
248 'akey' => wfMsg('accesskey-unwatch'));
249
250 }
251 }
252 } else {
253 /* show special page actions */
254
255 $content_actions['article'] = array('class' => 'selected',
256 'text' => 'Special Page',
257 'href' => 'javascript:void()',
258 'ttip' => wfMsg('tooltip-special'),
259 'akey' => '');
260
261 /*if ($wgTitle->getDbKey() == 'Movepage') {
262 $content_actions['move'] = array('class' => 'selected',
263 'i18n_key' => 'move',
264 'href' => '',
265 'akey' => '');
266 }*/
267 }
268 $tpl->setRef('content_actions', &$content_actions);
269
270
271 /* prepare an array of common navigation links */
272
273 $nav_urls = array();
274 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
275 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
276 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
277 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.$thispage));
278 $nav_urls['currentevents'] = array('href' => $this->makeI18nUrl('currentevents'));
279 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.$thispage));
280 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
281 $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
282 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
283 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
284 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
285 $tpl->setRef( "nav_urls", &$nav_urls );
286
287
288 // execute template
289 $res = $tpl->execute();
290 // result may be an error
291 if (PEAR::isError($res)) {
292 echo $res->toString(), "\n";
293 } else {
294 echo $res;
295 }
296
297 }
298
299
300
301 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
302 $title = Title::makeTitle( NS_SPECIAL, $name );
303 return $title->escapeLocalURL( $urlaction );
304 }
305 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
306 $title = Title::newFromText( $name );
307 $title = $title->getTalkPage();
308 return $title->escapeLocalURL( $urlaction );
309 }
310 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
311 $title = Title::newFromText( $name );
312 #$title->setNamespace(0);
313 #$title = Title::makeTitle( Namespace::getSubject( $wgTitle->getNamespace() ), $wgTitle->getDbKey() );
314 $title= $title->getSubjectPage();
315 return $title->escapeLocalURL( $urlaction );
316 }
317 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
318 $title = Title::newFromText( wfMsg($name) );
319 if(!is_object($title)) {
320 $title = Title::newFromText( $name );
321 }
322 return $title->escapeLocalURL( $urlaction );
323 }
324 /*static*/ function makeUrl ( $name, $urlaction='' ) {
325 $title = Title::newFromText( $name );
326 return $title->escapeLocalURL( $urlaction );
327 }
328
329 }
330
331 class SkinDaVinci extends SkinPHPTal {
332 function initPage() {
333 SkinPHPTal::initPage();
334 $this->skinname = "davinci";
335 }
336 }
337
338 ?>