Fix Special:Import for new schema; make it create page records as needed and hook...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
155
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160
161 $this->mTitle = $wgTitle;
162 $this->mUser =& $wgUser;
163
164 $tpl =& $this->setupTemplate( $this->template, 'skins' );
165
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
168 #}
169 wfProfileOut( "$fname-init" );
170
171 wfProfileIn( "$fname-stuff" );
172 $this->thispage = $this->mTitle->getPrefixedDbKey();
173 $this->thisurl = $this->mTitle->getPrefixedURL();
174 $this->loggedin = $wgUser->isLoggedIn();
175 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
176 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
177 $this->username = $wgUser->getName();
178 $userPage = $wgUser->getUserPage();
179 $this->userpage = $userPage->getPrefixedText();
180 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
181
182 $this->usercss = $this->userjs = $this->userjsprev = false;
183 $this->setupUserCss();
184 $this->setupUserJs();
185 $this->titletxt = $this->mTitle->getPrefixedText();
186 wfProfileOut( "$fname-stuff" );
187
188 wfProfileIn( "$fname-stuff2" );
189 $tpl->set( 'title', $wgOut->getPageTitle() );
190 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
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 'ttip' => wfMsg('tooltip-'.$format)
214 );
215 }
216 $tpl->setRef( 'feeds', $feeds );
217 } else {
218 $tpl->set( 'feeds', false );
219 }
220 $tpl->setRef( 'mimetype', $wgMimeType );
221 $tpl->setRef( 'charset', $wgOutputEncoding );
222 $tpl->set( 'headlinks', $out->getHeadLinks() );
223 $tpl->setRef( 'wgScript', $wgScript );
224 $tpl->setRef( 'skinname', $this->skinname );
225 $tpl->setRef( 'stylename', $this->stylename );
226 $tpl->setRef( 'loggedin', $this->loggedin );
227 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
228 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
229 /* XXX currently unused, might get useful later
230 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
231 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
232 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
233 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
234 $tpl->set( "helppage", wfMsg('helppage'));
235 */
236 $tpl->set( 'searchaction', $this->escapeSearchLink() );
237 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
238 $tpl->setRef( 'stylepath', $wgStylePath );
239 $tpl->setRef( 'logopath', $wgLogo );
240 $tpl->setRef( "lang", $wgContLanguageCode );
241 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
242 $tpl->set( 'rtl', $wgContLang->isRTL() );
243 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
244 $tpl->setRef( 'username', $this->username );
245 $tpl->setRef( 'userpage', $this->userpage);
246 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
247 $tpl->setRef( 'usercss', $this->usercss);
248 $tpl->setRef( 'userjs', $this->userjs);
249 $tpl->setRef( 'userjsprev', $this->userjsprev);
250 global $wgUseSiteJs;
251 if ($wgUseSiteJs) {
252 if($this->loggedin) {
253 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
254 } else {
255 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
256 }
257 } else {
258 $tpl->set('jsvarurl', false);
259 }
260 if( $wgUser->getNewtalk() ) {
261 $usertitle = $this->mUser->getUserPage();
262 $usertalktitle = $usertitle->getTalkPage();
263 if( !$usertalktitle->equals( $this->mTitle ) ) {
264 $ntl = wfMsg( 'newmessages',
265 $this->makeKnownLinkObj(
266 $usertalktitle,
267 wfMsg('newmessageslink')
268 )
269 );
270 # Disable Cache
271 $wgOut->setSquidMaxage(0);
272 }
273 } else {
274 $ntl = '';
275 }
276 wfProfileOut( "$fname-stuff2" );
277
278 wfProfileIn( "$fname-stuff3" );
279 $tpl->setRef( 'newtalk', $ntl );
280 $tpl->setRef( 'skin', $this);
281 $tpl->set( 'logo', $this->logoText() );
282 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
283 if ( !$wgDisableCounters ) {
284 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
285 if ( $viewcount ) {
286 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
287 } else {
288 $tpl->set('viewcount', false);
289 }
290 }
291
292 if ($wgPageShowWatchingUsers) {
293 $dbr =& wfGetDB( DB_SLAVE );
294 extract( $dbr->tableNames( 'watchlist' ) );
295 $sql = "SELECT COUNT(*) AS n FROM $watchlist
296 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
297 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
298 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
299 $x = $dbr->fetchObject( $res );
300 $numberofwatchingusers = $x->n;
301 if ($numberofwatchingusers > 0) {
302 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
303 } else {
304 $tpl->set('numberofwatchingusers', false);
305 }
306 } else {
307 $tpl->set('numberofwatchingusers', false);
308 }
309
310 $tpl->set('lastmod', $this->lastModified());
311 $tpl->set('copyright',$this->getCopyright());
312
313 $this->credits = false;
314
315 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
316 require_once("Credits.php");
317 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
318 }
319
320 $tpl->setRef( 'credits', $this->credits );
321
322 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
323 $tpl->set('copyright', $this->getCopyright());
324 $tpl->set('viewcount', false);
325 $tpl->set('lastmod', false);
326 $tpl->set('credits', false);
327 $tpl->set('numberofwatchingusers', false);
328 } else {
329 $tpl->set('copyright', false);
330 $tpl->set('viewcount', false);
331 $tpl->set('lastmod', false);
332 $tpl->set('credits', false);
333 $tpl->set('numberofwatchingusers', false);
334 }
335 wfProfileOut( "$fname-stuff3" );
336
337 wfProfileIn( "$fname-stuff4" );
338 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
339 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
340 $tpl->set( 'disclaimer', $this->disclaimerLink() );
341 $tpl->set( 'about', $this->aboutLink() );
342
343 $tpl->setRef( 'debug', $out->mDebugtext );
344 $tpl->set( 'reporttime', $out->reportTime() );
345 $tpl->set( 'sitenotice', $wgSiteNotice );
346 $tpl->set( 'tagline', wfMsg('tagline') );
347
348 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
349 $out->mBodytext .= $printfooter ;
350 $tpl->setRef( 'bodytext', $out->mBodytext );
351
352 # Language links
353 $language_urls = array();
354 foreach( $wgOut->getLanguageLinks() as $l ) {
355 $nt = Title::newFromText( $l );
356 $language_urls[] = array('href' => $nt->getFullURL(),
357 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
358 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
359 }
360 if(count($language_urls)) {
361 $tpl->setRef( 'language_urls', $language_urls);
362 } else {
363 $tpl->set('language_urls', false);
364 }
365 wfProfileOut( "$fname-stuff4" );
366
367 # Personal toolbar
368 $tpl->set('personal_urls', $this->buildPersonalUrls());
369 $content_actions = $this->buildContentActionUrls();
370 $tpl->setRef('content_actions', $content_actions);
371
372 // XXX: attach this from javascript, same with section editing
373 if($this->iseditable && $wgUser->getOption("editondblclick") )
374 {
375 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
376 } else {
377 $tpl->set('body_ondblclick', false);
378 }
379 $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
380 $tpl->set( 'nav_urls', $this->buildNavUrls() );
381
382 // execute template
383 wfProfileIn( "$fname-execute" );
384 $res = $tpl->execute();
385 wfProfileOut( "$fname-execute" );
386
387 // result may be an error
388 $this->printOrError( $res );
389 wfProfileOut( $fname );
390 }
391
392 /**
393 * Output the string, or print error message if it's
394 * an error object of the appropriate type.
395 * For the base class, assume strings all around.
396 *
397 * @param mixed $str
398 * @access private
399 */
400 function printOrError( &$str ) {
401 echo $str;
402 }
403
404 /**
405 * build array of urls for personal toolbar
406 * @return array
407 * @access private
408 */
409 function buildPersonalUrls() {
410 $fname = 'SkinTemplate::buildPersonalUrls';
411 wfProfileIn( $fname );
412
413 /* set up the default links for the personal toolbar */
414 global $wgShowIPinHeader;
415 $personal_urls = array();
416 if ($this->loggedin) {
417 /* Logged in users personal toolbar */
418 $personal_urls['userpage'] = array(
419 'text' => wfMsg('mypage'),
420 'href' => $this->makeSpecialUrl('Mypage')
421 );
422 $personal_urls['mytalk'] = array(
423 'text' => wfMsg('mytalk'),
424 'href' => $this->makeSpecialUrl('Mytalk')
425 );
426 $personal_urls['preferences'] = array(
427 'text' => wfMsg('preferences'),
428 'href' => $this->makeSpecialUrl('Preferences')
429 );
430 $personal_urls['watchlist'] = array(
431 'text' => wfMsg('watchlist'),
432 'href' => $this->makeSpecialUrl('Watchlist')
433 );
434 $personal_urls['mycontris'] = array(
435 'text' => wfMsg('mycontris'),
436 'href' => $this->makeSpecialUrl('Mycontributions')
437 );
438 $personal_urls['logout'] = array(
439 'text' => wfMsg('userlogout'),
440 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
441 );
442 } else {
443 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
444 /* Anonymous with session users personal toolbar */
445 $personal_urls['anonuserpage'] = array(
446 'text' => wfMsg('mypage'),
447 'href' => $this->makeSpecialUrl('Mypage')
448 );
449 $personal_urls['mytalk'] = array(
450 'text' => wfMsg('mytalk'),
451 'href' => $this->makeSpecialUrl('Mytalk')
452 );
453
454 $personal_urls['anonlogin'] = array(
455 'text' => wfMsg('userlogin'),
456 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
457 );
458 } else {
459 /* Anonymous users personal toolbar */
460 $personal_urls['login'] = array(
461 'text' => wfMsg('userlogin'),
462 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
463 );
464 }
465 }
466 wfProfileOut( $fname );
467 return $personal_urls;
468 }
469
470
471 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
472 $classes = array();
473 if( $selected ) {
474 $classes[] = 'selected';
475 }
476 if( $checkEdit && $title->getArticleId() == 0 ) {
477 $classes[] = 'new';
478 }
479 return array(
480 'class' => implode( ' ', $classes ),
481 'text' => wfMsg( $message ),
482 'href' => $title->getLocalUrl( $query ) );
483 }
484
485 /**
486 * an array of edit links by default used for the tabs
487 * @return array
488 * @access private
489 */
490 function buildContentActionUrls () {
491 global $wgContLang;
492 $fname = 'SkinTemplate::buildContentActionUrls';
493 wfProfileIn( $fname );
494
495 global $wgUser, $wgRequest;
496 $action = $wgRequest->getText( 'action' );
497 $section = $wgRequest->getText( 'section' );
498 $oldid = $wgRequest->getVal( 'oldid' );
499 $diff = $wgRequest->getVal( 'diff' );
500 $content_actions = array();
501
502 if( $this->iscontent ) {
503
504 $nskey = $this->getNameSpaceKey();
505 $content_actions[$nskey] = $this->tabAction(
506 $this->mTitle->getSubjectPage(),
507 $nskey,
508 !$this->mTitle->isTalkPage() );
509
510 $content_actions['talk'] = $this->tabAction(
511 $this->mTitle->getTalkPage(),
512 'talk',
513 $this->mTitle->isTalkPage(),
514 '',
515 true);
516
517 wfProfileIn( "$fname-edit" );
518 if ( $this->mTitle->userCanEdit() ) {
519 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
520 $istalk = $this->mTitle->isTalkPage();
521 $istalkclass = $istalk?' istalk':'';
522 $content_actions['edit'] = array(
523 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
524 'text' => wfMsg('edit'),
525 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
526 );
527
528 if ( $istalk ) {
529 $content_actions['addsection'] = array(
530 'class' => $section == 'new'?'selected':false,
531 'text' => wfMsg('addsection'),
532 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
533 );
534 }
535 } else {
536 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
537 $content_actions['viewsource'] = array(
538 'class' => ($action == 'edit') ? 'selected' : false,
539 'text' => wfMsg('viewsource'),
540 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
541 );
542 }
543 wfProfileOut( "$fname-edit" );
544
545 wfProfileIn( "$fname-live" );
546 if ( $this->mTitle->getArticleId() ) {
547
548 $content_actions['history'] = array(
549 'class' => ($action == 'history') ? 'selected' : false,
550 'text' => wfMsg('history_short'),
551 'href' => $this->mTitle->getLocalUrl( 'action=history')
552 );
553
554 if($wgUser->isAllowed('protect')){
555 if(!$this->mTitle->isProtected()){
556 $content_actions['protect'] = array(
557 'class' => ($action == 'protect') ? 'selected' : false,
558 'text' => wfMsg('protect'),
559 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
560 );
561
562 } else {
563 $content_actions['unprotect'] = array(
564 'class' => ($action == 'unprotect') ? 'selected' : false,
565 'text' => wfMsg('unprotect'),
566 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
567 );
568 }
569 }
570 if($wgUser->isAllowed('delete')){
571 $content_actions['delete'] = array(
572 'class' => ($action == 'delete') ? 'selected' : false,
573 'text' => wfMsg('delete'),
574 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
575 );
576 }
577 if ( $wgUser->isLoggedIn() ) {
578 if ( $this->mTitle->userCanMove()) {
579 $content_actions['move'] = array(
580 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
581 'text' => wfMsg('move'),
582 'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ) )
583 );
584 }
585 }
586 } else {
587 //article doesn't exist or is deleted
588 if($wgUser->isAllowed('delete')){
589 if( $n = $this->mTitle->isDeleted() ) {
590 $content_actions['undelete'] = array(
591 'class' => false,
592 'text' => wfMsg( "undelete_short", $n ),
593 'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
594 );
595 }
596 }
597 }
598 wfProfileOut( "$fname-live" );
599
600 if ( $wgUser->isLoggedIn() and $action != 'submit' ) {
601 if( !$this->mTitle->userIsWatching()) {
602 $content_actions['watch'] = array(
603 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
604 'text' => wfMsg('watch'),
605 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
606 );
607 } else {
608 $content_actions['unwatch'] = array(
609 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
610 'text' => wfMsg('unwatch'),
611 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
612 );
613 }
614 }
615
616 } else {
617 /* show special page tab */
618
619 $content_actions['article'] = array(
620 'class' => 'selected',
621 'text' => wfMsg('specialpage'),
622 'href' => false
623 );
624 }
625
626 /* show links to different language variants */
627 global $wgDisableLangConversion;
628 $variants = $wgContLang->getVariants();
629 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
630 $preferred = $wgContLang->getPreferredVariant();
631 $actstr = '';
632 if( $action )
633 $actstr = 'action=' . $action . '&';
634 $vcount=0;
635 foreach( $variants as $code ) {
636 $varname = $wgContLang->getVariantname( $code );
637 if( $varname == 'disable' )
638 continue;
639 $selected = ( $code == $preferred )? 'selected' : false;
640 $content_actions['varlang-' . $vcount] = array(
641 'class' => $selected,
642 'text' => $varname,
643 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
644 );
645 $vcount ++;
646 }
647 }
648
649 wfProfileOut( $fname );
650 return $content_actions;
651 }
652
653 /**
654 * build array of global navigation links
655 * @return array
656 * @access private
657 */
658 function buildNavigationUrls () {
659 $fname = 'SkinTemplate::buildNavigationUrls';
660 wfProfileIn( $fname );
661
662 global $wgNavigationLinks;
663 $result = array();
664 foreach ( $wgNavigationLinks as $link ) {
665 $text = wfMsg( $link['text'] );
666 wfProfileIn( "$fname-{$link['text']}" );
667 if ($text != '-') {
668 $dest = wfMsgForContent( $link['href'] );
669 wfProfileIn( "$fname-{$link['text']}2" );
670 $result[] = array(
671 'text' => $text,
672 'href' => $this->makeInternalOrExternalUrl( $dest ),
673 'id' => 'n-'.$link['text']
674 );
675 wfProfileOut( "$fname-{$link['text']}2" );
676 }
677 wfProfileOut( "$fname-{$link['text']}" );
678 }
679 wfProfileOut( $fname );
680 return $result;
681 }
682
683 /**
684 * build array of common navigation links
685 * @return array
686 * @access private
687 */
688 function buildNavUrls () {
689 $fname = 'SkinTemplate::buildNavUrls';
690 wfProfileIn( $fname );
691
692 global $wgUser, $wgRequest;
693 global $wgSiteSupportPage, $wgDisableUploads;
694
695 $action = $wgRequest->getText( 'action' );
696 $oldid = $wgRequest->getVal( 'oldid' );
697 $diff = $wgRequest->getVal( 'diff' );
698
699 $nav_urls = array();
700 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
701 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
702 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
703 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
704 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
705 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
706 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
707 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
708 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
709 if( $this->loggedin && !$wgDisableUploads ) {
710 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
711 } else {
712 $nav_urls['upload'] = false;
713 }
714 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
715
716 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
717 $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
718 $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
719 }
720
721 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
722 $id = User::idFromName($this->mTitle->getText());
723 $ip = User::isIP($this->mTitle->getText());
724 } else {
725 $id = 0;
726 $ip = false;
727 }
728
729 if($id || $ip) { # both anons and non-anons have contri list
730 $nav_urls['contributions'] = array(
731 'href' => $this->makeSpecialUrl('Contributions', "target=" . $this->mTitle->getPartialURL() )
732 );
733 } else {
734 $nav_urls['contributions'] = false;
735 }
736 $nav_urls['emailuser'] = false;
737 if( $this->showEmailUser( $id ) ) {
738 $nav_urls['emailuser'] = array(
739 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $this->mTitle->getPartialURL() )
740 );
741 }
742 wfProfileOut( $fname );
743 return $nav_urls;
744 }
745
746 /**
747 * Generate strings used for xml 'id' names
748 * @return string
749 * @private
750 */
751 function getNameSpaceKey () {
752 switch ($this->mTitle->getNamespace()) {
753 case NS_MAIN:
754 case NS_TALK:
755 return 'nstab-main';
756 case NS_USER:
757 case NS_USER_TALK:
758 return 'nstab-user';
759 case NS_MEDIA:
760 return 'nstab-media';
761 case NS_SPECIAL:
762 return 'nstab-special';
763 case NS_PROJECT:
764 case NS_PROJECT_TALK:
765 return 'nstab-wp';
766 case NS_IMAGE:
767 case NS_IMAGE_TALK:
768 return 'nstab-image';
769 case NS_MEDIAWIKI:
770 case NS_MEDIAWIKI_TALK:
771 return 'nstab-mediawiki';
772 case NS_TEMPLATE:
773 case NS_TEMPLATE_TALK:
774 return 'nstab-template';
775 case NS_HELP:
776 case NS_HELP_TALK:
777 return 'nstab-help';
778 case NS_CATEGORY:
779 case NS_CATEGORY_TALK:
780 return 'nstab-category';
781 default:
782 return 'nstab-main';
783 }
784 }
785
786 /**
787 * @access private
788 */
789 function setupUserCss() {
790 $fname = 'SkinTemplate::setupUserCss';
791 wfProfileIn( $fname );
792
793 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
794
795 $sitecss = '';
796 $usercss = '';
797 $siteargs = '&maxage=' . $wgSquidMaxage;
798
799 # Add user-specific code if this is a user and we allow that kind of thing
800
801 if ( $wgAllowUserCss && $this->loggedin ) {
802 $action = $wgRequest->getText('action');
803
804 # if we're previewing the CSS page, use it
805 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
806 $siteargs = "&smaxage=0&maxage=0";
807 $usercss = $wgRequest->getText('wpTextbox1');
808 } else {
809 $usercss = '@import "' .
810 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
811 'action=raw&ctype=text/css') . '";' ."\n";
812 }
813
814 $siteargs .= '&ts=' . $wgUser->mTouched;
815 }
816
817 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
818
819 # If we use the site's dynamic CSS, throw that in, too
820 if ( $wgUseSiteCss ) {
821 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
822 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
823 }
824
825 # If we use any dynamic CSS, make a little CDATA block out of it.
826
827 if ( !empty($sitecss) || !empty($usercss) ) {
828 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
829 }
830 wfProfileOut( $fname );
831 }
832
833 /**
834 * @access private
835 */
836 function setupUserJs() {
837 $fname = 'SkinTemplate::setupUserJs';
838 wfProfileIn( $fname );
839
840 global $wgRequest, $wgAllowUserJs;
841 $action = $wgRequest->getText('action');
842
843 if( $wgAllowUserJs && $this->loggedin ) {
844 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
845 # XXX: additional security check/prompt?
846 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
847 } else {
848 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
849 }
850 }
851 wfProfileOut( $fname );
852 }
853
854 /**
855 * returns css with user-specific options
856 * @access public
857 */
858 function getUserStylesheet() {
859 $fname = 'SkinTemplate::getUserStylesheet';
860 wfProfileIn( $fname );
861
862 global $wgUser;
863 $s = "/* generated user stylesheet */\n";
864
865 if( $wgUser->isLoggedIn() ) {
866 if ( $wgUser->getOption( "underline" ) ) {
867 $s .= "a { text-decoration: underline; }\n";
868 } else {
869 $s .= "a { text-decoration: none; }\n";
870 }
871 }
872 if ( !$wgUser->getOption( "highlightbroken" ) ) {
873 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
874 }
875 if ( $wgUser->getOption( "justify" ) ) {
876 $s .= "#bodyContent { text-align: justify; }\n";
877 }
878 wfProfileOut( $fname );
879 return $s;
880 }
881
882 /**
883 * @access public
884 */
885 function getUserJs() {
886 $fname = 'SkinTemplate::getUserJs';
887 wfProfileIn( $fname );
888
889 global $wgStylePath;
890 $s = '/* generated javascript */';
891 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
892 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
893 $s .= wfMsg(ucfirst($this->skinname).'.js');
894
895 wfProfileOut( $fname );
896 return $s;
897 }
898 }
899
900 /**
901 * Generic wrapper for template functions, with interface
902 * compatible with what we use of PHPTAL 0.7.
903 * @package MediaWiki
904 * @subpackage Skins
905 */
906 class QuickTemplate {
907 /**
908 * @access public
909 */
910 function QuickTemplate() {
911 $this->data = array();
912 $this->translator = new MediaWiki_I18N();
913 }
914
915 /**
916 * @access public
917 */
918 function set( $name, $value ) {
919 $this->data[$name] = $value;
920 }
921
922 /**
923 * @access public
924 */
925 function setRef($name, &$value) {
926 $this->data[$name] =& $value;
927 }
928
929 /**
930 * @access public
931 */
932 function setTranslator( &$t ) {
933 $this->translator = &$t;
934 }
935
936 /**
937 * @access public
938 */
939 function execute() {
940 echo "Override this function.";
941 }
942
943
944 /**
945 * @access private
946 */
947 function text( $str ) {
948 echo htmlspecialchars( $this->data[$str] );
949 }
950
951 /**
952 * @access private
953 */
954 function html( $str ) {
955 echo $this->data[$str];
956 }
957
958 /**
959 * @access private
960 */
961 function msg( $str ) {
962 echo htmlspecialchars( $this->translator->translate( $str ) );
963 }
964
965 /**
966 * @access private
967 */
968 function msgHtml( $str ) {
969 echo $this->translator->translate( $str );
970 }
971
972 /**
973 * An ugly, ugly hack.
974 * @access private
975 */
976 function msgWiki( $str ) {
977 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
978
979 $text = $this->translator->translate( $str );
980 $parserOutput = $wgParser->parse( $text, $wgTitle,
981 $wgOut->mParserOptions, true );
982 echo $parserOutput->getText();
983 }
984
985 /**
986 * @access private
987 */
988 function haveData( $str ) {
989 return $this->data[$str];
990 }
991
992 /**
993 * @access private
994 */
995 function haveMsg( $str ) {
996 $msg = $this->translator->translate( $str );
997 return ($msg != '-') && ($msg != ''); # ????
998 }
999 }
1000
1001 } // end of if( defined( 'MEDIAWIKI' ) )
1002 ?>