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