fixed section anchors
[mediawiki.git] / includes / SkinPHPTal.php
blob26c4cc23d7b916d8e14c2ca9127e1fbf521a4947
1 <?php
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);
27 return $value;
31 class SkinPHPTal extends Skin {
32 var $template;
34 function initPage() {
35 $this->skinname = "davinci";
38 function outputPage( &$out ) {
39 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgOut;
40 global $wgScriptPath, $wgStyleSheetPath, $wgLanguageCode, $wgUseNewInterlanguage;
41 global $wgUseDatabaseMessages, $action;
43 $this->initPage();
44 $tpl = new PHPTAL($this->skinname . '.pt', '/usr/local/lib/wikipedia/templates');
45 if ( $wgUseDatabaseMessages ) {
47 $tpl->setTranslator(new MediaWiki_I18N());
50 $title = $wgTitle->getPrefixedText();
51 $tpl->setRef( "title", &$title ); // ?
52 $thispage = $wgTitle->getPrefixedDbKey();
53 $tpl->setRef( "thispage", &$thispage );
54 $tpl->set( "subtitle", $out->getSubtitle() );
56 $tpl->set( "editable", ($wgTitle->getNamespace != Namespace::getSpecial() ) );
57 $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
58 $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
59 $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
60 $tpl->set( "helppage", wfMsg('helppage'));
62 $language_urls = array();
63 foreach( $wgOut->getLanguageLinks() as $l ) {
64 $nt = Title::newFromText( $l );
65 $language_urls[] = array('href' => $nt->getFullURL(),
66 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?$wgLang->getLanguageName( $nt->getInterwiki()) : $l),
67 'class' => $wgLang->isRTL() ? 'rtl' : 'ltr');
69 if(count($language_urls) != 0 ) {
70 $tpl->setRef( 'language_urls', &$language_urls);
71 } else {
72 $tpl->set('language_urls', false);
76 /* set up the content actions */
77 $iscontent = ($wgTitle->getNamespace() != Namespace::getSpecial() );
79 $content_actions = array();
80 /*$content_actions['view'] = array('class' => ($action == 'view' and !Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',*/
81 $content_actions['view'] = array('class' => (!Namespace::isTalk( $wgTitle->getNamespace())) ? 'selected' : '',
82 'i18n_key' => 'view',
83 'href' => $this->makeArticleUrl($wgTitle->getPrefixedDbKey()),
84 'akey' => wfMsg('accesskeyview'));
87 /* the edit tab */
88 if( $iscontent) {
90 $content_actions['talk'] = array('class' => (Namespace::isTalk( $wgTitle->getNamespace()) ? 'selected' : ''),
91 'i18n_key' => 'talk',
92 'href' => $this->makeTalkUrl($title),
93 'akey' => wfMsg('accesskeytalk'));
95 if ( $wgTitle->userCanEdit() ) {
96 $content_actions['edit'] = array('class' => ($action == 'edit' or $action == 'submit') ? 'selected' : '',
97 'i18n_key' => 'edit',
98 'href' => $this->makeUrl($thispage, 'action=edit'),
99 'akey' => wfMsg('accesskeyedit'));
100 } else {
101 $content_actions['edit'] = array('class' => ($action == 'edit') ? 'selected' : '',
102 'i18n_key' => 'viewsource',
103 'href' => $this->makeUrl($thispage, 'action=edit'),
104 'akey' => wfMsg('accesskeyedit'));
106 $content_actions['history'] = array('class' => ($action == 'history') ? 'selected' : '',
107 'i18n_key' => 'history',
108 'href' => $this->makeUrl($thispage, 'action=history'),
109 'akey' => wfMsg('accesskeyhistory'));
112 $content_actions['revert'] = array('class' => ($action == 'revert') ? 'selected' : '',
113 'i18n_key' => 'revert',
114 'href' => $this->makeUrl($wgTitle->getPrefixedDbKey(), 'action=revert'),
115 'akey' => wfMsg('accesskeyrevert'));
117 if( $wgUser->getNewtalk() ) {
118 $content_actions['rollback'] = array('class' => ($action == 'rollback') ? 'selected' : '',
119 'i18n_key' => 'rollback',
120 'href' => $this->makeUrl($thispage, 'action=rollback'),
121 'akey' => wfMsg('accesskeyrollback'));
123 if($wgUser->isSysop()){
124 if(!$wgTitle->isProtected()){
125 $content_actions['protect'] = array('class' => ($action == 'protect') ? 'selected' : '',
126 'i18n_key' => 'protect',
127 'href' => $this->makeUrl($thispage, 'action=protect'),
128 'akey' => wfMsg('accesskeyprotect'));
130 } else {
131 $content_actions['unprotect'] = array('class' => ($action == 'unprotect') ? 'selected' : '',
132 'i18n_key' => 'unprotect',
133 'href' => $this->makeUrl($thispage, 'action=unprotect'),
134 'akey' => wfMsg('accesskeyprotect'));
136 $content_actions['delete'] = array('class' => ($action == 'delete') ? 'selected' : '',
137 'i18n_key' => 'delete',
138 'href' => $this->makeUrl($thispage, 'action=delete'),
139 'akey' => wfMsg('accesskeydelete'));
141 if ( $wgUser->getID() != 0 ) {
142 if ( $wgTitle->userCanEdit()) {
143 $content_actions['move'] = array('class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : '',
144 'i18n_key' => 'move',
145 'href' => $this->makeSpecialUrl('Movepage', 'target='.$thispage),
146 'akey' => wfMsg('accesskeymove'));
147 } else {
148 $content_actions['move'] = array('class' => 'inactive',
149 'i18n_key' => 'move',
150 'href' => '',
151 'akey' => '');
155 if ( $wgUser->getID() != 0 and $action != 'edit' and $action != 'submit' ) {
156 if( !$wgTitle->userIsWatching()) {
157 $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : '',
158 'i18n_key' => 'watch',
159 'href' => $this->makeUrl($thispage, 'action=watch'),
160 'akey' => wfMsg('accesskey-watch'));
161 } else {
162 $content_actions['watch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : '',
163 'i18n_key' => 'unwatch',
164 'href' => $this->makeUrl($thispage, 'action=unwatch'),
165 'akey' => wfMsg('accesskey-watch'));
169 } else {
170 /* show special page actions */
172 if ($wgTitle->getDbKey() == 'Movepage') {
173 $content_actions['move'] = array('class' => 'selected',
174 'i18n_key' => 'move',
175 'href' => '',
176 'akey' => '');
179 $tpl->setRef('content_actions', &$content_actions);
182 /* prepare an array of common navigation links */
184 $urls = array();
185 $urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
186 $urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
187 $urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
188 $urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.$thispage));
189 $urls['currentevents'] = array('href' => $this->makeI18nUrl('currentevents'));
190 $urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.$thispage));
191 $urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
192 $urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
193 $urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
194 $urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
195 $urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
196 $tpl->setRef( "urls", &$urls );
198 $tpl->setRef( "searchaction", &$wgScriptPath );
199 $tpl->setRef( "stylepath", &$wgStyleSheetPath );
200 $tpl->setRef( "lang", &$wgLanguageCode );
201 $tpl->set( "langname", $wgLang->getLanguageName( $wgLanguageCode ) );
203 $tpl->set( "username", $wgUser->getName() );
204 $tpl->set( "userpage", $wgLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName() );
205 $tpl->set( "loggedin", $wgUser->getID() != 0 );
206 $tpl->set( "sysop", $wgUser->isSysop() );
207 if( $wgUser->getNewtalk() ) {
208 $ntl = wfMsg( "newmessages",
209 $this->makeKnownLink(
210 $wgLang->getNsText( Namespace::getTalk( Namespace::getUser() ) )
211 . ":" . $wgUser->getName(),
212 wfMsg("newmessageslink") )
214 } else {
215 $ntl = "";
217 $tpl->setRef( "newtalk", &$ntl );
218 $tpl->setRef( "skin", &$this);
219 $tpl->set( "logo", $this->logoText() );
220 $tpl->set( "pagestats", $this->pageStats() );
222 $tpl->setRef( "debug", &$out->mDebugtext );
223 $tpl->set( "reporttime", $out->reportTime() );
225 $tpl->setRef( "bodytext", &$out->mBodytext );
227 // execute template
228 $res = $tpl->execute();
229 // result may be an error
230 if (PEAR::isError($res)) {
231 echo $res->toString(), "\n";
232 } else {
233 echo $res;
240 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
241 $title = Title::makeTitle( NS_SPECIAL, $name );
242 return $title->escapeLocalURL( $urlaction );
244 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
245 $title = Title::newFromText( $name );
246 $title = $title->getTalkPage();
247 return $title->escapeLocalURL( $urlaction );
249 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
250 $title = Title::newFromText( $name );
251 #$title->setNamespace(0);
252 #$title = Title::makeTitle( Namespace::getSubject( $wgTitle->getNamespace() ), $wgTitle->getDbKey() );
253 $title= $title->getSubjectPage();
254 return $title->escapeLocalURL( $urlaction );
256 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
257 $title = Title::newFromText( wfMsg($name) );
258 #$title->setNamespace(0);
259 #$title = Title::makeTitle( Namespace::getSubject( $wgTitle->getNamespace() ), $wgTitle->getDbKey() );
260 return $title->escapeLocalURL( $urlaction );
262 /*static*/ function makeUrl ( $name, $urlaction='' ) {
263 $title = Title::newFromText( $name );
264 return $title->escapeLocalURL( $urlaction );
269 class SkinDaVinci extends SkinPHPTal {
270 function initPage() {
271 SkinPHPTal::initPage();
272 $this->skinname = "davinci";