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