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
);
206 $subpagestr = $this->subPageSubtitle();
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
212 $undelete = $this->getUndeleteLink();
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $out->isSyndicated() ) {
222 foreach( $out->getSyndicationLinks() as $format => $link ) {
223 $feeds[$format] = array(
224 'text' => wfMsg( "feed-$format" ),
227 $tpl->setRef( 'feeds', $feeds );
229 $tpl->set( 'feeds', false );
231 if ($wgUseTrackbacks && $out->isArticleRelated()) {
232 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
234 $tpl->set( 'trackbackhtml', null );
237 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
238 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
239 $tpl->setRef( 'mimetype', $wgMimeType );
240 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
241 $tpl->setRef( 'charset', $wgOutputEncoding );
242 $tpl->set( 'headlinks', $out->getHeadLinks() );
243 $tpl->set( 'headscripts', $out->getScript() );
244 $tpl->set( 'csslinks', $out->buildCssLinks() );
245 $tpl->setRef( 'wgScript', $wgScript );
246 $tpl->setRef( 'skinname', $this->skinname
);
247 $tpl->set( 'skinclass', get_class( $this ) );
248 $tpl->setRef( 'stylename', $this->stylename
);
249 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
250 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
251 $tpl->setRef( 'loggedin', $this->loggedin
);
252 $tpl->set('notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
253 /* XXX currently unused, might get useful later
254 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
255 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
256 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
257 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
258 $tpl->set( "helppage", wfMsg('helppage'));
260 $tpl->set( 'searchaction', $this->escapeSearchLink() );
261 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
262 $tpl->setRef( 'stylepath', $wgStylePath );
263 $tpl->setRef( 'articlepath', $wgArticlePath );
264 $tpl->setRef( 'scriptpath', $wgScriptPath );
265 $tpl->setRef( 'serverurl', $wgServer );
266 $tpl->setRef( 'logopath', $wgLogo );
267 $tpl->setRef( "lang", $wgContLanguageCode );
268 $tpl->set( 'dir', $wgContLang->isRTL() ?
"rtl" : "ltr" );
269 $tpl->set( 'rtl', $wgContLang->isRTL() );
270 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
271 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
272 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
273 $tpl->setRef( 'userpage', $this->userpage
);
274 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href']);
275 $tpl->set( 'userlang', $wgLang->getCode() );
276 $tpl->set( 'pagecss', $this->setupPageCss() );
277 $tpl->setRef( 'usercss', $this->usercss
);
278 $tpl->setRef( 'userjs', $this->userjs
);
279 $tpl->setRef( 'userjsprev', $this->userjsprev
);
281 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
282 $tpl->set( 'jsvarurl',
284 "action=raw$jsCache&gen=js&useskin=" .
285 urlencode( $this->getSkinName() ) ) );
287 $tpl->set('jsvarurl', false);
289 $newtalks = $wgUser->getNewMessageLinks();
291 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
292 $usertitle = $this->mUser
->getUserPage();
293 $usertalktitle = $usertitle->getTalkPage();
294 if( !$usertalktitle->equals( $this->mTitle
) ) {
295 $ntl = wfMsg( 'youhavenewmessages',
296 $this->makeKnownLinkObj(
298 wfMsgHtml( 'newmessageslink' ),
301 $this->makeKnownLinkObj(
303 wfMsgHtml( 'newmessagesdifflink' ),
308 $out->setSquidMaxage(0);
310 } else if (count($newtalks)) {
311 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
313 foreach ($newtalks as $newtalk) {
314 $msgs[] = Xml
::element("a",
315 array('href' => $newtalk["link"]), $newtalk["wiki"]);
317 $parts = implode($sep, $msgs);
318 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
319 $out->setSquidMaxage(0);
323 wfProfileOut( __METHOD__
."-stuff2" );
325 wfProfileIn( __METHOD__
."-stuff3" );
326 $tpl->setRef( 'newtalk', $ntl );
327 $tpl->setRef( 'skin', $this );
328 $tpl->set( 'logo', $this->logoText() );
329 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
330 $wgArticle and 0 != $wgArticle->getID() )
332 if ( !$wgDisableCounters ) {
333 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
335 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
337 $tpl->set('viewcount', false);
340 $tpl->set('viewcount', false);
343 if ($wgPageShowWatchingUsers) {
344 $dbr = wfGetDB( DB_SLAVE
);
345 $watchlist = $dbr->tableName( 'watchlist' );
346 $sql = "SELECT COUNT(*) AS n FROM $watchlist
347 WHERE wl_title='" . $dbr->strencode($this->mTitle
->getDBkey()) .
348 "' AND wl_namespace=" . $this->mTitle
->getNamespace() ;
349 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
350 $x = $dbr->fetchObject( $res );
351 $numberofwatchingusers = $x->n
;
352 if ($numberofwatchingusers > 0) {
353 $tpl->set('numberofwatchingusers',
354 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
355 $wgLang->formatNum($numberofwatchingusers))
358 $tpl->set('numberofwatchingusers', false);
361 $tpl->set('numberofwatchingusers', false);
364 $tpl->set('copyright',$this->getCopyright());
366 $this->credits
= false;
368 if( $wgMaxCredits != 0 ){
369 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
371 $tpl->set( 'lastmod', $this->lastModified() );
374 $tpl->setRef( 'credits', $this->credits
);
376 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
377 $tpl->set('copyright', $this->getCopyright());
378 $tpl->set('viewcount', false);
379 $tpl->set('lastmod', false);
380 $tpl->set('credits', false);
381 $tpl->set('numberofwatchingusers', false);
383 $tpl->set('copyright', false);
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
389 wfProfileOut( __METHOD__
."-stuff3" );
391 wfProfileIn( __METHOD__
."-stuff4" );
392 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
393 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
394 $tpl->set( 'disclaimer', $this->disclaimerLink() );
395 $tpl->set( 'privacy', $this->privacyLink() );
396 $tpl->set( 'about', $this->aboutLink() );
398 $tpl->setRef( 'debug', $out->mDebugtext
);
399 $tpl->set( 'reporttime', wfReportTime() );
400 $tpl->set( 'sitenotice', wfGetSiteNotice() );
401 $tpl->set( 'bottomscripts', $this->bottomScripts() );
403 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
404 $out->mBodytext
.= $printfooter ;
405 $tpl->setRef( 'bodytext', $out->mBodytext
);
408 $language_urls = array();
410 if ( !$wgHideInterlanguageLinks ) {
411 foreach( $out->getLanguageLinks() as $l ) {
412 $tmp = explode( ':', $l, 2 );
413 $class = 'interwiki-' . $tmp[0];
415 $nt = Title
::newFromText( $l );
417 $language_urls[] = array(
418 'href' => $nt->getFullURL(),
419 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != ''
420 ?
$wgContLang->getLanguageName( $nt->getInterwiki() )
423 'title' => ( $wgLang->getLanguageNameLocalized( $nt->getInterwiki() ) != ''
424 ?
$wgLang->getLanguageNameLocalized( $nt->getInterwiki() )
430 if(count($language_urls)) {
431 $tpl->setRef( 'language_urls', $language_urls);
433 $tpl->set('language_urls', false);
435 wfProfileOut( __METHOD__
."-stuff4" );
437 wfProfileIn( __METHOD__
."-stuff5" );
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable
&& $wgUser->getOption("editondblclick") )
446 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
447 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
449 $tpl->set('body_ondblclick', false);
451 $tpl->set( 'body_onload', false );
452 $tpl->set( 'sidebar', $this->buildSidebar() );
453 $tpl->set( 'nav_urls', $this->buildNavUrls() );
455 // original version by hansm
456 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
457 wfDebug( __METHOD__
. ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
460 // allow extensions adding stuff after the page content.
461 // See Skin::afterContentHook() for further documentation.
462 $tpl->set ('dataAfterContent', $this->afterContentHook());
463 wfProfileOut( __METHOD__
."-stuff5" );
466 wfProfileIn( __METHOD__
."-execute" );
467 $res = $tpl->execute();
468 wfProfileOut( __METHOD__
."-execute" );
470 // result may be an error
471 $this->printOrError( $res );
472 wfProfileOut( __METHOD__
);
476 * Output the string, or print error message if it's
477 * an error object of the appropriate type.
478 * For the base class, assume strings all around.
483 function printOrError( $str ) {
488 * build array of urls for personal toolbar
492 function buildPersonalUrls() {
493 global $wgTitle, $wgRequest;
495 $pageurl = $wgTitle->getLocalURL();
496 wfProfileIn( __METHOD__
);
498 /* set up the default links for the personal toolbar */
499 $personal_urls = array();
500 if ($this->loggedin
) {
501 $personal_urls['userpage'] = array(
502 'text' => $this->username
,
503 'href' => &$this->userpageUrlDetails
['href'],
504 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
505 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
507 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
508 $personal_urls['mytalk'] = array(
509 'text' => wfMsg('mytalk'),
510 'href' => &$usertalkUrlDetails['href'],
511 'class' => $usertalkUrlDetails['exists']?
false:'new',
512 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
514 $href = self
::makeSpecialUrl( 'Preferences' );
515 $personal_urls['preferences'] = array(
516 'text' => wfMsg( 'mypreferences' ),
518 'active' => ( $href == $pageurl )
520 $href = self
::makeSpecialUrl( 'Watchlist' );
521 $personal_urls['watchlist'] = array(
522 'text' => wfMsg( 'mywatchlist' ),
524 'active' => ( $href == $pageurl )
527 # We need to do an explicit check for Special:Contributions, as we
528 # have to match both the title, and the target (which could come
529 # from request values or be specified in "sub page" form. The plot
530 # thickens, because $wgTitle is altered for special pages, so doesn't
531 # contain the original alias-with-subpage.
532 $title = Title
::newFromText( $wgRequest->getText( 'title' ) );
533 if( $title instanceof Title
&& $title->getNamespace() == NS_SPECIAL
) {
534 list( $spName, $spPar ) =
535 SpecialPage
::resolveAliasWithSubpage( $title->getText() );
536 $active = $spName == 'Contributions'
537 && ( ( $spPar && $spPar == $this->username
)
538 ||
$wgRequest->getText( 'target' ) == $this->username
);
543 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
544 $personal_urls['mycontris'] = array(
545 'text' => wfMsg( 'mycontris' ),
549 $personal_urls['logout'] = array(
550 'text' => wfMsg( 'userlogout' ),
551 'href' => self
::makeSpecialUrl( 'Userlogout',
552 $wgTitle->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
558 $loginlink = $wgUser->isAllowed( 'createaccount' )
559 ?
'nav-login-createaccount'
561 if( $this->showIPinHeader() ) {
562 $href = &$this->userpageUrlDetails
['href'];
563 $personal_urls['anonuserpage'] = array(
564 'text' => $this->username
,
566 'class' => $this->userpageUrlDetails
['exists']?
false:'new',
567 'active' => ( $pageurl == $href )
569 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage
);
570 $href = &$usertalkUrlDetails['href'];
571 $personal_urls['anontalk'] = array(
572 'text' => wfMsg('anontalk'),
574 'class' => $usertalkUrlDetails['exists']?
false:'new',
575 'active' => ( $pageurl == $href )
577 $personal_urls['anonlogin'] = array(
578 'text' => wfMsg( $loginlink ),
579 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
580 'active' => $wgTitle->isSpecial( 'Userlogin' )
584 $personal_urls['login'] = array(
585 'text' => wfMsg( $loginlink ),
586 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
587 'active' => $wgTitle->isSpecial( 'Userlogin' )
592 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
593 wfProfileOut( __METHOD__
);
594 return $personal_urls;
597 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
600 $classes[] = 'selected';
602 if( $checkEdit && !$title->isKnown() ) {
604 $query = 'action=edit&redlink=1';
607 $text = wfMsg( $message );
608 if ( wfEmptyMsg( $message, $text ) ) {
610 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
614 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
615 $title, $message, $selected, $checkEdit,
616 &$classes, &$query, &$text, &$result)) ) {
621 'class' => implode( ' ', $classes ),
623 'href' => $title->getLocalUrl( $query ) );
626 function makeTalkUrlDetails( $name, $urlaction = '' ) {
627 $title = Title
::newFromText( $name );
628 if( !is_object($title) ) {
629 throw new MWException( __METHOD__
." given invalid pagename $name" );
631 $title = $title->getTalkPage();
632 self
::checkTitle( $title, $name );
634 'href' => $title->getLocalURL( $urlaction ),
635 'exists' => $title->getArticleID() != 0 ?
true : false
639 function makeArticleUrlDetails( $name, $urlaction = '' ) {
640 $title = Title
::newFromText( $name );
641 $title= $title->getSubjectPage();
642 self
::checkTitle( $title, $name );
644 'href' => $title->getLocalURL( $urlaction ),
645 'exists' => $title->getArticleID() != 0 ?
true : false
650 * an array of edit links by default used for the tabs
654 function buildContentActionUrls() {
655 global $wgContLang, $wgLang, $wgOut;
656 wfProfileIn( __METHOD__
);
658 global $wgUser, $wgRequest;
659 $action = $wgRequest->getText( 'action' );
660 $section = $wgRequest->getText( 'section' );
661 $content_actions = array();
663 $prevent_active_tabs = false ;
664 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
666 if( $this->iscontent
) {
667 $subjpage = $this->mTitle
->getSubjectPage();
668 $talkpage = $this->mTitle
->getTalkPage();
670 $nskey = $this->mTitle
->getNamespaceKey();
671 $content_actions[$nskey] = $this->tabAction(
674 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
677 $content_actions['talk'] = $this->tabAction(
680 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
684 wfProfileIn( __METHOD__
."-edit" );
685 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
686 $istalk = $this->mTitle
->isTalkPage();
687 $istalkclass = $istalk?
' istalk':'';
688 $content_actions['edit'] = array(
689 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ?
'selected' : '').$istalkclass,
690 'text' => $this->mTitle
->exists()
693 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
696 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
697 $content_actions['addsection'] = array(
698 'class' => $section == 'new'?
'selected':false,
699 'text' => wfMsg('addsection'),
700 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
703 } elseif ( $this->mTitle
->isKnown() ) {
704 $content_actions['viewsource'] = array(
705 'class' => ($action == 'edit') ?
'selected' : false,
706 'text' => wfMsg('viewsource'),
707 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
710 wfProfileOut( __METHOD__
."-edit" );
712 wfProfileIn( __METHOD__
."-live" );
713 if ( $this->mTitle
->exists() ) {
715 $content_actions['history'] = array(
716 'class' => ($action == 'history') ?
'selected' : false,
717 'text' => wfMsg('history_short'),
718 'href' => $this->mTitle
->getLocalUrl( 'action=history')
721 if( $wgUser->isAllowed('delete') ) {
722 $content_actions['delete'] = array(
723 'class' => ($action == 'delete') ?
'selected' : false,
724 'text' => wfMsg('delete'),
725 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
728 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
729 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
730 $content_actions['move'] = array(
731 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
732 'text' => wfMsg('move'),
733 'href' => $moveTitle->getLocalUrl()
737 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
738 if( !$this->mTitle
->isProtected() ){
739 $content_actions['protect'] = array(
740 'class' => ($action == 'protect') ?
'selected' : false,
741 'text' => wfMsg('protect'),
742 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
746 $content_actions['unprotect'] = array(
747 'class' => ($action == 'unprotect') ?
'selected' : false,
748 'text' => wfMsg('unprotect'),
749 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
754 //article doesn't exist or is deleted
755 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
756 if( $n = $this->mTitle
->isDeleted() ) {
757 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
758 $content_actions['undelete'] = array(
760 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
761 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
762 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
767 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
768 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
769 $content_actions['protect'] = array(
770 'class' => ($action == 'protect') ?
'selected' : false,
771 'text' => wfMsg('protect'),
772 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
776 $content_actions['unprotect'] = array(
777 'class' => ($action == 'unprotect') ?
'selected' : false,
778 'text' => wfMsg('unprotect'),
779 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
785 wfProfileOut( __METHOD__
."-live" );
787 if( $this->loggedin
) {
788 if( !$this->mTitle
->userIsWatching()) {
789 $content_actions['watch'] = array(
790 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
791 'text' => wfMsg('watch'),
792 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
795 $content_actions['unwatch'] = array(
796 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
797 'text' => wfMsg('unwatch'),
798 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
804 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
806 /* show special page tab */
808 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
809 'class' => 'selected',
810 'text' => wfMsg('nstab-special'),
811 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
814 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
817 /* show links to different language variants */
818 global $wgDisableLangConversion;
819 $variants = $wgContLang->getVariants();
820 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
821 $preferred = $wgContLang->getPreferredVariant();
823 foreach( $variants as $code ) {
824 $varname = $wgContLang->getVariantname( $code );
825 if( $varname == 'disable' )
827 $selected = ( $code == $preferred )?
'selected' : false;
828 $content_actions['varlang-' . $vcount] = array(
829 'class' => $selected,
831 'href' => $this->mTitle
->getLocalURL('',$code)
837 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
839 wfProfileOut( __METHOD__
);
840 return $content_actions;
846 * build array of common navigation links
850 function buildNavUrls() {
851 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
852 global $wgEnableUploads, $wgUploadNavigationUrl;
854 wfProfileIn( __METHOD__
);
856 $action = $wgRequest->getText( 'action' );
859 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
860 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
861 if ($wgUploadNavigationUrl) {
862 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
864 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
867 if ($wgUploadNavigationUrl)
868 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
870 $nav_urls['upload'] = false;
872 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
874 // default permalink to being off, will override it as required below.
875 $nav_urls['permalink'] = false;
877 // A print stylesheet is attached to all pages, but nobody ever
878 // figures that out. :) Add a link...
879 if( $this->iscontent
&& ($action == '' ||
$action == 'view' ||
$action == 'purge' ) ) {
880 $nav_urls['print'] = array(
881 'text' => wfMsg( 'printableversion' ),
882 'href' => $wgRequest->appendQuery( 'printable=yes' )
885 // Also add a "permalink" while we're at it
886 if ( $this->mRevisionId
) {
888 $nav_urls['permalink'] = array(
889 'text' => wfMsg( 'permalink' ),
890 'href' => "{$wgScript}?oldid={$this->mRevisionId}"
894 // Copy in case this undocumented, shady hook tries to mess with internals
895 $revid = $this->mRevisionId
;
896 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
899 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
900 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
901 $nav_urls['whatlinkshere'] = array(
902 'href' => $wlhTitle->getLocalUrl()
904 if( $this->mTitle
->getArticleId() ) {
905 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
906 $nav_urls['recentchangeslinked'] = array(
907 'href' => $rclTitle->getLocalUrl()
910 $nav_urls['recentchangeslinked'] = false;
912 if ($wgUseTrackbacks)
913 $nav_urls['trackbacklink'] = array(
914 'href' => $wgTitle->trackbackURL()
918 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
919 $id = User
::idFromName($this->mTitle
->getText());
920 $ip = User
::isIP($this->mTitle
->getText());
926 if($id ||
$ip) { # both anons and non-anons have contribs list
927 $nav_urls['contributions'] = array(
928 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
932 $logPage = SpecialPage
::getTitleFor( 'Log' );
933 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
934 . $this->mTitle
->getPartialUrl() ) );
936 $nav_urls['log'] = false;
939 if ( $wgUser->isAllowed( 'block' ) ) {
940 $nav_urls['blockip'] = array(
941 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
944 $nav_urls['blockip'] = false;
947 $nav_urls['contributions'] = false;
948 $nav_urls['log'] = false;
949 $nav_urls['blockip'] = false;
951 $nav_urls['emailuser'] = false;
952 if( $this->showEmailUser( $id ) ) {
953 $nav_urls['emailuser'] = array(
954 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
957 wfProfileOut( __METHOD__
);
962 * Generate strings used for xml 'id' names
966 function getNameSpaceKey() {
967 return $this->mTitle
->getNamespaceKey();
973 function setupUserJs( $allowUserJs ) {
974 wfProfileIn( __METHOD__
);
976 global $wgRequest, $wgJsMimeType;
977 $action = $wgRequest->getText('action');
979 if( $allowUserJs && $this->loggedin
) {
980 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
981 # XXX: additional security check/prompt?
982 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
984 $this->userjs
= self
::makeUrl($this->userpage
.'/'.$this->skinname
.'.js', 'action=raw&ctype='.$wgJsMimeType);
987 wfProfileOut( __METHOD__
);
991 * Code for extensions to hook into to provide per-page CSS, see
992 * extensions/PageCSS/PageCSS.php for an implementation of this.
996 function setupPageCss() {
997 wfProfileIn( __METHOD__
);
999 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1000 wfProfileOut( __METHOD__
);
1006 * Generic wrapper for template functions, with interface
1007 * compatible with what we use of PHPTAL 0.7.
1010 class QuickTemplate
{
1014 function QuickTemplate() {
1015 $this->data
= array();
1016 $this->translator
= new MediaWiki_I18N();
1022 function set( $name, $value ) {
1023 $this->data
[$name] = $value;
1029 function setRef($name, &$value) {
1030 $this->data
[$name] =& $value;
1036 function setTranslator( &$t ) {
1037 $this->translator
= &$t;
1043 function execute() {
1044 echo "Override this function.";
1051 function text( $str ) {
1052 echo htmlspecialchars( $this->data
[$str] );
1058 function jstext( $str ) {
1059 echo Xml
::escapeJsString( $this->data
[$str] );
1065 function html( $str ) {
1066 echo $this->data
[$str];
1072 function msg( $str ) {
1073 echo htmlspecialchars( $this->translator
->translate( $str ) );
1079 function msgHtml( $str ) {
1080 echo $this->translator
->translate( $str );
1084 * An ugly, ugly hack.
1087 function msgWiki( $str ) {
1088 global $wgParser, $wgTitle, $wgOut;
1090 $text = $this->translator
->translate( $str );
1091 $parserOutput = $wgParser->parse( $text, $wgTitle,
1092 $wgOut->parserOptions(), true );
1093 echo $parserOutput->getText();
1099 function haveData( $str ) {
1100 return isset( $this->data
[$str] );
1106 function haveMsg( $str ) {
1107 $msg = $this->translator
->translate( $str );
1108 return ($msg != '-') && ($msg != ''); # ????