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