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