Fix regression in even sizing of diff columns; forgot to restore a couple bits I...
[mediawiki.git] / includes / SkinTemplate.php
blob2f61a0b49dd82022d6149bb09b5b151aaf53555a
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 // Hook that allows last minute changes to the output page, e.g.
143 // adding of CSS or Javascript by extensions.
144 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
146 $oldid = $wgRequest->getVal( 'oldid' );
147 $diff = $wgRequest->getVal( 'diff' );
149 wfProfileIn( "$fname-init" );
150 $this->initPage( $out );
152 $this->mTitle =& $wgTitle;
153 $this->mUser =& $wgUser;
155 $tpl = $this->setupTemplate( $this->template, 'skins' );
157 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
158 $tpl->setTranslator(new MediaWiki_I18N());
160 wfProfileOut( "$fname-init" );
162 wfProfileIn( "$fname-stuff" );
163 $this->thispage = $this->mTitle->getPrefixedDbKey();
164 $this->thisurl = $this->mTitle->getPrefixedURL();
165 $this->loggedin = $wgUser->isLoggedIn();
166 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
167 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
168 $this->username = $wgUser->getName();
169 $userPage = $wgUser->getUserPage();
170 $this->userpage = $userPage->getPrefixedText();
172 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
173 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
174 } else {
175 # This won't be used in the standard skins, but we define it to preserve the interface
176 # To save time, we check for existence
177 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
180 $this->usercss = $this->userjs = $this->userjsprev = false;
181 $this->setupUserCss();
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt = $this->mTitle->getPrefixedText();
184 wfProfileOut( "$fname-stuff" );
186 wfProfileIn( "$fname-stuff2" );
187 $tpl->set( 'title', $wgOut->getPageTitle() );
188 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
190 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
194 $this->mTitle->getNsText();
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle->getText() );
200 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
203 $tpl->set( 'isarticle', $wgOut->isArticle() );
205 $tpl->setRef( "thispage", $this->thispage );
206 $subpagestr = $this->subPageSubtitle();
207 $tpl->set(
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
210 $out->getSubtitle()
212 $undelete = $this->getUndeleteLink();
213 $tpl->set(
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $wgOut->isSyndicated() ) {
221 $feeds = array();
222 foreach( $wgFeedClasses as $format => $class ) {
223 $linktext = $format;
224 if ( $format == "atom" ) {
225 $linktext = wfMsg( 'feed-atom' );
226 } else if ( $format == "rss" ) {
227 $linktext = wfMsg( 'feed-rss' );
229 $feeds[$format] = array(
230 'text' => $linktext,
231 'href' => $wgRequest->appendQuery( "feed=$format" )
234 $tpl->setRef( 'feeds', $feeds );
235 } else {
236 $tpl->set( 'feeds', false );
238 if ($wgUseTrackbacks && $out->isArticleRelated()) {
239 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
240 } else {
241 $tpl->set( 'trackbackhtml', null );
244 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
245 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
246 $tpl->setRef( 'mimetype', $wgMimeType );
247 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
248 $tpl->setRef( 'charset', $wgOutputEncoding );
249 $tpl->set( 'headlinks', $out->getHeadLinks() );
250 $tpl->set('headscripts', $out->getScript() );
251 $tpl->setRef( 'wgScript', $wgScript );
252 $tpl->setRef( 'skinname', $this->skinname );
253 $tpl->set( 'skinclass', get_class( $this ) );
254 $tpl->setRef( 'stylename', $this->stylename );
255 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
256 $tpl->setRef( 'loggedin', $this->loggedin );
257 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
258 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
259 /* XXX currently unused, might get useful later
260 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
261 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
262 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
263 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
264 $tpl->set( "helppage", wfMsg('helppage'));
266 $tpl->set( 'searchaction', $this->escapeSearchLink() );
267 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
268 $tpl->setRef( 'stylepath', $wgStylePath );
269 $tpl->setRef( 'articlepath', $wgArticlePath );
270 $tpl->setRef( 'scriptpath', $wgScriptPath );
271 $tpl->setRef( 'serverurl', $wgServer );
272 $tpl->setRef( 'logopath', $wgLogo );
273 $tpl->setRef( "lang", $wgContLanguageCode );
274 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
275 $tpl->set( 'rtl', $wgContLang->isRTL() );
276 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
277 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
278 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
279 $tpl->setRef( 'userpage', $this->userpage);
280 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
281 $tpl->set( 'userlang', $wgLang->getCode() );
282 $tpl->set( 'pagecss', $this->setupPageCss() );
283 $tpl->setRef( 'usercss', $this->usercss);
284 $tpl->setRef( 'userjs', $this->userjs);
285 $tpl->setRef( 'userjsprev', $this->userjsprev);
286 global $wgUseSiteJs;
287 if ($wgUseSiteJs) {
288 if($this->loggedin) {
289 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&smaxage=0&gen=js') );
290 } else {
291 $tpl->set( 'jsvarurl', self::makeUrl('-','action=raw&gen=js') );
293 } else {
294 $tpl->set('jsvarurl', false);
296 $newtalks = $wgUser->getNewMessageLinks();
298 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
299 $usertitle = $this->mUser->getUserPage();
300 $usertalktitle = $usertitle->getTalkPage();
301 if( !$usertalktitle->equals( $this->mTitle ) ) {
302 $ntl = wfMsg( 'youhavenewmessages',
303 $this->makeKnownLinkObj(
304 $usertalktitle,
305 wfMsgHtml( 'newmessageslink' ),
306 'redirect=no'
308 $this->makeKnownLinkObj(
309 $usertalktitle,
310 wfMsgHtml( 'newmessagesdifflink' ),
311 'diff=cur'
314 # Disable Cache
315 $wgOut->setSquidMaxage(0);
317 } else if (count($newtalks)) {
318 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
319 $msgs = array();
320 foreach ($newtalks as $newtalk) {
321 $msgs[] = wfElement("a",
322 array('href' => $newtalk["link"]), $newtalk["wiki"]);
324 $parts = implode($sep, $msgs);
325 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
326 $wgOut->setSquidMaxage(0);
327 } else {
328 $ntl = '';
330 wfProfileOut( "$fname-stuff2" );
332 wfProfileIn( "$fname-stuff3" );
333 $tpl->setRef( 'newtalk', $ntl );
334 $tpl->setRef( 'skin', $this);
335 $tpl->set( 'logo', $this->logoText() );
336 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
337 $wgArticle and 0 != $wgArticle->getID() )
339 if ( !$wgDisableCounters ) {
340 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
341 if ( $viewcount ) {
342 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
343 } else {
344 $tpl->set('viewcount', false);
346 } else {
347 $tpl->set('viewcount', false);
350 if ($wgPageShowWatchingUsers) {
351 $dbr = wfGetDB( DB_SLAVE );
352 $watchlist = $dbr->tableName( 'watchlist' );
353 $sql = "SELECT COUNT(*) AS n FROM $watchlist
354 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
355 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
356 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
357 $x = $dbr->fetchObject( $res );
358 $numberofwatchingusers = $x->n;
359 if ($numberofwatchingusers > 0) {
360 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
361 } else {
362 $tpl->set('numberofwatchingusers', false);
364 } else {
365 $tpl->set('numberofwatchingusers', false);
368 $tpl->set('copyright',$this->getCopyright());
370 $this->credits = false;
372 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
373 require_once("Credits.php");
374 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
375 } else {
376 $tpl->set('lastmod', $this->lastModified());
379 $tpl->setRef( 'credits', $this->credits );
381 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
382 $tpl->set('copyright', $this->getCopyright());
383 $tpl->set('viewcount', false);
384 $tpl->set('lastmod', false);
385 $tpl->set('credits', false);
386 $tpl->set('numberofwatchingusers', false);
387 } else {
388 $tpl->set('copyright', false);
389 $tpl->set('viewcount', false);
390 $tpl->set('lastmod', false);
391 $tpl->set('credits', false);
392 $tpl->set('numberofwatchingusers', false);
394 wfProfileOut( "$fname-stuff3" );
396 wfProfileIn( "$fname-stuff4" );
397 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
398 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
399 $tpl->set( 'disclaimer', $this->disclaimerLink() );
400 $tpl->set( 'privacy', $this->privacyLink() );
401 $tpl->set( 'about', $this->aboutLink() );
403 $tpl->setRef( 'debug', $out->mDebugtext );
404 $tpl->set( 'reporttime', $out->reportTime() );
405 $tpl->set( 'sitenotice', wfGetSiteNotice() );
406 $tpl->set( 'bottomscripts', $this->bottomScripts() );
408 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
409 $out->mBodytext .= $printfooter ;
410 $tpl->setRef( 'bodytext', $out->mBodytext );
412 # Language links
413 $language_urls = array();
415 if ( !$wgHideInterlanguageLinks ) {
416 foreach( $wgOut->getLanguageLinks() as $l ) {
417 $tmp = explode( ':', $l, 2 );
418 $class = 'interwiki-' . $tmp[0];
419 unset($tmp);
420 $nt = Title::newFromText( $l );
421 $language_urls[] = array(
422 'href' => $nt->getFullURL(),
423 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
424 'class' => $class
428 if(count($language_urls)) {
429 $tpl->setRef( 'language_urls', $language_urls);
430 } else {
431 $tpl->set('language_urls', false);
433 wfProfileOut( "$fname-stuff4" );
435 # Personal toolbar
436 $tpl->set('personal_urls', $this->buildPersonalUrls());
437 $content_actions = $this->buildContentActionUrls();
438 $tpl->setRef('content_actions', $content_actions);
440 // XXX: attach this from javascript, same with section editing
441 if($this->iseditable && $wgUser->getOption("editondblclick") )
443 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
444 } else {
445 $tpl->set('body_ondblclick', false);
447 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
448 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
449 } else {
450 $tpl->set( 'body_onload', false );
452 $tpl->set( 'sidebar', $this->buildSidebar() );
453 $tpl->set( 'nav_urls', $this->buildNavUrls() );
455 // original version by hansm
456 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
457 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
460 // execute template
461 wfProfileIn( "$fname-execute" );
462 $res = $tpl->execute();
463 wfProfileOut( "$fname-execute" );
465 // result may be an error
466 $this->printOrError( $res );
467 wfProfileOut( $fname );
471 * Output the string, or print error message if it's
472 * an error object of the appropriate type.
473 * For the base class, assume strings all around.
475 * @param mixed $str
476 * @private
478 function printOrError( $str ) {
479 echo $str;
483 * build array of urls for personal toolbar
484 * @return array
485 * @private
487 function buildPersonalUrls() {
488 global $wgTitle, $wgRequest;
490 $fname = 'SkinTemplate::buildPersonalUrls';
491 $pageurl = $wgTitle->getLocalURL();
492 wfProfileIn( $fname );
494 /* set up the default links for the personal toolbar */
495 $personal_urls = array();
496 if ($this->loggedin) {
497 $personal_urls['userpage'] = array(
498 'text' => $this->username,
499 'href' => &$this->userpageUrlDetails['href'],
500 'class' => $this->userpageUrlDetails['exists']?false:'new',
501 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
503 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
504 $personal_urls['mytalk'] = array(
505 'text' => wfMsg('mytalk'),
506 'href' => &$usertalkUrlDetails['href'],
507 'class' => $usertalkUrlDetails['exists']?false:'new',
508 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
510 $href = self::makeSpecialUrl( 'Preferences' );
511 $personal_urls['preferences'] = array(
512 'text' => wfMsg( 'mypreferences' ),
513 'href' => $href,
514 'active' => ( $href == $pageurl )
516 $href = self::makeSpecialUrl( 'Watchlist' );
517 $personal_urls['watchlist'] = array(
518 'text' => wfMsg( 'mywatchlist' ),
519 'href' => $href,
520 'active' => ( $href == $pageurl )
523 # We need to do an explicit check for Special:Contributions, as we
524 # have to match both the title, and the target (which could come
525 # from request values or be specified in "sub page" form. The plot
526 # thickens, because $wgTitle is altered for special pages, so doesn't
527 # contain the original alias-with-subpage.
528 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
529 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
530 list( $spName, $spPar ) =
531 SpecialPage::resolveAliasWithSubpage( $title->getText() );
532 $active = $spName == 'Contributions'
533 && ( ( $spPar && $spPar == $this->username )
534 || $wgRequest->getText( 'target' ) == $this->username );
535 } else {
536 $active = false;
539 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
540 $personal_urls['mycontris'] = array(
541 'text' => wfMsg( 'mycontris' ),
542 'href' => $href,
543 'active' => $active
545 $personal_urls['logout'] = array(
546 'text' => wfMsg( 'userlogout' ),
547 'href' => self::makeSpecialUrl( 'Userlogout',
548 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
550 'active' => false
552 } else {
553 if( $this->showIPinHeader() ) {
554 $href = &$this->userpageUrlDetails['href'];
555 $personal_urls['anonuserpage'] = array(
556 'text' => $this->username,
557 'href' => $href,
558 'class' => $this->userpageUrlDetails['exists']?false:'new',
559 'active' => ( $pageurl == $href )
561 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
562 $href = &$usertalkUrlDetails['href'];
563 $personal_urls['anontalk'] = array(
564 'text' => wfMsg('anontalk'),
565 'href' => $href,
566 'class' => $usertalkUrlDetails['exists']?false:'new',
567 'active' => ( $pageurl == $href )
569 $personal_urls['anonlogin'] = array(
570 'text' => wfMsg('userlogin'),
571 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
572 'active' => $wgTitle->isSpecial( 'Userlogin' )
574 } else {
576 $personal_urls['login'] = array(
577 'text' => wfMsg('userlogin'),
578 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
579 'active' => $wgTitle->isSpecial( 'Userlogin' )
584 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
585 wfProfileOut( $fname );
586 return $personal_urls;
589 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
590 $classes = array();
591 if( $selected ) {
592 $classes[] = 'selected';
594 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
595 $classes[] = 'new';
596 $query = 'action=edit';
599 $text = wfMsg( $message );
600 if ( wfEmptyMsg( $message, $text ) ) {
601 global $wgContLang;
602 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
605 return array(
606 'class' => implode( ' ', $classes ),
607 'text' => $text,
608 'href' => $title->getLocalUrl( $query ) );
611 function makeTalkUrlDetails( $name, $urlaction = '' ) {
612 $title = Title::newFromText( $name );
613 if( !is_object($title) ) {
614 throw new MWException( __METHOD__." given invalid pagename $name" );
616 $title = $title->getTalkPage();
617 self::checkTitle( $title, $name );
618 return array(
619 'href' => $title->getLocalURL( $urlaction ),
620 'exists' => $title->getArticleID() != 0 ? true : false
624 function makeArticleUrlDetails( $name, $urlaction = '' ) {
625 $title = Title::newFromText( $name );
626 $title= $title->getSubjectPage();
627 self::checkTitle( $title, $name );
628 return array(
629 'href' => $title->getLocalURL( $urlaction ),
630 'exists' => $title->getArticleID() != 0 ? true : false
635 * an array of edit links by default used for the tabs
636 * @return array
637 * @private
639 function buildContentActionUrls () {
640 global $wgContLang, $wgOut;
641 $fname = 'SkinTemplate::buildContentActionUrls';
642 wfProfileIn( $fname );
644 global $wgUser, $wgRequest;
645 $action = $wgRequest->getText( 'action' );
646 $section = $wgRequest->getText( 'section' );
647 $content_actions = array();
649 $prevent_active_tabs = false ;
650 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
652 if( $this->iscontent ) {
653 $subjpage = $this->mTitle->getSubjectPage();
654 $talkpage = $this->mTitle->getTalkPage();
656 $nskey = $this->mTitle->getNamespaceKey();
657 $content_actions[$nskey] = $this->tabAction(
658 $subjpage,
659 $nskey,
660 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
661 '', true);
663 $content_actions['talk'] = $this->tabAction(
664 $talkpage,
665 'talk',
666 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
668 true);
670 wfProfileIn( "$fname-edit" );
671 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
672 $istalk = $this->mTitle->isTalkPage();
673 $istalkclass = $istalk?' istalk':'';
674 $content_actions['edit'] = array(
675 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
676 'text' => wfMsg('edit'),
677 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
680 if ( $istalk || $wgOut->showNewSectionLink() ) {
681 $content_actions['addsection'] = array(
682 'class' => $section == 'new'?'selected':false,
683 'text' => wfMsg('addsection'),
684 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
687 } else {
688 $content_actions['viewsource'] = array(
689 'class' => ($action == 'edit') ? 'selected' : false,
690 'text' => wfMsg('viewsource'),
691 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
694 wfProfileOut( "$fname-edit" );
696 wfProfileIn( "$fname-live" );
697 if ( $this->mTitle->getArticleId() ) {
699 $content_actions['history'] = array(
700 'class' => ($action == 'history') ? 'selected' : false,
701 'text' => wfMsg('history_short'),
702 'href' => $this->mTitle->getLocalUrl( 'action=history')
705 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
706 if(!$this->mTitle->isProtected()){
707 $content_actions['protect'] = array(
708 'class' => ($action == 'protect') ? 'selected' : false,
709 'text' => wfMsg('protect'),
710 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
713 } else {
714 $content_actions['unprotect'] = array(
715 'class' => ($action == 'unprotect') ? 'selected' : false,
716 'text' => wfMsg('unprotect'),
717 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
721 if($wgUser->isAllowed('delete')){
722 $content_actions['delete'] = array(
723 'class' => ($action == 'delete') ? 'selected' : false,
724 'text' => wfMsg('delete'),
725 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
728 if ( $this->mTitle->quickUserCan( 'move' ) ) {
729 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
730 $content_actions['move'] = array(
731 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
732 'text' => wfMsg('move'),
733 'href' => $moveTitle->getLocalUrl()
736 } else {
737 //article doesn't exist or is deleted
738 if( $wgUser->isAllowed( 'delete' ) ) {
739 if( $n = $this->mTitle->isDeleted() ) {
740 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
741 $content_actions['undelete'] = array(
742 'class' => false,
743 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
744 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
745 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
750 wfProfileOut( "$fname-live" );
752 if( $this->loggedin ) {
753 if( !$this->mTitle->userIsWatching()) {
754 $content_actions['watch'] = array(
755 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
756 'text' => wfMsg('watch'),
757 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
759 } else {
760 $content_actions['unwatch'] = array(
761 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
762 'text' => wfMsg('unwatch'),
763 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
769 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
770 } else {
771 /* show special page tab */
773 $content_actions[$this->mTitle->getNamespaceKey()] = array(
774 'class' => 'selected',
775 'text' => wfMsg('nstab-special'),
776 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
779 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
782 /* show links to different language variants */
783 global $wgDisableLangConversion;
784 $variants = $wgContLang->getVariants();
785 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
786 $preferred = $wgContLang->getPreferredVariant();
787 $vcount=0;
788 foreach( $variants as $code ) {
789 $varname = $wgContLang->getVariantname( $code );
790 if( $varname == 'disable' )
791 continue;
792 $selected = ( $code == $preferred )? 'selected' : false;
793 $content_actions['varlang-' . $vcount] = array(
794 'class' => $selected,
795 'text' => $varname,
796 'href' => $this->mTitle->getLocalURL('',$code)
798 $vcount ++;
802 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
804 wfProfileOut( $fname );
805 return $content_actions;
811 * build array of common navigation links
812 * @return array
813 * @private
815 function buildNavUrls () {
816 global $wgUseTrackbacks, $wgTitle, $wgArticle;
818 $fname = 'SkinTemplate::buildNavUrls';
819 wfProfileIn( $fname );
821 global $wgUser, $wgRequest;
822 global $wgEnableUploads, $wgUploadNavigationUrl;
824 $action = $wgRequest->getText( 'action' );
826 $nav_urls = array();
827 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
828 if( $wgEnableUploads ) {
829 if ($wgUploadNavigationUrl) {
830 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
831 } else {
832 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
834 } else {
835 if ($wgUploadNavigationUrl)
836 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
837 else
838 $nav_urls['upload'] = false;
840 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
842 // default permalink to being off, will override it as required below.
843 $nav_urls['permalink'] = false;
845 // A print stylesheet is attached to all pages, but nobody ever
846 // figures that out. :) Add a link...
847 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
848 $nav_urls['print'] = array(
849 'text' => wfMsg( 'printableversion' ),
850 'href' => $wgRequest->appendQuery( 'printable=yes' )
853 // Also add a "permalink" while we're at it
854 if ( $this->mRevisionId ) {
855 $nav_urls['permalink'] = array(
856 'text' => wfMsg( 'permalink' ),
857 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
861 // Copy in case this undocumented, shady hook tries to mess with internals
862 $revid = $this->mRevisionId;
863 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
866 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
867 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
868 $nav_urls['whatlinkshere'] = array(
869 'href' => $wlhTitle->getLocalUrl()
871 if( $this->mTitle->getArticleId() ) {
872 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
873 $nav_urls['recentchangeslinked'] = array(
874 'href' => $rclTitle->getLocalUrl()
876 } else {
877 $nav_urls['recentchangeslinked'] = false;
879 if ($wgUseTrackbacks)
880 $nav_urls['trackbacklink'] = array(
881 'href' => $wgTitle->trackbackURL()
885 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
886 $id = User::idFromName($this->mTitle->getText());
887 $ip = User::isIP($this->mTitle->getText());
888 } else {
889 $id = 0;
890 $ip = false;
893 if($id || $ip) { # both anons and non-anons have contri list
894 $nav_urls['contributions'] = array(
895 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
897 if ( $wgUser->isAllowed( 'block' ) ) {
898 $nav_urls['blockip'] = array(
899 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
901 } else {
902 $nav_urls['blockip'] = false;
904 } else {
905 $nav_urls['contributions'] = false;
906 $nav_urls['blockip'] = false;
908 $nav_urls['emailuser'] = false;
909 if( $this->showEmailUser( $id ) ) {
910 $nav_urls['emailuser'] = array(
911 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
914 wfProfileOut( $fname );
915 return $nav_urls;
919 * Generate strings used for xml 'id' names
920 * @return string
921 * @private
923 function getNameSpaceKey () {
924 return $this->mTitle->getNamespaceKey();
928 * @private
930 function setupUserCss() {
931 $fname = 'SkinTemplate::setupUserCss';
932 wfProfileIn( $fname );
934 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
936 $sitecss = '';
937 $usercss = '';
938 $siteargs = '&maxage=' . $wgSquidMaxage;
939 if( $this->loggedin ) {
940 // Ensure that logged-in users' generated CSS isn't clobbered
941 // by anons' publicly cacheable generated CSS.
942 $siteargs .= '&smaxage=0';
945 # Add user-specific code if this is a user and we allow that kind of thing
947 if ( $wgAllowUserCss && $this->loggedin ) {
948 $action = $wgRequest->getText('action');
950 # if we're previewing the CSS page, use it
951 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
952 $siteargs = "&smaxage=0&maxage=0";
953 $usercss = $wgRequest->getText('wpTextbox1');
954 } else {
955 $usercss = '@import "' .
956 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
957 'action=raw&ctype=text/css') . '";' ."\n";
960 $siteargs .= '&ts=' . $wgUser->mTouched;
963 if( $wgContLang->isRTL() ) {
964 global $wgStyleVersion;
965 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
968 # If we use the site's dynamic CSS, throw that in, too
969 if ( $wgUseSiteCss ) {
970 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
971 $skinquery = '';
972 if (($us = $wgRequest->getVal('useskin', '')) !== '')
973 $skinquery = "&useskin=$us";
974 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
975 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
976 $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
979 # If we use any dynamic CSS, make a little CDATA block out of it.
981 if ( !empty($sitecss) || !empty($usercss) ) {
982 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
984 wfProfileOut( $fname );
988 * @private
990 function setupUserJs( $allowUserJs ) {
991 $fname = 'SkinTemplate::setupUserJs';
992 wfProfileIn( $fname );
994 global $wgRequest, $wgJsMimeType;
995 $action = $wgRequest->getText('action');
997 if( $allowUserJs && $this->loggedin ) {
998 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
999 # XXX: additional security check/prompt?
1000 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1001 } else {
1002 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1005 wfProfileOut( $fname );
1009 * Code for extensions to hook into to provide per-page CSS, see
1010 * extensions/PageCSS/PageCSS.php for an implementation of this.
1012 * @private
1014 function setupPageCss() {
1015 $fname = 'SkinTemplate::setupPageCss';
1016 wfProfileIn( $fname );
1017 $out = false;
1018 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1020 wfProfileOut( $fname );
1021 return $out;
1025 * returns css with user-specific options
1026 * @public
1029 function getUserStylesheet() {
1030 $fname = 'SkinTemplate::getUserStylesheet';
1031 wfProfileIn( $fname );
1033 $s = "/* generated user stylesheet */\n";
1034 $s .= $this->reallyDoGetUserStyles();
1035 wfProfileOut( $fname );
1036 return $s;
1040 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1041 * nated together. For some bizarre reason, it does *not* return any
1042 * custom user JS from subpages. Huh?
1044 * There's absolutely no reason to have separate Monobook/Common JSes.
1045 * Any JS that cares can just check the skin variable generated at the
1046 * top. For now Monobook.js will be maintained, but it should be consi-
1047 * dered deprecated.
1049 * @return string
1051 public function getUserJs() {
1052 $fname = 'SkinTemplate::getUserJs';
1053 wfProfileIn( $fname );
1055 $s = parent::getUserJs();
1056 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js (deprecated; migrate to Common.js!) */\n";
1058 // avoid inclusion of non defined user JavaScript (with custom skins only)
1059 // by checking for default message content
1060 $msgKey = ucfirst($this->skinname).'.js';
1061 $userJS = wfMsgForContent($msgKey);
1062 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1063 $s .= $userJS;
1066 wfProfileOut( $fname );
1067 return $s;
1072 * Generic wrapper for template functions, with interface
1073 * compatible with what we use of PHPTAL 0.7.
1074 * @addtogroup Skins
1076 class QuickTemplate {
1078 * @public
1080 function QuickTemplate() {
1081 $this->data = array();
1082 $this->translator = new MediaWiki_I18N();
1086 * @public
1088 function set( $name, $value ) {
1089 $this->data[$name] = $value;
1093 * @public
1095 function setRef($name, &$value) {
1096 $this->data[$name] =& $value;
1100 * @public
1102 function setTranslator( &$t ) {
1103 $this->translator = &$t;
1107 * @public
1109 function execute() {
1110 echo "Override this function.";
1115 * @private
1117 function text( $str ) {
1118 echo htmlspecialchars( $this->data[$str] );
1122 * @private
1124 function jstext( $str ) {
1125 echo Xml::escapeJsString( $this->data[$str] );
1129 * @private
1131 function html( $str ) {
1132 echo $this->data[$str];
1136 * @private
1138 function msg( $str ) {
1139 echo htmlspecialchars( $this->translator->translate( $str ) );
1143 * @private
1145 function msgHtml( $str ) {
1146 echo $this->translator->translate( $str );
1150 * An ugly, ugly hack.
1151 * @private
1153 function msgWiki( $str ) {
1154 global $wgParser, $wgTitle, $wgOut;
1156 $text = $this->translator->translate( $str );
1157 $parserOutput = $wgParser->parse( $text, $wgTitle,
1158 $wgOut->parserOptions(), true );
1159 echo $parserOutput->getText();
1163 * @private
1165 function haveData( $str ) {
1166 return isset( $this->data[$str] );
1170 * @private
1172 function haveMsg( $str ) {
1173 $msg = $this->translator->translate( $str );
1174 return ($msg != '-') && ($msg != ''); # ????