Localisation updates German
[mediawiki.git] / includes / SkinTemplate.php
blob4ba3f212223cdbe222cfb652028ab3be1047e861
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 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
24 * @private
25 * @addtogroup Skins
27 class MediaWiki_I18N {
28 var $_context = array();
30 function set($varName, $value) {
31 $this->_context[$varName] = $value;
34 function translate($value) {
35 $fname = 'SkinTemplate-translate';
36 wfProfileIn( $fname );
38 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
39 $value = preg_replace( '/^string:/', '', $value );
41 $value = wfMsg( $value );
42 // interpolate variables
43 $m = array();
44 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
45 list($src, $var) = $m;
46 wfSuppressWarnings();
47 $varValue = $this->_context[$var];
48 wfRestoreWarnings();
49 $value = str_replace($src, $varValue, $value);
51 wfProfileOut( $fname );
52 return $value;
56 /**
57 * Template-filler skin base class
58 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
59 * Based on Brion's smarty skin
60 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
62 * @todo Needs some serious refactoring into functions that correspond
63 * to the computations individual esi snippets need. Most importantly no body
64 * parsing for most of those of course.
66 * @addtogroup Skins
68 class SkinTemplate extends Skin {
69 /**#@+
70 * @private
73 /**
74 * Name of our skin, set in initPage()
75 * It probably need to be all lower case.
77 var $skinname;
79 /**
80 * Stylesheets set to use
81 * Sub directory in ./skins/ where various stylesheets are located
83 var $stylename;
85 /**
86 * For QuickTemplate, the name of the subclass which
87 * will actually fill the template.
89 var $template;
91 /**#@-*/
93 /**
94 * Setup the base parameters...
95 * Child classes should override this to set the name,
96 * style subdirectory, and template filler callback.
98 * @param OutputPage $out
100 function initPage( &$out ) {
101 parent::initPage( $out );
102 $this->skinname = 'monobook';
103 $this->stylename = 'monobook';
104 $this->template = 'QuickTemplate';
108 * Create the template engine object; we feed it a bunch of data
109 * and eventually it spits out some HTML. Should have interface
110 * roughly equivalent to PHPTAL 0.7.
112 * @param string $callback (or file)
113 * @param string $repository subdirectory where we keep template files
114 * @param string $cache_dir
115 * @return object
116 * @private
118 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
119 return new $classname();
123 * initialize various variables and generate the template
125 * @param OutputPage $out
126 * @public
128 function outputPage( &$out ) {
129 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
133 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks;
137 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
139 $fname = 'SkinTemplate::outputPage';
140 wfProfileIn( $fname );
142 $oldid = $wgRequest->getVal( 'oldid' );
143 $diff = $wgRequest->getVal( 'diff' );
145 wfProfileIn( "$fname-init" );
146 $this->initPage( $out );
148 $this->mTitle =& $wgTitle;
149 $this->mUser =& $wgUser;
151 $tpl = $this->setupTemplate( $this->template, 'skins' );
153 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
154 $tpl->setTranslator(new MediaWiki_I18N());
156 wfProfileOut( "$fname-init" );
158 wfProfileIn( "$fname-stuff" );
159 $this->thispage = $this->mTitle->getPrefixedDbKey();
160 $this->thisurl = $this->mTitle->getPrefixedURL();
161 $this->loggedin = $wgUser->isLoggedIn();
162 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
163 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
164 $this->username = $wgUser->getName();
165 $userPage = $wgUser->getUserPage();
166 $this->userpage = $userPage->getPrefixedText();
168 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
169 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
170 } else {
171 # This won't be used in the standard skins, but we define it to preserve the interface
172 # To save time, we check for existence
173 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
176 $this->usercss = $this->userjs = $this->userjsprev = false;
177 $this->setupUserCss();
178 $this->setupUserJs( $out->isUserJsAllowed() );
179 $this->titletxt = $this->mTitle->getPrefixedText();
180 wfProfileOut( "$fname-stuff" );
182 wfProfileIn( "$fname-stuff2" );
183 $tpl->set( 'title', $wgOut->getPageTitle() );
184 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
185 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
186 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
188 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
189 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
190 $this->mTitle->getNsText();
192 $tpl->set( 'nscanonical', $nsname );
193 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
194 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
195 $tpl->set( 'titletext', $this->mTitle->getText() );
196 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
197 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
199 $tpl->set( 'isarticle', $wgOut->isArticle() );
201 $tpl->setRef( "thispage", $this->thispage );
202 $subpagestr = $this->subPageSubtitle();
203 $tpl->set(
204 'subtitle', !empty($subpagestr)?
205 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
206 $out->getSubtitle()
208 $undelete = $this->getUndeleteLink();
209 $tpl->set(
210 "undelete", !empty($undelete)?
211 '<span class="subpages">'.$undelete.'</span>':
215 $tpl->set( 'catlinks', $this->getCategories());
216 if( $wgOut->isSyndicated() ) {
217 $feeds = array();
218 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
219 $feeds[$format] = array(
220 'text' => wfMsg( "feed-$format" ),
221 'href' => $link );
223 $tpl->setRef( 'feeds', $feeds );
224 } else {
225 $tpl->set( 'feeds', false );
227 if ($wgUseTrackbacks && $out->isArticleRelated()) {
228 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
229 } else {
230 $tpl->set( 'trackbackhtml', null );
233 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
234 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
235 $tpl->setRef( 'mimetype', $wgMimeType );
236 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
237 $tpl->setRef( 'charset', $wgOutputEncoding );
238 $tpl->set( 'headlinks', $out->getHeadLinks() );
239 $tpl->set('headscripts', $out->getScript() );
240 $tpl->setRef( 'wgScript', $wgScript );
241 $tpl->setRef( 'skinname', $this->skinname );
242 $tpl->set( 'skinclass', get_class( $this ) );
243 $tpl->setRef( 'stylename', $this->stylename );
244 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
245 $tpl->setRef( 'loggedin', $this->loggedin );
246 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
247 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
248 /* XXX currently unused, might get useful later
249 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
250 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
251 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
252 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
253 $tpl->set( "helppage", wfMsg('helppage'));
255 $tpl->set( 'searchaction', $this->escapeSearchLink() );
256 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
257 $tpl->setRef( 'stylepath', $wgStylePath );
258 $tpl->setRef( 'articlepath', $wgArticlePath );
259 $tpl->setRef( 'scriptpath', $wgScriptPath );
260 $tpl->setRef( 'serverurl', $wgServer );
261 $tpl->setRef( 'logopath', $wgLogo );
262 $tpl->setRef( "lang", $wgContLanguageCode );
263 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
264 $tpl->set( 'rtl', $wgContLang->isRTL() );
265 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
266 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
267 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
268 $tpl->setRef( 'userpage', $this->userpage);
269 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
270 $tpl->set( 'userlang', $wgLang->getCode() );
271 $tpl->set( 'pagecss', $this->setupPageCss() );
272 $tpl->setRef( 'usercss', $this->usercss);
273 $tpl->setRef( 'userjs', $this->userjs);
274 $tpl->setRef( 'userjsprev', $this->userjsprev);
275 global $wgUseSiteJs;
276 if ($wgUseSiteJs) {
277 $jsCache = $this->loggedin ? '&smaxage=0' : '';
278 $tpl->set( 'jsvarurl',
279 self::makeUrl('-',
280 "action=raw$jsCache&gen=js&useskin=" .
281 urlencode( $this->getSkinName() ) ) );
282 } else {
283 $tpl->set('jsvarurl', false);
285 $newtalks = $wgUser->getNewMessageLinks();
287 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
288 $usertitle = $this->mUser->getUserPage();
289 $usertalktitle = $usertitle->getTalkPage();
290 if( !$usertalktitle->equals( $this->mTitle ) ) {
291 $ntl = wfMsg( 'youhavenewmessages',
292 $this->makeKnownLinkObj(
293 $usertalktitle,
294 wfMsgHtml( 'newmessageslink' ),
295 'redirect=no'
297 $this->makeKnownLinkObj(
298 $usertalktitle,
299 wfMsgHtml( 'newmessagesdifflink' ),
300 'diff=cur'
303 # Disable Cache
304 $wgOut->setSquidMaxage(0);
306 } else if (count($newtalks)) {
307 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
308 $msgs = array();
309 foreach ($newtalks as $newtalk) {
310 $msgs[] = wfElement("a",
311 array('href' => $newtalk["link"]), $newtalk["wiki"]);
313 $parts = implode($sep, $msgs);
314 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
315 $wgOut->setSquidMaxage(0);
316 } else {
317 $ntl = '';
319 wfProfileOut( "$fname-stuff2" );
321 wfProfileIn( "$fname-stuff3" );
322 $tpl->setRef( 'newtalk', $ntl );
323 $tpl->setRef( 'skin', $this);
324 $tpl->set( 'logo', $this->logoText() );
325 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
326 $wgArticle and 0 != $wgArticle->getID() )
328 if ( !$wgDisableCounters ) {
329 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
330 if ( $viewcount ) {
331 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
332 } else {
333 $tpl->set('viewcount', false);
335 } else {
336 $tpl->set('viewcount', false);
339 if ($wgPageShowWatchingUsers) {
340 $dbr = wfGetDB( DB_SLAVE );
341 $watchlist = $dbr->tableName( 'watchlist' );
342 $sql = "SELECT COUNT(*) AS n FROM $watchlist
343 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
344 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
345 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
346 $x = $dbr->fetchObject( $res );
347 $numberofwatchingusers = $x->n;
348 if ($numberofwatchingusers > 0) {
349 $tpl->set('numberofwatchingusers',
350 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
351 $wgLang->formatNum($numberofwatchingusers))
353 } else {
354 $tpl->set('numberofwatchingusers', false);
356 } else {
357 $tpl->set('numberofwatchingusers', false);
360 $tpl->set('copyright',$this->getCopyright());
362 $this->credits = false;
364 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
365 require_once("Credits.php");
366 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
367 } else {
368 $tpl->set('lastmod', $this->lastModified());
371 $tpl->setRef( 'credits', $this->credits );
373 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
374 $tpl->set('copyright', $this->getCopyright());
375 $tpl->set('viewcount', false);
376 $tpl->set('lastmod', false);
377 $tpl->set('credits', false);
378 $tpl->set('numberofwatchingusers', false);
379 } else {
380 $tpl->set('copyright', false);
381 $tpl->set('viewcount', false);
382 $tpl->set('lastmod', false);
383 $tpl->set('credits', false);
384 $tpl->set('numberofwatchingusers', false);
386 wfProfileOut( "$fname-stuff3" );
388 wfProfileIn( "$fname-stuff4" );
389 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
390 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
391 $tpl->set( 'disclaimer', $this->disclaimerLink() );
392 $tpl->set( 'privacy', $this->privacyLink() );
393 $tpl->set( 'about', $this->aboutLink() );
395 $tpl->setRef( 'debug', $out->mDebugtext );
396 $tpl->set( 'reporttime', wfReportTime() );
397 $tpl->set( 'sitenotice', wfGetSiteNotice() );
398 $tpl->set( 'bottomscripts', $this->bottomScripts() );
400 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
401 $out->mBodytext .= $printfooter ;
402 $tpl->setRef( 'bodytext', $out->mBodytext );
404 # Language links
405 $language_urls = array();
407 if ( !$wgHideInterlanguageLinks ) {
408 foreach( $wgOut->getLanguageLinks() as $l ) {
409 $tmp = explode( ':', $l, 2 );
410 $class = 'interwiki-' . $tmp[0];
411 unset($tmp);
412 $nt = Title::newFromText( $l );
413 $language_urls[] = array(
414 'href' => $nt->getFullURL(),
415 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
416 'class' => $class
420 if(count($language_urls)) {
421 $tpl->setRef( 'language_urls', $language_urls);
422 } else {
423 $tpl->set('language_urls', false);
425 wfProfileOut( "$fname-stuff4" );
427 # Personal toolbar
428 $tpl->set('personal_urls', $this->buildPersonalUrls());
429 $content_actions = $this->buildContentActionUrls();
430 $tpl->setRef('content_actions', $content_actions);
432 // XXX: attach this from javascript, same with section editing
433 if($this->iseditable && $wgUser->getOption("editondblclick") )
435 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
436 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
437 } else {
438 $tpl->set('body_ondblclick', false);
440 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
441 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
442 } else {
443 $tpl->set( 'body_onload', false );
445 $tpl->set( 'sidebar', $this->buildSidebar() );
446 $tpl->set( 'nav_urls', $this->buildNavUrls() );
448 // original version by hansm
449 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
450 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
453 // execute template
454 wfProfileIn( "$fname-execute" );
455 $res = $tpl->execute();
456 wfProfileOut( "$fname-execute" );
458 // result may be an error
459 $this->printOrError( $res );
460 wfProfileOut( $fname );
464 * Output the string, or print error message if it's
465 * an error object of the appropriate type.
466 * For the base class, assume strings all around.
468 * @param mixed $str
469 * @private
471 function printOrError( $str ) {
472 echo $str;
476 * build array of urls for personal toolbar
477 * @return array
478 * @private
480 function buildPersonalUrls() {
481 global $wgTitle, $wgRequest;
483 $fname = 'SkinTemplate::buildPersonalUrls';
484 $pageurl = $wgTitle->getLocalURL();
485 wfProfileIn( $fname );
487 /* set up the default links for the personal toolbar */
488 $personal_urls = array();
489 if ($this->loggedin) {
490 $personal_urls['userpage'] = array(
491 'text' => $this->username,
492 'href' => &$this->userpageUrlDetails['href'],
493 'class' => $this->userpageUrlDetails['exists']?false:'new',
494 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
496 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
497 $personal_urls['mytalk'] = array(
498 'text' => wfMsg('mytalk'),
499 'href' => &$usertalkUrlDetails['href'],
500 'class' => $usertalkUrlDetails['exists']?false:'new',
501 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
503 $href = self::makeSpecialUrl( 'Preferences' );
504 $personal_urls['preferences'] = array(
505 'text' => wfMsg( 'mypreferences' ),
506 'href' => $href,
507 'active' => ( $href == $pageurl )
509 $href = self::makeSpecialUrl( 'Watchlist' );
510 $personal_urls['watchlist'] = array(
511 'text' => wfMsg( 'mywatchlist' ),
512 'href' => $href,
513 'active' => ( $href == $pageurl )
516 # We need to do an explicit check for Special:Contributions, as we
517 # have to match both the title, and the target (which could come
518 # from request values or be specified in "sub page" form. The plot
519 # thickens, because $wgTitle is altered for special pages, so doesn't
520 # contain the original alias-with-subpage.
521 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
522 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
523 list( $spName, $spPar ) =
524 SpecialPage::resolveAliasWithSubpage( $title->getText() );
525 $active = $spName == 'Contributions'
526 && ( ( $spPar && $spPar == $this->username )
527 || $wgRequest->getText( 'target' ) == $this->username );
528 } else {
529 $active = false;
532 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
533 $personal_urls['mycontris'] = array(
534 'text' => wfMsg( 'mycontris' ),
535 'href' => $href,
536 'active' => $active
538 $personal_urls['logout'] = array(
539 'text' => wfMsg( 'userlogout' ),
540 'href' => self::makeSpecialUrl( 'Userlogout',
541 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
543 'active' => false
545 } else {
546 global $wgUser;
547 $loginlink = $wgUser->isAllowed( 'createaccount' )
548 ? 'nav-login-createaccount'
549 : 'login';
550 if( $this->showIPinHeader() ) {
551 $href = &$this->userpageUrlDetails['href'];
552 $personal_urls['anonuserpage'] = array(
553 'text' => $this->username,
554 'href' => $href,
555 'class' => $this->userpageUrlDetails['exists']?false:'new',
556 'active' => ( $pageurl == $href )
558 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
559 $href = &$usertalkUrlDetails['href'];
560 $personal_urls['anontalk'] = array(
561 'text' => wfMsg('anontalk'),
562 'href' => $href,
563 'class' => $usertalkUrlDetails['exists']?false:'new',
564 'active' => ( $pageurl == $href )
566 $personal_urls['anonlogin'] = array(
567 'text' => wfMsg( $loginlink ),
568 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
569 'active' => $wgTitle->isSpecial( 'Userlogin' )
571 } else {
573 $personal_urls['login'] = array(
574 'text' => wfMsg( $loginlink ),
575 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
576 'active' => $wgTitle->isSpecial( 'Userlogin' )
581 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
582 wfProfileOut( $fname );
583 return $personal_urls;
586 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
587 $classes = array();
588 if( $selected ) {
589 $classes[] = 'selected';
591 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
592 $classes[] = 'new';
593 $query = 'action=edit';
596 $text = wfMsg( $message );
597 if ( wfEmptyMsg( $message, $text ) ) {
598 global $wgContLang;
599 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
602 $result = array();
603 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
604 $title, $message, $selected, $checkEdit,
605 &$classes, &$query, &$text, &$result)) ) {
606 return $result;
609 return array(
610 'class' => implode( ' ', $classes ),
611 'text' => $text,
612 'href' => $title->getLocalUrl( $query ) );
615 function makeTalkUrlDetails( $name, $urlaction = '' ) {
616 $title = Title::newFromText( $name );
617 if( !is_object($title) ) {
618 throw new MWException( __METHOD__." given invalid pagename $name" );
620 $title = $title->getTalkPage();
621 self::checkTitle( $title, $name );
622 return array(
623 'href' => $title->getLocalURL( $urlaction ),
624 'exists' => $title->getArticleID() != 0 ? true : false
628 function makeArticleUrlDetails( $name, $urlaction = '' ) {
629 $title = Title::newFromText( $name );
630 $title= $title->getSubjectPage();
631 self::checkTitle( $title, $name );
632 return array(
633 'href' => $title->getLocalURL( $urlaction ),
634 'exists' => $title->getArticleID() != 0 ? true : false
639 * an array of edit links by default used for the tabs
640 * @return array
641 * @private
643 function buildContentActionUrls () {
644 global $wgContLang, $wgLang, $wgOut;
645 $fname = 'SkinTemplate::buildContentActionUrls';
646 wfProfileIn( $fname );
648 global $wgUser, $wgRequest;
649 $action = $wgRequest->getText( 'action' );
650 $section = $wgRequest->getText( 'section' );
651 $content_actions = array();
653 $prevent_active_tabs = false ;
654 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
656 if( $this->iscontent ) {
657 $subjpage = $this->mTitle->getSubjectPage();
658 $talkpage = $this->mTitle->getTalkPage();
660 $nskey = $this->mTitle->getNamespaceKey();
661 $content_actions[$nskey] = $this->tabAction(
662 $subjpage,
663 $nskey,
664 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
665 '', true);
667 $content_actions['talk'] = $this->tabAction(
668 $talkpage,
669 'talk',
670 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
672 true);
674 wfProfileIn( "$fname-edit" );
675 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
676 $istalk = $this->mTitle->isTalkPage();
677 $istalkclass = $istalk?' istalk':'';
678 $content_actions['edit'] = array(
679 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
680 'text' => $this->mTitle->exists()
681 ? wfMsg( 'edit' )
682 : wfMsg( 'create' ),
683 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
686 if ( $istalk || $wgOut->showNewSectionLink() ) {
687 $content_actions['addsection'] = array(
688 'class' => $section == 'new'?'selected':false,
689 'text' => wfMsg('addsection'),
690 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
693 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
694 $content_actions['viewsource'] = array(
695 'class' => ($action == 'edit') ? 'selected' : false,
696 'text' => wfMsg('viewsource'),
697 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
700 wfProfileOut( "$fname-edit" );
702 wfProfileIn( "$fname-live" );
703 if ( $this->mTitle->getArticleId() ) {
705 $content_actions['history'] = array(
706 'class' => ($action == 'history') ? 'selected' : false,
707 'text' => wfMsg('history_short'),
708 'href' => $this->mTitle->getLocalUrl( 'action=history')
711 if($wgUser->isAllowed('delete')){
712 $content_actions['delete'] = array(
713 'class' => ($action == 'delete') ? 'selected' : false,
714 'text' => wfMsg('delete'),
715 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
718 if ( $this->mTitle->quickUserCan( 'move' ) ) {
719 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
720 $content_actions['move'] = array(
721 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
722 'text' => wfMsg('move'),
723 'href' => $moveTitle->getLocalUrl()
727 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
728 if(!$this->mTitle->isProtected()){
729 $content_actions['protect'] = array(
730 'class' => ($action == 'protect') ? 'selected' : false,
731 'text' => wfMsg('protect'),
732 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
735 } else {
736 $content_actions['unprotect'] = array(
737 'class' => ($action == 'unprotect') ? 'selected' : false,
738 'text' => wfMsg('unprotect'),
739 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
743 } else {
744 //article doesn't exist or is deleted
745 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
746 if( $n = $this->mTitle->isDeleted() ) {
747 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
748 $content_actions['undelete'] = array(
749 'class' => false,
750 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
751 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
752 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
757 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
758 if( !$this->mTitle->getRestrictions( 'create' ) ) {
759 $content_actions['protect'] = array(
760 'class' => ($action == 'protect') ? 'selected' : false,
761 'text' => wfMsg('protect'),
762 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
765 } else {
766 $content_actions['unprotect'] = array(
767 'class' => ($action == 'unprotect') ? 'selected' : false,
768 'text' => wfMsg('unprotect'),
769 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
775 wfProfileOut( "$fname-live" );
777 if( $this->loggedin ) {
778 if( !$this->mTitle->userIsWatching()) {
779 $content_actions['watch'] = array(
780 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
781 'text' => wfMsg('watch'),
782 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
784 } else {
785 $content_actions['unwatch'] = array(
786 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
787 'text' => wfMsg('unwatch'),
788 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
794 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
795 } else {
796 /* show special page tab */
798 $content_actions[$this->mTitle->getNamespaceKey()] = array(
799 'class' => 'selected',
800 'text' => wfMsg('nstab-special'),
801 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
804 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
807 /* show links to different language variants */
808 global $wgDisableLangConversion;
809 $variants = $wgContLang->getVariants();
810 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
811 $preferred = $wgContLang->getPreferredVariant();
812 $vcount=0;
813 foreach( $variants as $code ) {
814 $varname = $wgContLang->getVariantname( $code );
815 if( $varname == 'disable' )
816 continue;
817 $selected = ( $code == $preferred )? 'selected' : false;
818 $content_actions['varlang-' . $vcount] = array(
819 'class' => $selected,
820 'text' => $varname,
821 'href' => $this->mTitle->getLocalURL('',$code)
823 $vcount ++;
827 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
829 wfProfileOut( $fname );
830 return $content_actions;
836 * build array of common navigation links
837 * @return array
838 * @private
840 function buildNavUrls () {
841 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
842 global $wgEnableUploads, $wgUploadNavigationUrl;
844 $fname = 'SkinTemplate::buildNavUrls';
845 wfProfileIn( $fname );
847 $action = $wgRequest->getText( 'action' );
849 $nav_urls = array();
850 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
851 if( $wgEnableUploads ) {
852 if ($wgUploadNavigationUrl) {
853 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
854 } else {
855 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
857 } else {
858 if ($wgUploadNavigationUrl)
859 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
860 else
861 $nav_urls['upload'] = false;
863 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
865 // default permalink to being off, will override it as required below.
866 $nav_urls['permalink'] = false;
868 // A print stylesheet is attached to all pages, but nobody ever
869 // figures that out. :) Add a link...
870 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
871 $nav_urls['print'] = array(
872 'text' => wfMsg( 'printableversion' ),
873 'href' => $wgRequest->appendQuery( 'printable=yes' )
876 // Also add a "permalink" while we're at it
877 if ( $this->mRevisionId ) {
878 $nav_urls['permalink'] = array(
879 'text' => wfMsg( 'permalink' ),
880 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
884 // Copy in case this undocumented, shady hook tries to mess with internals
885 $revid = $this->mRevisionId;
886 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
889 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
890 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
891 $nav_urls['whatlinkshere'] = array(
892 'href' => $wlhTitle->getLocalUrl()
894 if( $this->mTitle->getArticleId() ) {
895 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
896 $nav_urls['recentchangeslinked'] = array(
897 'href' => $rclTitle->getLocalUrl()
899 } else {
900 $nav_urls['recentchangeslinked'] = false;
902 if ($wgUseTrackbacks)
903 $nav_urls['trackbacklink'] = array(
904 'href' => $wgTitle->trackbackURL()
908 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
909 $id = User::idFromName($this->mTitle->getText());
910 $ip = User::isIP($this->mTitle->getText());
911 } else {
912 $id = 0;
913 $ip = false;
916 if($id || $ip) { # both anons and non-anons have contribs list
917 $nav_urls['contributions'] = array(
918 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
921 if( $id ) {
922 $logPage = SpecialPage::getTitleFor( 'Log' );
923 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
924 . $this->mTitle->getPartialUrl() ) );
925 } else {
926 $nav_urls['log'] = false;
929 if ( $wgUser->isAllowed( 'block' ) ) {
930 $nav_urls['blockip'] = array(
931 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
933 } else {
934 $nav_urls['blockip'] = false;
936 } else {
937 $nav_urls['contributions'] = false;
938 $nav_urls['log'] = false;
939 $nav_urls['blockip'] = false;
941 $nav_urls['emailuser'] = false;
942 if( $this->showEmailUser( $id ) ) {
943 $nav_urls['emailuser'] = array(
944 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
947 wfProfileOut( $fname );
948 return $nav_urls;
952 * Generate strings used for xml 'id' names
953 * @return string
954 * @private
956 function getNameSpaceKey () {
957 return $this->mTitle->getNamespaceKey();
961 * @private
963 function setupUserCss() {
964 $fname = 'SkinTemplate::setupUserCss';
965 wfProfileIn( $fname );
967 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
969 $sitecss = '';
970 $usercss = '';
971 $siteargs = '&maxage=' . $wgSquidMaxage;
972 if( $this->loggedin ) {
973 // Ensure that logged-in users' generated CSS isn't clobbered
974 // by anons' publicly cacheable generated CSS.
975 $siteargs .= '&smaxage=0';
978 # Add user-specific code if this is a user and we allow that kind of thing
980 if ( $wgAllowUserCss && $this->loggedin ) {
981 $action = $wgRequest->getText('action');
983 # if we're previewing the CSS page, use it
984 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
985 $siteargs = "&smaxage=0&maxage=0";
986 $usercss = $wgRequest->getText('wpTextbox1');
987 } else {
988 $usercss = '@import "' .
989 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
990 'action=raw&ctype=text/css') . '";' ."\n";
993 $siteargs .= '&ts=' . $wgUser->mTouched;
996 if( $wgContLang->isRTL() ) {
997 global $wgStyleVersion;
998 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
1001 # If we use the site's dynamic CSS, throw that in, too
1002 if ( $wgUseSiteCss ) {
1003 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1004 $skinquery = '';
1005 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1006 $skinquery = "&useskin=$us";
1007 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1008 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
1009 $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1012 # If we use any dynamic CSS, make a little CDATA block out of it.
1014 if ( !empty($sitecss) || !empty($usercss) ) {
1015 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1017 wfProfileOut( $fname );
1021 * @private
1023 function setupUserJs( $allowUserJs ) {
1024 $fname = 'SkinTemplate::setupUserJs';
1025 wfProfileIn( $fname );
1027 global $wgRequest, $wgJsMimeType;
1028 $action = $wgRequest->getText('action');
1030 if( $allowUserJs && $this->loggedin ) {
1031 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1032 # XXX: additional security check/prompt?
1033 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1034 } else {
1035 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1038 wfProfileOut( $fname );
1042 * Code for extensions to hook into to provide per-page CSS, see
1043 * extensions/PageCSS/PageCSS.php for an implementation of this.
1045 * @private
1047 function setupPageCss() {
1048 $fname = 'SkinTemplate::setupPageCss';
1049 wfProfileIn( $fname );
1050 $out = false;
1051 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1053 wfProfileOut( $fname );
1054 return $out;
1058 * returns css with user-specific options
1059 * @public
1062 function getUserStylesheet() {
1063 $fname = 'SkinTemplate::getUserStylesheet';
1064 wfProfileIn( $fname );
1066 $s = "/* generated user stylesheet */\n";
1067 $s .= $this->reallyDoGetUserStyles();
1068 wfProfileOut( $fname );
1069 return $s;
1073 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1074 * nated together. For some bizarre reason, it does *not* return any
1075 * custom user JS from subpages. Huh?
1077 * There's absolutely no reason to have separate Monobook/Common JSes.
1078 * Any JS that cares can just check the skin variable generated at the
1079 * top. For now Monobook.js will be maintained, but it should be consi-
1080 * dered deprecated.
1082 * @return string
1084 public function getUserJs() {
1085 $fname = 'SkinTemplate::getUserJs';
1086 wfProfileIn( $fname );
1088 $s = parent::getUserJs();
1089 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1091 // avoid inclusion of non defined user JavaScript (with custom skins only)
1092 // by checking for default message content
1093 $msgKey = ucfirst($this->skinname).'.js';
1094 $userJS = wfMsgForContent($msgKey);
1095 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1096 $s .= $userJS;
1099 wfProfileOut( $fname );
1100 return $s;
1105 * Generic wrapper for template functions, with interface
1106 * compatible with what we use of PHPTAL 0.7.
1107 * @addtogroup Skins
1109 class QuickTemplate {
1111 * @public
1113 function QuickTemplate() {
1114 $this->data = array();
1115 $this->translator = new MediaWiki_I18N();
1119 * @public
1121 function set( $name, $value ) {
1122 $this->data[$name] = $value;
1126 * @public
1128 function setRef($name, &$value) {
1129 $this->data[$name] =& $value;
1133 * @public
1135 function setTranslator( &$t ) {
1136 $this->translator = &$t;
1140 * @public
1142 function execute() {
1143 echo "Override this function.";
1148 * @private
1150 function text( $str ) {
1151 echo htmlspecialchars( $this->data[$str] );
1155 * @private
1157 function jstext( $str ) {
1158 echo Xml::escapeJsString( $this->data[$str] );
1162 * @private
1164 function html( $str ) {
1165 echo $this->data[$str];
1169 * @private
1171 function msg( $str ) {
1172 echo htmlspecialchars( $this->translator->translate( $str ) );
1176 * @private
1178 function msgHtml( $str ) {
1179 echo $this->translator->translate( $str );
1183 * An ugly, ugly hack.
1184 * @private
1186 function msgWiki( $str ) {
1187 global $wgParser, $wgTitle, $wgOut;
1189 $text = $this->translator->translate( $str );
1190 $parserOutput = $wgParser->parse( $text, $wgTitle,
1191 $wgOut->parserOptions(), true );
1192 echo $parserOutput->getText();
1196 * @private
1198 function haveData( $str ) {
1199 return isset( $this->data[$str] );
1203 * @private
1205 function haveMsg( $str ) {
1206 $msg = $this->translator->translate( $str );
1207 return ($msg != '-') && ($msg != ''); # ????