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, $action, $wgFeedClasses, $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' );
152 wfProfileIn( __METHOD__
."-init" );
153 $this->initPage( $out );
156 $tpl = $this->setupTemplate( $this->template
, 'skins' );
158 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
159 $tpl->setTranslator(new MediaWiki_I18N());
161 wfProfileOut( __METHOD__
."-init" );
163 wfProfileIn( __METHOD__
."-stuff" );
164 $this->thispage
= $this->mTitle
->getPrefixedDbKey();
165 $this->thisurl
= $this->mTitle
->getPrefixedURL();
166 $this->loggedin
= $wgUser->isLoggedIn();
167 $this->iscontent
= ($this->mTitle
->getNamespace() != NS_SPECIAL
);
168 $this->iseditable
= ($this->iscontent
and !($action == 'edit' or $action == 'submit'));
169 $this->username
= $wgUser->getName();
171 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
172 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
174 # This won't be used in the standard skins, but we define it to preserve the interface
175 # To save time, we check for existence
176 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
179 $this->userjs
= $this->userjsprev
= false;
180 $this->setupUserCss( $out );
181 $this->setupUserJs( $out->isUserJsAllowed() );
182 $this->titletxt
= $this->mTitle
->getPrefixedText();
183 wfProfileOut( __METHOD__
."-stuff" );
185 wfProfileIn( __METHOD__
."-stuff2" );
186 $tpl->set( 'title', $out->getPageTitle() );
187 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
188 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
189 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
190 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer
::escapeClass( $this->getSkinName ( ) ) ) );
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
194 $this->mTitle
->getNsText();
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle
->getText() );
200 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
203 $tpl->set( 'isarticle', $out->isArticle() );
205 $tpl->setRef( "thispage", $this->thispage
);
207 $undelete = $this->getUndeleteLink();
209 "undelete", !empty($undelete)?
210 '<span class="subpages">'.$undelete.'</span>':
214 $tpl->set( 'catlinks', $this->getCategories());
215 if( $out->isSyndicated() ) {
217 foreach( $out->getSyndicationLinks() as $format => $link ) {
218 $feeds[$format] = array(
219 'text' => wfMsg( "feed-$format" ),
222 $tpl->setRef( 'feeds', $feeds );
224 $tpl->set( 'feeds', false );
226 if ($wgUseTrackbacks && $out->isArticleRelated()) {
227 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
229 $tpl->set( 'trackbackhtml', null );
232 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
233 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
234 $tpl->setRef( 'mimetype', $wgMimeType );
235 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
236 $tpl->setRef( 'charset', $wgOutputEncoding );
237 $tpl->set( 'headlinks', $out->getHeadLinks() );
238 $tpl->set( 'headscripts', $out->getScript() );
239 $tpl->set( 'csslinks', $out->buildCssLinks() );
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->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
246 $tpl->setRef( 'loggedin', $this->loggedin
);
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->setRef( 'usercss', $this->usercss
);
273 $tpl->setRef( 'userjs', $this->userjs
);
274 $tpl->setRef( 'userjsprev', $this->userjsprev
);
276 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
277 $tpl->set( 'jsvarurl',
279 "action=raw$jsCache&gen=js&useskin=" .
280 urlencode( $this->getSkinName() ) ) );
282 $tpl->set('jsvarurl', false);
284 $newtalks = $wgUser->getNewMessageLinks();
286 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
287 $usertitle = $this->mUser
->getUserPage();
288 $usertalktitle = $usertitle->getTalkPage();
289 if( !$usertalktitle->equals( $this->mTitle
) ) {
290 $ntl = wfMsg( 'youhavenewmessages',
291 $this->makeKnownLinkObj(
293 wfMsgHtml( 'newmessageslink' ),
296 $this->makeKnownLinkObj(
298 wfMsgHtml( 'newmessagesdifflink' ),
303 $out->setSquidMaxage(0);
305 } else if (count($newtalks)) {
306 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
308 foreach ($newtalks as $newtalk) {
309 $msgs[] = wfElement("a",
310 array('href' => $newtalk["link"]), $newtalk["wiki"]);
312 $parts = implode($sep, $msgs);
313 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
314 $out->setSquidMaxage(0);
318 wfProfileOut( __METHOD__
."-stuff2" );
320 wfProfileIn( __METHOD__
."-stuff3" );
321 $tpl->setRef( 'newtalk', $ntl );
322 $tpl->setRef( 'skin', $this );
323 $tpl->set( 'logo', $this->logoText() );
324 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
325 $wgArticle and 0 != $wgArticle->getID() )
327 if ( !$wgDisableCounters ) {
328 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
330 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
332 $tpl->set('viewcount', false);
335 $tpl->set('viewcount', false);
338 if ($wgPageShowWatchingUsers) {
339 $dbr = wfGetDB( DB_SLAVE
);
340 $watchlist = $dbr->tableName( 'watchlist' );
341 $sql = "SELECT COUNT(*) AS n FROM $watchlist
342 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
343 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
344 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
345 $x = $dbr->fetchObject( $res );
346 $numberofwatchingusers = $x->n
;
347 if ($numberofwatchingusers > 0) {
348 $tpl->set('numberofwatchingusers',
349 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
350 $wgLang->formatNum($numberofwatchingusers))
353 $tpl->set('numberofwatchingusers', false);
356 $tpl->set('numberofwatchingusers', false);
359 $tpl->set('copyright',$this->getCopyright());
361 $this->credits
= false;
363 if( $wgMaxCredits != 0 ){
364 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
366 $tpl->set( 'lastmod', $this->lastModified() );
369 $tpl->setRef( 'credits', $this->credits
);
371 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
372 $tpl->set('copyright', $this->getCopyright());
373 $tpl->set('viewcount', false);
374 $tpl->set('lastmod', false);
375 $tpl->set('credits', false);
376 $tpl->set('numberofwatchingusers', false);
378 $tpl->set('copyright', false);
379 $tpl->set('viewcount', false);
380 $tpl->set('lastmod', false);
381 $tpl->set('credits', false);
382 $tpl->set('numberofwatchingusers', false);
384 wfProfileOut( __METHOD__
."-stuff3" );
386 wfProfileIn( __METHOD__
."-stuff4" );
387 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
388 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
389 $tpl->set( 'disclaimer', $this->disclaimerLink() );
390 $tpl->set( 'privacy', $this->privacyLink() );
391 $tpl->set( 'about', $this->aboutLink() );
393 $tpl->setRef( 'debug', $out->mDebugtext
);
394 $tpl->set( 'reporttime', wfReportTime() );
395 $tpl->set( 'sitenotice', wfGetSiteNotice() );
396 $tpl->set( 'bottomscripts', $this->bottomScripts() );
398 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
399 $out->mBodytext
.= $printfooter ;
400 $tpl->setRef( 'bodytext', $out->mBodytext
);
403 $language_urls = array();
405 if ( !$wgHideInterlanguageLinks ) {
406 foreach( $out->getLanguageLinks() as $l ) {
407 $tmp = explode( ':', $l, 2 );
408 $class = 'interwiki-' . $tmp[0];
410 $nt = Title
::newFromText( $l );
412 $language_urls[] = array(
413 'href' => $nt->getFullURL(),
414 'text' => $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
415 $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( __METHOD__
."-stuff4" );
428 wfProfileIn( __METHOD__
."-stuff5" );
430 $tpl->set('personal_urls', $this->buildPersonalUrls());
431 $content_actions = $this->buildContentActionUrls();
432 $tpl->setRef('content_actions', $content_actions);
434 $subpagestr = $this->subPageSubtitle();
436 'subtitle', !empty($subpagestr) ?
437 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() : $out->getSubtitle()
440 // XXX: attach this from javascript, same with section editing
441 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
443 $encEditUrl = wfEscapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
444 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
446 $tpl->set('body_ondblclick', false);
448 $tpl->set( 'body_onload', false );
449 $tpl->set( 'sidebar', $this->buildSidebar() );
450 $tpl->set( 'nav_urls', $this->buildNavUrls() );
452 // original version by hansm
453 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
454 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
457 // allow extensions adding stuff after the page content.
458 // See Skin::afterContentHook() for further documentation.
459 $tpl->set ('dataAfterContent', $this->afterContentHook());
460 wfProfileOut( __METHOD__
."-stuff5" );
463 wfProfileIn( __METHOD__
."-execute" );
464 $res = $tpl->execute();
465 wfProfileOut( __METHOD__
."-execute" );
467 // result may be an error
468 $this->printOrError( $res );
469 wfProfileOut( __METHOD__
);
473 * Output the string, or print error message if it's
474 * an error object of the appropriate type.
475 * For the base class, assume strings all around.
480 function printOrError( $str ) {
485 * build array of urls for personal toolbar
489 function buildPersonalUrls() {
490 global $wgTitle, $wgRequest;
492 $pageurl = $wgTitle->getLocalURL();
493 wfProfileIn( __METHOD__
);
495 /* set up the default links for the personal toolbar */
496 $personal_urls = array();
497 if ($this->loggedin
) {
498 $personal_urls['userpage'] = array(
499 'text' => $this->username
,
500 'href' => &$this->userpageUrlDetails
['href'],
501 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
502 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
504 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
505 $personal_urls['mytalk'] = array(
506 'text' => wfMsg('mytalk'),
507 'href' => &$usertalkUrlDetails['href'],
508 'class' => $usertalkUrlDetails['exists']?
false:'new',
509 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
511 $href = self
::makeSpecialUrl( 'Preferences' );
512 $personal_urls['preferences'] = array(
513 'text' => wfMsg( 'mypreferences' ),
515 'active' => ( $href == $pageurl )
517 $href = self
::makeSpecialUrl( 'Watchlist' );
518 $personal_urls['watchlist'] = array(
519 'text' => wfMsg( 'mywatchlist' ),
521 'active' => ( $href == $pageurl )
524 # We need to do an explicit check for Special:Contributions, as we
525 # have to match both the title, and the target (which could come
526 # from request values or be specified in "sub page" form. The plot
527 # thickens, because $wgTitle is altered for special pages, so doesn't
528 # contain the original alias-with-subpage.
529 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
530 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
531 list( $spName, $spPar ) =
532 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
533 $active = $spName == 'Contributions'
534 && ( ( $spPar && $spPar == $this->username
)
535 ||
$wgRequest->getText( 'target' ) == $this->username
);
540 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
541 $personal_urls['mycontris'] = array(
542 'text' => wfMsg( 'mycontris' ),
546 $personal_urls['logout'] = array(
547 'text' => wfMsg( 'userlogout' ),
548 'href' => self
::makeSpecialUrl( 'Userlogout',
549 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
555 $loginlink = $wgUser->isAllowed( 'createaccount' )
556 ?
'nav-login-createaccount'
558 if( $this->showIPinHeader() ) {
559 $href = &$this->userpageUrlDetails
['href'];
560 $personal_urls['anonuserpage'] = array(
561 'text' => $this->username
,
563 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
564 'active' => ( $pageurl == $href )
566 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
567 $href = &$usertalkUrlDetails['href'];
568 $personal_urls['anontalk'] = array(
569 'text' => wfMsg('anontalk'),
571 'class' => $usertalkUrlDetails['exists']?
false:'new',
572 'active' => ( $pageurl == $href )
574 $personal_urls['anonlogin'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
581 $personal_urls['login'] = array(
582 'text' => wfMsg( $loginlink ),
583 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
584 'active' => $wgTitle->isSpecial( 'Userlogin' )
589 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
590 wfProfileOut( __METHOD__
);
591 return $personal_urls;
594 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
597 $classes[] = 'selected';
599 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 &&
600 !($title->getNamespace() == NS_IMAGE
&& wfFindFile( $title )) ) {
602 $query = 'action=edit';
605 $text = wfMsg( $message );
606 if ( wfEmptyMsg( $message, $text ) ) {
608 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
612 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
613 $title, $message, $selected, $checkEdit,
614 &$classes, &$query, &$text, &$result)) ) {
619 'class' => implode( ' ', $classes ),
621 'href' => $title->getLocalUrl( $query ) );
624 function makeTalkUrlDetails( $name, $urlaction = '' ) {
625 $title = Title
::newFromText( $name );
626 if( !is_object($title) ) {
627 throw new MWException( __METHOD__
." given invalid pagename $name" );
629 $title = $title->getTalkPage();
630 self
::checkTitle( $title, $name );
632 'href' => $title->getLocalURL( $urlaction ),
633 'exists' => $title->getArticleID() != 0 ?
true : false
637 function makeArticleUrlDetails( $name, $urlaction = '' ) {
638 $title = Title
::newFromText( $name );
639 $title= $title->getSubjectPage();
640 self
::checkTitle( $title, $name );
642 'href' => $title->getLocalURL( $urlaction ),
643 'exists' => $title->getArticleID() != 0 ?
true : false
648 * an array of edit links by default used for the tabs
652 function buildContentActionUrls() {
653 global $wgContLang, $wgLang, $wgOut;
654 wfProfileIn( __METHOD__
);
656 global $wgUser, $wgRequest;
657 $action = $wgRequest->getText( 'action', 'view' );
658 $section = $wgRequest->getText( 'section' );
659 $content_actions = array();
661 $prevent_active_tabs = false ;
662 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
664 if( $this->iscontent
) {
665 $subjpage = $this->mTitle
->getSubjectPage();
666 $talkpage = $this->mTitle
->getTalkPage();
668 $nskey = $this->mTitle
->getNamespaceKey();
669 $content_actions[$nskey] = $this->tabAction(
672 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
675 $content_actions['talk'] = $this->tabAction(
678 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
682 wfProfileIn( __METHOD__
."-edit" );
683 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
684 $istalk = $this->mTitle
->isTalkPage();
685 $istalkclass = $istalk?
' istalk':'';
686 $content_actions['edit'] = array(
687 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
688 'text' => $this->mTitle
->exists()
691 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
694 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
695 $content_actions['addsection'] = array(
696 'class' => $section == 'new'?
'selected':false,
697 'text' => wfMsg('addsection'),
698 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
701 # Give notice if this page is locked for others
702 if( ($action == 'view' ||
$action == 'purge') && $this->mTitle
->isProtected( 'edit' ) ) {
703 $wgOut->appendSubtitle( "<span class='plainlinks'>" .
704 wfMsgExt('protected-sub-allowed',array('parse'),$this->mTitle
->getFullUrl('action=protect')) .
708 } elseif ( $this->mTitle
->exists() ||
$this->mTitle
->isAlwaysKnown() ) {
709 $content_actions['viewsource'] = array(
710 'class' => ($action == 'edit') ?
'selected' : false,
711 'text' => wfMsg('viewsource'),
712 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
714 # Give notice if this page is locked
715 if( ($action == 'view' ||
$action == 'purge') && $this->mTitle
->isProtected( 'edit' ) ) {
716 $wgOut->appendSubtitle( "<span class='plainlinks'>" .
717 wfMsgExt('protected-sub-disallowed',array('parseinline'),$this->mTitle
->getFullUrl('action=protect')) .
722 wfProfileOut( __METHOD__
."-edit" );
724 wfProfileIn( __METHOD__
."-live" );
725 if ( $this->mTitle
->exists() ) {
727 $content_actions['history'] = array(
728 'class' => ($action == 'history') ?
'selected' : false,
729 'text' => wfMsg('history_short'),
730 'href' => $this->mTitle
->getLocalUrl( 'action=history')
733 if( $wgUser->isAllowed('delete') ) {
734 $content_actions['delete'] = array(
735 'class' => ($action == 'delete') ?
'selected' : false,
736 'text' => wfMsg('delete'),
737 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
740 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
741 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
742 $content_actions['move'] = array(
743 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
744 'text' => wfMsg('move'),
745 'href' => $moveTitle->getLocalUrl()
749 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
750 if( !$this->mTitle
->isProtected() ){
751 $content_actions['protect'] = array(
752 'class' => ($action == 'protect') ?
'selected' : false,
753 'text' => wfMsg('protect'),
754 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
758 $content_actions['unprotect'] = array(
759 'class' => ($action == 'unprotect') ?
'selected' : false,
760 'text' => wfMsg('unprotect'),
761 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
766 //article doesn't exist or is deleted
767 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
768 if( $n = $this->mTitle
->isDeleted() ) {
769 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
770 $content_actions['undelete'] = array(
772 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
773 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
774 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
779 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
780 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
781 $content_actions['protect'] = array(
782 'class' => ($action == 'protect') ?
'selected' : false,
783 'text' => wfMsg('protect'),
784 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
788 $content_actions['unprotect'] = array(
789 'class' => ($action == 'unprotect') ?
'selected' : false,
790 'text' => wfMsg('unprotect'),
791 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
797 wfProfileOut( __METHOD__
."-live" );
799 if( $this->loggedin
) {
800 if( !$this->mTitle
->userIsWatching()) {
801 $content_actions['watch'] = array(
802 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
803 'text' => wfMsg('watch'),
804 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
807 $content_actions['unwatch'] = array(
808 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
809 'text' => wfMsg('unwatch'),
810 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
816 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
818 /* show special page tab */
820 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
821 'class' => 'selected',
822 'text' => wfMsg('nstab-special'),
823 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
826 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
829 /* show links to different language variants */
830 global $wgDisableLangConversion;
831 $variants = $wgContLang->getVariants();
832 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
833 $preferred = $wgContLang->getPreferredVariant();
835 foreach( $variants as $code ) {
836 $varname = $wgContLang->getVariantname( $code );
837 if( $varname == 'disable' )
839 $selected = ( $code == $preferred )?
'selected' : false;
840 $content_actions['varlang-' . $vcount] = array(
841 'class' => $selected,
843 'href' => $this->mTitle
->getLocalURL('',$code)
849 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
851 wfProfileOut( __METHOD__
);
852 return $content_actions;
858 * build array of common navigation links
862 function buildNavUrls() {
863 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
864 global $wgEnableUploads, $wgUploadNavigationUrl;
866 wfProfileIn( __METHOD__
);
868 $action = $wgRequest->getText( 'action' );
871 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
872 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
873 if ($wgUploadNavigationUrl) {
874 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
876 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
879 if ($wgUploadNavigationUrl)
880 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
882 $nav_urls['upload'] = false;
884 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
886 // default permalink to being off, will override it as required below.
887 $nav_urls['permalink'] = false;
889 // A print stylesheet is attached to all pages, but nobody ever
890 // figures that out. :) Add a link...
891 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
892 $nav_urls['print'] = array(
893 'text' => wfMsg( 'printableversion' ),
894 'href' => $wgRequest->appendQuery( 'printable=yes' )
897 // Also add a "permalink" while we're at it
898 if ( $this->mRevisionId
) {
899 $nav_urls['permalink'] = array(
900 'text' => wfMsg( 'permalink' ),
901 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
905 // Copy in case this undocumented, shady hook tries to mess with internals
906 $revid = $this->mRevisionId
;
907 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
910 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
911 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
912 $nav_urls['whatlinkshere'] = array(
913 'href' => $wlhTitle->getLocalUrl()
915 if( $this->mTitle
->getArticleId() ) {
916 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
917 $nav_urls['recentchangeslinked'] = array(
918 'href' => $rclTitle->getLocalUrl()
921 $nav_urls['recentchangeslinked'] = false;
923 if ($wgUseTrackbacks)
924 $nav_urls['trackbacklink'] = array(
925 'href' => $wgTitle->trackbackURL()
929 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
930 $id = User
::idFromName($this->mTitle
->getText());
931 $ip = User
::isIP($this->mTitle
->getText());
937 if($id ||
$ip) { # both anons and non-anons have contribs list
938 $nav_urls['contributions'] = array(
939 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
943 $logPage = SpecialPage
::getTitleFor( 'Log' );
944 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
945 . $this->mTitle
->getPartialUrl() ) );
947 $nav_urls['log'] = false;
950 if ( $wgUser->isAllowed( 'block' ) ) {
951 $nav_urls['blockip'] = array(
952 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
955 $nav_urls['blockip'] = false;
958 $nav_urls['contributions'] = false;
959 $nav_urls['log'] = false;
960 $nav_urls['blockip'] = false;
962 $nav_urls['emailuser'] = false;
963 if( $this->showEmailUser( $id ) ) {
964 $nav_urls['emailuser'] = array(
965 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
968 wfProfileOut( __METHOD__
);
973 * Generate strings used for xml 'id' names
977 function getNameSpaceKey() {
978 return $this->mTitle
->getNamespaceKey();
984 function setupUserJs( $allowUserJs ) {
985 wfProfileIn( __METHOD__
);
987 global $wgRequest, $wgJsMimeType;
988 $action = $wgRequest->getText('action');
990 if( $allowUserJs && $this->loggedin
) {
991 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
992 # XXX: additional security check/prompt?
993 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
995 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
998 wfProfileOut( __METHOD__
);
1002 * Code for extensions to hook into to provide per-page CSS, see
1003 * extensions/PageCSS/PageCSS.php for an implementation of this.
1007 function setupPageCss() {
1008 wfProfileIn( __METHOD__
);
1010 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1011 wfProfileOut( __METHOD__
);
1017 * Generic wrapper for template functions, with interface
1018 * compatible with what we use of PHPTAL 0.7.
1021 class QuickTemplate
{
1025 function QuickTemplate() {
1026 $this->data
= array();
1027 $this->translator
= new MediaWiki_I18N();
1033 function set( $name, $value ) {
1034 $this->data
[$name] = $value;
1040 function setRef($name, &$value) {
1041 $this->data
[$name] =& $value;
1047 function setTranslator( &$t ) {
1048 $this->translator
= &$t;
1054 function execute() {
1055 echo "Override this function.";
1062 function text( $str ) {
1063 echo htmlspecialchars( $this->data
[$str] );
1069 function jstext( $str ) {
1070 echo Xml
::escapeJsString( $this->data
[$str] );
1076 function html( $str ) {
1077 echo $this->data
[$str];
1083 function msg( $str ) {
1084 echo htmlspecialchars( $this->translator
->translate( $str ) );
1090 function msgHtml( $str ) {
1091 echo $this->translator
->translate( $str );
1095 * An ugly, ugly hack.
1098 function msgWiki( $str ) {
1099 global $wgParser, $wgTitle, $wgOut;
1101 $text = $this->translator
->translate( $str );
1102 $parserOutput = $wgParser->parse( $text, $wgTitle,
1103 $wgOut->parserOptions(), true );
1104 echo $parserOutput->getText();
1110 function haveData( $str ) {
1111 return isset( $this->data
[$str] );
1117 function haveMsg( $str ) {
1118 $msg = $this->translator
->translate( $str );
1119 return ($msg != '-') && ($msg != ''); # ????