2 if ( ! defined( 'MEDIAWIKI' ) )
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
21 * Template-filler skin base class
22 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
23 * Based on Brion's smarty skin
24 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
26 * Todo: Needs some serious refactoring into functions that correspond
27 * to the computations individual esi snippets need. Most importantly no body
28 * parsing for most of those of course.
34 * Wrapper object for MediaWiki's localization functions,
35 * to be passed to the template engine.
39 class MediaWiki_I18N
{
40 var $_context = array();
42 function set($varName, $value) {
43 $this->_context
[$varName] = $value;
46 function translate($value) {
47 $fname = 'SkinTemplate-translate';
48 wfProfileIn( $fname );
50 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
51 $value = preg_replace( '/^string:/', '', $value );
53 $value = wfMsg( $value );
54 // interpolate variables
56 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
57 list($src, $var) = $m;
59 $varValue = $this->_context
[$var];
61 $value = str_replace($src, $varValue, $value);
63 wfProfileOut( $fname );
71 class SkinTemplate
extends Skin
{
77 * Name of our skin, set in initPage()
78 * It probably need to be all lower case.
83 * Stylesheets set to use
84 * Sub directory in ./skins/ where various stylesheets are located
89 * For QuickTemplate, the name of the subclass which
90 * will actually fill the template.
97 * Setup the base parameters...
98 * Child classes should override this to set the name,
99 * style subdirectory, and template filler callback.
101 * @param OutputPage $out
103 function initPage( &$out ) {
104 parent
::initPage( $out );
105 $this->skinname
= 'monobook';
106 $this->stylename
= 'monobook';
107 $this->template
= 'QuickTemplate';
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param string $callback (or file)
116 * @param string $repository subdirectory where we keep template files
117 * @param string $cache_dir
121 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
122 return new $classname();
126 * initialize various variables and generate the template
128 * @param OutputPage $out
131 function outputPage( &$out ) {
132 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
133 global $wgScript, $wgStylePath, $wgContLanguageCode;
134 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
135 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
136 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
137 global $wgMaxCredits, $wgShowCreditsIfMax;
138 global $wgPageShowWatchingUsers;
139 global $wgUseTrackbacks;
140 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
142 $fname = 'SkinTemplate::outputPage';
143 wfProfileIn( $fname );
145 // Hook that allows last minute changes to the output page, e.g.
146 // adding of CSS or Javascript by extensions.
147 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
152 wfProfileIn( "$fname-init" );
153 $this->initPage( $out );
155 $this->mTitle
=& $wgTitle;
156 $this->mUser
=& $wgUser;
158 $tpl = $this->setupTemplate( $this->template
, 'skins' );
160 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
161 $tpl->setTranslator(new MediaWiki_I18N());
163 wfProfileOut( "$fname-init" );
165 wfProfileIn( "$fname-stuff" );
166 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
167 $this->thisurl
= $this->mTitle
->getPrefixedURL();
168 $this->loggedin
= $wgUser->isLoggedIn();
169 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
170 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
171 $this->username
= $wgUser->getName();
172 $userPage = $wgUser->getUserPage();
173 $this->userpage
= $userPage->getPrefixedText();
175 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
176 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
183 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss();
185 $this->setupUserJs();
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( "$fname-stuff" );
189 wfProfileIn( "$fname-stuff2" );
190 $tpl->set( 'title', $wgOut->getPageTitle() );
191 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
193 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
195 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
196 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
197 $this->mTitle
->getNsText();
199 $tpl->set( 'nscanonical', $nsname );
200 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
201 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
202 $tpl->set( 'titletext', $this->mTitle
->getText() );
203 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
204 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
206 $tpl->set( 'isarticle', $wgOut->isArticle() );
208 $tpl->setRef( "thispage", $this->thispage
);
209 $subpagestr = $this->subPageSubtitle();
211 'subtitle', !empty($subpagestr)?
212 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
215 $undelete = $this->getUndeleteLink();
217 "undelete", !empty($undelete)?
218 '<span class="subpages">'.$undelete.'</span>':
222 $tpl->set( 'catlinks', $this->getCategories());
223 if( $wgOut->isSyndicated() ) {
225 foreach( $wgFeedClasses as $format => $class ) {
227 if ( $format == "atom" ) {
228 $linktext = wfMsg( 'feed-atom' );
229 } else if ( $format == "rss" ) {
230 $linktext = wfMsg( 'feed-rss' );
232 $feeds[$format] = array(
234 'href' => $wgRequest->appendQuery( "feed=$format" )
237 $tpl->setRef( 'feeds', $feeds );
239 $tpl->set( 'feeds', false );
241 if ($wgUseTrackbacks && $out->isArticleRelated()) {
242 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
244 $tpl->set( 'trackbackhtml', null );
247 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
248 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set('headscripts', $out->getScript() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname
);
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename
);
258 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
259 $tpl->setRef( 'loggedin', $this->loggedin
);
260 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
261 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
271 $tpl->setRef( 'stylepath', $wgStylePath );
272 $tpl->setRef( 'articlepath', $wgArticlePath );
273 $tpl->setRef( 'scriptpath', $wgScriptPath );
274 $tpl->setRef( 'serverurl', $wgServer );
275 $tpl->setRef( 'logopath', $wgLogo );
276 $tpl->setRef( "lang", $wgContLanguageCode );
277 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
278 $tpl->set( 'rtl', $wgContLang->isRTL() );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
282 $tpl->setRef( 'userpage', $this->userpage
);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'pagecss', $this->setupPageCss() );
286 $tpl->setRef( 'usercss', $this->usercss
);
287 $tpl->setRef( 'userjs', $this->userjs
);
288 $tpl->setRef( 'userjsprev', $this->userjsprev
);
291 if($this->loggedin
) {
292 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
294 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
297 $tpl->set('jsvarurl', false);
299 $newtalks = $wgUser->getNewMessageLinks();
301 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
302 $usertitle = $this->mUser
->getUserPage();
303 $usertalktitle = $usertitle->getTalkPage();
304 if( !$usertalktitle->equals( $this->mTitle
) ) {
305 $ntl = wfMsg( 'youhavenewmessages',
306 $this->makeKnownLinkObj(
308 wfMsgHtml( 'newmessageslink' ),
311 $this->makeKnownLinkObj(
313 wfMsgHtml( 'newmessagesdifflink' ),
318 $wgOut->setSquidMaxage(0);
320 } else if (count($newtalks)) {
321 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
323 foreach ($newtalks as $newtalk) {
324 $msgs[] = wfElement("a",
325 array('href' => $newtalk["link"]), $newtalk["wiki"]);
327 $parts = implode($sep, $msgs);
328 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
329 $wgOut->setSquidMaxage(0);
333 wfProfileOut( "$fname-stuff2" );
335 wfProfileIn( "$fname-stuff3" );
336 $tpl->setRef( 'newtalk', $ntl );
337 $tpl->setRef( 'skin', $this);
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
340 $wgArticle and 0 != $wgArticle->getID() )
342 if ( !$wgDisableCounters ) {
343 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
345 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
347 $tpl->set('viewcount', false);
350 $tpl->set('viewcount', false);
353 if ($wgPageShowWatchingUsers) {
354 $dbr =& wfGetDB( DB_SLAVE
);
355 $watchlist = $dbr->tableName( 'watchlist' );
356 $sql = "SELECT COUNT(*) AS n FROM $watchlist
357 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
358 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
359 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n
;
362 if ($numberofwatchingusers > 0) {
363 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
365 $tpl->set('numberofwatchingusers', false);
368 $tpl->set('numberofwatchingusers', false);
371 $tpl->set('copyright',$this->getCopyright());
373 $this->credits
= false;
375 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
376 require_once("Credits.php");
377 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
379 $tpl->set('lastmod', $this->lastModified());
382 $tpl->setRef( 'credits', $this->credits
);
384 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
385 $tpl->set('copyright', $this->getCopyright());
386 $tpl->set('viewcount', false);
387 $tpl->set('lastmod', false);
388 $tpl->set('credits', false);
389 $tpl->set('numberofwatchingusers', false);
391 $tpl->set('copyright', false);
392 $tpl->set('viewcount', false);
393 $tpl->set('lastmod', false);
394 $tpl->set('credits', false);
395 $tpl->set('numberofwatchingusers', false);
397 wfProfileOut( "$fname-stuff3" );
399 wfProfileIn( "$fname-stuff4" );
400 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
401 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
402 $tpl->set( 'disclaimer', $this->disclaimerLink() );
403 $tpl->set( 'privacy', $this->privacyLink() );
404 $tpl->set( 'about', $this->aboutLink() );
406 $tpl->setRef( 'debug', $out->mDebugtext
);
407 $tpl->set( 'reporttime', $out->reportTime() );
408 $tpl->set( 'sitenotice', wfGetSiteNotice() );
409 $tpl->set( 'bottomscripts', $this->bottomScripts() );
411 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
412 $out->mBodytext
.= $printfooter ;
413 $tpl->setRef( 'bodytext', $out->mBodytext
);
416 $language_urls = array();
418 if ( !$wgHideInterlanguageLinks ) {
419 foreach( $wgOut->getLanguageLinks() as $l ) {
420 $tmp = explode( ':', $l, 2 );
421 $class = 'interwiki-' . $tmp[0];
423 $nt = Title
::newFromText( $l );
424 $language_urls[] = array(
425 'href' => $nt->getFullURL(),
426 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
431 if(count($language_urls)) {
432 $tpl->setRef( 'language_urls', $language_urls);
434 $tpl->set('language_urls', false);
436 wfProfileOut( "$fname-stuff4" );
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
446 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
448 $tpl->set('body_ondblclick', false);
450 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
451 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
453 $tpl->set( 'body_onload', false );
455 $tpl->set( 'sidebar', $this->buildSidebar() );
456 $tpl->set( 'nav_urls', $this->buildNavUrls() );
458 // original version by hansm
459 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
460 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
464 wfProfileIn( "$fname-execute" );
465 $res = $tpl->execute();
466 wfProfileOut( "$fname-execute" );
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( $fname );
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
481 function printOrError( $str ) {
486 * build array of urls for personal toolbar
490 function buildPersonalUrls() {
491 global $wgTitle, $wgShowIPinHeader;
493 $fname = 'SkinTemplate::buildPersonalUrls';
494 $pageurl = $wgTitle->getLocalURL();
495 wfProfileIn( $fname );
497 /* set up the default links for the personal toolbar */
498 $personal_urls = array();
499 if ($this->loggedin
) {
500 $personal_urls['userpage'] = array(
501 'text' => $this->username
,
502 'href' => &$this->userpageUrlDetails
['href'],
503 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
504 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
506 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
507 $personal_urls['mytalk'] = array(
508 'text' => wfMsg('mytalk'),
509 'href' => &$usertalkUrlDetails['href'],
510 'class' => $usertalkUrlDetails['exists']?
false:'new',
511 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
513 $href = self
::makeSpecialUrl( 'Preferences' );
514 $personal_urls['preferences'] = array(
515 'text' => wfMsg( 'mypreferences' ),
516 'href' => self
::makeSpecialUrl( 'Preferences' ),
517 'active' => ( $href == $pageurl )
519 $href = self
::makeSpecialUrl( 'Watchlist' );
520 $personal_urls['watchlist'] = array(
521 'text' => wfMsg( 'watchlist' ),
523 'active' => ( $href == $pageurl )
525 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
526 $personal_urls['mycontris'] = array(
527 'text' => wfMsg( 'mycontris' ),
529 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
530 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
531 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
533 $personal_urls['logout'] = array(
534 'text' => wfMsg( 'userlogout' ),
535 'href' => self
::makeSpecialUrl( 'Userlogout',
536 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
541 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
542 $href = &$this->userpageUrlDetails
['href'];
543 $personal_urls['anonuserpage'] = array(
544 'text' => $this->username
,
546 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
547 'active' => ( $pageurl == $href )
549 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
550 $href = &$usertalkUrlDetails['href'];
551 $personal_urls['anontalk'] = array(
552 'text' => wfMsg('anontalk'),
554 'class' => $usertalkUrlDetails['exists']?
false:'new',
555 'active' => ( $pageurl == $href )
557 $personal_urls['anonlogin'] = array(
558 'text' => wfMsg('userlogin'),
559 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
560 'active' => $wgTitle->isSpecial( 'Userlogin' )
564 $personal_urls['login'] = array(
565 'text' => wfMsg('userlogin'),
566 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
567 'active' => $wgTitle->isSpecial( 'Userlogin' )
572 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
573 wfProfileOut( $fname );
574 return $personal_urls;
578 * Returns true if the IP should be shown in the header
580 function showIPinHeader() {
581 global $wgShowIPinHeader;
582 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
585 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
588 $classes[] = 'selected';
590 if( $checkEdit && $title->getArticleId() == 0 ) {
592 $query = 'action=edit';
595 $text = wfMsg( $message );
596 if ( wfEmptyMsg( $message, $text ) ) {
598 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
602 'class' => implode( ' ', $classes ),
604 'href' => $title->getLocalUrl( $query ) );
607 function makeTalkUrlDetails( $name, $urlaction = '' ) {
608 $title = Title
::newFromText( $name );
609 $title = $title->getTalkPage();
610 self
::checkTitle( $title, $name );
612 'href' => $title->getLocalURL( $urlaction ),
613 'exists' => $title->getArticleID() != 0 ?
true : false
617 function makeArticleUrlDetails( $name, $urlaction = '' ) {
618 $title = Title
::newFromText( $name );
619 $title= $title->getSubjectPage();
620 self
::checkTitle( $title, $name );
622 'href' => $title->getLocalURL( $urlaction ),
623 'exists' => $title->getArticleID() != 0 ?
true : false
628 * an array of edit links by default used for the tabs
632 function buildContentActionUrls () {
633 global $wgContLang, $wgOut;
634 $fname = 'SkinTemplate::buildContentActionUrls';
635 wfProfileIn( $fname );
637 global $wgUser, $wgRequest;
638 $action = $wgRequest->getText( 'action' );
639 $section = $wgRequest->getText( 'section' );
640 $content_actions = array();
642 $prevent_active_tabs = false ;
643 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
645 if( $this->iscontent
) {
646 $subjpage = $this->mTitle
->getSubjectPage();
647 $talkpage = $this->mTitle
->getTalkPage();
649 $nskey = $this->mTitle
->getNamespaceKey();
650 $content_actions[$nskey] = $this->tabAction(
653 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
656 $content_actions['talk'] = $this->tabAction(
659 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
663 wfProfileIn( "$fname-edit" );
664 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
665 $istalk = $this->mTitle
->isTalkPage();
666 $istalkclass = $istalk?
' istalk':'';
667 $content_actions['edit'] = array(
668 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
669 'text' => wfMsg('edit'),
670 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
673 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
674 $content_actions['addsection'] = array(
675 'class' => $section == 'new'?
'selected':false,
676 'text' => wfMsg('addsection'),
677 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
681 $content_actions['viewsource'] = array(
682 'class' => ($action == 'edit') ?
'selected' : false,
683 'text' => wfMsg('viewsource'),
684 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
687 wfProfileOut( "$fname-edit" );
689 wfProfileIn( "$fname-live" );
690 if ( $this->mTitle
->getArticleId() ) {
692 $content_actions['history'] = array(
693 'class' => ($action == 'history') ?
'selected' : false,
694 'text' => wfMsg('history_short'),
695 'href' => $this->mTitle
->getLocalUrl( 'action=history')
698 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
699 if(!$this->mTitle
->isProtected()){
700 $content_actions['protect'] = array(
701 'class' => ($action == 'protect') ?
'selected' : false,
702 'text' => wfMsg('protect'),
703 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
707 $content_actions['unprotect'] = array(
708 'class' => ($action == 'unprotect') ?
'selected' : false,
709 'text' => wfMsg('unprotect'),
710 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
714 if($wgUser->isAllowed('delete')){
715 $content_actions['delete'] = array(
716 'class' => ($action == 'delete') ?
'selected' : false,
717 'text' => wfMsg('delete'),
718 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
721 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
722 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
723 $content_actions['move'] = array(
724 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
725 'text' => wfMsg('move'),
726 'href' => $moveTitle->getLocalUrl()
730 //article doesn't exist or is deleted
731 if( $wgUser->isAllowed( 'delete' ) ) {
732 if( $n = $this->mTitle
->isDeleted() ) {
733 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
734 $content_actions['undelete'] = array(
736 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
737 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
738 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
743 wfProfileOut( "$fname-live" );
745 if( $this->loggedin
) {
746 if( !$this->mTitle
->userIsWatching()) {
747 $content_actions['watch'] = array(
748 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
749 'text' => wfMsg('watch'),
750 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
753 $content_actions['unwatch'] = array(
754 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
755 'text' => wfMsg('unwatch'),
756 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
761 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
763 /* show special page tab */
765 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
766 'class' => 'selected',
767 'text' => wfMsg('nstab-special'),
768 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
771 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
774 /* show links to different language variants */
775 global $wgDisableLangConversion;
776 $variants = $wgContLang->getVariants();
777 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
778 $preferred = $wgContLang->getPreferredVariant();
780 foreach( $variants as $code ) {
781 $varname = $wgContLang->getVariantname( $code );
782 if( $varname == 'disable' )
784 $selected = ( $code == $preferred )?
'selected' : false;
785 $content_actions['varlang-' . $vcount] = array(
786 'class' => $selected,
788 'href' => $this->mTitle
->getLocalURL('',$code)
794 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
796 wfProfileOut( $fname );
797 return $content_actions;
803 * build array of common navigation links
807 function buildNavUrls () {
808 global $wgUseTrackbacks, $wgTitle, $wgArticle;
810 $fname = 'SkinTemplate::buildNavUrls';
811 wfProfileIn( $fname );
813 global $wgUser, $wgRequest;
814 global $wgEnableUploads, $wgUploadNavigationUrl;
816 $action = $wgRequest->getText( 'action' );
817 $oldid = $wgRequest->getVal( 'oldid' );
820 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
821 if( $wgEnableUploads ) {
822 if ($wgUploadNavigationUrl) {
823 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
825 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
828 if ($wgUploadNavigationUrl)
829 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
831 $nav_urls['upload'] = false;
833 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
835 // default permalink to being off, will override it as required below.
836 $nav_urls['permalink'] = false;
838 // A print stylesheet is attached to all pages, but nobody ever
839 // figures that out. :) Add a link...
840 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
841 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
842 if ( !( $revid == 0 ) )
843 $nav_urls['print'] = array(
844 'text' => wfMsg( 'printableversion' ),
845 'href' => $wgRequest->appendQuery( 'printable=yes' )
848 // Also add a "permalink" while we're at it
850 $nav_urls['permalink'] = array(
851 'text' => wfMsg( 'permalink' ),
855 if ( !( $revid == 0 ) )
856 $nav_urls['permalink'] = array(
857 'text' => wfMsg( 'permalink' ),
858 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
862 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
865 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
866 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
867 $nav_urls['whatlinkshere'] = array(
868 'href' => $wlhTitle->getLocalUrl()
870 if( $this->mTitle
->getArticleId() ) {
871 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
872 $nav_urls['recentchangeslinked'] = array(
873 'href' => $rclTitle->getLocalUrl()
876 $nav_urls['recentchangeslinked'] = false;
878 if ($wgUseTrackbacks)
879 $nav_urls['trackbacklink'] = array(
880 'href' => $wgTitle->trackbackURL()
884 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
885 $id = User
::idFromName($this->mTitle
->getText());
886 $ip = User
::isIP($this->mTitle
->getText());
892 if($id ||
$ip) { # both anons and non-anons have contri list
893 $nav_urls['contributions'] = array(
894 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
896 if ( $wgUser->isAllowed( 'block' ) ) {
897 $nav_urls['blockip'] = array(
898 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
901 $nav_urls['blockip'] = false;
904 $nav_urls['contributions'] = false;
905 $nav_urls['blockip'] = false;
907 $nav_urls['emailuser'] = false;
908 if( $this->showEmailUser( $id ) ) {
909 $nav_urls['emailuser'] = array(
910 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
913 wfProfileOut( $fname );
918 * Generate strings used for xml 'id' names
922 function getNameSpaceKey () {
923 return $this->mTitle
->getNamespaceKey();
929 function setupUserCss() {
930 $fname = 'SkinTemplate::setupUserCss';
931 wfProfileIn( $fname );
933 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
937 $siteargs = '&maxage=' . $wgSquidMaxage;
938 if( $this->loggedin
) {
939 // Ensure that logged-in users' generated CSS isn't clobbered
940 // by anons' publicly cacheable generated CSS.
941 $siteargs .= '&smaxage=0';
944 # Add user-specific code if this is a user and we allow that kind of thing
946 if ( $wgAllowUserCss && $this->loggedin
) {
947 $action = $wgRequest->getText('action');
949 # if we're previewing the CSS page, use it
950 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
951 $siteargs = "&smaxage=0&maxage=0";
952 $usercss = $wgRequest->getText('wpTextbox1');
954 $usercss = '@import "' .
955 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
956 'action=raw&ctype=text/css') . '";' ."\n";
959 $siteargs .= '&ts=' . $wgUser->mTouched
;
962 if( $wgContLang->isRTL() ) {
963 global $wgStyleVersion;
964 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
967 # If we use the site's dynamic CSS, throw that in, too
968 if ( $wgUseSiteCss ) {
969 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
970 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
971 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
972 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
975 # If we use any dynamic CSS, make a little CDATA block out of it.
977 if ( !empty($sitecss) ||
!empty($usercss) ) {
978 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
980 wfProfileOut( $fname );
986 function setupUserJs() {
987 $fname = 'SkinTemplate::setupUserJs';
988 wfProfileIn( $fname );
990 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
991 $action = $wgRequest->getText('action');
993 if( $wgAllowUserJs && $this->loggedin
) {
994 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
995 # XXX: additional security check/prompt?
996 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
998 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1001 wfProfileOut( $fname );
1005 * Code for extensions to hook into to provide per-page CSS, see
1006 * extensions/PageCSS/PageCSS.php for an implementation of this.
1010 function setupPageCss() {
1011 $fname = 'SkinTemplate::setupPageCss';
1012 wfProfileIn( $fname );
1014 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1016 wfProfileOut( $fname );
1021 * returns css with user-specific options
1025 function getUserStylesheet() {
1026 $fname = 'SkinTemplate::getUserStylesheet';
1027 wfProfileIn( $fname );
1029 $s = "/* generated user stylesheet */\n";
1030 $s .= $this->reallyDoGetUserStyles();
1031 wfProfileOut( $fname );
1036 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1037 * nated together. For some bizarre reason, it does *not* return any
1038 * custom user JS from subpages. Huh?
1040 * There's absolutely no reason to have separate Monobook/Common JSes.
1041 * Any JS that cares can just check the skin variable generated at the
1042 * top. For now Monobook.js will be maintained, but it should be consi-
1047 public function getUserJs() {
1048 $fname = 'SkinTemplate::getUserJs';
1049 wfProfileIn( $fname );
1051 $s = parent
::getUserJs();
1052 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1054 // avoid inclusion of non defined user JavaScript (with custom skins only)
1055 // by checking for default message content
1056 $msgKey = ucfirst($this->skinname
).'.js';
1057 $userJS = wfMsgForContent($msgKey);
1058 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1062 wfProfileOut( $fname );
1068 * Generic wrapper for template functions, with interface
1069 * compatible with what we use of PHPTAL 0.7.
1072 class QuickTemplate
{
1076 function QuickTemplate() {
1077 $this->data
= array();
1078 $this->translator
= new MediaWiki_I18N();
1084 function set( $name, $value ) {
1085 $this->data
[$name] = $value;
1091 function setRef($name, &$value) {
1092 $this->data
[$name] =& $value;
1098 function setTranslator( &$t ) {
1099 $this->translator
= &$t;
1105 function execute() {
1106 echo "Override this function.";
1113 function text( $str ) {
1114 echo htmlspecialchars( $this->data
[$str] );
1120 function jstext( $str ) {
1121 echo Xml
::escapeJsString( $this->data
[$str] );
1127 function html( $str ) {
1128 echo $this->data
[$str];
1134 function msg( $str ) {
1135 echo htmlspecialchars( $this->translator
->translate( $str ) );
1141 function msgHtml( $str ) {
1142 echo $this->translator
->translate( $str );
1146 * An ugly, ugly hack.
1149 function msgWiki( $str ) {
1150 global $wgParser, $wgTitle, $wgOut;
1152 $text = $this->translator
->translate( $str );
1153 $parserOutput = $wgParser->parse( $text, $wgTitle,
1154 $wgOut->parserOptions(), true );
1155 echo $parserOutput->getText();
1161 function haveData( $str ) {
1162 return isset( $this->data
[$str] );
1168 function haveMsg( $str ) {
1169 $msg = $this->translator
->translate( $str );
1170 return ($msg != '-') && ($msg != ''); # ????