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' );
115 /* add specific javascript the base Skin class */
116 function setupSkinUserJs( OutputPage
$out ){
120 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
121 $siteGenScriptFile = self
::makeUrl( '-',
122 "action=raw$jsCache&gen=js&useskin=" .
123 urlencode( $this->getSkinName() ) ) ;
124 $this->jsvarurl
= $siteGenScriptFile;
129 * Create the template engine object; we feed it a bunch of data
130 * and eventually it spits out some HTML. Should have interface
131 * roughly equivalent to PHPTAL 0.7.
133 * @param $callback string (or file)
134 * @param $repository string: subdirectory where we keep template files
135 * @param $cache_dir string
139 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
140 return new $classname();
144 * initialize various variables and generate the template
146 * @param $out OutputPage
148 function outputPage( OutputPage
$out ) {
149 global $wgArticle, $wgUser, $wgLang, $wgContLang;
150 global $wgScript, $wgStylePath, $wgContLanguageCode;
151 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
152 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
153 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
154 global $wgMaxCredits, $wgShowCreditsIfMax;
155 global $wgPageShowWatchingUsers;
156 global $wgUseTrackbacks, $wgUseSiteJs;
157 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
159 wfProfileIn( __METHOD__
);
161 $oldid = $wgRequest->getVal( 'oldid' );
162 $diff = $wgRequest->getVal( 'diff' );
163 $action = $wgRequest->getVal( 'action', 'view' );
165 wfProfileIn( __METHOD__
. '-init' );
166 $this->initPage( $out );
169 $tpl = $this->setupTemplate( $this->template
, 'skins' );
171 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
172 $tpl->setTranslator( new MediaWiki_I18N() );
174 wfProfileOut( __METHOD__
. '-init' );
176 wfProfileIn( __METHOD__
. '-stuff' );
177 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
178 $this->thisurl
= $this->mTitle
->getPrefixedURL();
179 $query = $wgRequest->getValues();
180 unset( $query['title'] );
181 $this->thisquery
= wfArrayToCGI( $query );
182 $this->loggedin
= $wgUser->isLoggedIn();
183 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
184 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
185 $this->username
= $wgUser->getName();
187 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
188 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
190 # This won't be used in the standard skins, but we define it to preserve the interface
191 # To save time, we check for existence
192 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
195 $this->userjs
= $this->userjsprev
= false;
196 $this->setupUserCss( $out );
197 $this->setupUserJs( $out->isUserJsAllowed() );
198 $this->titletxt
= $this->mTitle
->getPrefixedText();
199 wfProfileOut( __METHOD__
. '-stuff' );
201 wfProfileIn( __METHOD__
. '-stuff2' );
202 $tpl->set( 'title', $out->getPageTitle() );
203 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
204 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
205 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
206 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
208 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
209 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
210 $this->mTitle
->getNsText();
212 $tpl->set( 'nscanonical', $nsname );
213 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
214 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
215 $tpl->set( 'titletext', $this->mTitle
->getText() );
216 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
217 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
219 $tpl->set( 'isarticle', $out->isArticle() );
221 $tpl->setRef( 'thispage', $this->thispage
);
222 $subpagestr = $this->subPageSubtitle();
224 'subtitle', !empty( $subpagestr ) ?
225 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
228 $undelete = $this->getUndeleteLink();
230 'undelete', !empty( $undelete ) ?
231 '<span class="subpages">'.$undelete.'</span>' :
235 $tpl->set( 'catlinks', $this->getCategories() );
236 if( $out->isSyndicated() ) {
238 foreach( $out->getSyndicationLinks() as $format => $link ) {
239 $feeds[$format] = array(
240 'text' => wfMsg( "feed-$format" ),
244 $tpl->setRef( 'feeds', $feeds );
246 $tpl->set( 'feeds', false );
248 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
249 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
251 $tpl->set( 'trackbackhtml', null );
254 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
255 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
256 $tpl->setRef( 'mimetype', $wgMimeType );
257 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
258 $tpl->setRef( 'charset', $wgOutputEncoding );
259 $tpl->set( 'headlinks', $out->getHeadLinks() );
261 //moved headscripts to near end of template header output
263 $tpl->set( 'csslinks', $out->buildCssLinks() );
264 $tpl->setRef( 'wgScript', $wgScript );
265 $tpl->setRef( 'skinname', $this->skinname
);
266 $tpl->set( 'skinclass', get_class( $this ) );
267 $tpl->setRef( 'stylename', $this->stylename
);
268 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
269 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
270 $tpl->setRef( 'loggedin', $this->loggedin
);
271 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
272 /* XXX currently unused, might get useful later
273 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
274 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
275 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
276 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
277 $tpl->set( "helppage", wfMsg('helppage'));
279 $tpl->set( 'searchaction', $this->escapeSearchLink() );
280 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
281 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
282 $tpl->setRef( 'stylepath', $wgStylePath );
283 $tpl->setRef( 'articlepath', $wgArticlePath );
284 $tpl->setRef( 'scriptpath', $wgScriptPath );
285 $tpl->setRef( 'serverurl', $wgServer );
286 $tpl->setRef( 'logopath', $wgLogo );
287 $tpl->setRef( 'lang', $wgContLanguageCode );
288 $tpl->set( 'dir', $wgContLang->isRTL() ?
'rtl' : 'ltr' );
289 $tpl->set( 'rtl', $wgContLang->isRTL() );
290 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
291 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
292 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
293 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
294 $tpl->setRef( 'userpage', $this->userpage
);
295 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
296 $tpl->set( 'userlang', $wgLang->getCode() );
297 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
298 $tpl->set( 'pagecss', $this->setupPageCss() );
299 $tpl->setRef( 'usercss', $this->usercss
);
300 $tpl->setRef( 'userjs', $this->userjs
);
301 $tpl->setRef( 'userjsprev', $this->userjsprev
);
303 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
304 $tpl->set( 'jsvarurl',
306 "action=raw$jsCache&gen=js&useskin=" .
307 urlencode( $this->getSkinName() ) ) );
309 $tpl->set( 'jsvarurl', false );
312 $newtalks = $wgUser->getNewMessageLinks();
314 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
315 $usertitle = $this->mUser
->getUserPage();
316 $usertalktitle = $usertitle->getTalkPage();
318 if( !$usertalktitle->equals( $this->mTitle
) ) {
319 $newmessageslink = $this->link(
321 wfMsgHtml( 'newmessageslink' ),
323 array( 'redirect' => 'no' ),
324 array( 'known', 'noclasses' )
327 $newmessagesdifflink = $this->link(
329 wfMsgHtml( 'newmessagesdifflink' ),
331 array( 'diff' => 'cur' ),
332 array( 'known', 'noclasses' )
336 'youhavenewmessages',
341 $out->setSquidMaxage( 0 );
343 } else if( count( $newtalks ) ) {
344 // _>" " for BC <= 1.16
345 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
347 foreach( $newtalks as $newtalk ) {
348 $msgs[] = Xml
::element('a',
349 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
351 $parts = implode( $sep, $msgs );
352 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
353 $out->setSquidMaxage( 0 );
357 wfProfileOut( __METHOD__
. '-stuff2' );
359 wfProfileIn( __METHOD__
. '-stuff3' );
360 $tpl->setRef( 'newtalk', $ntl );
361 $tpl->setRef( 'skin', $this );
362 $tpl->set( 'logo', $this->logoText() );
363 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
364 $wgArticle and 0 != $wgArticle->getID() ){
365 if ( !$wgDisableCounters ) {
366 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
368 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
370 $tpl->set( 'viewcount', false );
373 $tpl->set( 'viewcount', false );
376 if( $wgPageShowWatchingUsers ) {
377 $dbr = wfGetDB( DB_SLAVE
);
378 $watchlist = $dbr->tableName( 'watchlist' );
379 $res = $dbr->select( 'watchlist',
380 array( 'COUNT(*) AS n' ),
381 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
384 $x = $dbr->fetchObject( $res );
385 $numberofwatchingusers = $x->n
;
386 if( $numberofwatchingusers > 0 ) {
387 $tpl->set( 'numberofwatchingusers',
388 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
389 $wgLang->formatNum( $numberofwatchingusers ) )
392 $tpl->set( 'numberofwatchingusers', false );
395 $tpl->set( 'numberofwatchingusers', false );
398 $tpl->set( 'copyright', $this->getCopyright() );
400 $this->credits
= false;
402 if( $wgMaxCredits != 0 ){
403 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
405 $tpl->set( 'lastmod', $this->lastModified() );
408 $tpl->setRef( 'credits', $this->credits
);
410 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
411 $tpl->set( 'copyright', $this->getCopyright() );
412 $tpl->set( 'viewcount', false );
413 $tpl->set( 'lastmod', false );
414 $tpl->set( 'credits', false );
415 $tpl->set( 'numberofwatchingusers', false );
417 $tpl->set( 'copyright', false );
418 $tpl->set( 'viewcount', false );
419 $tpl->set( 'lastmod', false );
420 $tpl->set( 'credits', false );
421 $tpl->set( 'numberofwatchingusers', false );
423 wfProfileOut( __METHOD__
. '-stuff3' );
425 wfProfileIn( __METHOD__
. '-stuff4' );
426 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
427 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
428 $tpl->set( 'disclaimer', $this->disclaimerLink() );
429 $tpl->set( 'privacy', $this->privacyLink() );
430 $tpl->set( 'about', $this->aboutLink() );
432 $tpl->setRef( 'debug', $out->mDebugtext
);
433 $tpl->set( 'reporttime', wfReportTime() );
434 $tpl->set( 'sitenotice', wfGetSiteNotice() );
435 $tpl->set( 'bottomscripts', $this->bottomScripts() );
437 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
438 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
439 $tpl->setRef( 'bodytext', $out->mBodytext
);
442 $language_urls = array();
444 if ( !$wgHideInterlanguageLinks ) {
445 foreach( $out->getLanguageLinks() as $l ) {
446 $tmp = explode( ':', $l, 2 );
447 $class = 'interwiki-' . $tmp[0];
449 $nt = Title
::newFromText( $l );
451 $language_urls[] = array(
452 'href' => $nt->getFullURL(),
453 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
454 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
460 if( count( $language_urls ) ) {
461 $tpl->setRef( 'language_urls', $language_urls );
463 $tpl->set( 'language_urls', false );
465 wfProfileOut( __METHOD__
. '-stuff4' );
467 wfProfileIn( __METHOD__
. '-stuff5' );
469 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
470 $content_actions = $this->buildContentActionUrls();
471 $tpl->setRef( 'content_actions', $content_actions );
473 // XXX: attach this from javascript, same with section editing
474 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
475 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
476 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
478 $tpl->set( 'body_ondblclick', false );
480 $tpl->set( 'body_onload', false );
481 $tpl->set( 'sidebar', $this->buildSidebar() );
482 $tpl->set( 'nav_urls', $this->buildNavUrls() );
484 //set the head script near the end (in case above actions result in adding scripts)
485 $tpl->set( 'headscripts', $out->getScript() );
487 // original version by hansm
488 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
489 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
492 // allow extensions adding stuff after the page content.
493 // See Skin::afterContentHook() for further documentation.
494 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
495 wfProfileOut( __METHOD__
. '-stuff5' );
498 wfProfileIn( __METHOD__
. '-execute' );
499 $res = $tpl->execute();
500 wfProfileOut( __METHOD__
. '-execute' );
502 // result may be an error
503 $this->printOrError( $res );
504 wfProfileOut( __METHOD__
);
508 * Output the string, or print error message if it's
509 * an error object of the appropriate type.
510 * For the base class, assume strings all around.
515 function printOrError( $str ) {
520 * build array of urls for personal toolbar
524 function buildPersonalUrls() {
525 global $wgOut, $wgRequest;
527 $title = $wgOut->getTitle();
528 $pageurl = $title->getLocalURL();
529 wfProfileIn( __METHOD__
);
531 /* set up the default links for the personal toolbar */
532 $personal_urls = array();
533 if( $this->loggedin
) {
534 $personal_urls['userpage'] = array(
535 'text' => $this->username
,
536 'href' => &$this->userpageUrlDetails
['href'],
537 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
538 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
540 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
541 $personal_urls['mytalk'] = array(
542 'text' => wfMsg( 'mytalk' ),
543 'href' => &$usertalkUrlDetails['href'],
544 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
545 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
547 $href = self
::makeSpecialUrl( 'Preferences' );
548 $personal_urls['preferences'] = array(
549 'text' => wfMsg( 'mypreferences' ),
551 'active' => ( $href == $pageurl )
553 $href = self
::makeSpecialUrl( 'Watchlist' );
554 $personal_urls['watchlist'] = array(
555 'text' => wfMsg( 'mywatchlist' ),
557 'active' => ( $href == $pageurl )
560 # We need to do an explicit check for Special:Contributions, as we
561 # have to match both the title, and the target (which could come
562 # from request values or be specified in "sub page" form. The plot
563 # thickens, because $wgTitle is altered for special pages, so doesn't
564 # contain the original alias-with-subpage.
565 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
566 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
567 list( $spName, $spPar ) =
568 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
569 $active = $spName == 'Contributions'
570 && ( ( $spPar && $spPar == $this->username
)
571 ||
$wgRequest->getText( 'target' ) == $this->username
);
576 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
577 $personal_urls['mycontris'] = array(
578 'text' => wfMsg( 'mycontris' ),
582 $personal_urls['logout'] = array(
583 'text' => wfMsg( 'userlogout' ),
584 'href' => self
::makeSpecialUrl( 'Userlogout',
585 $title->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}&returntoquery={$this->thisquery}"
591 $loginlink = $wgUser->isAllowed( 'createaccount' )
592 ?
'nav-login-createaccount'
594 if( $this->showIPinHeader() ) {
595 $href = &$this->userpageUrlDetails
['href'];
596 $personal_urls['anonuserpage'] = array(
597 'text' => $this->username
,
599 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
600 'active' => ( $pageurl == $href )
602 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
603 $href = &$usertalkUrlDetails['href'];
604 $personal_urls['anontalk'] = array(
605 'text' => wfMsg( 'anontalk' ),
607 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
608 'active' => ( $pageurl == $href )
610 $personal_urls['anonlogin'] = array(
611 'text' => wfMsg( $loginlink ),
612 'href' => self
::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
613 'active' => $title->isSpecial( 'Userlogin' )
616 $personal_urls['login'] = array(
617 'text' => wfMsg( $loginlink ),
618 'href' => self
::makeSpecialUrl( 'Userlogin', "returnto={$this->thisurl}&returntoquery={$this->thisquery}" ),
619 'active' => $title->isSpecial( 'Userlogin' )
624 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
625 wfProfileOut( __METHOD__
);
626 return $personal_urls;
629 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
632 $classes[] = 'selected';
634 if( $checkEdit && !$title->isKnown() ) {
636 $query = 'action=edit&redlink=1';
639 $text = wfMsg( $message );
640 if ( wfEmptyMsg( $message, $text ) ) {
642 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
646 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
647 $title, $message, $selected, $checkEdit,
648 &$classes, &$query, &$text, &$result ) ) ) {
653 'class' => implode( ' ', $classes ),
655 'href' => $title->getLocalUrl( $query ) );
658 function makeTalkUrlDetails( $name, $urlaction = '' ) {
659 $title = Title
::newFromText( $name );
660 if( !is_object( $title ) ) {
661 throw new MWException( __METHOD__
. " given invalid pagename $name" );
663 $title = $title->getTalkPage();
664 self
::checkTitle( $title, $name );
666 'href' => $title->getLocalURL( $urlaction ),
667 'exists' => $title->getArticleID() != 0 ?
true : false
671 function makeArticleUrlDetails( $name, $urlaction = '' ) {
672 $title = Title
::newFromText( $name );
673 $title= $title->getSubjectPage();
674 self
::checkTitle( $title, $name );
676 'href' => $title->getLocalURL( $urlaction ),
677 'exists' => $title->getArticleID() != 0 ?
true : false
682 * an array of edit links by default used for the tabs
686 function buildContentActionUrls() {
687 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
689 wfProfileIn( __METHOD__
);
691 $action = $wgRequest->getVal( 'action', 'view' );
692 $section = $wgRequest->getVal( 'section' );
693 $content_actions = array();
695 $prevent_active_tabs = false;
696 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
698 if( $this->iscontent
) {
699 $subjpage = $this->mTitle
->getSubjectPage();
700 $talkpage = $this->mTitle
->getTalkPage();
702 $nskey = $this->mTitle
->getNamespaceKey();
703 $content_actions[$nskey] = $this->tabAction(
706 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
710 $content_actions['talk'] = $this->tabAction(
713 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
718 wfProfileIn( __METHOD__
. '-edit' );
719 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
720 $istalk = $this->mTitle
->isTalkPage();
721 $istalkclass = $istalk?
' istalk':'';
722 $content_actions['edit'] = array(
723 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
724 'text' => $this->mTitle
->exists()
727 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
730 // adds new section link if page is a current revision of a talk page or
731 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
732 if ( !$wgOut->forceHideNewSectionLink() ) {
733 $content_actions['addsection'] = array(
734 'class' => $section == 'new' ?
'selected' : false,
735 'text' => wfMsg( 'addsection' ),
736 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
740 } elseif ( $this->mTitle
->isKnown() ) {
741 $content_actions['viewsource'] = array(
742 'class' => ($action == 'edit') ?
'selected' : false,
743 'text' => wfMsg( 'viewsource' ),
744 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
747 wfProfileOut( __METHOD__
. '-edit' );
749 wfProfileIn( __METHOD__
. '-live' );
750 if ( $this->mTitle
->exists() ) {
752 $content_actions['history'] = array(
753 'class' => ($action == 'history') ?
'selected' : false,
754 'text' => wfMsg( 'history_short' ),
755 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
759 if( $wgUser->isAllowed( 'delete' ) ) {
760 $content_actions['delete'] = array(
761 'class' => ($action == 'delete') ?
'selected' : false,
762 'text' => wfMsg( 'delete' ),
763 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
766 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
767 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
768 $content_actions['move'] = array(
769 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
770 'text' => wfMsg( 'move' ),
771 'href' => $moveTitle->getLocalUrl()
775 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
776 if( !$this->mTitle
->isProtected() ){
777 $content_actions['protect'] = array(
778 'class' => ($action == 'protect') ?
'selected' : false,
779 'text' => wfMsg( 'protect' ),
780 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
784 $content_actions['unprotect'] = array(
785 'class' => ($action == 'unprotect') ?
'selected' : false,
786 'text' => wfMsg( 'unprotect' ),
787 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
792 //article doesn't exist or is deleted
793 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
794 if( $n = $this->mTitle
->isDeleted() ) {
795 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
796 $content_actions['undelete'] = array(
798 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
799 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
800 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
805 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
806 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
807 $content_actions['protect'] = array(
808 'class' => ($action == 'protect') ?
'selected' : false,
809 'text' => wfMsg( 'protect' ),
810 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
814 $content_actions['unprotect'] = array(
815 'class' => ($action == 'unprotect') ?
'selected' : false,
816 'text' => wfMsg( 'unprotect' ),
817 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
823 wfProfileOut( __METHOD__
. '-live' );
825 if( $this->loggedin
) {
826 if( !$this->mTitle
->userIsWatching()) {
827 $content_actions['watch'] = array(
828 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
829 'text' => wfMsg( 'watch' ),
830 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
833 $content_actions['unwatch'] = array(
834 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
835 'text' => wfMsg( 'unwatch' ),
836 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
842 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
844 /* show special page tab */
846 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
847 'class' => 'selected',
848 'text' => wfMsg('nstab-special'),
849 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
852 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
855 /* show links to different language variants */
856 global $wgDisableLangConversion;
857 $variants = $wgContLang->getVariants();
858 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
859 $preferred = $wgContLang->getPreferredVariant();
861 foreach( $variants as $code ) {
862 $varname = $wgContLang->getVariantname( $code );
863 if( $varname == 'disable' )
865 $selected = ( $code == $preferred )?
'selected' : false;
866 $content_actions['varlang-' . $vcount] = array(
867 'class' => $selected,
869 'href' => $this->mTitle
->getLocalURL( '', $code )
875 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
877 wfProfileOut( __METHOD__
);
878 return $content_actions;
882 * build array of common navigation links
886 function buildNavUrls() {
887 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
888 global $wgEnableUploads, $wgUploadNavigationUrl;
890 wfProfileIn( __METHOD__
);
892 $action = $wgRequest->getVal( 'action', 'view' );
895 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
896 if( $wgUploadNavigationUrl ) {
897 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
898 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
899 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
901 $nav_urls['upload'] = false;
903 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
905 // default permalink to being off, will override it as required below.
906 $nav_urls['permalink'] = false;
908 // A print stylesheet is attached to all pages, but nobody ever
909 // figures that out. :) Add a link...
910 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
911 if ( !$wgRequest->getBool( 'printable' ) ) {
912 $nav_urls['print'] = array(
913 'text' => wfMsg( 'printableversion' ),
914 'href' => $wgRequest->appendQuery( 'printable=yes' )
918 // Also add a "permalink" while we're at it
919 if ( $this->mRevisionId
) {
920 $nav_urls['permalink'] = array(
921 'text' => wfMsg( 'permalink' ),
922 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
926 // Copy in case this undocumented, shady hook tries to mess with internals
927 $revid = $this->mRevisionId
;
928 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
931 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
932 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
933 $nav_urls['whatlinkshere'] = array(
934 'href' => $wlhTitle->getLocalUrl()
936 if( $this->mTitle
->getArticleId() ) {
937 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
938 $nav_urls['recentchangeslinked'] = array(
939 'href' => $rclTitle->getLocalUrl()
942 $nav_urls['recentchangeslinked'] = false;
944 if( $wgUseTrackbacks )
945 $nav_urls['trackbacklink'] = array(
946 'href' => $wgOut->getTitle()->trackbackURL()
950 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
951 $id = User
::idFromName( $this->mTitle
->getText() );
952 $ip = User
::isIP( $this->mTitle
->getText() );
958 if( $id ||
$ip ) { # both anons and non-anons have contribs list
959 $nav_urls['contributions'] = array(
960 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
964 $logPage = SpecialPage
::getTitleFor( 'Log' );
965 $nav_urls['log'] = array(
966 'href' => $logPage->getLocalUrl(
968 'user' => $this->mTitle
->getText()
973 $nav_urls['log'] = false;
976 if ( $wgUser->isAllowed( 'block' ) ) {
977 $nav_urls['blockip'] = array(
978 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
981 $nav_urls['blockip'] = false;
984 $nav_urls['contributions'] = false;
985 $nav_urls['log'] = false;
986 $nav_urls['blockip'] = false;
988 $nav_urls['emailuser'] = false;
989 if( $this->showEmailUser( $id ) ) {
990 $nav_urls['emailuser'] = array(
991 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
994 wfProfileOut( __METHOD__
);
999 * Generate strings used for xml 'id' names
1003 function getNameSpaceKey() {
1004 return $this->mTitle
->getNamespaceKey();
1010 function setupUserJs( $allowUserJs ) {
1011 global $wgRequest, $wgJsMimeType;
1012 wfProfileIn( __METHOD__
);
1014 $action = $wgRequest->getVal( 'action', 'view' );
1016 if( $allowUserJs && $this->loggedin
) {
1017 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1018 # XXX: additional security check/prompt?
1019 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1021 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1024 wfProfileOut( __METHOD__
);
1028 * Code for extensions to hook into to provide per-page CSS, see
1029 * extensions/PageCSS/PageCSS.php for an implementation of this.
1033 function setupPageCss() {
1034 wfProfileIn( __METHOD__
);
1036 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1037 wfProfileOut( __METHOD__
);
1041 public function commonPrintStylesheet() {
1047 * Generic wrapper for template functions, with interface
1048 * compatible with what we use of PHPTAL 0.7.
1051 class QuickTemplate
{
1055 public function QuickTemplate() {
1056 $this->data
= array();
1057 $this->translator
= new MediaWiki_I18N();
1061 * Sets the value $value to $name
1065 public function set( $name, $value ) {
1066 $this->data
[$name] = $value;
1073 public function setRef( $name, &$value ) {
1074 $this->data
[$name] =& $value;
1080 public function setTranslator( &$t ) {
1081 $this->translator
= &$t;
1085 * Main function, used by classes that subclass QuickTemplate
1086 * to show the actual HTML output
1088 public function execute() {
1089 echo 'Override this function.';
1095 function text( $str ) {
1096 echo htmlspecialchars( $this->data
[$str] );
1102 function jstext( $str ) {
1103 echo Xml
::escapeJsString( $this->data
[$str] );
1109 function html( $str ) {
1110 echo $this->data
[$str];
1116 function msg( $str ) {
1117 echo htmlspecialchars( $this->translator
->translate( $str ) );
1123 function msgHtml( $str ) {
1124 echo $this->translator
->translate( $str );
1128 * An ugly, ugly hack.
1131 function msgWiki( $str ) {
1132 global $wgParser, $wgOut;
1134 $text = $this->translator
->translate( $str );
1135 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1136 $wgOut->parserOptions(), true );
1137 echo $parserOutput->getText();
1143 function haveData( $str ) {
1144 return isset( $this->data
[$str] );
1150 function haveMsg( $str ) {
1151 $msg = $this->translator
->translate( $str );
1152 return ( $msg != '-' ) && ( $msg != '' ); # ????