Tweaks to Special:ListGroupRights:
[mediawiki.git] / includes / SkinTemplate.php
blob0c73d15c7f023ea7bb24738ebed9e2ced3bfa289
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 wfProfileIn( __METHOD__ );
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace($src, $varValue, $value);
50 wfProfileOut( __METHOD__ );
51 return $value;
55 /**
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
65 * @addtogroup Skins
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
72 /**
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
76 var $skinname;
78 /**
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
82 var $stylename;
84 /**
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
88 var $template;
90 /**#@-*/
92 /**
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
97 * @param OutputPage $out
99 function initPage( &$out ) {
100 parent::initPage( $out );
101 $this->skinname = 'monobook';
102 $this->stylename = 'monobook';
103 $this->template = 'QuickTemplate';
107 * Create the template engine object; we feed it a bunch of data
108 * and eventually it spits out some HTML. Should have interface
109 * roughly equivalent to PHPTAL 0.7.
111 * @param string $callback (or file)
112 * @param string $repository subdirectory where we keep template files
113 * @param string $cache_dir
114 * @return object
115 * @private
117 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
118 return new $classname();
122 * initialize various variables and generate the template
124 * @param OutputPage $out
125 * @public
127 function outputPage( &$out ) {
128 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
129 global $wgScript, $wgStylePath, $wgContLanguageCode;
130 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
131 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
132 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
133 global $wgMaxCredits, $wgShowCreditsIfMax;
134 global $wgPageShowWatchingUsers;
135 global $wgUseTrackbacks;
136 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
138 wfProfileIn( __METHOD__ );
140 $oldid = $wgRequest->getVal( 'oldid' );
141 $diff = $wgRequest->getVal( 'diff' );
143 wfProfileIn( __METHOD__."-init" );
144 $this->initPage( $out );
146 $this->mTitle =& $wgTitle;
147 $this->mUser =& $wgUser;
149 $tpl = $this->setupTemplate( $this->template, 'skins' );
151 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
152 $tpl->setTranslator(new MediaWiki_I18N());
154 wfProfileOut( __METHOD__."-init" );
156 wfProfileIn( __METHOD__."-stuff" );
157 $this->thispage = $this->mTitle->getPrefixedDbKey();
158 $this->thisurl = $this->mTitle->getPrefixedURL();
159 $this->loggedin = $wgUser->isLoggedIn();
160 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
161 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
162 $this->username = $wgUser->getName();
163 $userPage = $wgUser->getUserPage();
164 $this->userpage = $userPage->getPrefixedText();
166 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
167 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
168 } else {
169 # This won't be used in the standard skins, but we define it to preserve the interface
170 # To save time, we check for existence
171 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
174 $this->usercss = $this->userjs = $this->userjsprev = false;
175 $this->setupUserCss();
176 $this->setupUserJs( $out->isUserJsAllowed() );
177 $this->titletxt = $this->mTitle->getPrefixedText();
178 wfProfileOut( __METHOD__."-stuff" );
180 wfProfileIn( __METHOD__."-stuff2" );
181 $tpl->set( 'title', $wgOut->getPageTitle() );
182 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
183 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
184 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
186 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
187 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
188 $this->mTitle->getNsText();
190 $tpl->set( 'nscanonical', $nsname );
191 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
192 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
193 $tpl->set( 'titletext', $this->mTitle->getText() );
194 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
195 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
197 $tpl->set( 'isarticle', $wgOut->isArticle() );
199 $tpl->setRef( "thispage", $this->thispage );
200 $subpagestr = $this->subPageSubtitle();
201 $tpl->set(
202 'subtitle', !empty($subpagestr)?
203 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
204 $out->getSubtitle()
206 $undelete = $this->getUndeleteLink();
207 $tpl->set(
208 "undelete", !empty($undelete)?
209 '<span class="subpages">'.$undelete.'</span>':
213 $tpl->set( 'catlinks', $this->getCategories());
214 if( $wgOut->isSyndicated() ) {
215 $feeds = array();
216 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
217 $feeds[$format] = array(
218 'text' => wfMsg( "feed-$format" ),
219 'href' => $link );
221 $tpl->setRef( 'feeds', $feeds );
222 } else {
223 $tpl->set( 'feeds', false );
225 if ($wgUseTrackbacks && $out->isArticleRelated()) {
226 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
227 } else {
228 $tpl->set( 'trackbackhtml', null );
231 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
232 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
233 $tpl->setRef( 'mimetype', $wgMimeType );
234 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
235 $tpl->setRef( 'charset', $wgOutputEncoding );
236 $tpl->set( 'headlinks', $out->getHeadLinks() );
237 $tpl->set('headscripts', $out->getScript() );
238 $tpl->setRef( 'wgScript', $wgScript );
239 $tpl->setRef( 'skinname', $this->skinname );
240 $tpl->set( 'skinclass', get_class( $this ) );
241 $tpl->setRef( 'stylename', $this->stylename );
242 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
243 $tpl->setRef( 'loggedin', $this->loggedin );
244 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
245 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
246 /* XXX currently unused, might get useful later
247 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
248 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
249 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
250 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
251 $tpl->set( "helppage", wfMsg('helppage'));
253 $tpl->set( 'searchaction', $this->escapeSearchLink() );
254 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
255 $tpl->setRef( 'stylepath', $wgStylePath );
256 $tpl->setRef( 'articlepath', $wgArticlePath );
257 $tpl->setRef( 'scriptpath', $wgScriptPath );
258 $tpl->setRef( 'serverurl', $wgServer );
259 $tpl->setRef( 'logopath', $wgLogo );
260 $tpl->setRef( "lang", $wgContLanguageCode );
261 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
262 $tpl->set( 'rtl', $wgContLang->isRTL() );
263 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
264 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
265 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
266 $tpl->setRef( 'userpage', $this->userpage);
267 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
268 $tpl->set( 'userlang', $wgLang->getCode() );
269 $tpl->set( 'pagecss', $this->setupPageCss() );
270 $tpl->set( 'printcss', $this->getPrintCss() );
271 $tpl->setRef( 'usercss', $this->usercss);
272 $tpl->setRef( 'userjs', $this->userjs);
273 $tpl->setRef( 'userjsprev', $this->userjsprev);
274 global $wgUseSiteJs;
275 if ($wgUseSiteJs) {
276 $jsCache = $this->loggedin ? '&smaxage=0' : '';
277 $tpl->set( 'jsvarurl',
278 self::makeUrl('-',
279 "action=raw$jsCache&gen=js&useskin=" .
280 urlencode( $this->getSkinName() ) ) );
281 } else {
282 $tpl->set('jsvarurl', false);
284 $newtalks = $wgUser->getNewMessageLinks();
286 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
287 $usertitle = $this->mUser->getUserPage();
288 $usertalktitle = $usertitle->getTalkPage();
289 if( !$usertalktitle->equals( $this->mTitle ) ) {
290 $ntl = wfMsg( 'youhavenewmessages',
291 $this->makeKnownLinkObj(
292 $usertalktitle,
293 wfMsgHtml( 'newmessageslink' ),
294 'redirect=no'
296 $this->makeKnownLinkObj(
297 $usertalktitle,
298 wfMsgHtml( 'newmessagesdifflink' ),
299 'diff=cur'
302 # Disable Cache
303 $wgOut->setSquidMaxage(0);
305 } else if (count($newtalks)) {
306 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
307 $msgs = array();
308 foreach ($newtalks as $newtalk) {
309 $msgs[] = wfElement("a",
310 array('href' => $newtalk["link"]), $newtalk["wiki"]);
312 $parts = implode($sep, $msgs);
313 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
314 $wgOut->setSquidMaxage(0);
315 } else {
316 $ntl = '';
318 wfProfileOut( __METHOD__."-stuff2" );
320 wfProfileIn( __METHOD__."-stuff3" );
321 $tpl->setRef( 'newtalk', $ntl );
322 $tpl->setRef( 'skin', $this);
323 $tpl->set( 'logo', $this->logoText() );
324 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
325 $wgArticle and 0 != $wgArticle->getID() )
327 if ( !$wgDisableCounters ) {
328 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
329 if ( $viewcount ) {
330 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
331 } else {
332 $tpl->set('viewcount', false);
334 } else {
335 $tpl->set('viewcount', false);
338 if ($wgPageShowWatchingUsers) {
339 $dbr = wfGetDB( DB_SLAVE );
340 $watchlist = $dbr->tableName( 'watchlist' );
341 $sql = "SELECT COUNT(*) AS n FROM $watchlist
342 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
343 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
344 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
345 $x = $dbr->fetchObject( $res );
346 $numberofwatchingusers = $x->n;
347 if ($numberofwatchingusers > 0) {
348 $tpl->set('numberofwatchingusers',
349 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
350 $wgLang->formatNum($numberofwatchingusers))
352 } else {
353 $tpl->set('numberofwatchingusers', false);
355 } else {
356 $tpl->set('numberofwatchingusers', false);
359 $tpl->set('copyright',$this->getCopyright());
361 $this->credits = false;
363 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
364 require_once("Credits.php");
365 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
366 } else {
367 $tpl->set('lastmod', $this->lastModified());
370 $tpl->setRef( 'credits', $this->credits );
372 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
373 $tpl->set('copyright', $this->getCopyright());
374 $tpl->set('viewcount', false);
375 $tpl->set('lastmod', false);
376 $tpl->set('credits', false);
377 $tpl->set('numberofwatchingusers', false);
378 } else {
379 $tpl->set('copyright', false);
380 $tpl->set('viewcount', false);
381 $tpl->set('lastmod', false);
382 $tpl->set('credits', false);
383 $tpl->set('numberofwatchingusers', false);
385 wfProfileOut( __METHOD__."-stuff3" );
387 wfProfileIn( __METHOD__."-stuff4" );
388 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
389 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
390 $tpl->set( 'disclaimer', $this->disclaimerLink() );
391 $tpl->set( 'privacy', $this->privacyLink() );
392 $tpl->set( 'about', $this->aboutLink() );
394 $tpl->setRef( 'debug', $out->mDebugtext );
395 $tpl->set( 'reporttime', wfReportTime() );
396 $tpl->set( 'sitenotice', wfGetSiteNotice() );
397 $tpl->set( 'bottomscripts', $this->bottomScripts() );
399 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
400 $out->mBodytext .= $printfooter ;
401 $tpl->setRef( 'bodytext', $out->mBodytext );
403 # Language links
404 $language_urls = array();
406 if ( !$wgHideInterlanguageLinks ) {
407 foreach( $wgOut->getLanguageLinks() as $l ) {
408 $tmp = explode( ':', $l, 2 );
409 $class = 'interwiki-' . $tmp[0];
410 unset($tmp);
411 $nt = Title::newFromText( $l );
412 $language_urls[] = array(
413 'href' => $nt->getFullURL(),
414 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
415 'class' => $class
419 if(count($language_urls)) {
420 $tpl->setRef( 'language_urls', $language_urls);
421 } else {
422 $tpl->set('language_urls', false);
424 wfProfileOut( __METHOD__."-stuff4" );
426 # Personal toolbar
427 $tpl->set('personal_urls', $this->buildPersonalUrls());
428 $content_actions = $this->buildContentActionUrls();
429 $tpl->setRef('content_actions', $content_actions);
431 // XXX: attach this from javascript, same with section editing
432 if($this->iseditable && $wgUser->getOption("editondblclick") )
434 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
435 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
436 } else {
437 $tpl->set('body_ondblclick', false);
439 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
440 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
441 } else {
442 $tpl->set( 'body_onload', false );
444 $tpl->set( 'sidebar', $this->buildSidebar() );
445 $tpl->set( 'nav_urls', $this->buildNavUrls() );
447 // original version by hansm
448 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
449 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
452 // execute template
453 wfProfileIn( __METHOD__."-execute" );
454 $res = $tpl->execute();
455 wfProfileOut( __METHOD__."-execute" );
457 // result may be an error
458 $this->printOrError( $res );
459 wfProfileOut( __METHOD__ );
463 * Output the string, or print error message if it's
464 * an error object of the appropriate type.
465 * For the base class, assume strings all around.
467 * @param mixed $str
468 * @private
470 function printOrError( $str ) {
471 echo $str;
475 * build array of urls for personal toolbar
476 * @return array
477 * @private
479 function buildPersonalUrls() {
480 global $wgTitle, $wgRequest;
482 $pageurl = $wgTitle->getLocalURL();
483 wfProfileIn( __METHOD__ );
485 /* set up the default links for the personal toolbar */
486 $personal_urls = array();
487 if ($this->loggedin) {
488 $personal_urls['userpage'] = array(
489 'text' => $this->username,
490 'href' => &$this->userpageUrlDetails['href'],
491 'class' => $this->userpageUrlDetails['exists']?false:'new',
492 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
494 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
495 $personal_urls['mytalk'] = array(
496 'text' => wfMsg('mytalk'),
497 'href' => &$usertalkUrlDetails['href'],
498 'class' => $usertalkUrlDetails['exists']?false:'new',
499 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
501 $href = self::makeSpecialUrl( 'Preferences' );
502 $personal_urls['preferences'] = array(
503 'text' => wfMsg( 'mypreferences' ),
504 'href' => $href,
505 'active' => ( $href == $pageurl )
507 $href = self::makeSpecialUrl( 'Watchlist' );
508 $personal_urls['watchlist'] = array(
509 'text' => wfMsg( 'mywatchlist' ),
510 'href' => $href,
511 'active' => ( $href == $pageurl )
514 # We need to do an explicit check for Special:Contributions, as we
515 # have to match both the title, and the target (which could come
516 # from request values or be specified in "sub page" form. The plot
517 # thickens, because $wgTitle is altered for special pages, so doesn't
518 # contain the original alias-with-subpage.
519 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
520 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
521 list( $spName, $spPar ) =
522 SpecialPage::resolveAliasWithSubpage( $title->getText() );
523 $active = $spName == 'Contributions'
524 && ( ( $spPar && $spPar == $this->username )
525 || $wgRequest->getText( 'target' ) == $this->username );
526 } else {
527 $active = false;
530 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
531 $personal_urls['mycontris'] = array(
532 'text' => wfMsg( 'mycontris' ),
533 'href' => $href,
534 'active' => $active
536 $personal_urls['logout'] = array(
537 'text' => wfMsg( 'userlogout' ),
538 'href' => self::makeSpecialUrl( 'Userlogout',
539 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
541 'active' => false
543 } else {
544 global $wgUser;
545 $loginlink = $wgUser->isAllowed( 'createaccount' )
546 ? 'nav-login-createaccount'
547 : 'login';
548 if( $this->showIPinHeader() ) {
549 $href = &$this->userpageUrlDetails['href'];
550 $personal_urls['anonuserpage'] = array(
551 'text' => $this->username,
552 'href' => $href,
553 'class' => $this->userpageUrlDetails['exists']?false:'new',
554 'active' => ( $pageurl == $href )
556 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
557 $href = &$usertalkUrlDetails['href'];
558 $personal_urls['anontalk'] = array(
559 'text' => wfMsg('anontalk'),
560 'href' => $href,
561 'class' => $usertalkUrlDetails['exists']?false:'new',
562 'active' => ( $pageurl == $href )
564 $personal_urls['anonlogin'] = array(
565 'text' => wfMsg( $loginlink ),
566 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
567 'active' => $wgTitle->isSpecial( 'Userlogin' )
569 } else {
571 $personal_urls['login'] = array(
572 'text' => wfMsg( $loginlink ),
573 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
574 'active' => $wgTitle->isSpecial( 'Userlogin' )
579 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
580 wfProfileOut( __METHOD__ );
581 return $personal_urls;
584 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
585 $classes = array();
586 if( $selected ) {
587 $classes[] = 'selected';
589 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
590 $classes[] = 'new';
591 $query = 'action=edit';
594 $text = wfMsg( $message );
595 if ( wfEmptyMsg( $message, $text ) ) {
596 global $wgContLang;
597 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
600 $result = array();
601 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
602 $title, $message, $selected, $checkEdit,
603 &$classes, &$query, &$text, &$result)) ) {
604 return $result;
607 return array(
608 'class' => implode( ' ', $classes ),
609 'text' => $text,
610 'href' => $title->getLocalUrl( $query ) );
613 function makeTalkUrlDetails( $name, $urlaction = '' ) {
614 $title = Title::newFromText( $name );
615 if( !is_object($title) ) {
616 throw new MWException( __METHOD__." given invalid pagename $name" );
618 $title = $title->getTalkPage();
619 self::checkTitle( $title, $name );
620 return array(
621 'href' => $title->getLocalURL( $urlaction ),
622 'exists' => $title->getArticleID() != 0 ? true : false
626 function makeArticleUrlDetails( $name, $urlaction = '' ) {
627 $title = Title::newFromText( $name );
628 $title= $title->getSubjectPage();
629 self::checkTitle( $title, $name );
630 return array(
631 'href' => $title->getLocalURL( $urlaction ),
632 'exists' => $title->getArticleID() != 0 ? true : false
637 * an array of edit links by default used for the tabs
638 * @return array
639 * @private
641 function buildContentActionUrls () {
642 global $wgContLang, $wgLang, $wgOut;
643 wfProfileIn( __METHOD__ );
645 global $wgUser, $wgRequest;
646 $action = $wgRequest->getText( 'action' );
647 $section = $wgRequest->getText( 'section' );
648 $content_actions = array();
650 $prevent_active_tabs = false ;
651 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
653 if( $this->iscontent ) {
654 $subjpage = $this->mTitle->getSubjectPage();
655 $talkpage = $this->mTitle->getTalkPage();
657 $nskey = $this->mTitle->getNamespaceKey();
658 $content_actions[$nskey] = $this->tabAction(
659 $subjpage,
660 $nskey,
661 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
662 '', true);
664 $content_actions['talk'] = $this->tabAction(
665 $talkpage,
666 'talk',
667 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
669 true);
671 wfProfileIn( __METHOD__."-edit" );
672 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
673 $istalk = $this->mTitle->isTalkPage();
674 $istalkclass = $istalk?' istalk':'';
675 $content_actions['edit'] = array(
676 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
677 'text' => $this->mTitle->exists()
678 ? wfMsg( 'edit' )
679 : wfMsg( 'create' ),
680 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
683 if ( $istalk || $wgOut->showNewSectionLink() ) {
684 $content_actions['addsection'] = array(
685 'class' => $section == 'new'?'selected':false,
686 'text' => wfMsg('addsection'),
687 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
690 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
691 $content_actions['viewsource'] = array(
692 'class' => ($action == 'edit') ? 'selected' : false,
693 'text' => wfMsg('viewsource'),
694 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
697 wfProfileOut( __METHOD__."-edit" );
699 wfProfileIn( __METHOD__."-live" );
700 if ( $this->mTitle->getArticleId() ) {
702 $content_actions['history'] = array(
703 'class' => ($action == 'history') ? 'selected' : false,
704 'text' => wfMsg('history_short'),
705 'href' => $this->mTitle->getLocalUrl( 'action=history')
708 if($wgUser->isAllowed('delete')){
709 $content_actions['delete'] = array(
710 'class' => ($action == 'delete') ? 'selected' : false,
711 'text' => wfMsg('delete'),
712 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
715 if ( $this->mTitle->quickUserCan( 'move' ) ) {
716 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
717 $content_actions['move'] = array(
718 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
719 'text' => wfMsg('move'),
720 'href' => $moveTitle->getLocalUrl()
724 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
725 if(!$this->mTitle->isProtected()){
726 $content_actions['protect'] = array(
727 'class' => ($action == 'protect') ? 'selected' : false,
728 'text' => wfMsg('protect'),
729 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
732 } else {
733 $content_actions['unprotect'] = array(
734 'class' => ($action == 'unprotect') ? 'selected' : false,
735 'text' => wfMsg('unprotect'),
736 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
740 } else {
741 //article doesn't exist or is deleted
742 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
743 if( $n = $this->mTitle->isDeleted() ) {
744 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
745 $content_actions['undelete'] = array(
746 'class' => false,
747 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
748 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
749 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
754 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
755 if( !$this->mTitle->getRestrictions( 'create' ) ) {
756 $content_actions['protect'] = array(
757 'class' => ($action == 'protect') ? 'selected' : false,
758 'text' => wfMsg('protect'),
759 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
762 } else {
763 $content_actions['unprotect'] = array(
764 'class' => ($action == 'unprotect') ? 'selected' : false,
765 'text' => wfMsg('unprotect'),
766 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
772 wfProfileOut( __METHOD__."-live" );
774 if( $this->loggedin ) {
775 if( !$this->mTitle->userIsWatching()) {
776 $content_actions['watch'] = array(
777 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
778 'text' => wfMsg('watch'),
779 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
781 } else {
782 $content_actions['unwatch'] = array(
783 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
784 'text' => wfMsg('unwatch'),
785 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
791 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
792 } else {
793 /* show special page tab */
795 $content_actions[$this->mTitle->getNamespaceKey()] = array(
796 'class' => 'selected',
797 'text' => wfMsg('nstab-special'),
798 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
801 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
804 /* show links to different language variants */
805 global $wgDisableLangConversion;
806 $variants = $wgContLang->getVariants();
807 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
808 $preferred = $wgContLang->getPreferredVariant();
809 $vcount=0;
810 foreach( $variants as $code ) {
811 $varname = $wgContLang->getVariantname( $code );
812 if( $varname == 'disable' )
813 continue;
814 $selected = ( $code == $preferred )? 'selected' : false;
815 $content_actions['varlang-' . $vcount] = array(
816 'class' => $selected,
817 'text' => $varname,
818 'href' => $this->mTitle->getLocalURL('',$code)
820 $vcount ++;
824 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
826 wfProfileOut( __METHOD__ );
827 return $content_actions;
833 * build array of common navigation links
834 * @return array
835 * @private
837 function buildNavUrls () {
838 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
839 global $wgEnableUploads, $wgUploadNavigationUrl;
841 wfProfileIn( __METHOD__ );
843 $action = $wgRequest->getText( 'action' );
845 $nav_urls = array();
846 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
847 if( $wgEnableUploads ) {
848 if ($wgUploadNavigationUrl) {
849 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
850 } else {
851 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
853 } else {
854 if ($wgUploadNavigationUrl)
855 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
856 else
857 $nav_urls['upload'] = false;
859 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
861 // default permalink to being off, will override it as required below.
862 $nav_urls['permalink'] = false;
864 // A print stylesheet is attached to all pages, but nobody ever
865 // figures that out. :) Add a link...
866 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
867 $nav_urls['print'] = array(
868 'text' => wfMsg( 'printableversion' ),
869 'href' => $wgRequest->appendQuery( 'printable=yes' )
872 // Also add a "permalink" while we're at it
873 if ( $this->mRevisionId ) {
874 $nav_urls['permalink'] = array(
875 'text' => wfMsg( 'permalink' ),
876 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
880 // Copy in case this undocumented, shady hook tries to mess with internals
881 $revid = $this->mRevisionId;
882 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
885 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
886 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
887 $nav_urls['whatlinkshere'] = array(
888 'href' => $wlhTitle->getLocalUrl()
890 if( $this->mTitle->getArticleId() ) {
891 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
892 $nav_urls['recentchangeslinked'] = array(
893 'href' => $rclTitle->getLocalUrl()
895 } else {
896 $nav_urls['recentchangeslinked'] = false;
898 if ($wgUseTrackbacks)
899 $nav_urls['trackbacklink'] = array(
900 'href' => $wgTitle->trackbackURL()
904 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
905 $id = User::idFromName($this->mTitle->getText());
906 $ip = User::isIP($this->mTitle->getText());
907 } else {
908 $id = 0;
909 $ip = false;
912 if($id || $ip) { # both anons and non-anons have contribs list
913 $nav_urls['contributions'] = array(
914 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
917 if( $id ) {
918 $logPage = SpecialPage::getTitleFor( 'Log' );
919 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
920 . $this->mTitle->getPartialUrl() ) );
921 } else {
922 $nav_urls['log'] = false;
925 if ( $wgUser->isAllowed( 'block' ) ) {
926 $nav_urls['blockip'] = array(
927 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
929 } else {
930 $nav_urls['blockip'] = false;
932 } else {
933 $nav_urls['contributions'] = false;
934 $nav_urls['log'] = false;
935 $nav_urls['blockip'] = false;
937 $nav_urls['emailuser'] = false;
938 if( $this->showEmailUser( $id ) ) {
939 $nav_urls['emailuser'] = array(
940 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
943 wfProfileOut( __METHOD__ );
944 return $nav_urls;
948 * Generate strings used for xml 'id' names
949 * @return string
950 * @private
952 function getNameSpaceKey () {
953 return $this->mTitle->getNamespaceKey();
957 * @private
959 function setupUserCss() {
960 wfProfileIn( __METHOD__ );
962 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
964 $sitecss = '';
965 $usercss = '';
966 $siteargs = '&maxage=' . $wgSquidMaxage;
967 if( $this->loggedin ) {
968 // Ensure that logged-in users' generated CSS isn't clobbered
969 // by anons' publicly cacheable generated CSS.
970 $siteargs .= '&smaxage=0';
973 # Add user-specific code if this is a user and we allow that kind of thing
975 if ( $wgAllowUserCss && $this->loggedin ) {
976 $action = $wgRequest->getText('action');
978 # if we're previewing the CSS page, use it
979 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
980 $siteargs = "&smaxage=0&maxage=0";
981 $usercss = $wgRequest->getText('wpTextbox1');
982 } else {
983 $usercss = '@import "' .
984 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
985 'action=raw&ctype=text/css') . '";' ."\n";
988 $siteargs .= '&ts=' . $wgUser->mTouched;
991 if( $wgContLang->isRTL() ) {
992 global $wgStyleVersion;
993 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
996 # If we use the site's dynamic CSS, throw that in, too
997 if ( $wgUseSiteCss ) {
998 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
999 $skinquery = '';
1000 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1001 $skinquery = "&useskin=$us";
1002 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1003 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
1004 $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1007 # If we use any dynamic CSS, make a little CDATA block out of it.
1009 if ( !empty($sitecss) || !empty($usercss) ) {
1010 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1012 wfProfileOut( __METHOD__ );
1016 * @private
1018 function setupUserJs( $allowUserJs ) {
1019 wfProfileIn( __METHOD__ );
1021 global $wgRequest, $wgJsMimeType;
1022 $action = $wgRequest->getText('action');
1024 if( $allowUserJs && $this->loggedin ) {
1025 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1026 # XXX: additional security check/prompt?
1027 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1028 } else {
1029 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1032 wfProfileOut( __METHOD__ );
1036 * Code for extensions to hook into to provide per-page CSS, see
1037 * extensions/PageCSS/PageCSS.php for an implementation of this.
1039 * @private
1041 function setupPageCss() {
1042 wfProfileIn( __METHOD__ );
1043 $out = false;
1044 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1046 wfProfileOut( __METHOD__ );
1047 return $out;
1051 * returns css with user-specific options
1053 public function getUserStylesheet() {
1054 wfProfileIn( __METHOD__ );
1056 $s = "/* generated user stylesheet */\n";
1057 $s .= $this->reallyDoGetUserStyles();
1058 wfProfileOut( __METHOD__ );
1059 return $s;
1063 * Returns the print stylesheet for this skin. In all default skins this
1064 * is just commonPrint.css, but third-party skins may want to modify it.
1066 * @return string
1068 protected function getPrintCss() {
1069 global $wgStylePath;
1070 return $wgStylePath . "/common/commonPrint.css";
1074 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1075 * nated together. For some bizarre reason, it does *not* return any
1076 * custom user JS from subpages. Huh?
1078 * There's absolutely no reason to have separate Monobook/Common JSes.
1079 * Any JS that cares can just check the skin variable generated at the
1080 * top. For now Monobook.js will be maintained, but it should be consi-
1081 * dered deprecated.
1083 * @return string
1085 public function getUserJs() {
1086 wfProfileIn( __METHOD__ );
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( __METHOD__ );
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 != ''); # ????