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