604425161d829537afd579aecf674bcebb5d010a
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 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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.
30 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
31 * and is optional. You'll need to install PHPTAL manually to use
32 * skins that depend on it.
38 require_once 'GlobalFunctions.php';
41 * Wrapper object for MediaWiki's localization functions,
42 * to be passed to the template engine.
47 class MediaWiki_I18N
{
48 var $_context = array();
50 function set($varName, $value) {
51 $this->_context
[$varName] = $value;
54 function translate($value) {
55 $fname = 'SkinTemplate-translate';
56 wfProfileIn( $fname );
58 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
59 $value = preg_replace( '/^string:/', '', $value );
61 $value = wfMsg( $value );
62 // interpolate variables
63 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
64 list($src, $var) = $m;
66 $varValue = $this->_context
[$var];
68 $value = str_replace($src, $varValue, $value);
70 wfProfileOut( $fname );
79 class SkinTemplate
extends Skin
{
85 * Name of our skin, set in initPage()
86 * It probably need to be all lower case.
91 * Stylesheets set to use
92 * Sub directory in ./skins/ where various stylesheets are located
97 * For QuickTemplate, the name of the subclass which
98 * will actually fill the template.
100 * In PHPTal mode, name of PHPTal template to be used.
101 * '.pt' will be automaticly added to it on PHPTAL object creation
108 * Setup the base parameters...
109 * Child classes should override this to set the name,
110 * style subdirectory, and template filler callback.
112 * @param OutputPage $out
114 function initPage( &$out ) {
115 parent
::initPage( $out );
116 $this->skinname
= 'monobook';
117 $this->stylename
= 'monobook';
118 $this->template
= 'QuickTemplate';
122 * Create the template engine object; we feed it a bunch of data
123 * and eventually it spits out some HTML. Should have interface
124 * roughly equivalent to PHPTAL 0.7.
126 * @param string $callback (or file)
127 * @param string $repository subdirectory where we keep template files
128 * @param string $cache_dir
132 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
133 return new $classname();
137 * initialize various variables and generate the template
139 * @param OutputPage $out
142 function outputPage( &$out ) {
143 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
144 global $wgScript, $wgStylePath, $wgContLanguageCode;
145 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
146 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
147 global $wgMaxCredits, $wgShowCreditsIfMax;
148 global $wgPageShowWatchingUsers;
149 global $wgUseTrackbacks;
152 $fname = 'SkinTemplate::outputPage';
153 wfProfileIn( $fname );
155 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157 wfProfileIn( "$fname-init" );
158 $this->initPage( $out );
160 $this->mTitle
=& $wgTitle;
161 $this->mUser
=& $wgUser;
163 $tpl = $this->setupTemplate( $this->template
, 'skins' );
165 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
166 $tpl->setTranslator(new MediaWiki_I18N());
168 wfProfileOut( "$fname-init" );
170 wfProfileIn( "$fname-stuff" );
171 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
172 $this->thisurl
= $this->mTitle
->getPrefixedURL();
173 $this->loggedin
= $wgUser->isLoggedIn();
174 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
175 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
176 $this->username
= $wgUser->getName();
177 $userPage = $wgUser->getUserPage();
178 $this->userpage
= $userPage->getPrefixedText();
180 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
181 $this->userpageUrlDetails
= $this->makeUrlDetails($this->userpage
);
183 # This won't be used in the standard skins, but we define it to preserve the interface
184 # To save time, we check for existence
185 $this->userpageUrlDetails
= $this->makeKnownUrlDetails($this->userpage
);
188 $this->usercss
= $this->userjs
= $this->userjsprev
= false;
189 $this->setupUserCss();
190 $this->setupUserJs();
191 $this->titletxt
= $this->mTitle
->getPrefixedText();
192 wfProfileOut( "$fname-stuff" );
194 wfProfileIn( "$fname-stuff2" );
195 $tpl->set( 'title', $wgOut->getPageTitle() );
196 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
198 $tpl->setRef( "thispage", $this->thispage
);
199 $subpagestr = $this->subPageSubtitle();
201 'subtitle', !empty($subpagestr)?
202 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
205 $undelete = $this->getUndeleteLink();
207 "undelete", !empty($undelete)?
208 '<span class="subpages">'.$undelete.'</span>':
212 $tpl->set( 'catlinks', $this->getCategories());
213 if( $wgOut->isSyndicated() ) {
215 foreach( $wgFeedClasses as $format => $class ) {
216 $feeds[$format] = array(
218 'href' => $wgRequest->appendQuery( "feed=$format" )
221 $tpl->setRef( 'feeds', $feeds );
223 $tpl->set( 'feeds', false );
225 if ($wgUseTrackbacks && $out->isArticleRelated())
226 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF());
228 $tpl->setRef( 'mimetype', $wgMimeType );
229 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
230 $tpl->setRef( 'charset', $wgOutputEncoding );
231 $tpl->set( 'headlinks', $out->getHeadLinks() );
232 $tpl->set('headscripts', $out->getScript() );
233 $tpl->setRef( 'wgScript', $wgScript );
234 $tpl->setRef( 'skinname', $this->skinname
);
235 $tpl->setRef( 'stylename', $this->stylename
);
236 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
237 $tpl->setRef( 'loggedin', $this->loggedin
);
238 $tpl->set('nsclass', 'ns-'.$this->mTitle
->getNamespace());
239 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
240 /* XXX currently unused, might get useful later
241 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
242 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
243 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
244 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
245 $tpl->set( "helppage", wfMsg('helppage'));
247 $tpl->set( 'searchaction', $this->escapeSearchLink() );
248 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
249 $tpl->setRef( 'stylepath', $wgStylePath );
250 $tpl->setRef( 'logopath', $wgLogo );
251 $tpl->setRef( "lang", $wgContLanguageCode );
252 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
253 $tpl->set( 'rtl', $wgContLang->isRTL() );
254 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
255 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
256 $tpl->setRef( 'username', $this->username
);
257 $tpl->setRef( 'userpage', $this->userpage
);
258 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
259 $tpl->set( 'pagecss', $this->setupPageCss() );
260 $tpl->setRef( 'usercss', $this->usercss
);
261 $tpl->setRef( 'userjs', $this->userjs
);
262 $tpl->setRef( 'userjsprev', $this->userjsprev
);
265 if($this->loggedin
) {
266 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
268 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
271 $tpl->set('jsvarurl', false);
273 $newtalks = $wgUser->getNewMessageLinks();
275 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) {
276 $usertitle = $this->mUser
->getUserPage();
277 $usertalktitle = $usertitle->getTalkPage();
278 if( !$usertalktitle->equals( $this->mTitle
) ) {
279 $ntl = wfMsg( 'youhavenewmessages',
280 $this->makeKnownLinkObj(
282 wfMsgHtml( 'newmessageslink' )
284 $this->makeKnownLinkObj(
286 wfMsgHtml( 'newmessagesdifflink' ),
291 $wgOut->setSquidMaxage(0);
293 } else if (count($newtalks)) {
294 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
296 foreach ($newtalks as $newtalk) {
297 $msgs[] = wfElement("a",
298 array('href' => $newtalk["link"]), $newtalk["wiki"]);
300 $parts = implode($sep, $msgs);
301 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
302 $wgOut->setSquidMaxage(0);
306 wfProfileOut( "$fname-stuff2" );
308 wfProfileIn( "$fname-stuff3" );
309 $tpl->setRef( 'newtalk', $ntl );
310 $tpl->setRef( 'skin', $this);
311 $tpl->set( 'logo', $this->logoText() );
312 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
313 if ( !$wgDisableCounters ) {
314 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
316 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
318 $tpl->set('viewcount', false);
321 $tpl->set('viewcount', false);
324 if ($wgPageShowWatchingUsers) {
325 $dbr =& wfGetDB( DB_SLAVE
);
326 extract( $dbr->tableNames( 'watchlist' ) );
327 $sql = "SELECT COUNT(*) AS n FROM $watchlist
328 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBKey()) .
329 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
330 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
331 $x = $dbr->fetchObject( $res );
332 $numberofwatchingusers = $x->n
;
333 if ($numberofwatchingusers > 0) {
334 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
336 $tpl->set('numberofwatchingusers', false);
339 $tpl->set('numberofwatchingusers', false);
342 $tpl->set('copyright',$this->getCopyright());
344 $this->credits
= false;
346 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
347 require_once("Credits.php");
348 $this->credits
= getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
350 $tpl->set('lastmod', $this->lastModified());
353 $tpl->setRef( 'credits', $this->credits
);
355 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
356 $tpl->set('copyright', $this->getCopyright());
357 $tpl->set('viewcount', false);
358 $tpl->set('lastmod', false);
359 $tpl->set('credits', false);
360 $tpl->set('numberofwatchingusers', false);
362 $tpl->set('copyright', false);
363 $tpl->set('viewcount', false);
364 $tpl->set('lastmod', false);
365 $tpl->set('credits', false);
366 $tpl->set('numberofwatchingusers', false);
368 wfProfileOut( "$fname-stuff3" );
370 wfProfileIn( "$fname-stuff4" );
371 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
372 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
373 $tpl->set( 'disclaimer', $this->disclaimerLink() );
374 $tpl->set( 'privacy', $this->privacyLink() );
375 $tpl->set( 'about', $this->aboutLink() );
377 $tpl->setRef( 'debug', $out->mDebugtext
);
378 $tpl->set( 'reporttime', $out->reportTime() );
379 $tpl->set( 'sitenotice', wfGetSiteNotice() );
381 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
382 $out->mBodytext
.= $printfooter ;
383 $tpl->setRef( 'bodytext', $out->mBodytext
);
386 $language_urls = array();
388 if ( !$wgHideInterlanguageLinks ) {
389 foreach( $wgOut->getLanguageLinks() as $l ) {
390 $tmp = explode( ':', $l, 2 );
391 $class = 'interwiki-' . $tmp[0];
393 $nt = Title
::newFromText( $l );
394 $language_urls[] = array(
395 'href' => $nt->getFullURL(),
396 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
401 if(count($language_urls)) {
402 $tpl->setRef( 'language_urls', $language_urls);
404 $tpl->set('language_urls', false);
406 wfProfileOut( "$fname-stuff4" );
409 $tpl->set('personal_urls', $this->buildPersonalUrls());
410 $content_actions = $this->buildContentActionUrls();
411 $tpl->setRef('content_actions', $content_actions);
413 // XXX: attach this from javascript, same with section editing
414 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
416 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
418 $tpl->set('body_ondblclick', false);
420 if( $this->iseditable
&& $wgUser->getOption( 'editsectiononrightclick' ) ) {
421 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
423 $tpl->set( 'body_onload', false );
425 $tpl->set( 'sidebar', $this->buildSidebar() );
426 $tpl->set( 'nav_urls', $this->buildNavUrls() );
429 wfProfileIn( "$fname-execute" );
430 $res = $tpl->execute();
431 wfProfileOut( "$fname-execute" );
433 // result may be an error
434 $this->printOrError( $res );
435 wfProfileOut( $fname );
439 * Output the string, or print error message if it's
440 * an error object of the appropriate type.
441 * For the base class, assume strings all around.
446 function printOrError( &$str ) {
451 * build array of urls for personal toolbar
455 function buildPersonalUrls() {
456 global $wgTitle, $wgShowIPinHeader, $wgContLang;
458 $fname = 'SkinTemplate::buildPersonalUrls';
459 $pageurl = $wgTitle->getLocalURL();
460 wfProfileIn( $fname );
462 /* set up the default links for the personal toolbar */
463 $personal_urls = array();
464 if ($this->loggedin
) {
465 $personal_urls['userpage'] = array(
466 'text' => $this->username
,
467 'href' => &$this->userpageUrlDetails
['href'],
468 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
469 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
471 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
472 $personal_urls['mytalk'] = array(
473 'text' => wfMsg('mytalk'),
474 'href' => &$usertalkUrlDetails['href'],
475 'class' => $usertalkUrlDetails['exists']?
false:'new',
476 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
478 $href = $this->makeSpecialUrl('Preferences');
479 $personal_urls['preferences'] = array(
480 'text' => wfMsg('preferences'),
481 'href' => $this->makeSpecialUrl('Preferences'),
482 'active' => ( $href == $pageurl )
484 $href = $this->makeSpecialUrl('Watchlist');
485 $personal_urls['watchlist'] = array(
486 'text' => wfMsg('watchlist'),
488 'active' => ( $href == $pageurl )
490 $href = $this->makeSpecialUrl("Contributions/$this->username");
491 $personal_urls['mycontris'] = array(
492 'text' => wfMsg('mycontris'),
494 # FIXME # 'active' => ( $href == $pageurl . '/' . $this->username )
496 $personal_urls['logout'] = array(
497 'text' => wfMsg('userlogout'),
498 'href' => $this->makeSpecialUrl( 'Userlogout',
499 $wgTitle->getNamespace() === NS_SPECIAL
&& $wgTitle->getText() === 'Preferences' ?
'' : "returnto={$this->thisurl}"
503 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
504 $href = &$this->userpageUrlDetails
['href'];
505 $personal_urls['anonuserpage'] = array(
506 'text' => $this->username
,
508 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
509 'active' => ( $pageurl == $href )
511 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
512 $href = &$usertalkUrlDetails['href'];
513 $personal_urls['anontalk'] = array(
514 'text' => wfMsg('anontalk'),
516 'class' => $usertalkUrlDetails['exists']?
false:'new',
517 'active' => ( $pageurl == $href )
519 $personal_urls['anonlogin'] = array(
520 'text' => wfMsg('userlogin'),
521 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
522 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
526 $personal_urls['login'] = array(
527 'text' => wfMsg('userlogin'),
528 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl
),
529 'active' => ( NS_SPECIAL
== $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )
533 wfProfileOut( $fname );
534 return $personal_urls;
538 * Returns true if the IP should be shown in the header
540 function showIPinHeader() {
541 global $wgShowIPinHeader;
542 return $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] );
545 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
548 $classes[] = 'selected';
550 if( $checkEdit && $title->getArticleId() == 0 ) {
552 $query = 'action=edit';
555 $text = wfMsg( $message );
556 if ( $text == "<$message>" ) {
557 $text = html_entity_decode($text);
561 'class' => implode( ' ', $classes ),
563 'href' => $title->getLocalUrl( $query ) );
566 function makeTalkUrlDetails( $name, $urlaction='' ) {
567 $title = Title
::newFromText( $name );
568 $title = $title->getTalkPage();
569 $this->checkTitle($title, $name);
571 'href' => $title->getLocalURL( $urlaction ),
572 'exists' => $title->getArticleID() != 0?
true:false
576 function makeArticleUrlDetails( $name, $urlaction='' ) {
577 $title = Title
::newFromText( $name );
578 $title= $title->getSubjectPage();
579 $this->checkTitle($title, $name);
581 'href' => $title->getLocalURL( $urlaction ),
582 'exists' => $title->getArticleID() != 0?
true:false
587 * an array of edit links by default used for the tabs
591 function buildContentActionUrls () {
592 global $wgContLang, $wgDBprefix;
593 $fname = 'SkinTemplate::buildContentActionUrls';
594 wfProfileIn( $fname );
596 global $wgUser, $wgRequest;
597 $action = $wgRequest->getText( 'action' );
598 $section = $wgRequest->getText( 'section' );
599 $content_actions = array();
601 $prevent_active_tabs = false ;
602 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
604 if( $this->iscontent
) {
605 $subjpage = $this->mTitle
->getSubjectPage();
606 $talkpage = $this->mTitle
->getTalkPage();
608 $nskey = $this->getNameSpaceKey();
609 $content_actions[$nskey] = $this->tabAction(
612 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
615 $content_actions['talk'] = $this->tabAction(
618 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
622 wfProfileIn( "$fname-edit" );
623 if ( $this->mTitle
->userCanEdit() ) {
624 $istalk = $this->mTitle
->isTalkPage();
625 $istalkclass = $istalk?
' istalk':'';
626 $content_actions['edit'] = array(
627 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
628 'text' => wfMsg('edit'),
629 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
633 $content_actions['addsection'] = array(
634 'class' => $section == 'new'?
'selected':false,
635 'text' => wfMsg('addsection'),
636 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
640 $content_actions['viewsource'] = array(
641 'class' => ($action == 'edit') ?
'selected' : false,
642 'text' => wfMsg('viewsource'),
643 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
646 wfProfileOut( "$fname-edit" );
648 wfProfileIn( "$fname-live" );
649 if ( $this->mTitle
->getArticleId() ) {
651 $content_actions['history'] = array(
652 'class' => ($action == 'history') ?
'selected' : false,
653 'text' => wfMsg('history_short'),
654 'href' => $this->mTitle
->getLocalUrl( 'action=history')
657 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
658 if(!$this->mTitle
->isProtected()){
659 $content_actions['protect'] = array(
660 'class' => ($action == 'protect') ?
'selected' : false,
661 'text' => wfMsg('protect'),
662 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
666 $content_actions['unprotect'] = array(
667 'class' => ($action == 'unprotect') ?
'selected' : false,
668 'text' => wfMsg('unprotect'),
669 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
673 if($wgUser->isAllowed('delete')){
674 $content_actions['delete'] = array(
675 'class' => ($action == 'delete') ?
'selected' : false,
676 'text' => wfMsg('delete'),
677 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
680 if ( $this->mTitle
->userCanMove()) {
681 $content_actions['move'] = array(
682 'class' => ($this->mTitle
->getDbKey() == 'Movepage' and $this->mTitle
->getNamespace
== NS_SPECIAL
) ?
'selected' : false,
683 'text' => wfMsg('move'),
684 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
688 //article doesn't exist or is deleted
689 if($wgUser->isAllowed('delete')){
690 if( $n = $this->mTitle
->isDeleted() ) {
691 $content_actions['undelete'] = array(
693 'text' => ($n == 1) ?
wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
694 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
699 wfProfileOut( "$fname-live" );
701 if( $this->loggedin
) {
702 if( !$this->mTitle
->userIsWatching()) {
703 $content_actions['watch'] = array(
704 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
705 'text' => wfMsg('watch'),
706 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
709 $content_actions['unwatch'] = array(
710 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
711 'text' => wfMsg('unwatch'),
712 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
717 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
719 /* show special page tab */
721 $content_actions['article'] = array(
722 'class' => 'selected',
723 'text' => wfMsg('specialpage'),
724 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
727 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
730 /* show links to different language variants */
731 global $wgDisableLangConversion;
732 $variants = $wgContLang->getVariants();
733 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
734 $preferred = $wgContLang->getPreferredVariant();
737 $actstr = 'action=' . $action . '&';
739 foreach( $variants as $code ) {
740 $varname = $wgContLang->getVariantname( $code );
741 if( $varname == 'disable' )
743 $selected = ( $code == $preferred )?
'selected' : false;
744 $content_actions['varlang-' . $vcount] = array(
745 'class' => $selected,
747 'href' => $this->mTitle
->getLocalUrl( $actstr . 'variant=' . $code )
753 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
755 wfProfileOut( $fname );
756 return $content_actions;
762 * build array of common navigation links
766 function buildNavUrls () {
767 global $wgUseTrackbacks, $wgTitle, $wgArticle;
769 $fname = 'SkinTemplate::buildNavUrls';
770 wfProfileIn( $fname );
772 global $wgUser, $wgRequest;
773 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
775 $action = $wgRequest->getText( 'action' );
776 $oldid = $wgRequest->getVal( 'oldid' );
777 $diff = $wgRequest->getVal( 'diff' );
780 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
781 if( $wgEnableUploads ) {
782 if ($wgUploadNavigationUrl) {
783 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
785 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
788 if ($wgUploadNavigationUrl)
789 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
791 $nav_urls['upload'] = false;
793 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
796 // A print stylesheet is attached to all pages, but nobody ever
797 // figures that out. :) Add a link...
798 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
799 $revid = $wgArticle->getRevIdFetched();
800 if ( !( $revid == 0 ) )
801 $nav_urls['print'] = array(
802 'text' => wfMsg( 'printableversion' ),
803 'href' => $wgRequest->appendQuery( 'printable=yes' )
806 // Also add a "permalink" while we're at it
808 $nav_urls['permalink'] = array(
809 'text' => wfMsg( 'permalink' ),
813 if ( !( $revid == 0 ) )
814 $nav_urls['permalink'] = array(
815 'text' => wfMsg( 'permalink' ),
816 'href' => $wgTitle->getLocalURL( "oldid=$revid" )
820 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$oldid, &$revid ) );
823 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
824 $nav_urls['whatlinkshere'] = array(
825 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
827 if( $this->mTitle
->getArticleId() ) {
828 $nav_urls['recentchangeslinked'] = array(
829 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
832 if ($wgUseTrackbacks)
833 $nav_urls['trackbacklink'] = array(
834 'href' => $wgTitle->trackbackURL()
838 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
839 $id = User
::idFromName($this->mTitle
->getText());
840 $ip = User
::isIP($this->mTitle
->getText());
846 if($id ||
$ip) { # both anons and non-anons have contri list
847 $nav_urls['contributions'] = array(
848 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle
->getText() )
850 if ( $wgUser->isAllowed( 'block' ) )
851 $nav_urls['blockip'] = array(
852 'href' => $this->makeSpecialUrl( 'Blockip/' . $this->mTitle
->getText() )
855 $nav_urls['contributions'] = false;
857 $nav_urls['emailuser'] = false;
858 if( $this->showEmailUser( $id ) ) {
859 $nav_urls['emailuser'] = array(
860 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle
->getText() )
863 wfProfileOut( $fname );
868 * Generate strings used for xml 'id' names
872 function getNameSpaceKey () {
873 switch ($this->mTitle
->getNamespace()) {
881 return 'nstab-media';
883 return 'nstab-special';
885 case NS_PROJECT_TALK
:
889 return 'nstab-image';
891 case NS_MEDIAWIKI_TALK
:
892 return 'nstab-mediawiki';
894 case NS_TEMPLATE_TALK
:
895 return 'nstab-template';
900 case NS_CATEGORY_TALK
:
901 return 'nstab-category';
903 return 'nstab-' . strtolower( $this->mTitle
->getSubjectNsText() );
910 function setupUserCss() {
911 $fname = 'SkinTemplate::setupUserCss';
912 wfProfileIn( $fname );
914 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
918 $siteargs = '&maxage=' . $wgSquidMaxage;
920 # Add user-specific code if this is a user and we allow that kind of thing
922 if ( $wgAllowUserCss && $this->loggedin
) {
923 $action = $wgRequest->getText('action');
925 # if we're previewing the CSS page, use it
926 if( $this->mTitle
->isCssSubpage() and $this->userCanPreview( $action ) ) {
927 $siteargs = "&smaxage=0&maxage=0";
928 $usercss = $wgRequest->getText('wpTextbox1');
930 $usercss = '@import "' .
931 $this->makeUrl($this->userpage
. '/'.$this->skinname
.'.css',
932 'action=raw&ctype=text/css') . '";' ."\n";
935 $siteargs .= '&ts=' . $wgUser->mTouched
;
938 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename
. '/rtl.css";' . "\n";
940 # If we use the site's dynamic CSS, throw that in, too
941 if ( $wgUseSiteCss ) {
942 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
943 $sitecss .= '@import "' . $this->makeNSUrl('Common.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
944 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname
) . '.css', $query, NS_MEDIAWIKI
) . '";' . "\n";
945 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
948 # If we use any dynamic CSS, make a little CDATA block out of it.
950 if ( !empty($sitecss) ||
!empty($usercss) ) {
951 $this->usercss
= "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
953 wfProfileOut( $fname );
959 function setupUserJs() {
960 $fname = 'SkinTemplate::setupUserJs';
961 wfProfileIn( $fname );
963 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
964 $action = $wgRequest->getText('action');
966 if( $wgAllowUserJs && $this->loggedin
) {
967 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
968 # XXX: additional security check/prompt?
969 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
971 $this->userjs
= $this->makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
974 wfProfileOut( $fname );
978 * Code for extensions to hook into to provide per-page CSS, see
979 * extensions/PageCSS/PageCSS.php for an implementation of this.
983 function setupPageCss() {
984 $fname = 'SkinTemplate::setupPageCss';
985 wfProfileIn( $fname );
987 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
989 wfProfileOut( $fname );
994 * returns css with user-specific options
998 function getUserStylesheet() {
999 $fname = 'SkinTemplate::getUserStylesheet';
1000 wfProfileIn( $fname );
1003 $s = "/* generated user stylesheet */\n";
1004 $s .= $this->reallyDoGetUserStyles();
1005 wfProfileOut( $fname );
1012 function getUserJs() {
1013 $fname = 'SkinTemplate::getUserJs';
1014 wfProfileIn( $fname );
1016 global $wgStylePath;
1017 $s = '/* generated javascript */';
1018 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
1019 $s .= '/* MediaWiki:'.ucfirst($this->skinname
)." */\n";
1021 // avoid inclusion of non defined user JavaScript (with custom skins only)
1022 // by checking for default message content
1023 $msgKey = ucfirst($this->skinname
).'.js';
1024 $userJS = wfMsg($msgKey);
1025 if ('<'.$msgKey.'>' != $userJS) {
1029 wfProfileOut( $fname );
1035 * Generic wrapper for template functions, with interface
1036 * compatible with what we use of PHPTAL 0.7.
1037 * @package MediaWiki
1040 class QuickTemplate
{
1044 function QuickTemplate() {
1045 $this->data
= array();
1046 $this->translator
= new MediaWiki_I18N();
1052 function set( $name, $value ) {
1053 $this->data
[$name] = $value;
1059 function setRef($name, &$value) {
1060 $this->data
[$name] =& $value;
1066 function setTranslator( &$t ) {
1067 $this->translator
= &$t;
1073 function execute() {
1074 echo "Override this function.";
1081 function text( $str ) {
1082 echo htmlspecialchars( $this->data
[$str] );
1088 function html( $str ) {
1089 echo $this->data
[$str];
1095 function msg( $str ) {
1096 echo htmlspecialchars( $this->translator
->translate( $str ) );
1102 function msgHtml( $str ) {
1103 echo $this->translator
->translate( $str );
1107 * An ugly, ugly hack.
1110 function msgWiki( $str ) {
1111 global $wgParser, $wgTitle, $wgOut;
1113 $text = $this->translator
->translate( $str );
1114 $parserOutput = $wgParser->parse( $text, $wgTitle,
1115 $wgOut->mParserOptions
, true );
1116 echo $parserOutput->getText();
1122 function haveData( $str ) {
1123 return $this->data
[$str];
1129 function haveMsg( $str ) {
1130 $msg = $this->translator
->translate( $str );
1131 return ($msg != '-') && ($msg != ''); # ????