* Add a hook (SkinTemplateBuildNavUrlsNav_urlsAfterPermalink) which runs after
[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 if ($wgUploadNavigationUrl)
804 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
805 else
806 $nav_urls['upload'] = false;
807 }
808 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
809
810
811 // A print stylesheet is attached to all pages, but nobody ever
812 // figures that out. :) Add a link...
813 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
814 $revid = $wgArticle->getRevIdFetched();
815 if ( !( $revid == 0 ) )
816 $nav_urls['print'] = array(
817 'text' => wfMsg( 'printableversion' ),
818 'href' => $wgRequest->appendQuery( 'printable=yes' )
819 );
820
821 // Also add a "permalink" while we're at it
822 if ( (int)$oldid ) {
823 $nav_urls['permalink'] = array(
824 'text' => wfMsg( 'permalink' ),
825 'href' => ''
826 );
827 } else {
828 if ( !( $revid == 0 ) )
829 $nav_urls['permalink'] = array(
830 'text' => wfMsg( 'permalink' ),
831 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
832 );
833 }
834
835 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
836 }
837
838 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
839 $nav_urls['whatlinkshere'] = array(
840 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
841 );
842 $nav_urls['recentchangeslinked'] = array(
843 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
844 );
845 if ($wgUseTrackbacks)
846 $nav_urls['trackbacklink'] = array(
847 'href' => $wgTitle->trackbackURL()
848 );
849 }
850
851 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
852 $id = User::idFromName($this->mTitle->getText());
853 $ip = User::isIP($this->mTitle->getText());
854 } else {
855 $id = 0;
856 $ip = false;
857 }
858
859 if($id || $ip) { # both anons and non-anons have contri list
860 $nav_urls['contributions'] = array(
861 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
862 );
863 if ( $wgUser->isAllowed( 'protect' ) )
864 $nav_urls['blockip'] = array(
865 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle->getText() )
866 );
867 } else {
868 $nav_urls['contributions'] = false;
869 }
870 $nav_urls['emailuser'] = false;
871 if( $this->showEmailUser( $id ) ) {
872 $nav_urls['emailuser'] = array(
873 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
874 );
875 }
876 wfProfileOut( $fname );
877 return $nav_urls;
878 }
879
880 /**
881 * Generate strings used for xml 'id' names
882 * @return string
883 * @private
884 */
885 function getNameSpaceKey () {
886 switch ($this->mTitle->getNamespace()) {
887 case NS_MAIN:
888 case NS_TALK:
889 return 'nstab-main';
890 case NS_USER:
891 case NS_USER_TALK:
892 return 'nstab-user';
893 case NS_MEDIA:
894 return 'nstab-media';
895 case NS_SPECIAL:
896 return 'nstab-special';
897 case NS_PROJECT:
898 case NS_PROJECT_TALK:
899 return 'nstab-wp';
900 case NS_IMAGE:
901 case NS_IMAGE_TALK:
902 return 'nstab-image';
903 case NS_MEDIAWIKI:
904 case NS_MEDIAWIKI_TALK:
905 return 'nstab-mediawiki';
906 case NS_TEMPLATE:
907 case NS_TEMPLATE_TALK:
908 return 'nstab-template';
909 case NS_HELP:
910 case NS_HELP_TALK:
911 return 'nstab-help';
912 case NS_CATEGORY:
913 case NS_CATEGORY_TALK:
914 return 'nstab-category';
915 default:
916 return 'nstab-' . strtolower( $this->mTitle->getSubjectNsText() );
917 }
918 }
919
920 /**
921 * @access private
922 */
923 function setupUserCss() {
924 $fname = 'SkinTemplate::setupUserCss';
925 wfProfileIn( $fname );
926
927 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
928
929 $sitecss = '';
930 $usercss = '';
931 $siteargs = '&maxage=' . $wgSquidMaxage;
932
933 # Add user-specific code if this is a user and we allow that kind of thing
934
935 if ( $wgAllowUserCss && $this->loggedin ) {
936 $action = $wgRequest->getText('action');
937
938 # if we're previewing the CSS page, use it
939 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
940 $siteargs = "&smaxage=0&maxage=0";
941 $usercss = $wgRequest->getText('wpTextbox1');
942 } else {
943 $usercss = '@import "' .
944 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
945 'action=raw&ctype=text/css') . '";' ."\n";
946 }
947
948 $siteargs .= '&ts=' . $wgUser->mTouched;
949 }
950
951 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
952
953 # If we use the site's dynamic CSS, throw that in, too
954 if ( $wgUseSiteCss ) {
955 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
956 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
957 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', $query, NS_MEDIAWIKI) . '";' . "\n";
958 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
959 }
960
961 # If we use any dynamic CSS, make a little CDATA block out of it.
962
963 if ( !empty($sitecss) || !empty($usercss) ) {
964 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
965 }
966 wfProfileOut( $fname );
967 }
968
969 /**
970 * @access private
971 */
972 function setupUserJs() {
973 $fname = 'SkinTemplate::setupUserJs';
974 wfProfileIn( $fname );
975
976 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
977 $action = $wgRequest->getText('action');
978
979 if( $wgAllowUserJs && $this->loggedin ) {
980 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
981 # XXX: additional security check/prompt?
982 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
983 } else {
984 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
985 }
986 }
987 wfProfileOut( $fname );
988 }
989
990 /**
991 * Code for extensions to hook into to provide per-page CSS, see
992 * extensions/PageCSS/PageCSS.php for an implementation of this.
993 *
994 * @access private
995 */
996 function setupPageCss() {
997 $fname = 'SkinTemplate::setupPageCss';
998 wfProfileIn( $fname );
999 $out = false;
1000 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out, $this->mTitle->isProtected() ) );
1001 wfProfileOut( $fname );
1002 return $out;
1003 }
1004
1005 /**
1006 * returns css with user-specific options
1007 * @access public
1008 */
1009
1010 function getUserStylesheet() {
1011 $fname = 'SkinTemplate::getUserStylesheet';
1012 wfProfileIn( $fname );
1013
1014 global $wgUser;
1015 $s = "/* generated user stylesheet */\n";
1016 $s .= $this->reallyDoGetUserStyles();
1017 wfProfileOut( $fname );
1018 return $s;
1019 }
1020
1021 /**
1022 * @access public
1023 */
1024 function getUserJs() {
1025 $fname = 'SkinTemplate::getUserJs';
1026 wfProfileIn( $fname );
1027
1028 global $wgStylePath;
1029 $s = '/* generated javascript */';
1030 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1031 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
1032
1033 // avoid inclusion of non defined user JavaScript (with custom skins only)
1034 // by checking for default message content
1035 $msgKey = ucfirst($this->skinname).'.js';
1036 $userJS = wfMsg($msgKey);
1037 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
1038 $s .= $userJS;
1039 }
1040
1041 wfProfileOut( $fname );
1042 return $s;
1043 }
1044 }
1045
1046 /**
1047 * Generic wrapper for template functions, with interface
1048 * compatible with what we use of PHPTAL 0.7.
1049 * @package MediaWiki
1050 * @subpackage Skins
1051 */
1052 class QuickTemplate {
1053 /**
1054 * @access public
1055 */
1056 function QuickTemplate() {
1057 $this->data = array();
1058 $this->translator = new MediaWiki_I18N();
1059 }
1060
1061 /**
1062 * @access public
1063 */
1064 function set( $name, $value ) {
1065 $this->data[$name] = $value;
1066 }
1067
1068 /**
1069 * @access public
1070 */
1071 function setRef($name, &$value) {
1072 $this->data[$name] =& $value;
1073 }
1074
1075 /**
1076 * @access public
1077 */
1078 function setTranslator( &$t ) {
1079 $this->translator = &$t;
1080 }
1081
1082 /**
1083 * @access public
1084 */
1085 function execute() {
1086 echo "Override this function.";
1087 }
1088
1089
1090 /**
1091 * @access private
1092 */
1093 function text( $str ) {
1094 echo htmlspecialchars( $this->data[$str] );
1095 }
1096
1097 /**
1098 * @access private
1099 */
1100 function html( $str ) {
1101 echo $this->data[$str];
1102 }
1103
1104 /**
1105 * @access private
1106 */
1107 function msg( $str ) {
1108 echo htmlspecialchars( $this->translator->translate( $str ) );
1109 }
1110
1111 /**
1112 * @access private
1113 */
1114 function msgHtml( $str ) {
1115 echo $this->translator->translate( $str );
1116 }
1117
1118 /**
1119 * An ugly, ugly hack.
1120 * @access private
1121 */
1122 function msgWiki( $str ) {
1123 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1124
1125 $text = $this->translator->translate( $str );
1126 $parserOutput = $wgParser->parse( $text, $wgTitle,
1127 $wgOut->mParserOptions, true );
1128 echo $parserOutput->getText();
1129 }
1130
1131 /**
1132 * @access private
1133 */
1134 function haveData( $str ) {
1135 return $this->data[$str];
1136 }
1137
1138 /**
1139 * @access private
1140 */
1141 function haveMsg( $str ) {
1142 $msg = $this->translator->translate( $str );
1143 return ($msg != '-') && ($msg != ''); # ????
1144 }
1145 }
1146
1147 } // end of if( defined( 'MEDIAWIKI' ) )
1148 ?>