581772d3e32eecd57d0ee6b6f95dcb66a7b2a152
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 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
27 class MediaWiki_I18N
{
28 var $_context = array();
30 function set($varName, $value) {
31 $this->_context
[$varName] = $value;
34 function translate($value) {
35 $fname = 'SkinTemplate-translate';
36 wfProfileIn( $fname );
38 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
39 $value = preg_replace( '/^string:/', '', $value );
41 $value = wfMsg( $value );
42 // interpolate variables
44 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
45 list($src, $var) = $m;
47 $varValue = $this->_context
[$var];
49 $value = str_replace($src, $varValue, $value);
51 wfProfileOut( $fname );
57 * Template-filler skin base class
58 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
59 * Based on Brion's smarty skin
60 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
62 * @todo Needs some serious refactoring into functions that correspond
63 * to the computations individual esi snippets need. Most importantly no body
64 * parsing for most of those of course.
68 class SkinTemplate
extends Skin
{
74 * Name of our skin, set in initPage()
75 * It probably need to be all lower case.
80 * Stylesheets set to use
81 * Sub directory in ./skins/ where various stylesheets are located
86 * For QuickTemplate, the name of the subclass which
87 * will actually fill the template.
94 * Setup the base parameters...
95 * Child classes should override this to set the name,
96 * style subdirectory, and template filler callback.
98 * @param OutputPage $out
100 function initPage( &$out ) {
101 parent
::initPage( $out );
102 $this->skinname
= 'monobook';
103 $this->stylename
= 'monobook';
104 $this->template
= 'QuickTemplate';
108 * Create the template engine object; we feed it a bunch of data
109 * and eventually it spits out some HTML. Should have interface
110 * roughly equivalent to PHPTAL 0.7.
112 * @param string $callback (or file)
113 * @param string $repository subdirectory where we keep template files
114 * @param string $cache_dir
118 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
119 return new $classname();
123 * initialize various variables and generate the template
125 * @param OutputPage $out
128 function outputPage( &$out ) {
129 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
133 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks;
137 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
139 $fname = 'SkinTemplate::outputPage';
140 wfProfileIn( $fname );
142 $oldid = $wgRequest->getVal( 'oldid' );
143 $diff = $wgRequest->getVal( 'diff' );
145 wfProfileIn( "$fname-init" );
146 $this->initPage( $out );
148 $this->mTitle
=& $wgTitle;
149 $this->mUser
=& $wgUser;
151 $tpl = $this->setupTemplate( $this->template
, 'skins' );
153 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
154 $tpl->setTranslator(new MediaWiki_I18N());
156 wfProfileOut( "$fname-init" );
158 wfProfileIn( "$fname-stuff" );
159 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
160 $this->thisurl
= $this->mTitle
->getPrefixedURL();
161 $this->loggedin
= $wgUser->isLoggedIn();
162 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
163 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
164 $this->username
= $wgUser->getName();
165 $userPage = $wgUser->getUserPage();
166 $this->userpage
= $userPage->getPrefixedText();
168 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
169 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
171 # This won't be used in the standard skins, but we define it to preserve the interface
172 # To save time, we check for existence
173 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
176 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
177 $this->setupUserCss();
178 $this->setupUserJs( $out->isUserJsAllowed() );
179 $this->titletxt
= $this->mTitle
->getPrefixedText();
180 wfProfileOut( "$fname-stuff" );
182 wfProfileIn( "$fname-stuff2" );
183 $tpl->set( 'title', $wgOut->getPageTitle() );
184 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
185 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle
);
186 $tpl->set( 'pageclass', Sanitizer
::escapeClass( 'page-'.$this->mTitle
->getPrefixedText() ) );
188 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
189 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
190 $this->mTitle
->getNsText();
192 $tpl->set( 'nscanonical', $nsname );
193 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
194 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
195 $tpl->set( 'titletext', $this->mTitle
->getText() );
196 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
197 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
199 $tpl->set( 'isarticle', $wgOut->isArticle() );
201 $tpl->setRef( "thispage", $this->thispage
);
202 $subpagestr = $this->subPageSubtitle();
204 'subtitle', !empty($subpagestr)?
205 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
208 $undelete = $this->getUndeleteLink();
210 "undelete", !empty($undelete)?
211 '<span class="subpages">'.$undelete.'</span>':
215 $tpl->set( 'catlinks', $this->getCategories());
216 if( $wgOut->isSyndicated() ) {
218 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
219 $feeds[$format] = array(
220 'text' => wfMsg( "feed-$format" ),
223 $tpl->setRef( 'feeds', $feeds );
225 $tpl->set( 'feeds', false );
227 if ($wgUseTrackbacks && $out->isArticleRelated()) {
228 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
230 $tpl->set( 'trackbackhtml', null );
233 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
234 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
235 $tpl->setRef( 'mimetype', $wgMimeType );
236 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
237 $tpl->setRef( 'charset', $wgOutputEncoding );
238 $tpl->set( 'headlinks', $out->getHeadLinks() );
239 $tpl->set('headscripts', $out->getScript() );
240 $tpl->setRef( 'wgScript', $wgScript );
241 $tpl->setRef( 'skinname', $this->skinname
);
242 $tpl->set( 'skinclass', get_class( $this ) );
243 $tpl->setRef( 'stylename', $this->stylename
);
244 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
245 $tpl->setRef( 'loggedin', $this->loggedin
);
246 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
247 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
248 /* XXX currently unused, might get useful later
249 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
250 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
251 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
252 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
253 $tpl->set( "helppage", wfMsg('helppage'));
255 $tpl->set( 'searchaction', $this->escapeSearchLink() );
256 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
257 $tpl->setRef( 'stylepath', $wgStylePath );
258 $tpl->setRef( 'articlepath', $wgArticlePath );
259 $tpl->setRef( 'scriptpath', $wgScriptPath );
260 $tpl->setRef( 'serverurl', $wgServer );
261 $tpl->setRef( 'logopath', $wgLogo );
262 $tpl->setRef( "lang", $wgContLanguageCode );
263 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
264 $tpl->set( 'rtl', $wgContLang->isRTL() );
265 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
266 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
267 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
268 $tpl->setRef( 'userpage', $this->userpage
);
269 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
270 $tpl->set( 'userlang', $wgLang->getCode() );
271 $tpl->set( 'pagecss', $this->setupPageCss() );
272 $tpl->set( 'printcss', $this->getPrintCss() );
273 $tpl->setRef( 'usercss', $this->usercss
);
274 $tpl->setRef( 'userjs', $this->userjs
);
275 $tpl->setRef( 'userjsprev', $this->userjsprev
);
278 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
279 $tpl->set( 'jsvarurl',
281 "action=raw$jsCache&gen=js&useskin=" .
282 urlencode( $this->getSkinName() ) ) );
284 $tpl->set('jsvarurl', false);
286 $newtalks = $wgUser->getNewMessageLinks();
288 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
289 $usertitle = $this->mUser
->getUserPage();
290 $usertalktitle = $usertitle->getTalkPage();
291 if( !$usertalktitle->equals( $this->mTitle
) ) {
292 $ntl = wfMsg( 'youhavenewmessages',
293 $this->makeKnownLinkObj(
295 wfMsgHtml( 'newmessageslink' ),
298 $this->makeKnownLinkObj(
300 wfMsgHtml( 'newmessagesdifflink' ),
305 $wgOut->setSquidMaxage(0);
307 } else if (count($newtalks)) {
308 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
310 foreach ($newtalks as $newtalk) {
311 $msgs[] = wfElement("a",
312 array('href' => $newtalk["link"]), $newtalk["wiki"]);
314 $parts = implode($sep, $msgs);
315 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
316 $wgOut->setSquidMaxage(0);
320 wfProfileOut( "$fname-stuff2" );
322 wfProfileIn( "$fname-stuff3" );
323 $tpl->setRef( 'newtalk', $ntl );
324 $tpl->setRef( 'skin', $this);
325 $tpl->set( 'logo', $this->logoText() );
326 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
327 $wgArticle and 0 != $wgArticle->getID() )
329 if ( !$wgDisableCounters ) {
330 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
332 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
334 $tpl->set('viewcount', false);
337 $tpl->set('viewcount', false);
340 if ($wgPageShowWatchingUsers) {
341 $dbr = wfGetDB( DB_SLAVE
);
342 $watchlist = $dbr->tableName( 'watchlist' );
343 $sql = "SELECT COUNT(*) AS n FROM $watchlist
344 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
345 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
346 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
347 $x = $dbr->fetchObject( $res );
348 $numberofwatchingusers = $x->n
;
349 if ($numberofwatchingusers > 0) {
350 $tpl->set('numberofwatchingusers',
351 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
352 $wgLang->formatNum($numberofwatchingusers))
355 $tpl->set('numberofwatchingusers', false);
358 $tpl->set('numberofwatchingusers', false);
361 $tpl->set('copyright',$this->getCopyright());
363 $this->credits
= false;
365 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
366 require_once("Credits.php");
367 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
369 $tpl->set('lastmod', $this->lastModified());
372 $tpl->setRef( 'credits', $this->credits
);
374 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
375 $tpl->set('copyright', $this->getCopyright());
376 $tpl->set('viewcount', false);
377 $tpl->set('lastmod', false);
378 $tpl->set('credits', false);
379 $tpl->set('numberofwatchingusers', false);
381 $tpl->set('copyright', false);
382 $tpl->set('viewcount', false);
383 $tpl->set('lastmod', false);
384 $tpl->set('credits', false);
385 $tpl->set('numberofwatchingusers', false);
387 wfProfileOut( "$fname-stuff3" );
389 wfProfileIn( "$fname-stuff4" );
390 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
391 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
392 $tpl->set( 'disclaimer', $this->disclaimerLink() );
393 $tpl->set( 'privacy', $this->privacyLink() );
394 $tpl->set( 'about', $this->aboutLink() );
396 $tpl->setRef( 'debug', $out->mDebugtext
);
397 $tpl->set( 'reporttime', wfReportTime() );
398 $tpl->set( 'sitenotice', wfGetSiteNotice() );
399 $tpl->set( 'bottomscripts', $this->bottomScripts() );
401 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
402 $out->mBodytext
.= $printfooter ;
403 $tpl->setRef( 'bodytext', $out->mBodytext
);
406 $language_urls = array();
408 if ( !$wgHideInterlanguageLinks ) {
409 foreach( $wgOut->getLanguageLinks() as $l ) {
410 $tmp = explode( ':', $l, 2 );
411 $class = 'interwiki-' . $tmp[0];
413 $nt = Title
::newFromText( $l );
414 $language_urls[] = array(
415 'href' => $nt->getFullURL(),
416 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
421 if(count($language_urls)) {
422 $tpl->setRef( 'language_urls', $language_urls);
424 $tpl->set('language_urls', false);
426 wfProfileOut( "$fname-stuff4" );
429 $tpl->set('personal_urls', $this->buildPersonalUrls());
430 $content_actions = $this->buildContentActionUrls();
431 $tpl->setRef('content_actions', $content_actions);
433 // XXX: attach this from javascript, same with section editing
434 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
436 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
437 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
439 $tpl->set('body_ondblclick', false);
441 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
442 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
444 $tpl->set( 'body_onload', false );
446 $tpl->set( 'sidebar', $this->buildSidebar() );
447 $tpl->set( 'nav_urls', $this->buildNavUrls() );
449 // original version by hansm
450 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
451 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
455 wfProfileIn( "$fname-execute" );
456 $res = $tpl->execute();
457 wfProfileOut( "$fname-execute" );
459 // result may be an error
460 $this->printOrError( $res );
461 wfProfileOut( $fname );
465 * Output the string, or print error message if it's
466 * an error object of the appropriate type.
467 * For the base class, assume strings all around.
472 function printOrError( $str ) {
477 * build array of urls for personal toolbar
481 function buildPersonalUrls() {
482 global $wgTitle, $wgRequest;
484 $fname = 'SkinTemplate::buildPersonalUrls';
485 $pageurl = $wgTitle->getLocalURL();
486 wfProfileIn( $fname );
488 /* set up the default links for the personal toolbar */
489 $personal_urls = array();
490 if ($this->loggedin
) {
491 $personal_urls['userpage'] = array(
492 'text' => $this->username
,
493 'href' => &$this->userpageUrlDetails
['href'],
494 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
495 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
497 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
498 $personal_urls['mytalk'] = array(
499 'text' => wfMsg('mytalk'),
500 'href' => &$usertalkUrlDetails['href'],
501 'class' => $usertalkUrlDetails['exists']?
false:'new',
502 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
504 $href = self
::makeSpecialUrl( 'Preferences' );
505 $personal_urls['preferences'] = array(
506 'text' => wfMsg( 'mypreferences' ),
508 'active' => ( $href == $pageurl )
510 $href = self
::makeSpecialUrl( 'Watchlist' );
511 $personal_urls['watchlist'] = array(
512 'text' => wfMsg( 'mywatchlist' ),
514 'active' => ( $href == $pageurl )
517 # We need to do an explicit check for Special:Contributions, as we
518 # have to match both the title, and the target (which could come
519 # from request values or be specified in "sub page" form. The plot
520 # thickens, because $wgTitle is altered for special pages, so doesn't
521 # contain the original alias-with-subpage.
522 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
523 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
524 list( $spName, $spPar ) =
525 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
526 $active = $spName == 'Contributions'
527 && ( ( $spPar && $spPar == $this->username
)
528 ||
$wgRequest->getText( 'target' ) == $this->username
);
533 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
534 $personal_urls['mycontris'] = array(
535 'text' => wfMsg( 'mycontris' ),
539 $personal_urls['logout'] = array(
540 'text' => wfMsg( 'userlogout' ),
541 'href' => self
::makeSpecialUrl( 'Userlogout',
542 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
548 $loginlink = $wgUser->isAllowed( 'createaccount' )
549 ?
'nav-login-createaccount'
551 if( $this->showIPinHeader() ) {
552 $href = &$this->userpageUrlDetails
['href'];
553 $personal_urls['anonuserpage'] = array(
554 'text' => $this->username
,
556 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
557 'active' => ( $pageurl == $href )
559 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
560 $href = &$usertalkUrlDetails['href'];
561 $personal_urls['anontalk'] = array(
562 'text' => wfMsg('anontalk'),
564 'class' => $usertalkUrlDetails['exists']?
false:'new',
565 'active' => ( $pageurl == $href )
567 $personal_urls['anonlogin'] = array(
568 'text' => wfMsg( $loginlink ),
569 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
570 'active' => $wgTitle->isSpecial( 'Userlogin' )
574 $personal_urls['login'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
582 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
583 wfProfileOut( $fname );
584 return $personal_urls;
587 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
590 $classes[] = 'selected';
592 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
594 $query = 'action=edit';
597 $text = wfMsg( $message );
598 if ( wfEmptyMsg( $message, $text ) ) {
600 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
604 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
605 $title, $message, $selected, $checkEdit,
606 &$classes, &$query, &$text, &$result)) ) {
611 'class' => implode( ' ', $classes ),
613 'href' => $title->getLocalUrl( $query ) );
616 function makeTalkUrlDetails( $name, $urlaction = '' ) {
617 $title = Title
::newFromText( $name );
618 if( !is_object($title) ) {
619 throw new MWException( __METHOD__
." given invalid pagename $name" );
621 $title = $title->getTalkPage();
622 self
::checkTitle( $title, $name );
624 'href' => $title->getLocalURL( $urlaction ),
625 'exists' => $title->getArticleID() != 0 ?
true : false
629 function makeArticleUrlDetails( $name, $urlaction = '' ) {
630 $title = Title
::newFromText( $name );
631 $title= $title->getSubjectPage();
632 self
::checkTitle( $title, $name );
634 'href' => $title->getLocalURL( $urlaction ),
635 'exists' => $title->getArticleID() != 0 ?
true : false
640 * an array of edit links by default used for the tabs
644 function buildContentActionUrls () {
645 global $wgContLang, $wgLang, $wgOut;
646 $fname = 'SkinTemplate::buildContentActionUrls';
647 wfProfileIn( $fname );
649 global $wgUser, $wgRequest;
650 $action = $wgRequest->getText( 'action' );
651 $section = $wgRequest->getText( 'section' );
652 $content_actions = array();
654 $prevent_active_tabs = false ;
655 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
657 if( $this->iscontent
) {
658 $subjpage = $this->mTitle
->getSubjectPage();
659 $talkpage = $this->mTitle
->getTalkPage();
661 $nskey = $this->mTitle
->getNamespaceKey();
662 $content_actions[$nskey] = $this->tabAction(
665 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
668 $content_actions['talk'] = $this->tabAction(
671 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
675 wfProfileIn( "$fname-edit" );
676 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
677 $istalk = $this->mTitle
->isTalkPage();
678 $istalkclass = $istalk?
' istalk':'';
679 $content_actions['edit'] = array(
680 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
681 'text' => $this->mTitle
->exists()
684 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
687 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
688 $content_actions['addsection'] = array(
689 'class' => $section == 'new'?
'selected':false,
690 'text' => wfMsg('addsection'),
691 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
694 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
695 $content_actions['viewsource'] = array(
696 'class' => ($action == 'edit') ?
'selected' : false,
697 'text' => wfMsg('viewsource'),
698 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
701 wfProfileOut( "$fname-edit" );
703 wfProfileIn( "$fname-live" );
704 if ( $this->mTitle
->getArticleId() ) {
706 $content_actions['history'] = array(
707 'class' => ($action == 'history') ?
'selected' : false,
708 'text' => wfMsg('history_short'),
709 'href' => $this->mTitle
->getLocalUrl( 'action=history')
712 if($wgUser->isAllowed('delete')){
713 $content_actions['delete'] = array(
714 'class' => ($action == 'delete') ?
'selected' : false,
715 'text' => wfMsg('delete'),
716 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
719 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
720 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
721 $content_actions['move'] = array(
722 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
723 'text' => wfMsg('move'),
724 'href' => $moveTitle->getLocalUrl()
728 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
729 if(!$this->mTitle
->isProtected()){
730 $content_actions['protect'] = array(
731 'class' => ($action == 'protect') ?
'selected' : false,
732 'text' => wfMsg('protect'),
733 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
737 $content_actions['unprotect'] = array(
738 'class' => ($action == 'unprotect') ?
'selected' : false,
739 'text' => wfMsg('unprotect'),
740 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
745 //article doesn't exist or is deleted
746 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
747 if( $n = $this->mTitle
->isDeleted() ) {
748 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
749 $content_actions['undelete'] = array(
751 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
752 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
753 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
758 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
759 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
760 $content_actions['protect'] = array(
761 'class' => ($action == 'protect') ?
'selected' : false,
762 'text' => wfMsg('protect'),
763 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
767 $content_actions['unprotect'] = array(
768 'class' => ($action == 'unprotect') ?
'selected' : false,
769 'text' => wfMsg('unprotect'),
770 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
776 wfProfileOut( "$fname-live" );
778 if( $this->loggedin
) {
779 if( !$this->mTitle
->userIsWatching()) {
780 $content_actions['watch'] = array(
781 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
782 'text' => wfMsg('watch'),
783 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
786 $content_actions['unwatch'] = array(
787 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
788 'text' => wfMsg('unwatch'),
789 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
795 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
797 /* show special page tab */
799 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
800 'class' => 'selected',
801 'text' => wfMsg('nstab-special'),
802 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
805 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
808 /* show links to different language variants */
809 global $wgDisableLangConversion;
810 $variants = $wgContLang->getVariants();
811 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
812 $preferred = $wgContLang->getPreferredVariant();
814 foreach( $variants as $code ) {
815 $varname = $wgContLang->getVariantname( $code );
816 if( $varname == 'disable' )
818 $selected = ( $code == $preferred )?
'selected' : false;
819 $content_actions['varlang-' . $vcount] = array(
820 'class' => $selected,
822 'href' => $this->mTitle
->getLocalURL('',$code)
828 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
830 wfProfileOut( $fname );
831 return $content_actions;
837 * build array of common navigation links
841 function buildNavUrls () {
842 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
843 global $wgEnableUploads, $wgUploadNavigationUrl;
845 $fname = 'SkinTemplate::buildNavUrls';
846 wfProfileIn( $fname );
848 $action = $wgRequest->getText( 'action' );
851 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
852 if( $wgEnableUploads ) {
853 if ($wgUploadNavigationUrl) {
854 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
856 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
859 if ($wgUploadNavigationUrl)
860 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
862 $nav_urls['upload'] = false;
864 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
866 // default permalink to being off, will override it as required below.
867 $nav_urls['permalink'] = false;
869 // A print stylesheet is attached to all pages, but nobody ever
870 // figures that out. :) Add a link...
871 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
872 $nav_urls['print'] = array(
873 'text' => wfMsg( 'printableversion' ),
874 'href' => $wgRequest->appendQuery( 'printable=yes' )
877 // Also add a "permalink" while we're at it
878 if ( $this->mRevisionId
) {
879 $nav_urls['permalink'] = array(
880 'text' => wfMsg( 'permalink' ),
881 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
885 // Copy in case this undocumented, shady hook tries to mess with internals
886 $revid = $this->mRevisionId
;
887 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
890 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
891 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
892 $nav_urls['whatlinkshere'] = array(
893 'href' => $wlhTitle->getLocalUrl()
895 if( $this->mTitle
->getArticleId() ) {
896 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
897 $nav_urls['recentchangeslinked'] = array(
898 'href' => $rclTitle->getLocalUrl()
901 $nav_urls['recentchangeslinked'] = false;
903 if ($wgUseTrackbacks)
904 $nav_urls['trackbacklink'] = array(
905 'href' => $wgTitle->trackbackURL()
909 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
910 $id = User
::idFromName($this->mTitle
->getText());
911 $ip = User
::isIP($this->mTitle
->getText());
917 if($id ||
$ip) { # both anons and non-anons have contribs list
918 $nav_urls['contributions'] = array(
919 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
923 $logPage = SpecialPage
::getTitleFor( 'Log' );
924 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
925 . $this->mTitle
->getPartialUrl() ) );
927 $nav_urls['log'] = false;
930 if ( $wgUser->isAllowed( 'block' ) ) {
931 $nav_urls['blockip'] = array(
932 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
935 $nav_urls['blockip'] = false;
938 $nav_urls['contributions'] = false;
939 $nav_urls['log'] = false;
940 $nav_urls['blockip'] = false;
942 $nav_urls['emailuser'] = false;
943 if( $this->showEmailUser( $id ) ) {
944 $nav_urls['emailuser'] = array(
945 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
948 wfProfileOut( $fname );
953 * Generate strings used for xml 'id' names
957 function getNameSpaceKey () {
958 return $this->mTitle
->getNamespaceKey();
964 function setupUserCss() {
965 $fname = 'SkinTemplate::setupUserCss';
966 wfProfileIn( $fname );
968 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
972 $siteargs = '&maxage=' . $wgSquidMaxage;
973 if( $this->loggedin
) {
974 // Ensure that logged-in users' generated CSS isn't clobbered
975 // by anons' publicly cacheable generated CSS.
976 $siteargs .= '&smaxage=0';
979 # Add user-specific code if this is a user and we allow that kind of thing
981 if ( $wgAllowUserCss && $this->loggedin
) {
982 $action = $wgRequest->getText('action');
984 # if we're previewing the CSS page, use it
985 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
986 $siteargs = "&smaxage=0&maxage=0";
987 $usercss = $wgRequest->getText('wpTextbox1');
989 $usercss = '@import "' .
990 self
::makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
991 'action=raw&ctype=text/css') . '";' ."\n";
994 $siteargs .= '&ts=' . $wgUser->mTouched
;
997 if( $wgContLang->isRTL() ) {
998 global $wgStyleVersion;
999 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
1002 # If we use the site's dynamic CSS, throw that in, too
1003 if ( $wgUseSiteCss ) {
1004 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1006 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1007 $skinquery = "&useskin=$us";
1008 $sitecss .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1009 $sitecss .= '@import "' . self
::makeNSUrl( ucfirst( $this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
1010 $sitecss .= '@import "' . self
::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1013 # If we use any dynamic CSS, make a little CDATA block out of it.
1015 if ( !empty($sitecss) ||
!empty($usercss) ) {
1016 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1018 wfProfileOut( $fname );
1024 function setupUserJs( $allowUserJs ) {
1025 $fname = 'SkinTemplate::setupUserJs';
1026 wfProfileIn( $fname );
1028 global $wgRequest, $wgJsMimeType;
1029 $action = $wgRequest->getText('action');
1031 if( $allowUserJs && $this->loggedin
) {
1032 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1033 # XXX: additional security check/prompt?
1034 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1036 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
1039 wfProfileOut( $fname );
1043 * Code for extensions to hook into to provide per-page CSS, see
1044 * extensions/PageCSS/PageCSS.php for an implementation of this.
1048 function setupPageCss() {
1049 $fname = 'SkinTemplate::setupPageCss';
1050 wfProfileIn( $fname );
1052 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1054 wfProfileOut( $fname );
1059 * returns css with user-specific options
1061 public function getUserStylesheet() {
1062 $fname = 'SkinTemplate::getUserStylesheet';
1063 wfProfileIn( $fname );
1065 $s = "/* generated user stylesheet */\n";
1066 $s .= $this->reallyDoGetUserStyles();
1067 wfProfileOut( $fname );
1072 * Returns the print stylesheet for this skin. In all default skins this
1073 * is just commonPrint.css, but third-party skins may want to modify it.
1077 private function getPrintCss() {
1078 global $wgStylePath;
1079 return $wgStylePath . "/common/commonPrint.css";
1083 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1084 * nated together. For some bizarre reason, it does *not* return any
1085 * custom user JS from subpages. Huh?
1087 * There's absolutely no reason to have separate Monobook/Common JSes.
1088 * Any JS that cares can just check the skin variable generated at the
1089 * top. For now Monobook.js will be maintained, but it should be consi-
1094 public function getUserJs() {
1095 $fname = 'SkinTemplate::getUserJs';
1096 wfProfileIn( $fname );
1098 $s = parent
::getUserJs();
1099 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname
).".js (deprecated; migrate to Common.js!) */\n";
1101 // avoid inclusion of non defined user JavaScript (with custom skins only)
1102 // by checking for default message content
1103 $msgKey = ucfirst($this->skinname
).'.js';
1104 $userJS = wfMsgForContent($msgKey);
1105 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1109 wfProfileOut( $fname );
1115 * Generic wrapper for template functions, with interface
1116 * compatible with what we use of PHPTAL 0.7.
1119 class QuickTemplate
{
1123 function QuickTemplate() {
1124 $this->data
= array();
1125 $this->translator
= new MediaWiki_I18N();
1131 function set( $name, $value ) {
1132 $this->data
[$name] = $value;
1138 function setRef($name, &$value) {
1139 $this->data
[$name] =& $value;
1145 function setTranslator( &$t ) {
1146 $this->translator
= &$t;
1152 function execute() {
1153 echo "Override this function.";
1160 function text( $str ) {
1161 echo htmlspecialchars( $this->data
[$str] );
1167 function jstext( $str ) {
1168 echo Xml
::escapeJsString( $this->data
[$str] );
1174 function html( $str ) {
1175 echo $this->data
[$str];
1181 function msg( $str ) {
1182 echo htmlspecialchars( $this->translator
->translate( $str ) );
1188 function msgHtml( $str ) {
1189 echo $this->translator
->translate( $str );
1193 * An ugly, ugly hack.
1196 function msgWiki( $str ) {
1197 global $wgParser, $wgTitle, $wgOut;
1199 $text = $this->translator
->translate( $str );
1200 $parserOutput = $wgParser->parse( $text, $wgTitle,
1201 $wgOut->parserOptions(), true );
1202 echo $parserOutput->getText();
1208 function haveData( $str ) {
1209 return isset( $this->data
[$str] );
1215 function haveMsg( $str ) {
1216 $msg = $this->translator
->translate( $str );
1217 return ($msg != '-') && ($msg != ''); # ????