Show <nstab-foobar> instead of 'article' for the namespace tab. That's a
[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, $wgContLanguageCode;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $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
182 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
183 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
184 } else {
185 # This won't be used in the standard skins, but we define it to preserve the interface
186 # To save time, we check for existence
187 $this->userpageUrlDetails = $this->makeKnownUrlDetails($this->userpage);
188 }
189
190 $this->usercss = $this->userjs = $this->userjsprev = false;
191 $this->setupUserCss();
192 $this->setupUserJs();
193 $this->titletxt = $this->mTitle->getPrefixedText();
194 wfProfileOut( "$fname-stuff" );
195
196 wfProfileIn( "$fname-stuff2" );
197 $tpl->set( 'title', $wgOut->getPageTitle() );
198 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
199
200 $tpl->setRef( "thispage", $this->thispage );
201 $subpagestr = $this->subPageSubtitle();
202 $tpl->set(
203 'subtitle', !empty($subpagestr)?
204 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
205 $out->getSubtitle()
206 );
207 $undelete = $this->getUndeleteLink();
208 $tpl->set(
209 "undelete", !empty($undelete)?
210 '<span class="subpages">'.$undelete.'</span>':
211 ''
212 );
213
214 $tpl->set( 'catlinks', $this->getCategories());
215 if( $wgOut->isSyndicated() ) {
216 $feeds = array();
217 foreach( $wgFeedClasses as $format => $class ) {
218 $feeds[$format] = array(
219 'text' => $format,
220 'href' => $wgRequest->appendQuery( "feed=$format" ),
221 'ttip' => wfMsg('tooltip-'.$format)
222 );
223 }
224 $tpl->setRef( 'feeds', $feeds );
225 } else {
226 $tpl->set( 'feeds', false );
227 }
228 if ($wgUseTrackbacks && $out->isArticleRelated())
229 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
230
231 $tpl->setRef( 'mimetype', $wgMimeType );
232 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
233 $tpl->setRef( 'charset', $wgOutputEncoding );
234 $tpl->set( 'headlinks', $out->getHeadLinks() );
235 $tpl->set('headscripts', $out->getScript() );
236 $tpl->setRef( 'wgScript', $wgScript );
237 $tpl->setRef( 'skinname', $this->skinname );
238 $tpl->setRef( 'stylename', $this->stylename );
239 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
240 $tpl->setRef( 'loggedin', $this->loggedin );
241 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
242 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
243 /* XXX currently unused, might get useful later
244 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
245 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
246 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
247 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
248 $tpl->set( "helppage", wfMsg('helppage'));
249 */
250 $tpl->set( 'searchaction', $this->escapeSearchLink() );
251 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
252 $tpl->setRef( 'stylepath', $wgStylePath );
253 $tpl->setRef( 'logopath', $wgLogo );
254 $tpl->setRef( "lang", $wgContLanguageCode );
255 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
256 $tpl->set( 'rtl', $wgContLang->isRTL() );
257 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
258 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
259 $tpl->setRef( 'username', $this->username );
260 $tpl->setRef( 'userpage', $this->userpage);
261 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
262 $tpl->set( 'pagecss', $this->setupPageCss() );
263 $tpl->setRef( 'usercss', $this->usercss);
264 $tpl->setRef( 'userjs', $this->userjs);
265 $tpl->setRef( 'userjsprev', $this->userjsprev);
266 global $wgUseSiteJs;
267 if ($wgUseSiteJs) {
268 if($this->loggedin) {
269 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
270 } else {
271 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
272 }
273 } else {
274 $tpl->set('jsvarurl', false);
275 }
276 if( $wgUser->getNewtalk() ) {
277 $usertitle = $this->mUser->getUserPage();
278 $usertalktitle = $usertitle->getTalkPage();
279 if( !$usertalktitle->equals( $this->mTitle ) ) {
280 $ntl = wfMsg( 'newmessages',
281 $this->makeKnownLinkObj(
282 $usertalktitle,
283 wfMsg('newmessageslink')
284 )
285 );
286 # Disable Cache
287 $wgOut->setSquidMaxage(0);
288 }
289 } else {
290 $ntl = '';
291 }
292 wfProfileOut( "$fname-stuff2" );
293
294 wfProfileIn( "$fname-stuff3" );
295 $tpl->setRef( 'newtalk', $ntl );
296 $tpl->setRef( 'skin', $this);
297 $tpl->set( 'logo', $this->logoText() );
298 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
299 if ( !$wgDisableCounters ) {
300 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
301 if ( $viewcount ) {
302 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
303 } else {
304 $tpl->set('viewcount', false);
305 }
306 } else {
307 $tpl->set('viewcount', false);
308 }
309
310 if ($wgPageShowWatchingUsers) {
311 $dbr =& wfGetDB( DB_SLAVE );
312 extract( $dbr->tableNames( 'watchlist' ) );
313 $sql = "SELECT COUNT(*) AS n FROM $watchlist
314 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
315 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
316 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
317 $x = $dbr->fetchObject( $res );
318 $numberofwatchingusers = $x->n;
319 if ($numberofwatchingusers > 0) {
320 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
321 } else {
322 $tpl->set('numberofwatchingusers', false);
323 }
324 } else {
325 $tpl->set('numberofwatchingusers', false);
326 }
327
328 $tpl->set('copyright',$this->getCopyright());
329
330 $this->credits = false;
331
332 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
333 require_once("Credits.php");
334 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
335 } else {
336 $tpl->set('lastmod', $this->lastModified());
337 }
338
339 $tpl->setRef( 'credits', $this->credits );
340
341 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
342 $tpl->set('copyright', $this->getCopyright());
343 $tpl->set('viewcount', false);
344 $tpl->set('lastmod', false);
345 $tpl->set('credits', false);
346 $tpl->set('numberofwatchingusers', false);
347 } else {
348 $tpl->set('copyright', false);
349 $tpl->set('viewcount', false);
350 $tpl->set('lastmod', false);
351 $tpl->set('credits', false);
352 $tpl->set('numberofwatchingusers', false);
353 }
354 wfProfileOut( "$fname-stuff3" );
355
356 wfProfileIn( "$fname-stuff4" );
357 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
358 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
359 $tpl->set( 'disclaimer', $this->disclaimerLink() );
360 $tpl->set( 'privacy', $this->privacyLink() );
361 $tpl->set( 'about', $this->aboutLink() );
362
363 $tpl->setRef( 'debug', $out->mDebugtext );
364 $tpl->set( 'reporttime', $out->reportTime() );
365 $tpl->set( 'sitenotice', wfGetSiteNotice() );
366
367 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
368 $out->mBodytext .= $printfooter ;
369 $tpl->setRef( 'bodytext', $out->mBodytext );
370
371 # Language links
372 $language_urls = array();
373
374 if ( !$wgHideInterlanguageLinks ) {
375 foreach( $wgOut->getLanguageLinks() as $l ) {
376 $tmp = explode( ':', $l, 2 );
377 $class = 'interwiki-' . $tmp[0];
378 unset($tmp);
379 $nt = Title::newFromText( $l );
380 $language_urls[] = array(
381 'href' => $nt->getFullURL(),
382 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
383 'class' => $class
384 );
385 }
386 }
387 if(count($language_urls)) {
388 $tpl->setRef( 'language_urls', $language_urls);
389 } else {
390 $tpl->set('language_urls', false);
391 }
392 wfProfileOut( "$fname-stuff4" );
393
394 # Personal toolbar
395 $tpl->set('personal_urls', $this->buildPersonalUrls());
396 $content_actions = $this->buildContentActionUrls();
397 $tpl->setRef('content_actions', $content_actions);
398
399 // XXX: attach this from javascript, same with section editing
400 if($this->iseditable && $wgUser->getOption("editondblclick") )
401 {
402 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
403 } else {
404 $tpl->set('body_ondblclick', false);
405 }
406 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
407 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
408 } else {
409 $tpl->set( 'body_onload', false );
410 }
411 $tpl->set( 'sidebar', $this->buildSidebar() );
412 $tpl->set( 'nav_urls', $this->buildNavUrls() );
413
414 // execute template
415 wfProfileIn( "$fname-execute" );
416 $res = $tpl->execute();
417 wfProfileOut( "$fname-execute" );
418
419 // result may be an error
420 $this->printOrError( $res );
421 wfProfileOut( $fname );
422 }
423
424 /**
425 * Output the string, or print error message if it's
426 * an error object of the appropriate type.
427 * For the base class, assume strings all around.
428 *
429 * @param mixed $str
430 * @access private
431 */
432 function printOrError( &$str ) {
433 echo $str;
434 }
435
436 /**
437 * build array of urls for personal toolbar
438 * @return array
439 * @access private
440 */
441 function buildPersonalUrls() {
442 global $wgTitle, $wgShowIPinHeader, $wgContLang;
443
444 $fname = 'SkinTemplate::buildPersonalUrls';
445 $pageurl = $wgTitle->getLocalURL();
446 wfProfileIn( $fname );
447
448 /* set up the default links for the personal toolbar */
449 $personal_urls = array();
450 if ($this->loggedin) {
451 $personal_urls['userpage'] = array(
452 'text' => $this->username,
453 'href' => &$this->userpageUrlDetails['href'],
454 'class' => $this->userpageUrlDetails['exists']?false:'new',
455 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
456 );
457 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
458 $personal_urls['mytalk'] = array(
459 'text' => wfMsg('mytalk'),
460 'href' => &$usertalkUrlDetails['href'],
461 'class' => $usertalkUrlDetails['exists']?false:'new',
462 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
463 );
464 $href = $this->makeSpecialUrl('Preferences');
465 $personal_urls['preferences'] = array(
466 'text' => wfMsg('preferences'),
467 'href' => $this->makeSpecialUrl('Preferences'),
468 'active' => ( $href == $pageurl )
469 );
470 $href = $this->makeSpecialUrl('Watchlist');
471 $personal_urls['watchlist'] = array(
472 'text' => wfMsg('watchlist'),
473 'href' => $href,
474 'active' => ( $href == $pageurl )
475 );
476 $href = $this->makeSpecialUrl("Contributions/$this->username");
477 $personal_urls['mycontris'] = array(
478 'text' => wfMsg('mycontris'),
479 'href' => $href
480 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
481 );
482 $personal_urls['logout'] = array(
483 'text' => wfMsg('userlogout'),
484 'href' => $this->makeSpecialUrl( 'Userlogout',
485 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
486 )
487 );
488 } else {
489 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
490 $href = &$this->userpageUrlDetails['href'];
491 $personal_urls['anonuserpage'] = array(
492 'text' => $this->username,
493 'href' => $href,
494 'class' => $this->userpageUrlDetails['exists']?false:'new',
495 'active' => ( $pageurl == $href )
496 );
497 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
498 $href = &$usertalkUrlDetails['href'];
499 $personal_urls['anontalk'] = array(
500 'text' => wfMsg('anontalk'),
501 'href' => $href,
502 'class' => $usertalkUrlDetails['exists']?false:'new',
503 'active' => ( $pageurl == $href )
504 );
505 $personal_urls['anonlogin'] = array(
506 'text' => wfMsg('userlogin'),
507 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
508 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
509 );
510 } else {
511
512 $personal_urls['login'] = array(
513 'text' => wfMsg('userlogin'),
514 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
515 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
516 );
517 }
518 }
519 wfProfileOut( $fname );
520 return $personal_urls;
521 }
522
523 /**
524 * Returns true if the IP should be shown in the header
525 */
526 function showIPinHeader() {
527 global $wgShowIPinHeader;
528 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
529 }
530
531 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
532 $classes = array();
533 if( $selected ) {
534 $classes[] = 'selected';
535 }
536 if( $checkEdit && $title->getArticleId() == 0 ) {
537 $classes[] = 'new';
538 $query = 'action=edit';
539 }
540
541 $text = wfMsg( $message );
542 if ( $text == "&lt;$message&gt;" ) {
543 $text = html_entity_decode($text);
544 }
545
546 return array(
547 'class' => implode( ' ', $classes ),
548 'text' => $text,
549 'href' => $title->getLocalUrl( $query ) );
550 }
551
552 function makeTalkUrlDetails( $name, $urlaction='' ) {
553 $title = Title::newFromText( $name );
554 $title = $title->getTalkPage();
555 $this->checkTitle($title, $name);
556 return array(
557 'href' => $title->getLocalURL( $urlaction ),
558 'exists' => $title->getArticleID() != 0?true:false
559 );
560 }
561
562 function makeArticleUrlDetails( $name, $urlaction='' ) {
563 $title = Title::newFromText( $name );
564 $title= $title->getSubjectPage();
565 $this->checkTitle($title, $name);
566 return array(
567 'href' => $title->getLocalURL( $urlaction ),
568 'exists' => $title->getArticleID() != 0?true:false
569 );
570 }
571
572 /**
573 * an array of edit links by default used for the tabs
574 * @return array
575 * @access private
576 */
577 function buildContentActionUrls () {
578 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
579 $fname = 'SkinTemplate::buildContentActionUrls';
580 wfProfileIn( $fname );
581
582 global $wgUser, $wgRequest;
583 $action = $wgRequest->getText( 'action' );
584 $section = $wgRequest->getText( 'section' );
585 $content_actions = array();
586
587 $prevent_active_tabs = false ;
588 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
589
590 if( $this->iscontent ) {
591 $subjpage = $this->mTitle->getSubjectPage();
592 $talkpage = $this->mTitle->getTalkPage();
593
594 $nskey = $this->getNameSpaceKey();
595 $content_actions[$nskey] = $this->tabAction(
596 $subjpage,
597 $nskey,
598 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
599 '', true);
600
601 $content_actions['talk'] = $this->tabAction(
602 $talkpage,
603 'talk',
604 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
605 '',
606 true);
607
608 wfProfileIn( "$fname-edit" );
609 if ( $this->mTitle->userCanEdit() ) {
610 $istalk = $this->mTitle->isTalkPage();
611 $istalkclass = $istalk?' istalk':'';
612 $content_actions['edit'] = array(
613 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
614 'text' => wfMsg('edit'),
615 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
616 );
617
618 if ( $istalk ) {
619 $content_actions['addsection'] = array(
620 'class' => $section == 'new'?'selected':false,
621 'text' => wfMsg('addsection'),
622 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
623 );
624 }
625 } else {
626 $content_actions['viewsource'] = array(
627 'class' => ($action == 'edit') ? 'selected' : false,
628 'text' => wfMsg('viewsource'),
629 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
630 );
631 }
632 wfProfileOut( "$fname-edit" );
633
634 wfProfileIn( "$fname-live" );
635 if ( $this->mTitle->getArticleId() ) {
636
637 $content_actions['history'] = array(
638 'class' => ($action == 'history') ? 'selected' : false,
639 'text' => wfMsg('history_short'),
640 'href' => $this->mTitle->getLocalUrl( 'action=history')
641 );
642
643 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
644 if(!$this->mTitle->isProtected()){
645 $content_actions['protect'] = array(
646 'class' => ($action == 'protect') ? 'selected' : false,
647 'text' => wfMsg('protect'),
648 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
649 );
650
651 } else {
652 $content_actions['unprotect'] = array(
653 'class' => ($action == 'unprotect') ? 'selected' : false,
654 'text' => wfMsg('unprotect'),
655 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
656 );
657 }
658 }
659 if($wgUser->isAllowed('delete')){
660 $content_actions['delete'] = array(
661 'class' => ($action == 'delete') ? 'selected' : false,
662 'text' => wfMsg('delete'),
663 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
664 );
665 }
666 if ( $this->mTitle->userCanMove()) {
667 $content_actions['move'] = array(
668 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
669 'text' => wfMsg('move'),
670 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
671 );
672 }
673 } else {
674 //article doesn't exist or is deleted
675 if($wgUser->isAllowed('delete')){
676 if( $n = $this->mTitle->isDeleted() ) {
677 $content_actions['undelete'] = array(
678 'class' => false,
679 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
680 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
681 );
682 }
683 }
684 }
685 wfProfileOut( "$fname-live" );
686
687 if( $this->loggedin ) {
688 if( !$this->mTitle->userIsWatching()) {
689 $content_actions['watch'] = array(
690 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
691 'text' => wfMsg('watch'),
692 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
693 );
694 } else {
695 $content_actions['unwatch'] = array(
696 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
697 'text' => wfMsg('unwatch'),
698 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
699 );
700 }
701 }
702
703 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
704
705 if( $this->loggedin || $wgValidationForAnons ) { # and $action != 'submit' ) {
706 # Validate tab. TODO: add validation to logged-in user rights
707 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
708 if ( $this->mRevisionId ) $oid = intval( $this->mRevisionId ) ; # Use the oldid
709 else
710 {# Trying to get the current article revision through this weird stunt
711 $tid = $this->mTitle->getArticleID();
712 $tns = $this->mTitle->getNamespace();
713 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
714 $res = wfQuery( $sql, DB_READ );
715 if( $s = wfFetchObject( $res ) )
716 $oid = $s->page_latest ;
717 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
718 }
719 if ( $oid != "" ) {
720 $oid = "&revision={$oid}" ;
721 $content_actions['validate'] = array(
722 'class' => ($action == 'validate') ? 'selected' : false,
723 'text' => wfMsg('val_tab'),
724 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
725 );
726 }
727 }
728 }
729 } else {
730 /* show special page tab */
731
732 $content_actions['article'] = array(
733 'class' => 'selected',
734 'text' => wfMsg('specialpage'),
735 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
736 );
737
738 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
739 }
740
741 /* show links to different language variants */
742 global $wgDisableLangConversion;
743 $variants = $wgContLang->getVariants();
744 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
745 $preferred = $wgContLang->getPreferredVariant();
746 $actstr = '';
747 if( $action )
748 $actstr = 'action=' . $action . '&';
749 $vcount=0;
750 foreach( $variants as $code ) {
751 $varname = $wgContLang->getVariantname( $code );
752 if( $varname == 'disable' )
753 continue;
754 $selected = ( $code == $preferred )? 'selected' : false;
755 $content_actions['varlang-' . $vcount] = array(
756 'class' => $selected,
757 'text' => $varname,
758 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
759 );
760 $vcount ++;
761 }
762 }
763
764 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
765
766 wfProfileOut( $fname );
767 return $content_actions;
768 }
769
770
771
772 /**
773 * build array of common navigation links
774 * @return array
775 * @access private
776 */
777 function buildNavUrls () {
778 global $wgUseTrackbacks, $wgTitle, $wgArticle;
779
780 $fname = 'SkinTemplate::buildNavUrls';
781 wfProfileIn( $fname );
782
783 global $wgUser, $wgRequest;
784 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
785
786 $action = $wgRequest->getText( 'action' );
787 $oldid = $wgRequest->getVal( 'oldid' );
788 $diff = $wgRequest->getVal( 'diff' );
789
790 $nav_urls = array();
791 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
792 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
793 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
794 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
795 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
796 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
797 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
798 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
799 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
800 if( $wgEnableUploads ) {
801 if ($wgUploadNavigationUrl) {
802 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
803 } else {
804 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
805 }
806 } else {
807 if ($wgUploadNavigationUrl)
808 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
809 else
810 $nav_urls['upload'] = false;
811 }
812 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
813
814
815 // A print stylesheet is attached to all pages, but nobody ever
816 // figures that out. :) Add a link...
817 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
818 $revid = $wgArticle->getRevIdFetched();
819 if ( !( $revid == 0 ) )
820 $nav_urls['print'] = array(
821 'text' => wfMsg( 'printableversion' ),
822 'href' => $wgRequest->appendQuery( 'printable=yes' )
823 );
824
825 // Also add a "permalink" while we're at it
826 if ( (int)$oldid ) {
827 $nav_urls['permalink'] = array(
828 'text' => wfMsg( 'permalink' ),
829 'href' => ''
830 );
831 } else {
832 if ( !( $revid == 0 ) )
833 $nav_urls['permalink'] = array(
834 'text' => wfMsg( 'permalink' ),
835 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
836 );
837 }
838
839 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
840 }
841
842 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
843 $nav_urls['whatlinkshere'] = array(
844 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
845 );
846 if( $this->mTitle->getArticleId() ) {
847 $nav_urls['recentchangeslinked'] = array(
848 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
849 );
850 }
851 if ($wgUseTrackbacks)
852 $nav_urls['trackbacklink'] = array(
853 'href' => $wgTitle->trackbackURL()
854 );
855 }
856
857 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
858 $id = User::idFromName($this->mTitle->getText());
859 $ip = User::isIP($this->mTitle->getText());
860 } else {
861 $id = 0;
862 $ip = false;
863 }
864
865 if($id || $ip) { # both anons and non-anons have contri list
866 $nav_urls['contributions'] = array(
867 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
868 );
869 if ( $wgUser->isAllowed( 'protect' ) )
870 $nav_urls['blockip'] = array(
871 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
872 );
873 } else {
874 $nav_urls['contributions'] = false;
875 }
876 $nav_urls['emailuser'] = false;
877 if( $this->showEmailUser( $id ) ) {
878 $nav_urls['emailuser'] = array(
879 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
880 );
881 }
882 wfProfileOut( $fname );
883 return $nav_urls;
884 }
885
886 /**
887 * Generate strings used for xml 'id' names
888 * @return string
889 * @private
890 */
891 function getNameSpaceKey () {
892 switch ($this->mTitle->getNamespace()) {
893 case NS_MAIN:
894 case NS_TALK:
895 return 'nstab-main';
896 case NS_USER:
897 case NS_USER_TALK:
898 return 'nstab-user';
899 case NS_MEDIA:
900 return 'nstab-media';
901 case NS_SPECIAL:
902 return 'nstab-special';
903 case NS_PROJECT:
904 case NS_PROJECT_TALK:
905 return 'nstab-wp';
906 case NS_IMAGE:
907 case NS_IMAGE_TALK:
908 return 'nstab-image';
909 case NS_MEDIAWIKI:
910 case NS_MEDIAWIKI_TALK:
911 return 'nstab-mediawiki';
912 case NS_TEMPLATE:
913 case NS_TEMPLATE_TALK:
914 return 'nstab-template';
915 case NS_HELP:
916 case NS_HELP_TALK:
917 return 'nstab-help';
918 case NS_CATEGORY:
919 case NS_CATEGORY_TALK:
920 return 'nstab-category';
921 default:
922 return 'nstab-' . strtolower( $this->mTitle->getSubjectNsText() );
923 }
924 }
925
926 /**
927 * @access private
928 */
929 function setupUserCss() {
930 $fname = 'SkinTemplate::setupUserCss';
931 wfProfileIn( $fname );
932
933 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
934
935 $sitecss = '';
936 $usercss = '';
937 $siteargs = '&maxage=' . $wgSquidMaxage;
938
939 # Add user-specific code if this is a user and we allow that kind of thing
940
941 if ( $wgAllowUserCss && $this->loggedin ) {
942 $action = $wgRequest->getText('action');
943
944 # if we're previewing the CSS page, use it
945 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
946 $siteargs = "&smaxage=0&maxage=0";
947 $usercss = $wgRequest->getText('wpTextbox1');
948 } else {
949 $usercss = '@import "' .
950 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
951 'action=raw&ctype=text/css') . '";' ."\n";
952 }
953
954 $siteargs .= '&ts=' . $wgUser->mTouched;
955 }
956
957 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
958
959 # If we use the site's dynamic CSS, throw that in, too
960 if ( $wgUseSiteCss ) {
961 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
962 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
963 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
964 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
965 }
966
967 # If we use any dynamic CSS, make a little CDATA block out of it.
968
969 if ( !empty($sitecss) || !empty($usercss) ) {
970 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
971 }
972 wfProfileOut( $fname );
973 }
974
975 /**
976 * @access private
977 */
978 function setupUserJs() {
979 $fname = 'SkinTemplate::setupUserJs';
980 wfProfileIn( $fname );
981
982 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
983 $action = $wgRequest->getText('action');
984
985 if( $wgAllowUserJs && $this->loggedin ) {
986 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
987 # XXX: additional security check/prompt?
988 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
989 } else {
990 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
991 }
992 }
993 wfProfileOut( $fname );
994 }
995
996 /**
997 * Code for extensions to hook into to provide per-page CSS, see
998 * extensions/PageCSS/PageCSS.php for an implementation of this.
999 *
1000 * @access private
1001 */
1002 function setupPageCss() {
1003 $fname = 'SkinTemplate::setupPageCss';
1004 wfProfileIn( $fname );
1005 $out = false;
1006 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle->isProtected() ) );
1007 wfProfileOut( $fname );
1008 return $out;
1009 }
1010
1011 /**
1012 * returns css with user-specific options
1013 * @access public
1014 */
1015
1016 function getUserStylesheet() {
1017 $fname = 'SkinTemplate::getUserStylesheet';
1018 wfProfileIn( $fname );
1019
1020 global $wgUser;
1021 $s = "/* generated user stylesheet */\n";
1022 $s .= $this->reallyDoGetUserStyles();
1023 wfProfileOut( $fname );
1024 return $s;
1025 }
1026
1027 /**
1028 * @access public
1029 */
1030 function getUserJs() {
1031 $fname = 'SkinTemplate::getUserJs';
1032 wfProfileIn( $fname );
1033
1034 global $wgStylePath;
1035 $s = '/* generated javascript */';
1036 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1037 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
1038
1039 // avoid inclusion of non defined user JavaScript (with custom skins only)
1040 // by checking for default message content
1041 $msgKey = ucfirst($this->skinname).'.js';
1042 $userJS = wfMsg($msgKey);
1043 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
1044 $s .= $userJS;
1045 }
1046
1047 wfProfileOut( $fname );
1048 return $s;
1049 }
1050 }
1051
1052 /**
1053 * Generic wrapper for template functions, with interface
1054 * compatible with what we use of PHPTAL 0.7.
1055 * @package MediaWiki
1056 * @subpackage Skins
1057 */
1058 class QuickTemplate {
1059 /**
1060 * @access public
1061 */
1062 function QuickTemplate() {
1063 $this->data = array();
1064 $this->translator = new MediaWiki_I18N();
1065 }
1066
1067 /**
1068 * @access public
1069 */
1070 function set( $name, $value ) {
1071 $this->data[$name] = $value;
1072 }
1073
1074 /**
1075 * @access public
1076 */
1077 function setRef($name, &$value) {
1078 $this->data[$name] =& $value;
1079 }
1080
1081 /**
1082 * @access public
1083 */
1084 function setTranslator( &$t ) {
1085 $this->translator = &$t;
1086 }
1087
1088 /**
1089 * @access public
1090 */
1091 function execute() {
1092 echo "Override this function.";
1093 }
1094
1095
1096 /**
1097 * @access private
1098 */
1099 function text( $str ) {
1100 echo htmlspecialchars( $this->data[$str] );
1101 }
1102
1103 /**
1104 * @access private
1105 */
1106 function html( $str ) {
1107 echo $this->data[$str];
1108 }
1109
1110 /**
1111 * @access private
1112 */
1113 function msg( $str ) {
1114 echo htmlspecialchars( $this->translator->translate( $str ) );
1115 }
1116
1117 /**
1118 * @access private
1119 */
1120 function msgHtml( $str ) {
1121 echo $this->translator->translate( $str );
1122 }
1123
1124 /**
1125 * An ugly, ugly hack.
1126 * @access private
1127 */
1128 function msgWiki( $str ) {
1129 global $wgParser, $wgTitle, $wgOut;
1130
1131 $text = $this->translator->translate( $str );
1132 $parserOutput = $wgParser->parse( $text, $wgTitle,
1133 $wgOut->mParserOptions, true );
1134 echo $parserOutput->getText();
1135 }
1136
1137 /**
1138 * @access private
1139 */
1140 function haveData( $str ) {
1141 return $this->data[$str];
1142 }
1143
1144 /**
1145 * @access private
1146 */
1147 function haveMsg( $str ) {
1148 $msg = $this->translator->translate( $str );
1149 return ($msg != '-') && ($msg != ''); # ????
1150 }
1151 }
1152
1153 } // end of if( defined( 'MEDIAWIKI' ) )
1154 ?>