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