* Last commmit fixed, done properly now
[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
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( 'about', $this->aboutLink() );
361
362 $tpl->setRef( 'debug', $out->mDebugtext );
363 $tpl->set( 'reporttime', $out->reportTime() );
364 $tpl->set( 'sitenotice', wfGetSiteNotice() );
365
366 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
367 $out->mBodytext .= $printfooter ;
368 $tpl->setRef( 'bodytext', $out->mBodytext );
369
370 # Language links
371 $language_urls = array();
372
373 if ( !$wgHideInterlanguageLinks ) {
374 foreach( $wgOut->getLanguageLinks() as $l ) {
375 $tmp = explode( ':', $l, 2 );
376 $class = 'interwiki-' . $tmp[0];
377 unset($tmp);
378 $nt = Title::newFromText( $l );
379 $language_urls[] = array(
380 'href' => $nt->getFullURL(),
381 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
382 'class' => $class
383 );
384 }
385 }
386 if(count($language_urls)) {
387 $tpl->setRef( 'language_urls', $language_urls);
388 } else {
389 $tpl->set('language_urls', false);
390 }
391 wfProfileOut( "$fname-stuff4" );
392
393 # Personal toolbar
394 $tpl->set('personal_urls', $this->buildPersonalUrls());
395 $content_actions = $this->buildContentActionUrls();
396 $tpl->setRef('content_actions', $content_actions);
397
398 // XXX: attach this from javascript, same with section editing
399 if($this->iseditable && $wgUser->getOption("editondblclick") )
400 {
401 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
402 } else {
403 $tpl->set('body_ondblclick', false);
404 }
405 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
406 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
407 } else {
408 $tpl->set( 'body_onload', false );
409 }
410 $tpl->set( 'sidebar', $this->buildSidebar() );
411 $tpl->set( 'nav_urls', $this->buildNavUrls() );
412
413 // execute template
414 wfProfileIn( "$fname-execute" );
415 $res = $tpl->execute();
416 wfProfileOut( "$fname-execute" );
417
418 // result may be an error
419 $this->printOrError( $res );
420 wfProfileOut( $fname );
421 }
422
423 /**
424 * Output the string, or print error message if it's
425 * an error object of the appropriate type.
426 * For the base class, assume strings all around.
427 *
428 * @param mixed $str
429 * @access private
430 */
431 function printOrError( &$str ) {
432 echo $str;
433 }
434
435 /**
436 * build array of urls for personal toolbar
437 * @return array
438 * @access private
439 */
440 function buildPersonalUrls() {
441 global $wgTitle, $wgShowIPinHeader, $wgContLang;
442
443 $fname = 'SkinTemplate::buildPersonalUrls';
444 $pageurl = $wgTitle->getLocalURL();
445 wfProfileIn( $fname );
446
447 /* set up the default links for the personal toolbar */
448 $personal_urls = array();
449 if ($this->loggedin) {
450 $personal_urls['userpage'] = array(
451 'text' => $this->username,
452 'href' => &$this->userpageUrlDetails['href'],
453 'class' => $this->userpageUrlDetails['exists']?false:'new',
454 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
455 );
456 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
457 $personal_urls['mytalk'] = array(
458 'text' => wfMsg('mytalk'),
459 'href' => &$usertalkUrlDetails['href'],
460 'class' => $usertalkUrlDetails['exists']?false:'new',
461 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
462 );
463 $href = $this->makeSpecialUrl('Preferences');
464 $personal_urls['preferences'] = array(
465 'text' => wfMsg('preferences'),
466 'href' => $this->makeSpecialUrl('Preferences'),
467 'active' => ( $href == $pageurl )
468 );
469 $href = $this->makeSpecialUrl('Watchlist');
470 $personal_urls['watchlist'] = array(
471 'text' => wfMsg('watchlist'),
472 'href' => $href,
473 'active' => ( $href == $pageurl )
474 );
475 $href = $this->makeSpecialUrl("Contributions/$this->username");
476 $personal_urls['mycontris'] = array(
477 'text' => wfMsg('mycontris'),
478 'href' => $href
479 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
480 );
481 $personal_urls['logout'] = array(
482 'text' => wfMsg('userlogout'),
483 'href' => $this->makeSpecialUrl( 'Userlogout',
484 $wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"
485 )
486 );
487 } else {
488 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
489 $href = &$this->userpageUrlDetails['href'];
490 $personal_urls['anonuserpage'] = array(
491 'text' => $this->username,
492 'href' => $href,
493 'class' => $this->userpageUrlDetails['exists']?false:'new',
494 'active' => ( $pageurl == $href )
495 );
496 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
497 $href = &$usertalkUrlDetails['href'];
498 $personal_urls['anontalk'] = array(
499 'text' => wfMsg('anontalk'),
500 'href' => $href,
501 'class' => $usertalkUrlDetails['exists']?false:'new',
502 'active' => ( $pageurl == $href )
503 );
504 $personal_urls['anonlogin'] = array(
505 'text' => wfMsg('userlogin'),
506 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
507 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
508 );
509 } else {
510
511 $personal_urls['login'] = array(
512 'text' => wfMsg('userlogin'),
513 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),
514 'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
515 );
516 }
517 }
518 wfProfileOut( $fname );
519 return $personal_urls;
520 }
521
522 /**
523 * Returns true if the IP should be shown in the header
524 */
525 function showIPinHeader() {
526 global $wgShowIPinHeader;
527 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
528 }
529
530 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
531 $classes = array();
532 if( $selected ) {
533 $classes[] = 'selected';
534 }
535 if( $checkEdit && $title->getArticleId() == 0 ) {
536 $classes[] = 'new';
537 $query = 'action=edit';
538 }
539
540 $text = wfMsg( $message );
541 if ( $text == "&lt;$message&gt;" ) {
542 $text = wfMsg( 'nstab-main' );
543 }
544
545 return array(
546 'class' => implode( ' ', $classes ),
547 'text' => $text,
548 'href' => $title->getLocalUrl( $query ) );
549 }
550
551 function makeTalkUrlDetails( $name, $urlaction='' ) {
552 $title = Title::newFromText( $name );
553 $title = $title->getTalkPage();
554 $this->checkTitle($title, $name);
555 return array(
556 'href' => $title->getLocalURL( $urlaction ),
557 'exists' => $title->getArticleID() != 0?true:false
558 );
559 }
560
561 function makeArticleUrlDetails( $name, $urlaction='' ) {
562 $title = Title::newFromText( $name );
563 $title= $title->getSubjectPage();
564 $this->checkTitle($title, $name);
565 return array(
566 'href' => $title->getLocalURL( $urlaction ),
567 'exists' => $title->getArticleID() != 0?true:false
568 );
569 }
570
571 /**
572 * an array of edit links by default used for the tabs
573 * @return array
574 * @access private
575 */
576 function buildContentActionUrls () {
577 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
578 $fname = 'SkinTemplate::buildContentActionUrls';
579 wfProfileIn( $fname );
580
581 global $wgUser, $wgRequest;
582 $action = $wgRequest->getText( 'action' );
583 $section = $wgRequest->getText( 'section' );
584 $oldid = $wgRequest->getVal( 'oldid' );
585 $diff = $wgRequest->getVal( 'diff' );
586 $content_actions = array();
587
588 if( $this->iscontent ) {
589 $subjpage = $this->mTitle->getSubjectPage();
590 $talkpage = $this->mTitle->getTalkPage();
591
592 $nskey = $this->getNameSpaceKey();
593 $content_actions[$nskey] = $this->tabAction(
594 $subjpage,
595 $nskey,
596 !$this->mTitle->isTalkPage(),
597 '', true);
598
599 $content_actions['talk'] = $this->tabAction(
600 $talkpage,
601 'talk',
602 $this->mTitle->isTalkPage(),
603 '',
604 true);
605
606 wfProfileIn( "$fname-edit" );
607 if ( $this->mTitle->userCanEdit() ) {
608 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.intval( $oldid ) : false;
609 $istalk = $this->mTitle->isTalkPage();
610 $istalkclass = $istalk?' istalk':'';
611 $content_actions['edit'] = array(
612 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
613 'text' => wfMsg('edit'),
614 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
615 );
616
617 if ( $istalk ) {
618 $content_actions['addsection'] = array(
619 'class' => $section == 'new'?'selected':false,
620 'text' => wfMsg('addsection'),
621 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
622 );
623 }
624 } else {
625 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.intval( $oldid ) : '';
626 $content_actions['viewsource'] = array(
627 'class' => ($action == 'edit') ? 'selected' : false,
628 'text' => wfMsg('viewsource'),
629 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
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($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 if( $this->loggedin || $wgValidationForAnons ) { # and $action != 'submit' ) {
704 # Validate tab. TODO: add validation to logged-in user rights
705 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
706 if ( $oldid ) $oid = intval( $oldid ) ; # Use the oldid
707 else
708 {# Trying to get the current article revision through this weird stunt
709 $tid = $this->mTitle->getArticleID();
710 $tns = $this->mTitle->getNamespace();
711 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
712 $res = wfQuery( $sql, DB_READ );
713 if( $s = wfFetchObject( $res ) )
714 $oid = $s->page_latest ;
715 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
716 }
717 if ( $oid != "" ) {
718 $oid = "&revision={$oid}" ;
719 $content_actions['validate'] = array(
720 'class' => ($action == 'validate') ? 'selected' : false,
721 'text' => wfMsg('val_tab'),
722 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
723 );
724 }
725 }
726 }
727 } else {
728 /* show special page tab */
729
730 $content_actions['article'] = array(
731 'class' => 'selected',
732 'text' => wfMsg('specialpage'),
733 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
734 );
735 }
736
737 /* show links to different language variants */
738 global $wgDisableLangConversion;
739 $variants = $wgContLang->getVariants();
740 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
741 $preferred = $wgContLang->getPreferredVariant();
742 $actstr = '';
743 if( $action )
744 $actstr = 'action=' . $action . '&';
745 $vcount=0;
746 foreach( $variants as $code ) {
747 $varname = $wgContLang->getVariantname( $code );
748 if( $varname == 'disable' )
749 continue;
750 $selected = ( $code == $preferred )? 'selected' : false;
751 $content_actions['varlang-' . $vcount] = array(
752 'class' => $selected,
753 'text' => $varname,
754 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
755 );
756 $vcount ++;
757 }
758 }
759
760 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
761
762 wfProfileOut( $fname );
763 return $content_actions;
764 }
765
766
767
768 /**
769 * build array of common navigation links
770 * @return array
771 * @access private
772 */
773 function buildNavUrls () {
774 global $wgUseTrackbacks, $wgTitle, $wgArticle;
775
776 $fname = 'SkinTemplate::buildNavUrls';
777 wfProfileIn( $fname );
778
779 global $wgUser, $wgRequest;
780 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
781
782 $action = $wgRequest->getText( 'action' );
783 $oldid = $wgRequest->getVal( 'oldid' );
784 $diff = $wgRequest->getVal( 'diff' );
785
786 $nav_urls = array();
787 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
788 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
789 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
790 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
791 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
792 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
793 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
794 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
795 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
796 if( $wgEnableUploads ) {
797 if ($wgUploadNavigationUrl) {
798 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
799 } else {
800 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
801 }
802 } else {
803 $nav_urls['upload'] = false;
804 }
805 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
806
807
808 // A print stylesheet is attached to all pages, but nobody ever
809 // figures that out. :) Add a link...
810 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
811 $revid = $wgArticle->getRevIdFetched();
812 if ( !( $revid == 0 ) )
813 $nav_urls['print'] = array(
814 'text' => wfMsg( 'printableversion' ),
815 'href' => $wgRequest->appendQuery( 'printable=yes' )
816 );
817
818 // Also add a "permalink" while we're at it
819 if ( (int)$oldid ) {
820 $nav_urls['permalink'] = array(
821 'text' => wfMsg( 'permalink' ),
822 'href' => ''
823 );
824 } else {
825 if ( !( $revid == 0 ) )
826 $nav_urls['permalink'] = array(
827 'text' => wfMsg( 'permalink' ),
828 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
829 );
830 }
831 }
832
833 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
834 $nav_urls['whatlinkshere'] = array(
835 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
836 );
837 $nav_urls['recentchangeslinked'] = array(
838 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
839 );
840 if ($wgUseTrackbacks)
841 $nav_urls['trackbacklink'] = array(
842 'href' => $wgTitle->trackbackURL()
843 );
844 }
845
846 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
847 $id = User::idFromName($this->mTitle->getText());
848 $ip = User::isIP($this->mTitle->getText());
849 } else {
850 $id = 0;
851 $ip = false;
852 }
853
854 if($id || $ip) { # both anons and non-anons have contri list
855 $nav_urls['contributions'] = array(
856 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
857 );
858 if ( $wgUser->isAllowed( 'protect' ) )
859 $nav_urls['blockip'] = array(
860 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
861 );
862 } else {
863 $nav_urls['contributions'] = false;
864 }
865 $nav_urls['emailuser'] = false;
866 if( $this->showEmailUser( $id ) ) {
867 $nav_urls['emailuser'] = array(
868 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
869 );
870 }
871 wfProfileOut( $fname );
872 return $nav_urls;
873 }
874
875 /**
876 * Generate strings used for xml 'id' names
877 * @return string
878 * @private
879 */
880 function getNameSpaceKey () {
881 switch ($this->mTitle->getNamespace()) {
882 case NS_MAIN:
883 case NS_TALK:
884 return 'nstab-main';
885 case NS_USER:
886 case NS_USER_TALK:
887 return 'nstab-user';
888 case NS_MEDIA:
889 return 'nstab-media';
890 case NS_SPECIAL:
891 return 'nstab-special';
892 case NS_PROJECT:
893 case NS_PROJECT_TALK:
894 return 'nstab-wp';
895 case NS_IMAGE:
896 case NS_IMAGE_TALK:
897 return 'nstab-image';
898 case NS_MEDIAWIKI:
899 case NS_MEDIAWIKI_TALK:
900 return 'nstab-mediawiki';
901 case NS_TEMPLATE:
902 case NS_TEMPLATE_TALK:
903 return 'nstab-template';
904 case NS_HELP:
905 case NS_HELP_TALK:
906 return 'nstab-help';
907 case NS_CATEGORY:
908 case NS_CATEGORY_TALK:
909 return 'nstab-category';
910 default:
911 return 'nstab-' . strtolower( $this->mTitle->getSubjectNsText() );
912 }
913 }
914
915 /**
916 * @access private
917 */
918 function setupUserCss() {
919 $fname = 'SkinTemplate::setupUserCss';
920 wfProfileIn( $fname );
921
922 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
923
924 $sitecss = '';
925 $usercss = '';
926 $siteargs = '&maxage=' . $wgSquidMaxage;
927
928 # Add user-specific code if this is a user and we allow that kind of thing
929
930 if ( $wgAllowUserCss && $this->loggedin ) {
931 $action = $wgRequest->getText('action');
932
933 # if we're previewing the CSS page, use it
934 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
935 $siteargs = "&smaxage=0&maxage=0";
936 $usercss = $wgRequest->getText('wpTextbox1');
937 } else {
938 $usercss = '@import "' .
939 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
940 'action=raw&ctype=text/css') . '";' ."\n";
941 }
942
943 $siteargs .= '&ts=' . $wgUser->mTouched;
944 }
945
946 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
947
948 # If we use the site's dynamic CSS, throw that in, too
949 if ( $wgUseSiteCss ) {
950 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
951 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
952 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
953 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
954 }
955
956 # If we use any dynamic CSS, make a little CDATA block out of it.
957
958 if ( !empty($sitecss) || !empty($usercss) ) {
959 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
960 }
961 wfProfileOut( $fname );
962 }
963
964 /**
965 * @access private
966 */
967 function setupUserJs() {
968 $fname = 'SkinTemplate::setupUserJs';
969 wfProfileIn( $fname );
970
971 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
972 $action = $wgRequest->getText('action');
973
974 if( $wgAllowUserJs && $this->loggedin ) {
975 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
976 # XXX: additional security check/prompt?
977 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
978 } else {
979 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
980 }
981 }
982 wfProfileOut( $fname );
983 }
984
985 /**
986 * Code for extensions to hook into to provide per-page CSS, see
987 * extension/PageCSS/PageCSS.php for an implementation of this.
988 *
989 * @access private
990 */
991 function setupPageCss() {
992 $fname = 'SkinTemplate::setupPageCss';
993 wfProfileIn( $fname );
994 $out = false;
995 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle->isProtected() ) );
996 wfProfileOut( $fname );
997 return $out;
998 }
999
1000 /**
1001 * returns css with user-specific options
1002 * @access public
1003 */
1004
1005 function getUserStylesheet() {
1006 $fname = 'SkinTemplate::getUserStylesheet';
1007 wfProfileIn( $fname );
1008
1009 global $wgUser;
1010 $s = "/* generated user stylesheet */\n";
1011 $s .= $this->reallyDoGetUserStyles();
1012 wfProfileOut( $fname );
1013 return $s;
1014 }
1015
1016 /**
1017 * @access public
1018 */
1019 function getUserJs() {
1020 $fname = 'SkinTemplate::getUserJs';
1021 wfProfileIn( $fname );
1022
1023 global $wgStylePath;
1024 $s = '/* generated javascript */';
1025 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1026 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
1027
1028 // avoid inclusion of non defined user JavaScript (with custom skins only)
1029 // by checking for default message content
1030 $msgKey = ucfirst($this->skinname).'.js';
1031 $userJS = wfMsg($msgKey);
1032 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
1033 $s .= $userJS;
1034 }
1035
1036 wfProfileOut( $fname );
1037 return $s;
1038 }
1039 }
1040
1041 /**
1042 * Generic wrapper for template functions, with interface
1043 * compatible with what we use of PHPTAL 0.7.
1044 * @package MediaWiki
1045 * @subpackage Skins
1046 */
1047 class QuickTemplate {
1048 /**
1049 * @access public
1050 */
1051 function QuickTemplate() {
1052 $this->data = array();
1053 $this->translator = new MediaWiki_I18N();
1054 }
1055
1056 /**
1057 * @access public
1058 */
1059 function set( $name, $value ) {
1060 $this->data[$name] = $value;
1061 }
1062
1063 /**
1064 * @access public
1065 */
1066 function setRef($name, &$value) {
1067 $this->data[$name] =& $value;
1068 }
1069
1070 /**
1071 * @access public
1072 */
1073 function setTranslator( &$t ) {
1074 $this->translator = &$t;
1075 }
1076
1077 /**
1078 * @access public
1079 */
1080 function execute() {
1081 echo "Override this function.";
1082 }
1083
1084
1085 /**
1086 * @access private
1087 */
1088 function text( $str ) {
1089 echo htmlspecialchars( $this->data[$str] );
1090 }
1091
1092 /**
1093 * @access private
1094 */
1095 function html( $str ) {
1096 echo $this->data[$str];
1097 }
1098
1099 /**
1100 * @access private
1101 */
1102 function msg( $str ) {
1103 echo htmlspecialchars( $this->translator->translate( $str ) );
1104 }
1105
1106 /**
1107 * @access private
1108 */
1109 function msgHtml( $str ) {
1110 echo $this->translator->translate( $str );
1111 }
1112
1113 /**
1114 * An ugly, ugly hack.
1115 * @access private
1116 */
1117 function msgWiki( $str ) {
1118 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1119
1120 $text = $this->translator->translate( $str );
1121 $parserOutput = $wgParser->parse( $text, $wgTitle,
1122 $wgOut->mParserOptions, true );
1123 echo $parserOutput->getText();
1124 }
1125
1126 /**
1127 * @access private
1128 */
1129 function haveData( $str ) {
1130 return $this->data[$str];
1131 }
1132
1133 /**
1134 * @access private
1135 */
1136 function haveMsg( $str ) {
1137 $msg = $this->translator->translate( $str );
1138 return ($msg != '-') && ($msg != ''); # ????
1139 }
1140 }
1141
1142 } // end of if( defined( 'MEDIAWIKI' ) )
1143 ?>