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