* Giving interwiki links a class so that they can be styled individually
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152 global $wgUseTrackbacks;
153
154 $fname = 'SkinTemplate::outputPage';
155 wfProfileIn( $fname );
156
157 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
158
159 wfProfileIn( "$fname-init" );
160 $this->initPage( $out );
161
162 $this->mTitle =& $wgTitle;
163 $this->mUser =& $wgUser;
164
165 $tpl = $this->setupTemplate( $this->template, 'skins' );
166
167 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
168 $tpl->setTranslator(new MediaWiki_I18N());
169 #}
170 wfProfileOut( "$fname-init" );
171
172 wfProfileIn( "$fname-stuff" );
173 $this->thispage = $this->mTitle->getPrefixedDbKey();
174 $this->thisurl = $this->mTitle->getPrefixedURL();
175 $this->loggedin = $wgUser->isLoggedIn();
176 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
177 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
178 $this->username = $wgUser->getName();
179 $userPage = $wgUser->getUserPage();
180 $this->userpage = $userPage->getPrefixedText();
181 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
182
183 $this->usercss = $this->userjs = $this->userjsprev = false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt = $this->mTitle->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
188
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192
193 $tpl->setRef( "thispage", $this->thispage );
194 $subpagestr = $this->subPageSubtitle();
195 $tpl->set(
196 'subtitle', !empty($subpagestr)?
197 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
198 $out->getSubtitle()
199 );
200 $undelete = $this->getUndeleteLink();
201 $tpl->set(
202 "undelete", !empty($undelete)?
203 '<span class="subpages">'.$undelete.'</span>':
204 ''
205 );
206
207 $tpl->set( 'catlinks', $this->getCategories());
208 if( $wgOut->isSyndicated() ) {
209 $feeds = array();
210 foreach( $wgFeedClasses as $format => $class ) {
211 $feeds[$format] = array(
212 'text' => $format,
213 'href' => $wgRequest->appendQuery( "feed=$format" ),
214 'ttip' => wfMsg('tooltip-'.$format)
215 );
216 }
217 $tpl->setRef( 'feeds', $feeds );
218 } else {
219 $tpl->set( 'feeds', false );
220 }
221 if ($wgUseTrackbacks && $out->isArticleRelated())
222 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
223
224 $tpl->setRef( 'mimetype', $wgMimeType );
225 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
226 $tpl->setRef( 'charset', $wgOutputEncoding );
227 $tpl->set( 'headlinks', $out->getHeadLinks() );
228 $tpl->setRef( 'wgScript', $wgScript );
229 $tpl->setRef( 'skinname', $this->skinname );
230 $tpl->setRef( 'stylename', $this->stylename );
231 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
232 $tpl->setRef( 'loggedin', $this->loggedin );
233 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
234 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
235 /* XXX currently unused, might get useful later
236 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
237 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
238 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
239 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
240 $tpl->set( "helppage", wfMsg('helppage'));
241 */
242 $tpl->set( 'searchaction', $this->escapeSearchLink() );
243 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
244 $tpl->setRef( 'stylepath', $wgStylePath );
245 $tpl->setRef( 'logopath', $wgLogo );
246 $tpl->setRef( "lang", $wgContLanguageCode );
247 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
248 $tpl->set( 'rtl', $wgContLang->isRTL() );
249 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
250 $tpl->setRef( 'username', $this->username );
251 $tpl->setRef( 'userpage', $this->userpage);
252 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
253 $tpl->setRef( 'usercss', $this->usercss);
254 $tpl->setRef( 'userjs', $this->userjs);
255 $tpl->setRef( 'userjsprev', $this->userjsprev);
256 global $wgUseSiteJs;
257 if ($wgUseSiteJs) {
258 if($this->loggedin) {
259 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
260 } else {
261 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
262 }
263 } else {
264 $tpl->set('jsvarurl', false);
265 }
266 if( $wgUser->getNewtalk() ) {
267 $usertitle = $this->mUser->getUserPage();
268 $usertalktitle = $usertitle->getTalkPage();
269 if( !$usertalktitle->equals( $this->mTitle ) ) {
270 $ntl = wfMsg( 'newmessages',
271 $this->makeKnownLinkObj(
272 $usertalktitle,
273 wfMsg('newmessageslink')
274 )
275 );
276 # Disable Cache
277 $wgOut->setSquidMaxage(0);
278 }
279 } else {
280 $ntl = '';
281 }
282 wfProfileOut( "$fname-stuff2" );
283
284 wfProfileIn( "$fname-stuff3" );
285 $tpl->setRef( 'newtalk', $ntl );
286 $tpl->setRef( 'skin', $this);
287 $tpl->set( 'logo', $this->logoText() );
288 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
289 if ( !$wgDisableCounters ) {
290 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
291 if ( $viewcount ) {
292 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
293 } else {
294 $tpl->set('viewcount', false);
295 }
296 } else {
297 $tpl->set('viewcount', false);
298 }
299
300 if ($wgPageShowWatchingUsers) {
301 $dbr =& wfGetDB( DB_SLAVE );
302 extract( $dbr->tableNames( 'watchlist' ) );
303 $sql = "SELECT COUNT(*) AS n FROM $watchlist
304 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
305 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
306 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
307 $x = $dbr->fetchObject( $res );
308 $numberofwatchingusers = $x->n;
309 if ($numberofwatchingusers > 0) {
310 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
311 } else {
312 $tpl->set('numberofwatchingusers', false);
313 }
314 } else {
315 $tpl->set('numberofwatchingusers', false);
316 }
317
318 $tpl->set('copyright',$this->getCopyright());
319
320 $this->credits = false;
321
322 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
323 require_once("Credits.php");
324 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
325 } else {
326 $tpl->set('lastmod', $this->lastModified());
327 }
328
329 $tpl->setRef( 'credits', $this->credits );
330
331 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
332 $tpl->set('copyright', $this->getCopyright());
333 $tpl->set('viewcount', false);
334 $tpl->set('lastmod', false);
335 $tpl->set('credits', false);
336 $tpl->set('numberofwatchingusers', false);
337 } else {
338 $tpl->set('copyright', false);
339 $tpl->set('viewcount', false);
340 $tpl->set('lastmod', false);
341 $tpl->set('credits', false);
342 $tpl->set('numberofwatchingusers', false);
343 }
344 wfProfileOut( "$fname-stuff3" );
345
346 wfProfileIn( "$fname-stuff4" );
347 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
348 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
349 $tpl->set( 'disclaimer', $this->disclaimerLink() );
350 $tpl->set( 'about', $this->aboutLink() );
351
352 $tpl->setRef( 'debug', $out->mDebugtext );
353 $tpl->set( 'reporttime', $out->reportTime() );
354 $tpl->set( 'sitenotice', wfGetSiteNotice() );
355
356 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
357 $out->mBodytext .= $printfooter ;
358 $tpl->setRef( 'bodytext', $out->mBodytext );
359
360 # Language links
361 $language_urls = array();
362
363 if ( !$wgHideInterlanguageLinks ) {
364 foreach( $wgOut->getLanguageLinks() as $l ) {
365 $tmp = explode( ':', $l, 2 );
366 $class = 'interwiki-' . $tmp[0];
367 unset($tmp);
368 $nt = Title::newFromText( $l );
369 $language_urls[] = array(
370 'href' => $nt->getFullURL(),
371 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
372 'class' => $class
373 );
374 }
375 }
376 if(count($language_urls)) {
377 $tpl->setRef( 'language_urls', $language_urls);
378 } else {
379 $tpl->set('language_urls', false);
380 }
381 wfProfileOut( "$fname-stuff4" );
382
383 # Personal toolbar
384 $tpl->set('personal_urls', $this->buildPersonalUrls());
385 $content_actions = $this->buildContentActionUrls();
386 $tpl->setRef('content_actions', $content_actions);
387
388 // XXX: attach this from javascript, same with section editing
389 if($this->iseditable && $wgUser->getOption("editondblclick") )
390 {
391 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
392 } else {
393 $tpl->set('body_ondblclick', false);
394 }
395 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
396 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
397 } else {
398 $tpl->set( 'body_onload', false );
399 }
400 $tpl->set( 'sidebar', $this->buildSidebar() );
401 $tpl->set( 'nav_urls', $this->buildNavUrls() );
402
403 // execute template
404 wfProfileIn( "$fname-execute" );
405 $res = $tpl->execute();
406 wfProfileOut( "$fname-execute" );
407
408 // result may be an error
409 $this->printOrError( $res );
410 wfProfileOut( $fname );
411 }
412
413 /**
414 * Output the string, or print error message if it's
415 * an error object of the appropriate type.
416 * For the base class, assume strings all around.
417 *
418 * @param mixed $str
419 * @access private
420 */
421 function printOrError( &$str ) {
422 echo $str;
423 }
424
425 /**
426 * build array of urls for personal toolbar
427 * @return array
428 * @access private
429 */
430 function buildPersonalUrls() {
431 $fname = 'SkinTemplate::buildPersonalUrls';
432 wfProfileIn( $fname );
433
434 /* set up the default links for the personal toolbar */
435 global $wgShowIPinHeader;
436 $personal_urls = array();
437 if ($this->loggedin) {
438 $personal_urls['userpage'] = array(
439 'text' => $this->username,
440 'href' => &$this->userpageUrlDetails['href'],
441 'class' => $this->userpageUrlDetails['exists']?false:'new'
442 );
443 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
444 $personal_urls['mytalk'] = array(
445 'text' => wfMsg('mytalk'),
446 'href' => &$usertalkUrlDetails['href'],
447 'class' => $usertalkUrlDetails['exists']?false:'new'
448 );
449 $personal_urls['preferences'] = array(
450 'text' => wfMsg('preferences'),
451 'href' => $this->makeSpecialUrl('Preferences')
452 );
453 $personal_urls['watchlist'] = array(
454 'text' => wfMsg('watchlist'),
455 'href' => $this->makeSpecialUrl('Watchlist')
456 );
457 $personal_urls['mycontris'] = array(
458 'text' => wfMsg('mycontris'),
459 'href' => $this->makeSpecialUrl("Contributions/$this->username")
460 );
461 $personal_urls['logout'] = array(
462 'text' => wfMsg('userlogout'),
463 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
464 );
465 } else {
466 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
467 $personal_urls['anonuserpage'] = array(
468 'text' => $this->username,
469 'href' => &$this->userpageUrlDetails['href'],
470 'class' => $this->userpageUrlDetails['exists']?false:'new'
471 );
472 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
473 $personal_urls['anontalk'] = array(
474 'text' => wfMsg('anontalk'),
475 'href' => &$usertalkUrlDetails['href'],
476 'class' => $usertalkUrlDetails['exists']?false:'new'
477 );
478 $personal_urls['anonlogin'] = array(
479 'text' => wfMsg('userlogin'),
480 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
481 );
482 } else {
483
484 $personal_urls['login'] = array(
485 'text' => wfMsg('userlogin'),
486 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
487 );
488 }
489 }
490 wfProfileOut( $fname );
491 return $personal_urls;
492 }
493
494
495 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
496 $classes = array();
497 if( $selected ) {
498 $classes[] = 'selected';
499 }
500 if( $checkEdit && $title->getArticleId() == 0 ) {
501 $classes[] = 'new';
502 $query = 'action=edit';
503 }
504 return array(
505 'class' => implode( ' ', $classes ),
506 'text' => wfMsg( $message ),
507 'href' => $title->getLocalUrl( $query ) );
508 }
509
510 function makeTalkUrlDetails( $name, $urlaction='' ) {
511 $title = Title::newFromText( $name );
512 $title = $title->getTalkPage();
513 $this->checkTitle($title, $name);
514 return array(
515 'href' => $title->getLocalURL( $urlaction ),
516 'exists' => $title->getArticleID() != 0?true:false
517 );
518 }
519
520 function makeArticleUrlDetails( $name, $urlaction='' ) {
521 $title = Title::newFromText( $name );
522 $title= $title->getSubjectPage();
523 $this->checkTitle($title, $name);
524 return array(
525 'href' => $title->getLocalURL( $urlaction ),
526 'exists' => $title->getArticleID() != 0?true:false
527 );
528 }
529
530 /**
531 * an array of edit links by default used for the tabs
532 * @return array
533 * @access private
534 */
535 function buildContentActionUrls () {
536 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
537 $fname = 'SkinTemplate::buildContentActionUrls';
538 wfProfileIn( $fname );
539
540 global $wgUser, $wgRequest;
541 $action = $wgRequest->getText( 'action' );
542 $section = $wgRequest->getText( 'section' );
543 $oldid = $wgRequest->getVal( 'oldid' );
544 $diff = $wgRequest->getVal( 'diff' );
545 $content_actions = array();
546
547 if( $this->iscontent ) {
548 $subjpage = $this->mTitle->getSubjectPage();
549 $talkpage = $this->mTitle->getTalkPage();
550
551 $nskey = $this->getNameSpaceKey();
552 $content_actions[$nskey] = $this->tabAction(
553 $subjpage,
554 $nskey,
555 !$this->mTitle->isTalkPage(),
556 '', true);
557
558 $content_actions['talk'] = $this->tabAction(
559 $talkpage,
560 'talk',
561 $this->mTitle->isTalkPage(),
562 '',
563 true);
564
565 wfProfileIn( "$fname-edit" );
566 if ( $this->mTitle->userCanEdit() ) {
567 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
568 $istalk = $this->mTitle->isTalkPage();
569 $istalkclass = $istalk?' istalk':'';
570 $content_actions['edit'] = array(
571 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
572 'text' => wfMsg('edit'),
573 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
574 );
575
576 if ( $istalk ) {
577 $content_actions['addsection'] = array(
578 'class' => $section == 'new'?'selected':false,
579 'text' => wfMsg('addsection'),
580 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
581 );
582 }
583 } else {
584 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
585 $content_actions['viewsource'] = array(
586 'class' => ($action == 'edit') ? 'selected' : false,
587 'text' => wfMsg('viewsource'),
588 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
589 );
590 }
591 wfProfileOut( "$fname-edit" );
592
593 wfProfileIn( "$fname-live" );
594 if ( $this->mTitle->getArticleId() ) {
595
596 $content_actions['history'] = array(
597 'class' => ($action == 'history') ? 'selected' : false,
598 'text' => wfMsg('history_short'),
599 'href' => $this->mTitle->getLocalUrl( 'action=history')
600 );
601
602 if($wgUser->isAllowed('protect')){
603 if(!$this->mTitle->isProtected()){
604 $content_actions['protect'] = array(
605 'class' => ($action == 'protect') ? 'selected' : false,
606 'text' => wfMsg('protect'),
607 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
608 );
609
610 } else {
611 $content_actions['unprotect'] = array(
612 'class' => ($action == 'unprotect') ? 'selected' : false,
613 'text' => wfMsg('unprotect'),
614 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
615 );
616 }
617 }
618 if($wgUser->isAllowed('delete')){
619 $content_actions['delete'] = array(
620 'class' => ($action == 'delete') ? 'selected' : false,
621 'text' => wfMsg('delete'),
622 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
623 );
624 }
625 if ( $wgUser->isLoggedIn() ) {
626 if ( $this->mTitle->userCanMove()) {
627 $content_actions['move'] = array(
628 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
629 'text' => wfMsg('move'),
630 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
631 );
632 }
633 }
634 } else {
635 //article doesn't exist or is deleted
636 if($wgUser->isAllowed('delete')){
637 if( $n = $this->mTitle->isDeleted() ) {
638 $content_actions['undelete'] = array(
639 'class' => false,
640 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
641 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
642 );
643 }
644 }
645 }
646 wfProfileOut( "$fname-live" );
647
648 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
649 if( !$this->mTitle->userIsWatching()) {
650 $content_actions['watch'] = array(
651 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
652 'text' => wfMsg('watch'),
653 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
654 );
655 } else {
656 $content_actions['unwatch'] = array(
657 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
658 'text' => wfMsg('unwatch'),
659 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
660 );
661 }
662 }
663
664 if( $wgUser->isLoggedIn() || $wgValidationForAnons ) { # and $action != 'submit' ) {
665 # Validate tab. TODO: add validation to logged-in user rights
666 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
667 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
668 else
669 {# Trying to get the current article revision through this weird stunt
670 $tid = $this->mTitle->getArticleID();
671 $tns = $this->mTitle->getNamespace();
672 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
673 $res = wfQuery( $sql, DB_READ );
674 if( $s = wfFetchObject( $res ) )
675 $oid = $s->page_latest ;
676 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
677 }
678 if ( $oid != "" ) {
679 $oid = "&revision={$oid}" ;
680 $content_actions['validate'] = array(
681 'class' => ($action == 'validate') ? 'selected' : false,
682 'text' => wfMsg('val_tab'),
683 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
684 );
685 }
686 }
687 }
688 } else {
689 /* show special page tab */
690
691 $content_actions['article'] = array(
692 'class' => 'selected',
693 'text' => wfMsg('specialpage'),
694 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
695 );
696 }
697
698 /* show links to different language variants */
699 global $wgDisableLangConversion;
700 $variants = $wgContLang->getVariants();
701 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
702 $preferred = $wgContLang->getPreferredVariant();
703 $actstr = '';
704 if( $action )
705 $actstr = 'action=' . $action . '&';
706 $vcount=0;
707 foreach( $variants as $code ) {
708 $varname = $wgContLang->getVariantname( $code );
709 if( $varname == 'disable' )
710 continue;
711 $selected = ( $code == $preferred )? 'selected' : false;
712 $content_actions['varlang-' . $vcount] = array(
713 'class' => $selected,
714 'text' => $varname,
715 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
716 );
717 $vcount ++;
718 }
719 }
720
721 wfRunHooks( 'SkinTemplateContentActions', array(&$content_actions) );
722
723 wfProfileOut( $fname );
724 return $content_actions;
725 }
726
727
728
729 /**
730 * build array of common navigation links
731 * @return array
732 * @access private
733 */
734 function buildNavUrls () {
735 global $wgUseTrackbacks, $wgTitle;
736
737 $fname = 'SkinTemplate::buildNavUrls';
738 wfProfileIn( $fname );
739
740 global $wgUser, $wgRequest;
741 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
742
743 $action = $wgRequest->getText( 'action' );
744 $oldid = $wgRequest->getVal( 'oldid' );
745 $diff = $wgRequest->getVal( 'diff' );
746
747 $nav_urls = array();
748 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
749 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
750 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
751 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
752 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
753 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
754 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
755 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
756 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
757 if( $wgEnableUploads ) {
758 if ($wgUploadNavigationUrl) {
759 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
760 } else {
761 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
762 }
763 } else {
764 $nav_urls['upload'] = false;
765 }
766 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
767
768
769 // A print stylesheet is attached to all pages, but nobody ever
770 // figures that out. :) Add a link...
771 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
772 $nav_urls['print'] = array(
773 'text' => wfMsg( 'printableversion' ),
774 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
775 }
776
777 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
778 $nav_urls['whatlinkshere'] = array(
779 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
780 );
781 $nav_urls['recentchangeslinked'] = array(
782 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
783 );
784 if ($wgUseTrackbacks)
785 $nav_urls['trackbacklink'] = array(
786 'href' => $wgTitle->trackbackURL()
787 );
788 }
789
790 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
791 $id = User::idFromName($this->mTitle->getText());
792 $ip = User::isIP($this->mTitle->getText());
793 } else {
794 $id = 0;
795 $ip = false;
796 }
797
798 if($id || $ip) { # both anons and non-anons have contri list
799 $nav_urls['contributions'] = array(
800 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
801 );
802 } else {
803 $nav_urls['contributions'] = false;
804 }
805 $nav_urls['emailuser'] = false;
806 if( $this->showEmailUser( $id ) ) {
807 $nav_urls['emailuser'] = array(
808 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
809 );
810 }
811 wfProfileOut( $fname );
812 return $nav_urls;
813 }
814
815 /**
816 * Generate strings used for xml 'id' names
817 * @return string
818 * @private
819 */
820 function getNameSpaceKey () {
821 switch ($this->mTitle->getNamespace()) {
822 case NS_MAIN:
823 case NS_TALK:
824 return 'nstab-main';
825 case NS_USER:
826 case NS_USER_TALK:
827 return 'nstab-user';
828 case NS_MEDIA:
829 return 'nstab-media';
830 case NS_SPECIAL:
831 return 'nstab-special';
832 case NS_PROJECT:
833 case NS_PROJECT_TALK:
834 return 'nstab-wp';
835 case NS_IMAGE:
836 case NS_IMAGE_TALK:
837 return 'nstab-image';
838 case NS_MEDIAWIKI:
839 case NS_MEDIAWIKI_TALK:
840 return 'nstab-mediawiki';
841 case NS_TEMPLATE:
842 case NS_TEMPLATE_TALK:
843 return 'nstab-template';
844 case NS_HELP:
845 case NS_HELP_TALK:
846 return 'nstab-help';
847 case NS_CATEGORY:
848 case NS_CATEGORY_TALK:
849 return 'nstab-category';
850 default:
851 return 'nstab-main';
852 }
853 }
854
855 /**
856 * @access private
857 */
858 function setupUserCss() {
859 $fname = 'SkinTemplate::setupUserCss';
860 wfProfileIn( $fname );
861
862 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
863
864 $sitecss = '';
865 $usercss = '';
866 $siteargs = '&maxage=' . $wgSquidMaxage;
867
868 # Add user-specific code if this is a user and we allow that kind of thing
869
870 if ( $wgAllowUserCss && $this->loggedin ) {
871 $action = $wgRequest->getText('action');
872
873 # if we're previewing the CSS page, use it
874 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
875 $siteargs = "&smaxage=0&maxage=0";
876 $usercss = $wgRequest->getText('wpTextbox1');
877 } else {
878 $usercss = '@import "' .
879 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
880 'action=raw&ctype=text/css') . '";' ."\n";
881 }
882
883 $siteargs .= '&ts=' . $wgUser->mTouched;
884 }
885
886 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
887
888 # If we use the site's dynamic CSS, throw that in, too
889 if ( $wgUseSiteCss ) {
890 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
891 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
892 }
893
894 # If we use any dynamic CSS, make a little CDATA block out of it.
895
896 if ( !empty($sitecss) || !empty($usercss) ) {
897 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
898 }
899 wfProfileOut( $fname );
900 }
901
902 /**
903 * @access private
904 */
905 function setupUserJs() {
906 $fname = 'SkinTemplate::setupUserJs';
907 wfProfileIn( $fname );
908
909 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
910 $action = $wgRequest->getText('action');
911
912 if( $wgAllowUserJs && $this->loggedin ) {
913 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
914 # XXX: additional security check/prompt?
915 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
916 } else {
917 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
918 }
919 }
920 wfProfileOut( $fname );
921 }
922
923 /**
924 * returns css with user-specific options
925 * @access public
926 */
927
928 function getUserStylesheet() {
929 $fname = 'SkinTemplate::getUserStylesheet';
930 wfProfileIn( $fname );
931
932 global $wgUser;
933 $s = "/* generated user stylesheet */\n";
934 $s .= $this->reallyDoGetUserStyles();
935 wfProfileOut( $fname );
936 return $s;
937 }
938
939 /**
940 * @access public
941 */
942 function getUserJs() {
943 $fname = 'SkinTemplate::getUserJs';
944 wfProfileIn( $fname );
945
946 global $wgStylePath;
947 $s = '/* generated javascript */';
948 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
949 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
950
951 // avoid inclusion of non defined user JavaScript (with custom skins only)
952 // by checking for default message content
953 $msgKey = ucfirst($this->skinname).'.js';
954 $userJS = wfMsg($msgKey);
955 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
956 $s .= $userJS;
957 }
958
959 wfProfileOut( $fname );
960 return $s;
961 }
962 }
963
964 /**
965 * Generic wrapper for template functions, with interface
966 * compatible with what we use of PHPTAL 0.7.
967 * @package MediaWiki
968 * @subpackage Skins
969 */
970 class QuickTemplate {
971 /**
972 * @access public
973 */
974 function QuickTemplate() {
975 $this->data = array();
976 $this->translator = new MediaWiki_I18N();
977 }
978
979 /**
980 * @access public
981 */
982 function set( $name, $value ) {
983 $this->data[$name] = $value;
984 }
985
986 /**
987 * @access public
988 */
989 function setRef($name, &$value) {
990 $this->data[$name] =& $value;
991 }
992
993 /**
994 * @access public
995 */
996 function setTranslator( &$t ) {
997 $this->translator = &$t;
998 }
999
1000 /**
1001 * @access public
1002 */
1003 function execute() {
1004 echo "Override this function.";
1005 }
1006
1007
1008 /**
1009 * @access private
1010 */
1011 function text( $str ) {
1012 echo htmlspecialchars( $this->data[$str] );
1013 }
1014
1015 /**
1016 * @access private
1017 */
1018 function html( $str ) {
1019 echo $this->data[$str];
1020 }
1021
1022 /**
1023 * @access private
1024 */
1025 function msg( $str ) {
1026 echo htmlspecialchars( $this->translator->translate( $str ) );
1027 }
1028
1029 /**
1030 * @access private
1031 */
1032 function msgHtml( $str ) {
1033 echo $this->translator->translate( $str );
1034 }
1035
1036 /**
1037 * An ugly, ugly hack.
1038 * @access private
1039 */
1040 function msgWiki( $str ) {
1041 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1042
1043 $text = $this->translator->translate( $str );
1044 $parserOutput = $wgParser->parse( $text, $wgTitle,
1045 $wgOut->mParserOptions, true );
1046 echo $parserOutput->getText();
1047 }
1048
1049 /**
1050 * @access private
1051 */
1052 function haveData( $str ) {
1053 return $this->data[$str];
1054 }
1055
1056 /**
1057 * @access private
1058 */
1059 function haveMsg( $str ) {
1060 $msg = $this->translator->translate( $str );
1061 return ($msg != '-') && ($msg != ''); # ????
1062 }
1063 }
1064
1065 } // end of if( defined( 'MEDIAWIKI' ) )
1066 ?>