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 wfProfileIn( __METHOD__
);
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
40 $value = wfMsg( $value );
41 // interpolate variables
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
46 $varValue = $this->_context
[$var];
48 $value = str_replace($src, $varValue, $value);
50 wfProfileOut( __METHOD__
);
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
67 class SkinTemplate
extends Skin
{
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
97 * @param $out OutputPage
99 function initPage( OutputPage
$out ) {
100 parent
::initPage( $out );
101 $this->skinname
= 'monobook';
102 $this->stylename
= 'monobook';
103 $this->template
= 'QuickTemplate';
107 * Add specific styles for this skin
109 * @param $out OutputPage
111 function setupSkinUserCss( OutputPage
$out ){
112 $out->addStyle( 'common/shared.css', 'screen' );
113 $out->addStyle( 'common/commonPrint.css', 'print' );
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
121 * @param $callback string (or file)
122 * @param $repository string: subdirectory where we keep template files
123 * @param $cache_dir string
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
132 * initialize various variables and generate the template
134 * @param $out OutputPage
136 function outputPage( OutputPage
$out ) {
137 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang;
138 global $wgScript, $wgStylePath, $wgContLanguageCode;
139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
141 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
142 global $wgMaxCredits, $wgShowCreditsIfMax;
143 global $wgPageShowWatchingUsers;
144 global $wgUseTrackbacks, $wgUseSiteJs;
145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
147 wfProfileIn( __METHOD__
);
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151 $action = $wgRequest->getVal( 'action', 'view' );
153 wfProfileIn( __METHOD__
."-init" );
154 $this->initPage( $out );
157 $tpl = $this->setupTemplate( $this->template
, 'skins' );
159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
160 $tpl->setTranslator(new MediaWiki_I18N());
162 wfProfileOut( __METHOD__
."-init" );
164 wfProfileIn( __METHOD__
."-stuff" );
165 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
166 $this->thisurl
= $this->mTitle
->getPrefixedURL();
167 $this->loggedin
= $wgUser->isLoggedIn();
168 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
169 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
170 $this->username
= $wgUser->getName();
172 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
173 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
175 # This won't be used in the standard skins, but we define it to preserve the interface
176 # To save time, we check for existence
177 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
180 $this->userjs
= $this->userjsprev
= false;
181 $this->setupUserCss( $out );
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt
= $this->mTitle
->getPrefixedText();
184 wfProfileOut( __METHOD__
."-stuff" );
186 wfProfileIn( __METHOD__
."-stuff2" );
187 $tpl->set( 'title', $out->getPageTitle() );
188 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
190 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
191 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer
::escapeClass( $this->getSkinName ( ) ) ) );
193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
194 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
195 $this->mTitle
->getNsText();
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle
->getText() );
201 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
202 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
204 $tpl->set( 'isarticle', $out->isArticle() );
206 $tpl->setRef( "thispage", $this->thispage
);
207 $subpagestr = $this->subPageSubtitle();
209 'subtitle', !empty($subpagestr)?
210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
213 $undelete = $this->getUndeleteLink();
215 "undelete", !empty($undelete)?
216 '<span class="subpages">'.$undelete.'</span>':
220 $tpl->set( 'catlinks', $this->getCategories());
221 if( $out->isSyndicated() ) {
223 foreach( $out->getSyndicationLinks() as $format => $link ) {
224 $feeds[$format] = array(
225 'text' => wfMsg( "feed-$format" ),
228 $tpl->setRef( 'feeds', $feeds );
230 $tpl->set( 'feeds', false );
232 if ($wgUseTrackbacks && $out->isArticleRelated()) {
233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
235 $tpl->set( 'trackbackhtml', null );
238 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
239 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
240 $tpl->setRef( 'mimetype', $wgMimeType );
241 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
242 $tpl->setRef( 'charset', $wgOutputEncoding );
243 $tpl->set( 'headlinks', $out->getHeadLinks() );
244 $tpl->set( 'headscripts', $out->getScript() );
245 $tpl->set( 'csslinks', $out->buildCssLinks() );
246 $tpl->setRef( 'wgScript', $wgScript );
247 $tpl->setRef( 'skinname', $this->skinname
);
248 $tpl->set( 'skinclass', get_class( $this ) );
249 $tpl->setRef( 'stylename', $this->stylename
);
250 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
251 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
252 $tpl->setRef( 'loggedin', $this->loggedin
);
253 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
254 /* XXX currently unused, might get useful later
255 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
256 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
257 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
258 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
259 $tpl->set( "helppage", wfMsg('helppage'));
261 $tpl->set( 'searchaction', $this->escapeSearchLink() );
262 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
263 $tpl->setRef( 'stylepath', $wgStylePath );
264 $tpl->setRef( 'articlepath', $wgArticlePath );
265 $tpl->setRef( 'scriptpath', $wgScriptPath );
266 $tpl->setRef( 'serverurl', $wgServer );
267 $tpl->setRef( 'logopath', $wgLogo );
268 $tpl->setRef( "lang", $wgContLanguageCode );
269 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
270 $tpl->set( 'rtl', $wgContLang->isRTL() );
271 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
272 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
273 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
274 $tpl->setRef( 'userpage', $this->userpage
);
275 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
276 $tpl->set( 'userlang', $wgLang->getCode() );
277 $tpl->set( 'pagecss', $this->setupPageCss() );
278 $tpl->setRef( 'usercss', $this->usercss
);
279 $tpl->setRef( 'userjs', $this->userjs
);
280 $tpl->setRef( 'userjsprev', $this->userjsprev
);
282 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
283 $tpl->set( 'jsvarurl',
285 "action=raw$jsCache&gen=js&useskin=" .
286 urlencode( $this->getSkinName() ) ) );
288 $tpl->set('jsvarurl', false);
290 $newtalks = $wgUser->getNewMessageLinks();
292 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
293 $usertitle = $this->mUser
->getUserPage();
294 $usertalktitle = $usertitle->getTalkPage();
295 if( !$usertalktitle->equals( $this->mTitle
) ) {
296 $ntl = wfMsg( 'youhavenewmessages',
297 $this->makeKnownLinkObj(
299 wfMsgHtml( 'newmessageslink' ),
302 $this->makeKnownLinkObj(
304 wfMsgHtml( 'newmessagesdifflink' ),
309 $out->setSquidMaxage(0);
311 } else if (count($newtalks)) {
312 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
314 foreach ($newtalks as $newtalk) {
315 $msgs[] = Xml
::element("a",
316 array('href' => $newtalk["link"]), $newtalk["wiki"]);
318 $parts = implode($sep, $msgs);
319 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
320 $out->setSquidMaxage(0);
324 wfProfileOut( __METHOD__
."-stuff2" );
326 wfProfileIn( __METHOD__
."-stuff3" );
327 $tpl->setRef( 'newtalk', $ntl );
328 $tpl->setRef( 'skin', $this );
329 $tpl->set( 'logo', $this->logoText() );
330 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
331 $wgArticle and 0 != $wgArticle->getID() )
333 if ( !$wgDisableCounters ) {
334 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
336 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
338 $tpl->set('viewcount', false);
341 $tpl->set('viewcount', false);
344 if ($wgPageShowWatchingUsers) {
345 $dbr = wfGetDB( DB_SLAVE
);
346 $watchlist = $dbr->tableName( 'watchlist' );
347 $sql = "SELECT COUNT(*) AS n FROM $watchlist
348 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
349 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
350 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
351 $x = $dbr->fetchObject( $res );
352 $numberofwatchingusers = $x->n
;
353 if ($numberofwatchingusers > 0) {
354 $tpl->set('numberofwatchingusers',
355 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
356 $wgLang->formatNum($numberofwatchingusers))
359 $tpl->set('numberofwatchingusers', false);
362 $tpl->set('numberofwatchingusers', false);
365 $tpl->set('copyright',$this->getCopyright());
367 $this->credits
= false;
369 if( $wgMaxCredits != 0 ){
370 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
372 $tpl->set( 'lastmod', $this->lastModified() );
375 $tpl->setRef( 'credits', $this->credits
);
377 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
378 $tpl->set('copyright', $this->getCopyright());
379 $tpl->set('viewcount', false);
380 $tpl->set('lastmod', false);
381 $tpl->set('credits', false);
382 $tpl->set('numberofwatchingusers', false);
384 $tpl->set('copyright', false);
385 $tpl->set('viewcount', false);
386 $tpl->set('lastmod', false);
387 $tpl->set('credits', false);
388 $tpl->set('numberofwatchingusers', false);
390 wfProfileOut( __METHOD__
."-stuff3" );
392 wfProfileIn( __METHOD__
."-stuff4" );
393 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
394 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
395 $tpl->set( 'disclaimer', $this->disclaimerLink() );
396 $tpl->set( 'privacy', $this->privacyLink() );
397 $tpl->set( 'about', $this->aboutLink() );
399 $tpl->setRef( 'debug', $out->mDebugtext
);
400 $tpl->set( 'reporttime', wfReportTime() );
401 $tpl->set( 'sitenotice', wfGetSiteNotice() );
402 $tpl->set( 'bottomscripts', $this->bottomScripts() );
404 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
405 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
406 $tpl->setRef( 'bodytext', $out->mBodytext
);
409 $language_urls = array();
411 if ( !$wgHideInterlanguageLinks ) {
412 foreach( $out->getLanguageLinks() as $l ) {
413 $tmp = explode( ':', $l, 2 );
414 $class = 'interwiki-' . $tmp[0];
416 $nt = Title
::newFromText( $l );
418 $language_urls[] = array(
419 'href' => $nt->getFullURL(),
420 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?
$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
426 if(count($language_urls)) {
427 $tpl->setRef( 'language_urls', $language_urls);
429 $tpl->set('language_urls', false);
431 wfProfileOut( __METHOD__
."-stuff4" );
433 wfProfileIn( __METHOD__
."-stuff5" );
435 $tpl->set('personal_urls', $this->buildPersonalUrls());
436 $content_actions = $this->buildContentActionUrls();
437 $tpl->setRef('content_actions', $content_actions);
439 // XXX: attach this from javascript, same with section editing
440 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
442 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
443 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
445 $tpl->set('body_ondblclick', false);
447 $tpl->set( 'body_onload', false );
448 $tpl->set( 'sidebar', $this->buildSidebar() );
449 $tpl->set( 'nav_urls', $this->buildNavUrls() );
451 // original version by hansm
452 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
453 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
456 // allow extensions adding stuff after the page content.
457 // See Skin::afterContentHook() for further documentation.
458 $tpl->set ('dataAfterContent', $this->afterContentHook());
459 wfProfileOut( __METHOD__
."-stuff5" );
462 wfProfileIn( __METHOD__
."-execute" );
463 $res = $tpl->execute();
464 wfProfileOut( __METHOD__
."-execute" );
466 // result may be an error
467 $this->printOrError( $res );
468 wfProfileOut( __METHOD__
);
472 * Output the string, or print error message if it's
473 * an error object of the appropriate type.
474 * For the base class, assume strings all around.
479 function printOrError( $str ) {
484 * build array of urls for personal toolbar
488 function buildPersonalUrls() {
489 global $wgTitle, $wgRequest;
491 $pageurl = $wgTitle->getLocalURL();
492 wfProfileIn( __METHOD__
);
494 /* set up the default links for the personal toolbar */
495 $personal_urls = array();
496 if ($this->loggedin
) {
497 $personal_urls['userpage'] = array(
498 'text' => $this->username
,
499 'href' => &$this->userpageUrlDetails
['href'],
500 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
501 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
503 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
504 $personal_urls['mytalk'] = array(
505 'text' => wfMsg('mytalk'),
506 'href' => &$usertalkUrlDetails['href'],
507 'class' => $usertalkUrlDetails['exists']?
false:'new',
508 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
510 $href = self
::makeSpecialUrl( 'Preferences' );
511 $personal_urls['preferences'] = array(
512 'text' => wfMsg( 'mypreferences' ),
514 'active' => ( $href == $pageurl )
516 $href = self
::makeSpecialUrl( 'Watchlist' );
517 $personal_urls['watchlist'] = array(
518 'text' => wfMsg( 'mywatchlist' ),
520 'active' => ( $href == $pageurl )
523 # We need to do an explicit check for Special:Contributions, as we
524 # have to match both the title, and the target (which could come
525 # from request values or be specified in "sub page" form. The plot
526 # thickens, because $wgTitle is altered for special pages, so doesn't
527 # contain the original alias-with-subpage.
528 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
529 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
530 list( $spName, $spPar ) =
531 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
532 $active = $spName == 'Contributions'
533 && ( ( $spPar && $spPar == $this->username
)
534 ||
$wgRequest->getText( 'target' ) == $this->username
);
539 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
540 $personal_urls['mycontris'] = array(
541 'text' => wfMsg( 'mycontris' ),
545 $personal_urls['logout'] = array(
546 'text' => wfMsg( 'userlogout' ),
547 'href' => self
::makeSpecialUrl( 'Userlogout',
548 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
554 $loginlink = $wgUser->isAllowed( 'createaccount' )
555 ?
'nav-login-createaccount'
557 if( $this->showIPinHeader() ) {
558 $href = &$this->userpageUrlDetails
['href'];
559 $personal_urls['anonuserpage'] = array(
560 'text' => $this->username
,
562 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
563 'active' => ( $pageurl == $href )
565 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
566 $href = &$usertalkUrlDetails['href'];
567 $personal_urls['anontalk'] = array(
568 'text' => wfMsg('anontalk'),
570 'class' => $usertalkUrlDetails['exists']?
false:'new',
571 'active' => ( $pageurl == $href )
573 $personal_urls['anonlogin'] = array(
574 'text' => wfMsg( $loginlink ),
575 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
576 'active' => $wgTitle->isSpecial( 'Userlogin' )
580 $personal_urls['login'] = array(
581 'text' => wfMsg( $loginlink ),
582 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
583 'active' => $wgTitle->isSpecial( 'Userlogin' )
588 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
589 wfProfileOut( __METHOD__
);
590 return $personal_urls;
593 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
596 $classes[] = 'selected';
598 if( $checkEdit && !$title->isKnown() ) {
600 $query = 'action=edit&redlink=1';
603 $text = wfMsg( $message );
604 if ( wfEmptyMsg( $message, $text ) ) {
606 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
610 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
611 $title, $message, $selected, $checkEdit,
612 &$classes, &$query, &$text, &$result)) ) {
617 'class' => implode( ' ', $classes ),
619 'href' => $title->getLocalUrl( $query ) );
622 function makeTalkUrlDetails( $name, $urlaction = '' ) {
623 $title = Title
::newFromText( $name );
624 if( !is_object($title) ) {
625 throw new MWException( __METHOD__
." given invalid pagename $name" );
627 $title = $title->getTalkPage();
628 self
::checkTitle( $title, $name );
630 'href' => $title->getLocalURL( $urlaction ),
631 'exists' => $title->getArticleID() != 0 ?
true : false
635 function makeArticleUrlDetails( $name, $urlaction = '' ) {
636 $title = Title
::newFromText( $name );
637 $title= $title->getSubjectPage();
638 self
::checkTitle( $title, $name );
640 'href' => $title->getLocalURL( $urlaction ),
641 'exists' => $title->getArticleID() != 0 ?
true : false
646 * an array of edit links by default used for the tabs
650 function buildContentActionUrls() {
651 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
653 wfProfileIn( __METHOD__
);
655 $action = $wgRequest->getVal( 'action', 'view' );
656 $section = $wgRequest->getVal( 'section' );
657 $content_actions = array();
659 $prevent_active_tabs = false ;
660 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
662 if( $this->iscontent
) {
663 $subjpage = $this->mTitle
->getSubjectPage();
664 $talkpage = $this->mTitle
->getTalkPage();
666 $nskey = $this->mTitle
->getNamespaceKey();
667 $content_actions[$nskey] = $this->tabAction(
670 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
673 $content_actions['talk'] = $this->tabAction(
676 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
680 wfProfileIn( __METHOD__
."-edit" );
681 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
682 $istalk = $this->mTitle
->isTalkPage();
683 $istalkclass = $istalk?
' istalk':'';
684 $content_actions['edit'] = array(
685 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
686 'text' => $this->mTitle
->exists()
689 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
692 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
693 if ( !$wgOut->forceHideNewSectionLink() ) {
694 $content_actions['addsection'] = array(
695 'class' => $section == 'new' ?
'selected' : false,
696 'text' => wfMsg('addsection'),
697 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
701 } elseif ( $this->mTitle
->isKnown() ) {
702 $content_actions['viewsource'] = array(
703 'class' => ($action == 'edit') ?
'selected' : false,
704 'text' => wfMsg('viewsource'),
705 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
708 wfProfileOut( __METHOD__
."-edit" );
710 wfProfileIn( __METHOD__
."-live" );
711 if ( $this->mTitle
->exists() ) {
713 $content_actions['history'] = array(
714 'class' => ($action == 'history') ?
'selected' : false,
715 'text' => wfMsg('history_short'),
716 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
720 if( $wgUser->isAllowed('delete') ) {
721 $content_actions['delete'] = array(
722 'class' => ($action == 'delete') ?
'selected' : false,
723 'text' => wfMsg('delete'),
724 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
727 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
728 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
729 $content_actions['move'] = array(
730 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
731 'text' => wfMsg('move'),
732 'href' => $moveTitle->getLocalUrl()
736 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
737 if( !$this->mTitle
->isProtected() ){
738 $content_actions['protect'] = array(
739 'class' => ($action == 'protect') ?
'selected' : false,
740 'text' => wfMsg('protect'),
741 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
745 $content_actions['unprotect'] = array(
746 'class' => ($action == 'unprotect') ?
'selected' : false,
747 'text' => wfMsg('unprotect'),
748 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
753 //article doesn't exist or is deleted
754 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
755 if( $n = $this->mTitle
->isDeleted() ) {
756 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
757 $content_actions['undelete'] = array(
759 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
760 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
761 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
766 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
767 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
768 $content_actions['protect'] = array(
769 'class' => ($action == 'protect') ?
'selected' : false,
770 'text' => wfMsg('protect'),
771 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
775 $content_actions['unprotect'] = array(
776 'class' => ($action == 'unprotect') ?
'selected' : false,
777 'text' => wfMsg('unprotect'),
778 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
784 wfProfileOut( __METHOD__
."-live" );
786 if( $this->loggedin
) {
787 if( !$this->mTitle
->userIsWatching()) {
788 $content_actions['watch'] = array(
789 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
790 'text' => wfMsg('watch'),
791 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
794 $content_actions['unwatch'] = array(
795 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
796 'text' => wfMsg('unwatch'),
797 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
803 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
805 /* show special page tab */
807 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
808 'class' => 'selected',
809 'text' => wfMsg('nstab-special'),
810 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
813 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
816 /* show links to different language variants */
817 global $wgDisableLangConversion;
818 $variants = $wgContLang->getVariants();
819 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
820 $preferred = $wgContLang->getPreferredVariant();
822 foreach( $variants as $code ) {
823 $varname = $wgContLang->getVariantname( $code );
824 if( $varname == 'disable' )
826 $selected = ( $code == $preferred )?
'selected' : false;
827 $content_actions['varlang-' . $vcount] = array(
828 'class' => $selected,
830 'href' => $this->mTitle
->getLocalURL('',$code)
836 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
838 wfProfileOut( __METHOD__
);
839 return $content_actions;
845 * build array of common navigation links
849 function buildNavUrls() {
850 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
851 global $wgEnableUploads, $wgUploadNavigationUrl;
853 wfProfileIn( __METHOD__
);
855 $action = $wgRequest->getVal( 'action', 'view' );
858 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
859 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
860 if ($wgUploadNavigationUrl) {
861 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
863 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
866 if ($wgUploadNavigationUrl)
867 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
869 $nav_urls['upload'] = false;
871 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
873 // default permalink to being off, will override it as required below.
874 $nav_urls['permalink'] = false;
876 // A print stylesheet is attached to all pages, but nobody ever
877 // figures that out. :) Add a link...
878 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
879 $nav_urls['print'] = array(
880 'text' => wfMsg( 'printableversion' ),
881 'href' => $wgRequest->appendQuery( 'printable=yes' )
884 // Also add a "permalink" while we're at it
885 if ( $this->mRevisionId
) {
886 $nav_urls['permalink'] = array(
887 'text' => wfMsg( 'permalink' ),
888 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
892 // Copy in case this undocumented, shady hook tries to mess with internals
893 $revid = $this->mRevisionId
;
894 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
897 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
898 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
899 $nav_urls['whatlinkshere'] = array(
900 'href' => $wlhTitle->getLocalUrl()
902 if( $this->mTitle
->getArticleId() ) {
903 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
904 $nav_urls['recentchangeslinked'] = array(
905 'href' => $rclTitle->getLocalUrl()
908 $nav_urls['recentchangeslinked'] = false;
910 if ($wgUseTrackbacks)
911 $nav_urls['trackbacklink'] = array(
912 'href' => $wgTitle->trackbackURL()
916 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
917 $id = User
::idFromName($this->mTitle
->getText());
918 $ip = User
::isIP($this->mTitle
->getText());
924 if($id ||
$ip) { # both anons and non-anons have contribs list
925 $nav_urls['contributions'] = array(
926 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
930 $logPage = SpecialPage
::getTitleFor( 'Log' );
931 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
932 . $this->mTitle
->getPartialUrl() ) );
934 $nav_urls['log'] = false;
937 if ( $wgUser->isAllowed( 'block' ) ) {
938 $nav_urls['blockip'] = array(
939 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
942 $nav_urls['blockip'] = false;
945 $nav_urls['contributions'] = false;
946 $nav_urls['log'] = false;
947 $nav_urls['blockip'] = false;
949 $nav_urls['emailuser'] = false;
950 if( $this->showEmailUser( $id ) ) {
951 $nav_urls['emailuser'] = array(
952 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
955 wfProfileOut( __METHOD__
);
960 * Generate strings used for xml 'id' names
964 function getNameSpaceKey() {
965 return $this->mTitle
->getNamespaceKey();
971 function setupUserJs( $allowUserJs ) {
972 global $wgRequest, $wgJsMimeType;
974 wfProfileIn( __METHOD__
);
976 $action = $wgRequest->getVal( 'action', 'view' );
978 if( $allowUserJs && $this->loggedin
) {
979 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
980 # XXX: additional security check/prompt?
981 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
983 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
986 wfProfileOut( __METHOD__
);
990 * Code for extensions to hook into to provide per-page CSS, see
991 * extensions/PageCSS/PageCSS.php for an implementation of this.
995 function setupPageCss() {
996 wfProfileIn( __METHOD__
);
998 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
999 wfProfileOut( __METHOD__
);
1005 * Generic wrapper for template functions, with interface
1006 * compatible with what we use of PHPTAL 0.7.
1009 class QuickTemplate
{
1013 function QuickTemplate() {
1014 $this->data
= array();
1015 $this->translator
= new MediaWiki_I18N();
1021 function set( $name, $value ) {
1022 $this->data
[$name] = $value;
1028 function setRef($name, &$value) {
1029 $this->data
[$name] =& $value;
1035 function setTranslator( &$t ) {
1036 $this->translator
= &$t;
1042 function execute() {
1043 echo "Override this function.";
1050 function text( $str ) {
1051 echo htmlspecialchars( $this->data
[$str] );
1057 function jstext( $str ) {
1058 echo Xml
::escapeJsString( $this->data
[$str] );
1064 function html( $str ) {
1065 echo $this->data
[$str];
1071 function msg( $str ) {
1072 echo htmlspecialchars( $this->translator
->translate( $str ) );
1078 function msgHtml( $str ) {
1079 echo $this->translator
->translate( $str );
1083 * An ugly, ugly hack.
1086 function msgWiki( $str ) {
1087 global $wgParser, $wgTitle, $wgOut;
1089 $text = $this->translator
->translate( $str );
1090 $parserOutput = $wgParser->parse( $text, $wgTitle,
1091 $wgOut->parserOptions(), true );
1092 echo $parserOutput->getText();
1098 function haveData( $str ) {
1099 return isset( $this->data
[$str] );
1105 function haveMsg( $str ) {
1106 $msg = $this->translator
->translate( $str );
1107 return ($msg != '-') && ($msg != ''); # ????