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.
35 * Wrapper object for MediaWiki's localization functions,
36 * to be passed to the template engine.
41 class MediaWiki_I18N
{
42 var $_context = array();
44 function set($varName, $value) {
45 $this->_context
[$varName] = $value;
48 function translate($value) {
49 $fname = 'SkinTemplate-translate';
50 wfProfileIn( $fname );
52 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
53 $value = preg_replace( '/^string:/', '', $value );
55 $value = wfMsg( $value );
56 // interpolate variables
58 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
59 list($src, $var) = $m;
61 $varValue = $this->_context
[$var];
63 $value = str_replace($src, $varValue, $value);
65 wfProfileOut( $fname );
74 class SkinTemplate
extends Skin
{
80 * Name of our skin, set in initPage()
81 * It probably need to be all lower case.
86 * Stylesheets set to use
87 * Sub directory in ./skins/ where various stylesheets are located
92 * For QuickTemplate, the name of the subclass which
93 * will actually fill the template.
100 * Setup the base parameters...
101 * Child classes should override this to set the name,
102 * style subdirectory, and template filler callback.
104 * @param OutputPage $out
106 function initPage( &$out ) {
107 parent
::initPage( $out );
108 $this->skinname
= 'monobook';
109 $this->stylename
= 'monobook';
110 $this->template
= 'QuickTemplate';
114 * Create the template engine object; we feed it a bunch of data
115 * and eventually it spits out some HTML. Should have interface
116 * roughly equivalent to PHPTAL 0.7.
118 * @param string $callback (or file)
119 * @param string $repository subdirectory where we keep template files
120 * @param string $cache_dir
124 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
125 return new $classname();
129 * initialize various variables and generate the template
131 * @param OutputPage $out
134 function outputPage( &$out ) {
135 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
145 $fname = 'SkinTemplate::outputPage';
146 wfProfileIn( $fname );
148 // Hook that allows last minute changes to the output page, e.g.
149 // adding of CSS or Javascript by extensions.
150 wfRunHooks( 'BeforePageDisplay', array( &$out ) );
152 $oldid = $wgRequest->getVal( 'oldid' );
153 $diff = $wgRequest->getVal( 'diff' );
155 wfProfileIn( "$fname-init" );
156 $this->initPage( $out );
158 $this->mTitle
=& $wgTitle;
159 $this->mUser
=& $wgUser;
161 $tpl = $this->setupTemplate( $this->template
, 'skins' );
163 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
164 $tpl->setTranslator(new MediaWiki_I18N());
166 wfProfileOut( "$fname-init" );
168 wfProfileIn( "$fname-stuff" );
169 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
170 $this->thisurl
= $this->mTitle
->getPrefixedURL();
171 $this->loggedin
= $wgUser->isLoggedIn();
172 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
173 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
174 $this->username
= $wgUser->getName();
175 $userPage = $wgUser->getUserPage();
176 $this->userpage
= $userPage->getPrefixedText();
178 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
179 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
181 # This won't be used in the standard skins, but we define it to preserve the interface
182 # To save time, we check for existence
183 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
186 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
187 $this->setupUserCss();
188 $this->setupUserJs();
189 $this->titletxt
= $this->mTitle
->getPrefixedText();
190 wfProfileOut( "$fname-stuff" );
192 wfProfileIn( "$fname-stuff2" );
193 $tpl->set( 'title', $wgOut->getPageTitle() );
194 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
195 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
196 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$wgTitle->getPrefixedText() ) );
198 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
199 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
200 $this->mTitle
->getNsText();
202 $tpl->set( 'nscanonical', $nsname );
203 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
204 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
205 $tpl->set( 'titletext', $this->mTitle
->getText() );
206 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
207 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
209 $tpl->set( 'isarticle', $wgOut->isArticle() );
211 $tpl->setRef( "thispage", $this->thispage
);
212 $subpagestr = $this->subPageSubtitle();
214 'subtitle', !empty($subpagestr)?
215 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
218 $undelete = $this->getUndeleteLink();
220 "undelete", !empty($undelete)?
221 '<span class="subpages">'.$undelete.'</span>':
225 $tpl->set( 'catlinks', $this->getCategories());
226 if( $wgOut->isSyndicated() ) {
228 foreach( $wgFeedClasses as $format => $class ) {
230 if ( $format == "atom" ) {
231 $linktext = wfMsg( 'feed-atom' );
232 } else if ( $format == "rss" ) {
233 $linktext = wfMsg( 'feed-rss' );
235 $feeds[$format] = array(
237 'href' => $wgRequest->appendQuery( "feed=$format" )
240 $tpl->setRef( 'feeds', $feeds );
242 $tpl->set( 'feeds', false );
244 if ($wgUseTrackbacks && $out->isArticleRelated()) {
245 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
247 $tpl->set( 'trackbackhtml', null );
250 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
251 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
252 $tpl->setRef( 'mimetype', $wgMimeType );
253 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
254 $tpl->setRef( 'charset', $wgOutputEncoding );
255 $tpl->set( 'headlinks', $out->getHeadLinks() );
256 $tpl->set('headscripts', $out->getScript() );
257 $tpl->setRef( 'wgScript', $wgScript );
258 $tpl->setRef( 'skinname', $this->skinname
);
259 $tpl->set( 'skinclass', get_class( $this ) );
260 $tpl->setRef( 'stylename', $this->stylename
);
261 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
262 $tpl->setRef( 'loggedin', $this->loggedin
);
263 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
264 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
265 /* XXX currently unused, might get useful later
266 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
267 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
268 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
269 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
270 $tpl->set( "helppage", wfMsg('helppage'));
272 $tpl->set( 'searchaction', $this->escapeSearchLink() );
273 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
274 $tpl->setRef( 'stylepath', $wgStylePath );
275 $tpl->setRef( 'articlepath', $wgArticlePath );
276 $tpl->setRef( 'scriptpath', $wgScriptPath );
277 $tpl->setRef( 'serverurl', $wgServer );
278 $tpl->setRef( 'logopath', $wgLogo );
279 $tpl->setRef( "lang", $wgContLanguageCode );
280 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
281 $tpl->set( 'rtl', $wgContLang->isRTL() );
282 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
283 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
284 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
285 $tpl->setRef( 'userpage', $this->userpage
);
286 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
287 $tpl->set( 'userlang', $wgLang->getCode() );
288 $tpl->set( 'pagecss', $this->setupPageCss() );
289 $tpl->setRef( 'usercss', $this->usercss
);
290 $tpl->setRef( 'userjs', $this->userjs
);
291 $tpl->setRef( 'userjsprev', $this->userjsprev
);
294 if($this->loggedin
) {
295 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&smaxage=0&gen=js') );
297 $tpl->set( 'jsvarurl', self
::makeUrl('-','action=raw&gen=js') );
300 $tpl->set('jsvarurl', false);
302 $newtalks = $wgUser->getNewMessageLinks();
304 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
305 $usertitle = $this->mUser
->getUserPage();
306 $usertalktitle = $usertitle->getTalkPage();
307 if( !$usertalktitle->equals( $this->mTitle
) ) {
308 $ntl = wfMsg( 'youhavenewmessages',
309 $this->makeKnownLinkObj(
311 wfMsgHtml( 'newmessageslink' ),
314 $this->makeKnownLinkObj(
316 wfMsgHtml( 'newmessagesdifflink' ),
321 $wgOut->setSquidMaxage(0);
323 } else if (count($newtalks)) {
324 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
326 foreach ($newtalks as $newtalk) {
327 $msgs[] = wfElement("a",
328 array('href' => $newtalk["link"]), $newtalk["wiki"]);
330 $parts = implode($sep, $msgs);
331 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
332 $wgOut->setSquidMaxage(0);
336 wfProfileOut( "$fname-stuff2" );
338 wfProfileIn( "$fname-stuff3" );
339 $tpl->setRef( 'newtalk', $ntl );
340 $tpl->setRef( 'skin', $this);
341 $tpl->set( 'logo', $this->logoText() );
342 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
343 $wgArticle and 0 != $wgArticle->getID() )
345 if ( !$wgDisableCounters ) {
346 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
348 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
350 $tpl->set('viewcount', false);
353 $tpl->set('viewcount', false);
356 if ($wgPageShowWatchingUsers) {
357 $dbr =& wfGetDB( DB_SLAVE
);
358 $watchlist = $dbr->tableName( 'watchlist' );
359 $sql = "SELECT COUNT(*) AS n FROM $watchlist
360 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
361 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
362 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
363 $x = $dbr->fetchObject( $res );
364 $numberofwatchingusers = $x->n
;
365 if ($numberofwatchingusers > 0) {
366 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
368 $tpl->set('numberofwatchingusers', false);
371 $tpl->set('numberofwatchingusers', false);
374 $tpl->set('copyright',$this->getCopyright());
376 $this->credits
= false;
378 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
379 require_once("Credits.php");
380 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
382 $tpl->set('lastmod', $this->lastModified());
385 $tpl->setRef( 'credits', $this->credits
);
387 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
388 $tpl->set('copyright', $this->getCopyright());
389 $tpl->set('viewcount', false);
390 $tpl->set('lastmod', false);
391 $tpl->set('credits', false);
392 $tpl->set('numberofwatchingusers', false);
394 $tpl->set('copyright', false);
395 $tpl->set('viewcount', false);
396 $tpl->set('lastmod', false);
397 $tpl->set('credits', false);
398 $tpl->set('numberofwatchingusers', false);
400 wfProfileOut( "$fname-stuff3" );
402 wfProfileIn( "$fname-stuff4" );
403 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
404 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
405 $tpl->set( 'disclaimer', $this->disclaimerLink() );
406 $tpl->set( 'privacy', $this->privacyLink() );
407 $tpl->set( 'about', $this->aboutLink() );
409 $tpl->setRef( 'debug', $out->mDebugtext
);
410 $tpl->set( 'reporttime', $out->reportTime() );
411 $tpl->set( 'sitenotice', wfGetSiteNotice() );
412 $tpl->set( 'bottomscripts', $this->bottomScripts() );
414 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
415 $out->mBodytext
.= $printfooter ;
416 $tpl->setRef( 'bodytext', $out->mBodytext
);
419 $language_urls = array();
421 if ( !$wgHideInterlanguageLinks ) {
422 foreach( $wgOut->getLanguageLinks() as $l ) {
423 $tmp = explode( ':', $l, 2 );
424 $class = 'interwiki-' . $tmp[0];
426 $nt = Title
::newFromText( $l );
427 $language_urls[] = array(
428 'href' => $nt->getFullURL(),
429 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
434 if(count($language_urls)) {
435 $tpl->setRef( 'language_urls', $language_urls);
437 $tpl->set('language_urls', false);
439 wfProfileOut( "$fname-stuff4" );
442 $tpl->set('personal_urls', $this->buildPersonalUrls());
443 $content_actions = $this->buildContentActionUrls();
444 $tpl->setRef('content_actions', $content_actions);
446 // XXX: attach this from javascript, same with section editing
447 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
449 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
451 $tpl->set('body_ondblclick', false);
453 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
454 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
456 $tpl->set( 'body_onload', false );
458 $tpl->set( 'sidebar', $this->buildSidebar() );
459 $tpl->set( 'nav_urls', $this->buildNavUrls() );
461 // original version by hansm
462 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
463 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
467 wfProfileIn( "$fname-execute" );
468 $res = $tpl->execute();
469 wfProfileOut( "$fname-execute" );
471 // result may be an error
472 $this->printOrError( $res );
473 wfProfileOut( $fname );
477 * Output the string, or print error message if it's
478 * an error object of the appropriate type.
479 * For the base class, assume strings all around.
484 function printOrError( &$str ) {
489 * build array of urls for personal toolbar
493 function buildPersonalUrls() {
494 global $wgTitle, $wgShowIPinHeader;
496 $fname = 'SkinTemplate::buildPersonalUrls';
497 $pageurl = $wgTitle->getLocalURL();
498 wfProfileIn( $fname );
500 /* set up the default links for the personal toolbar */
501 $personal_urls = array();
502 if ($this->loggedin
) {
503 $personal_urls['userpage'] = array(
504 'text' => $this->username
,
505 'href' => &$this->userpageUrlDetails
['href'],
506 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
507 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
509 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
510 $personal_urls['mytalk'] = array(
511 'text' => wfMsg('mytalk'),
512 'href' => &$usertalkUrlDetails['href'],
513 'class' => $usertalkUrlDetails['exists']?
false:'new',
514 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
516 $href = self
::makeSpecialUrl( 'Preferences' );
517 $personal_urls['preferences'] = array(
518 'text' => wfMsg( 'mypreferences' ),
519 'href' => self
::makeSpecialUrl( 'Preferences' ),
520 'active' => ( $href == $pageurl )
522 $href = self
::makeSpecialUrl( 'Watchlist' );
523 $personal_urls['watchlist'] = array(
524 'text' => wfMsg( 'watchlist' ),
526 'active' => ( $href == $pageurl )
528 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
529 $personal_urls['mycontris'] = array(
530 'text' => wfMsg( 'mycontris' ),
532 // FIXME # 'active' was disabed in r11346 with message: "disable bold link to my contributions; link was bold on all
533 // Special:Contributions, not just current user's (fix me please!)". Until resolved, explicitly setting active to false.
534 'active' => false # ( ( $href == $pageurl . '/' . $this->username )
536 $personal_urls['logout'] = array(
537 'text' => wfMsg( 'userlogout' ),
538 'href' => self
::makeSpecialUrl( 'Userlogout',
539 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
544 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
545 $href = &$this->userpageUrlDetails
['href'];
546 $personal_urls['anonuserpage'] = array(
547 'text' => $this->username
,
549 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
550 'active' => ( $pageurl == $href )
552 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
553 $href = &$usertalkUrlDetails['href'];
554 $personal_urls['anontalk'] = array(
555 'text' => wfMsg('anontalk'),
557 'class' => $usertalkUrlDetails['exists']?
false:'new',
558 'active' => ( $pageurl == $href )
560 $personal_urls['anonlogin'] = array(
561 'text' => wfMsg('userlogin'),
562 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
563 'active' => $wgTitle->isSpecial( 'Userlogin' )
567 $personal_urls['login'] = array(
568 'text' => wfMsg('userlogin'),
569 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
570 'active' => $wgTitle->isSpecial( 'Userlogin' )
575 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
576 wfProfileOut( $fname );
577 return $personal_urls;
581 * Returns true if the IP should be shown in the header
583 function showIPinHeader() {
584 global $wgShowIPinHeader;
585 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
588 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
591 $classes[] = 'selected';
593 if( $checkEdit && $title->getArticleId() == 0 ) {
595 $query = 'action=edit';
598 $text = wfMsg( $message );
599 if ( wfEmptyMsg( $message, $text ) ) {
601 $text = $wgContLang->getFormattedNsText( Namespace::getSubject( $title->getNamespace() ) );
605 'class' => implode( ' ', $classes ),
607 'href' => $title->getLocalUrl( $query ) );
610 function makeTalkUrlDetails( $name, $urlaction = '' ) {
611 $title = Title
::newFromText( $name );
612 $title = $title->getTalkPage();
613 self
::checkTitle( $title, $name );
615 'href' => $title->getLocalURL( $urlaction ),
616 'exists' => $title->getArticleID() != 0 ?
true : false
620 function makeArticleUrlDetails( $name, $urlaction = '' ) {
621 $title = Title
::newFromText( $name );
622 $title= $title->getSubjectPage();
623 self
::checkTitle( $title, $name );
625 'href' => $title->getLocalURL( $urlaction ),
626 'exists' => $title->getArticleID() != 0 ?
true : false
631 * an array of edit links by default used for the tabs
635 function buildContentActionUrls () {
636 global $wgContLang, $wgOut;
637 $fname = 'SkinTemplate::buildContentActionUrls';
638 wfProfileIn( $fname );
640 global $wgUser, $wgRequest;
641 $action = $wgRequest->getText( 'action' );
642 $section = $wgRequest->getText( 'section' );
643 $content_actions = array();
645 $prevent_active_tabs = false ;
646 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
648 if( $this->iscontent
) {
649 $subjpage = $this->mTitle
->getSubjectPage();
650 $talkpage = $this->mTitle
->getTalkPage();
652 $nskey = $this->mTitle
->getNamespaceKey();
653 $content_actions[$nskey] = $this->tabAction(
656 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
659 $content_actions['talk'] = $this->tabAction(
662 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
666 wfProfileIn( "$fname-edit" );
667 if ( $this->mTitle
->userCanEdit() && ( $this->mTitle
->exists() ||
$this->mTitle
->userCanCreate() ) ) {
668 $istalk = $this->mTitle
->isTalkPage();
669 $istalkclass = $istalk?
' istalk':'';
670 $content_actions['edit'] = array(
671 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
672 'text' => wfMsg('edit'),
673 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
676 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
677 $content_actions['addsection'] = array(
678 'class' => $section == 'new'?
'selected':false,
679 'text' => wfMsg('addsection'),
680 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
684 $content_actions['viewsource'] = array(
685 'class' => ($action == 'edit') ?
'selected' : false,
686 'text' => wfMsg('viewsource'),
687 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
690 wfProfileOut( "$fname-edit" );
692 wfProfileIn( "$fname-live" );
693 if ( $this->mTitle
->getArticleId() ) {
695 $content_actions['history'] = array(
696 'class' => ($action == 'history') ?
'selected' : false,
697 'text' => wfMsg('history_short'),
698 'href' => $this->mTitle
->getLocalUrl( 'action=history')
701 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
702 if(!$this->mTitle
->isProtected()){
703 $content_actions['protect'] = array(
704 'class' => ($action == 'protect') ?
'selected' : false,
705 'text' => wfMsg('protect'),
706 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
710 $content_actions['unprotect'] = array(
711 'class' => ($action == 'unprotect') ?
'selected' : false,
712 'text' => wfMsg('unprotect'),
713 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
717 if($wgUser->isAllowed('delete')){
718 $content_actions['delete'] = array(
719 'class' => ($action == 'delete') ?
'selected' : false,
720 'text' => wfMsg('delete'),
721 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
724 if ( $this->mTitle
->userCanMove()) {
725 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
726 $content_actions['move'] = array(
727 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
728 'text' => wfMsg('move'),
729 'href' => $moveTitle->getLocalUrl()
733 //article doesn't exist or is deleted
734 if( $wgUser->isAllowed( 'delete' ) ) {
735 if( $n = $this->mTitle
->isDeleted() ) {
736 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
737 $content_actions['undelete'] = array(
739 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
740 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
741 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
746 wfProfileOut( "$fname-live" );
748 if( $this->loggedin
) {
749 if( !$this->mTitle
->userIsWatching()) {
750 $content_actions['watch'] = array(
751 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
752 'text' => wfMsg('watch'),
753 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
756 $content_actions['unwatch'] = array(
757 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
758 'text' => wfMsg('unwatch'),
759 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
764 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
766 /* show special page tab */
768 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
769 'class' => 'selected',
770 'text' => wfMsg('specialpage'),
771 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
774 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
777 /* show links to different language variants */
778 global $wgDisableLangConversion;
779 $variants = $wgContLang->getVariants();
780 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
781 $preferred = $wgContLang->getPreferredVariant();
783 foreach( $variants as $code ) {
784 $varname = $wgContLang->getVariantname( $code );
785 if( $varname == 'disable' )
787 $selected = ( $code == $preferred )?
'selected' : false;
788 $content_actions['varlang-' . $vcount] = array(
789 'class' => $selected,
791 'href' => $this->mTitle
->getLocalURL('',$code)
797 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
799 wfProfileOut( $fname );
800 return $content_actions;
806 * build array of common navigation links
810 function buildNavUrls () {
811 global $wgUseTrackbacks, $wgTitle, $wgArticle;
813 $fname = 'SkinTemplate::buildNavUrls';
814 wfProfileIn( $fname );
816 global $wgUser, $wgRequest;
817 global $wgEnableUploads, $wgUploadNavigationUrl;
819 $action = $wgRequest->getText( 'action' );
820 $oldid = $wgRequest->getVal( 'oldid' );
823 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
824 if( $wgEnableUploads ) {
825 if ($wgUploadNavigationUrl) {
826 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
828 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
831 if ($wgUploadNavigationUrl)
832 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
834 $nav_urls['upload'] = false;
836 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
838 // default permalink to being off, will override it as required below.
839 $nav_urls['permalink'] = false;
841 // A print stylesheet is attached to all pages, but nobody ever
842 // figures that out. :) Add a link...
843 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
844 $revid = $wgArticle ?
$wgArticle->getLatest() : 0;
845 if ( !( $revid == 0 ) )
846 $nav_urls['print'] = array(
847 'text' => wfMsg( 'printableversion' ),
848 'href' => $wgRequest->appendQuery( 'printable=yes' )
851 // Also add a "permalink" while we're at it
853 $nav_urls['permalink'] = array(
854 'text' => wfMsg( 'permalink' ),
858 if ( !( $revid == 0 ) )
859 $nav_urls['permalink'] = array(
860 'text' => wfMsg( 'permalink' ),
861 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
865 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
868 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
869 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
870 $nav_urls['whatlinkshere'] = array(
871 'href' => $wlhTitle->getLocalUrl()
873 if( $this->mTitle
->getArticleId() ) {
874 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
875 $nav_urls['recentchangeslinked'] = array(
876 'href' => $rclTitle->getLocalUrl()
879 $nav_urls['recentchangeslinked'] = false;
881 if ($wgUseTrackbacks)
882 $nav_urls['trackbacklink'] = array(
883 'href' => $wgTitle->trackbackURL()
887 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
888 $id = User
::idFromName($this->mTitle
->getText());
889 $ip = User
::isIP($this->mTitle
->getText());
895 if($id ||
$ip) { # both anons and non-anons have contri list
896 $nav_urls['contributions'] = array(
897 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
899 if ( $wgUser->isAllowed( 'block' ) ) {
900 $nav_urls['blockip'] = array(
901 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
904 $nav_urls['blockip'] = false;
907 $nav_urls['contributions'] = false;
908 $nav_urls['blockip'] = false;
910 $nav_urls['emailuser'] = false;
911 if( $this->showEmailUser( $id ) ) {
912 $nav_urls['emailuser'] = array(
913 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
916 wfProfileOut( $fname );
921 * Generate strings used for xml 'id' names
925 function getNameSpaceKey () {
926 return $this->mTitle
->getNamespaceKey();
932 function setupUserCss() {
933 $fname = 'SkinTemplate::setupUserCss';
934 wfProfileIn( $fname );
936 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
940 $siteargs = '&maxage=' . $wgSquidMaxage;
941 if( $this->loggedin
) {
942 // Ensure that logged-in users' generated CSS isn't clobbered
943 // by anons' publicly cacheable generated CSS.
944 $siteargs .= '&smaxage=0';
947 # Add user-specific code if this is a user and we allow that kind of thing
949 if ( $wgAllowUserCss && $this->loggedin
) {
950 $action = $wgRequest->getText('action');
952 # if we're previewing the CSS page, use it
953 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
954 $siteargs = "&smaxage=0&maxage=0";
955 $usercss = $wgRequest->getText('wpTextbox1');
957 $usercss = '@import "' .
958 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
959 'action=raw&ctype=text/css') . '";' ."\n";
962 $siteargs .= '&ts=' . $wgUser->mTouched
;
965 if( $wgContLang->isRTL() ) {
966 global $wgStyleVersion;
967 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
970 # If we use the site's dynamic CSS, throw that in, too
971 if ( $wgUseSiteCss ) {
972 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
973 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
974 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
975 $sitecss .= '@import "' . self
::makeUrl( '-', 'action=raw&gen=css' . $siteargs ) . '";' . "\n";
978 # If we use any dynamic CSS, make a little CDATA block out of it.
980 if ( !empty($sitecss) ||
!empty($usercss) ) {
981 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
983 wfProfileOut( $fname );
989 function setupUserJs() {
990 $fname = 'SkinTemplate::setupUserJs';
991 wfProfileIn( $fname );
993 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
994 $action = $wgRequest->getText('action');
996 if( $wgAllowUserJs && $this->loggedin
) {
997 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
998 # XXX: additional security check/prompt?
999 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1001 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1004 wfProfileOut( $fname );
1008 * Code for extensions to hook into to provide per-page CSS, see
1009 * extensions/PageCSS/PageCSS.php for an implementation of this.
1013 function setupPageCss() {
1014 $fname = 'SkinTemplate::setupPageCss';
1015 wfProfileIn( $fname );
1017 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1019 wfProfileOut( $fname );
1024 * returns css with user-specific options
1028 function getUserStylesheet() {
1029 $fname = 'SkinTemplate::getUserStylesheet';
1030 wfProfileIn( $fname );
1032 $s = "/* generated user stylesheet */\n";
1033 $s .= $this->reallyDoGetUserStyles();
1034 wfProfileOut( $fname );
1039 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1040 * nated together. For some bizarre reason, it does *not* return any
1041 * custom user JS from subpages. Huh?
1043 * There's absolutely no reason to have separate Monobook/Common JSes.
1044 * Any JS that cares can just check the skin variable generated at the
1045 * top. For now Monobook.js will be maintained, but it should be consi-
1050 public function getUserJs() {
1051 $fname = 'SkinTemplate::getUserJs';
1052 wfProfileIn( $fname );
1054 $s = parent
::getUserJs();
1055 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1057 // avoid inclusion of non defined user JavaScript (with custom skins only)
1058 // by checking for default message content
1059 $msgKey = ucfirst($this->skinname
).'.js';
1060 $userJS = wfMsgForContent($msgKey);
1061 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1065 wfProfileOut( $fname );
1071 * Generic wrapper for template functions, with interface
1072 * compatible with what we use of PHPTAL 0.7.
1073 * @package MediaWiki
1076 class QuickTemplate
{
1080 function QuickTemplate() {
1081 $this->data
= array();
1082 $this->translator
= new MediaWiki_I18N();
1088 function set( $name, $value ) {
1089 $this->data
[$name] = $value;
1095 function setRef($name, &$value) {
1096 $this->data
[$name] =& $value;
1102 function setTranslator( &$t ) {
1103 $this->translator
= &$t;
1109 function execute() {
1110 echo "Override this function.";
1117 function text( $str ) {
1118 echo htmlspecialchars( $this->data
[$str] );
1124 function jstext( $str ) {
1125 echo Xml
::escapeJsString( $this->data
[$str] );
1131 function html( $str ) {
1132 echo $this->data
[$str];
1138 function msg( $str ) {
1139 echo htmlspecialchars( $this->translator
->translate( $str ) );
1145 function msgHtml( $str ) {
1146 echo $this->translator
->translate( $str );
1150 * An ugly, ugly hack.
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();
1165 function haveData( $str ) {
1166 return isset( $this->data
[$str] );
1172 function haveMsg( $str ) {
1173 $msg = $this->translator
->translate( $str );
1174 return ($msg != '-') && ($msg != ''); # ????