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