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, it probably needs to be all lower case. Child classes
74 * should override the default.
76 var $skinname = 'monobook';
79 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
80 * are located. Child classes should override the default.
82 var $stylename = 'monobook';
85 * For QuickTemplate, the name of the subclass which will actually fill the
86 * template. Child classes should override the default.
88 var $template = 'QuickTemplate';
93 * Add specific styles for this skin
95 * @param $out OutputPage
97 function setupSkinUserCss( OutputPage
$out ){
98 $out->addStyle( 'common/shared.css', 'screen' );
99 $out->addStyle( 'common/commonPrint.css', 'print' );
101 /* add specific javascript the base Skin class */
102 function setupSkinUserJs( OutputPage
$out ){
106 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
107 $siteGenScriptFile = self
::makeUrl( '-',
108 "action=raw$jsCache&gen=js&useskin=" .
109 urlencode( $this->getSkinName() ) ) ;
110 $this->jsvarurl
= $siteGenScriptFile;
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param $callback string (or file)
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
130 * initialize various variables and generate the template
132 * @param $out OutputPage
134 function outputPage( OutputPage
$out ) {
135 global $wgArticle, $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
145 wfProfileIn( __METHOD__
);
147 $oldid = $wgRequest->getVal( 'oldid' );
148 $diff = $wgRequest->getVal( 'diff' );
149 $action = $wgRequest->getVal( 'action', 'view' );
151 wfProfileIn( __METHOD__
. '-init' );
152 $this->initPage( $out );
155 $tpl = $this->setupTemplate( $this->template
, 'skins' );
157 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
158 $tpl->setTranslator( new MediaWiki_I18N() );
160 wfProfileOut( __METHOD__
. '-init' );
162 wfProfileIn( __METHOD__
. '-stuff' );
163 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
164 $this->thisurl
= $this->mTitle
->getPrefixedURL();
165 $query = $wgRequest->getValues();
166 unset( $query['title'] );
167 unset( $query['returnto'] );
168 unset( $query['returntoquery'] );
169 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
170 $this->loggedin
= $wgUser->isLoggedIn();
171 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
172 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
173 $this->username
= $wgUser->getName();
175 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
176 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
178 # This won't be used in the standard skins, but we define it to preserve the interface
179 # To save time, we check for existence
180 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
183 $this->userjs
= $this->userjsprev
= false;
184 $this->setupUserCss( $out );
185 $this->setupUserJs( $out->isUserJsAllowed() );
186 $this->titletxt
= $this->mTitle
->getPrefixedText();
187 wfProfileOut( __METHOD__
. '-stuff' );
189 wfProfileIn( __METHOD__
. '-stuff2' );
190 $tpl->set( 'title', $out->getPageTitle() );
191 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
192 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
193 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
194 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
196 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
197 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
198 $this->mTitle
->getNsText();
200 $tpl->set( 'nscanonical', $nsname );
201 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
202 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
203 $tpl->set( 'titletext', $this->mTitle
->getText() );
204 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
205 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
207 $tpl->set( 'isarticle', $out->isArticle() );
209 $tpl->setRef( 'thispage', $this->thispage
);
210 $subpagestr = $this->subPageSubtitle();
212 'subtitle', !empty( $subpagestr ) ?
213 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
216 $undelete = $this->getUndeleteLink();
218 'undelete', !empty( $undelete ) ?
219 '<span class="subpages">'.$undelete.'</span>' :
223 $tpl->set( 'catlinks', $this->getCategories() );
224 if( $out->isSyndicated() ) {
226 foreach( $out->getSyndicationLinks() as $format => $link ) {
227 $feeds[$format] = array(
228 'text' => wfMsg( "feed-$format" ),
232 $tpl->setRef( 'feeds', $feeds );
234 $tpl->set( 'feeds', false );
236 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
237 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
239 $tpl->set( 'trackbackhtml', null );
242 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
243 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
244 $tpl->setRef( 'mimetype', $wgMimeType );
245 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
246 $tpl->setRef( 'charset', $wgOutputEncoding );
247 $tpl->set( 'headlinks', $out->getHeadLinks() );
249 //moved headscripts to near end of template header output
251 $tpl->set( 'csslinks', $out->buildCssLinks() );
252 $tpl->setRef( 'wgScript', $wgScript );
253 $tpl->setRef( 'skinname', $this->skinname
);
254 $tpl->set( 'skinclass', get_class( $this ) );
255 $tpl->setRef( 'stylename', $this->stylename
);
256 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
257 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
258 $tpl->setRef( 'loggedin', $this->loggedin
);
259 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
260 /* XXX currently unused, might get useful later
261 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
262 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
263 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
264 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
265 $tpl->set( "helppage", wfMsg('helppage'));
267 $tpl->set( 'searchaction', $this->escapeSearchLink() );
268 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
269 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
270 $tpl->setRef( 'stylepath', $wgStylePath );
271 $tpl->setRef( 'articlepath', $wgArticlePath );
272 $tpl->setRef( 'scriptpath', $wgScriptPath );
273 $tpl->setRef( 'serverurl', $wgServer );
274 $tpl->setRef( 'logopath', $wgLogo );
275 $tpl->setRef( 'lang', $wgContLanguageCode );
276 $tpl->set( 'dir', $wgContLang->isRTL() ?
'rtl' : 'ltr' );
277 $tpl->set( 'rtl', $wgContLang->isRTL() );
278 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
279 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
280 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
281 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
282 $tpl->setRef( 'userpage', $this->userpage
);
283 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
284 $tpl->set( 'userlang', $wgLang->getCode() );
285 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
286 $tpl->set( 'pagecss', $this->setupPageCss() );
287 $tpl->setRef( 'usercss', $this->usercss
);
288 $tpl->setRef( 'userjs', $this->userjs
);
289 $tpl->setRef( 'userjsprev', $this->userjsprev
);
291 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
292 $tpl->set( 'jsvarurl',
294 "action=raw$jsCache&gen=js&useskin=" .
295 urlencode( $this->getSkinName() ) ) );
297 $tpl->set( 'jsvarurl', false );
300 $newtalks = $wgUser->getNewMessageLinks();
302 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
303 $usertitle = $this->mUser
->getUserPage();
304 $usertalktitle = $usertitle->getTalkPage();
306 if( !$usertalktitle->equals( $this->mTitle
) ) {
307 $newmessageslink = $this->link(
309 wfMsgHtml( 'newmessageslink' ),
311 array( 'redirect' => 'no' ),
312 array( 'known', 'noclasses' )
315 $newmessagesdifflink = $this->link(
317 wfMsgHtml( 'newmessagesdifflink' ),
319 array( 'diff' => 'cur' ),
320 array( 'known', 'noclasses' )
324 'youhavenewmessages',
329 $out->setSquidMaxage( 0 );
331 } else if( count( $newtalks ) ) {
332 // _>" " for BC <= 1.16
333 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
335 foreach( $newtalks as $newtalk ) {
336 $msgs[] = Xml
::element('a',
337 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
339 $parts = implode( $sep, $msgs );
340 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
341 $out->setSquidMaxage( 0 );
345 wfProfileOut( __METHOD__
. '-stuff2' );
347 wfProfileIn( __METHOD__
. '-stuff3' );
348 $tpl->setRef( 'newtalk', $ntl );
349 $tpl->setRef( 'skin', $this );
350 $tpl->set( 'logo', $this->logoText() );
351 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
352 $wgArticle and 0 != $wgArticle->getID() ){
353 if ( !$wgDisableCounters ) {
354 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
356 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
358 $tpl->set( 'viewcount', false );
361 $tpl->set( 'viewcount', false );
364 if( $wgPageShowWatchingUsers ) {
365 $dbr = wfGetDB( DB_SLAVE
);
366 $watchlist = $dbr->tableName( 'watchlist' );
367 $res = $dbr->select( 'watchlist',
368 array( 'COUNT(*) AS n' ),
369 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
372 $x = $dbr->fetchObject( $res );
373 $numberofwatchingusers = $x->n
;
374 if( $numberofwatchingusers > 0 ) {
375 $tpl->set( 'numberofwatchingusers',
376 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
377 $wgLang->formatNum( $numberofwatchingusers ) )
380 $tpl->set( 'numberofwatchingusers', false );
383 $tpl->set( 'numberofwatchingusers', false );
386 $tpl->set( 'copyright', $this->getCopyright() );
388 $this->credits
= false;
390 if( $wgMaxCredits != 0 ){
391 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
393 $tpl->set( 'lastmod', $this->lastModified() );
396 $tpl->setRef( 'credits', $this->credits
);
398 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
399 $tpl->set( 'copyright', $this->getCopyright() );
400 $tpl->set( 'viewcount', false );
401 $tpl->set( 'lastmod', false );
402 $tpl->set( 'credits', false );
403 $tpl->set( 'numberofwatchingusers', false );
405 $tpl->set( 'copyright', false );
406 $tpl->set( 'viewcount', false );
407 $tpl->set( 'lastmod', false );
408 $tpl->set( 'credits', false );
409 $tpl->set( 'numberofwatchingusers', false );
411 wfProfileOut( __METHOD__
. '-stuff3' );
413 wfProfileIn( __METHOD__
. '-stuff4' );
414 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
415 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
416 $tpl->set( 'disclaimer', $this->disclaimerLink() );
417 $tpl->set( 'privacy', $this->privacyLink() );
418 $tpl->set( 'about', $this->aboutLink() );
420 $tpl->setRef( 'debug', $out->mDebugtext
);
421 $tpl->set( 'reporttime', wfReportTime() );
422 $tpl->set( 'sitenotice', wfGetSiteNotice() );
423 $tpl->set( 'bottomscripts', $this->bottomScripts() );
425 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
426 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
427 $tpl->setRef( 'bodytext', $out->mBodytext
);
430 $language_urls = array();
432 if ( !$wgHideInterlanguageLinks ) {
433 foreach( $out->getLanguageLinks() as $l ) {
434 $tmp = explode( ':', $l, 2 );
435 $class = 'interwiki-' . $tmp[0];
437 $nt = Title
::newFromText( $l );
439 $language_urls[] = array(
440 'href' => $nt->getFullURL(),
441 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
442 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
448 if( count( $language_urls ) ) {
449 $tpl->setRef( 'language_urls', $language_urls );
451 $tpl->set( 'language_urls', false );
453 wfProfileOut( __METHOD__
. '-stuff4' );
455 wfProfileIn( __METHOD__
. '-stuff5' );
457 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
458 $content_actions = $this->buildContentActionUrls();
459 $tpl->setRef( 'content_actions', $content_actions );
461 // XXX: attach this from javascript, same with section editing
462 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
463 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
464 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
466 $tpl->set( 'body_ondblclick', false );
468 $tpl->set( 'body_onload', false );
469 $tpl->set( 'sidebar', $this->buildSidebar() );
470 $tpl->set( 'nav_urls', $this->buildNavUrls() );
472 //set the head script near the end (in case above actions result in adding scripts)
473 $tpl->set( 'headscripts', $out->getScript() );
475 // original version by hansm
476 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
477 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
480 // allow extensions adding stuff after the page content.
481 // See Skin::afterContentHook() for further documentation.
482 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
483 wfProfileOut( __METHOD__
. '-stuff5' );
486 wfProfileIn( __METHOD__
. '-execute' );
487 $res = $tpl->execute();
488 wfProfileOut( __METHOD__
. '-execute' );
490 // result may be an error
491 $this->printOrError( $res );
492 wfProfileOut( __METHOD__
);
496 * Output the string, or print error message if it's
497 * an error object of the appropriate type.
498 * For the base class, assume strings all around.
503 function printOrError( $str ) {
508 * build array of urls for personal toolbar
512 function buildPersonalUrls() {
513 global $wgOut, $wgRequest;
515 $title = $wgOut->getTitle();
516 $pageurl = $title->getLocalURL();
517 wfProfileIn( __METHOD__
);
519 /* set up the default links for the personal toolbar */
520 $personal_urls = array();
521 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
522 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
523 $returnto = "returnto=$page";
524 if( $this->thisquery
!= '' )
525 $returnto .= "&returntoquery=$query";
526 if( $this->loggedin
) {
527 $personal_urls['userpage'] = array(
528 'text' => $this->username
,
529 'href' => &$this->userpageUrlDetails
['href'],
530 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
531 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
533 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
534 $personal_urls['mytalk'] = array(
535 'text' => wfMsg( 'mytalk' ),
536 'href' => &$usertalkUrlDetails['href'],
537 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
538 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
540 $href = self
::makeSpecialUrl( 'Preferences' );
541 $personal_urls['preferences'] = array(
542 'text' => wfMsg( 'mypreferences' ),
544 'active' => ( $href == $pageurl )
546 $href = self
::makeSpecialUrl( 'Watchlist' );
547 $personal_urls['watchlist'] = array(
548 'text' => wfMsg( 'mywatchlist' ),
550 'active' => ( $href == $pageurl )
553 # We need to do an explicit check for Special:Contributions, as we
554 # have to match both the title, and the target (which could come
555 # from request values or be specified in "sub page" form. The plot
556 # thickens, because $wgTitle is altered for special pages, so doesn't
557 # contain the original alias-with-subpage.
558 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
559 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
560 list( $spName, $spPar ) =
561 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
562 $active = $spName == 'Contributions'
563 && ( ( $spPar && $spPar == $this->username
)
564 ||
$wgRequest->getText( 'target' ) == $this->username
);
569 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
570 $personal_urls['mycontris'] = array(
571 'text' => wfMsg( 'mycontris' ),
575 $personal_urls['logout'] = array(
576 'text' => wfMsg( 'userlogout' ),
577 'href' => self
::makeSpecialUrl( 'Userlogout',
578 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
584 $loginlink = $wgUser->isAllowed( 'createaccount' )
585 ?
'nav-login-createaccount'
587 if( $this->showIPinHeader() ) {
588 $href = &$this->userpageUrlDetails
['href'];
589 $personal_urls['anonuserpage'] = array(
590 'text' => $this->username
,
592 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
593 'active' => ( $pageurl == $href )
595 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
596 $href = &$usertalkUrlDetails['href'];
597 $personal_urls['anontalk'] = array(
598 'text' => wfMsg( 'anontalk' ),
600 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
601 'active' => ( $pageurl == $href )
603 $personal_urls['anonlogin'] = array(
604 'text' => wfMsg( $loginlink ),
605 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
606 'active' => $title->isSpecial( 'Userlogin' )
609 $personal_urls['login'] = array(
610 'text' => wfMsg( $loginlink ),
611 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
612 'active' => $title->isSpecial( 'Userlogin' )
617 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
618 wfProfileOut( __METHOD__
);
619 return $personal_urls;
622 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
625 $classes[] = 'selected';
627 if( $checkEdit && !$title->isKnown() ) {
629 $query = 'action=edit&redlink=1';
632 $text = wfMsg( $message );
633 if ( wfEmptyMsg( $message, $text ) ) {
635 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
639 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
640 $title, $message, $selected, $checkEdit,
641 &$classes, &$query, &$text, &$result ) ) ) {
646 'class' => implode( ' ', $classes ),
648 'href' => $title->getLocalUrl( $query ) );
651 function makeTalkUrlDetails( $name, $urlaction = '' ) {
652 $title = Title
::newFromText( $name );
653 if( !is_object( $title ) ) {
654 throw new MWException( __METHOD__
. " given invalid pagename $name" );
656 $title = $title->getTalkPage();
657 self
::checkTitle( $title, $name );
659 'href' => $title->getLocalURL( $urlaction ),
660 'exists' => $title->getArticleID() != 0 ?
true : false
664 function makeArticleUrlDetails( $name, $urlaction = '' ) {
665 $title = Title
::newFromText( $name );
666 $title= $title->getSubjectPage();
667 self
::checkTitle( $title, $name );
669 'href' => $title->getLocalURL( $urlaction ),
670 'exists' => $title->getArticleID() != 0 ?
true : false
675 * an array of edit links by default used for the tabs
679 function buildContentActionUrls() {
680 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
682 wfProfileIn( __METHOD__
);
684 $action = $wgRequest->getVal( 'action', 'view' );
685 $section = $wgRequest->getVal( 'section' );
686 $content_actions = array();
688 $prevent_active_tabs = false;
689 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
691 if( $this->iscontent
) {
692 $subjpage = $this->mTitle
->getSubjectPage();
693 $talkpage = $this->mTitle
->getTalkPage();
695 $nskey = $this->mTitle
->getNamespaceKey();
696 $content_actions[$nskey] = $this->tabAction(
699 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
703 $content_actions['talk'] = $this->tabAction(
706 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
711 wfProfileIn( __METHOD__
. '-edit' );
712 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
713 $istalk = $this->mTitle
->isTalkPage();
714 $istalkclass = $istalk?
' istalk':'';
715 $content_actions['edit'] = array(
716 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
717 'text' => $this->mTitle
->exists()
720 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
723 // adds new section link if page is a current revision of a talk page or
724 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
725 if ( !$wgOut->forceHideNewSectionLink() ) {
726 $content_actions['addsection'] = array(
727 'class' => $section == 'new' ?
'selected' : false,
728 'text' => wfMsg( 'addsection' ),
729 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
733 } elseif ( $this->mTitle
->isKnown() ) {
734 $content_actions['viewsource'] = array(
735 'class' => ($action == 'edit') ?
'selected' : false,
736 'text' => wfMsg( 'viewsource' ),
737 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
740 wfProfileOut( __METHOD__
. '-edit' );
742 wfProfileIn( __METHOD__
. '-live' );
743 if ( $this->mTitle
->exists() ) {
745 $content_actions['history'] = array(
746 'class' => ($action == 'history') ?
'selected' : false,
747 'text' => wfMsg( 'history_short' ),
748 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
752 if( $wgUser->isAllowed( 'delete' ) ) {
753 $content_actions['delete'] = array(
754 'class' => ($action == 'delete') ?
'selected' : false,
755 'text' => wfMsg( 'delete' ),
756 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
759 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
760 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
761 $content_actions['move'] = array(
762 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
763 'text' => wfMsg( 'move' ),
764 'href' => $moveTitle->getLocalUrl()
768 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
769 if( !$this->mTitle
->isProtected() ){
770 $content_actions['protect'] = array(
771 'class' => ($action == 'protect') ?
'selected' : false,
772 'text' => wfMsg( 'protect' ),
773 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
777 $content_actions['unprotect'] = array(
778 'class' => ($action == 'unprotect') ?
'selected' : false,
779 'text' => wfMsg( 'unprotect' ),
780 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
785 //article doesn't exist or is deleted
786 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
787 if( $n = $this->mTitle
->isDeleted() ) {
788 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
789 $content_actions['undelete'] = array(
791 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
792 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
793 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
798 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
799 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
800 $content_actions['protect'] = array(
801 'class' => ($action == 'protect') ?
'selected' : false,
802 'text' => wfMsg( 'protect' ),
803 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
807 $content_actions['unprotect'] = array(
808 'class' => ($action == 'unprotect') ?
'selected' : false,
809 'text' => wfMsg( 'unprotect' ),
810 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
816 wfProfileOut( __METHOD__
. '-live' );
818 if( $this->loggedin
) {
819 if( !$this->mTitle
->userIsWatching()) {
820 $content_actions['watch'] = array(
821 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
822 'text' => wfMsg( 'watch' ),
823 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
826 $content_actions['unwatch'] = array(
827 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
828 'text' => wfMsg( 'unwatch' ),
829 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
835 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
837 /* show special page tab */
839 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
840 'class' => 'selected',
841 'text' => wfMsg('nstab-special'),
842 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
845 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
848 /* show links to different language variants */
849 global $wgDisableLangConversion;
850 $variants = $wgContLang->getVariants();
851 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
852 $preferred = $wgContLang->getPreferredVariant();
854 foreach( $variants as $code ) {
855 $varname = $wgContLang->getVariantname( $code );
856 if( $varname == 'disable' )
858 $selected = ( $code == $preferred )?
'selected' : false;
859 $content_actions['varlang-' . $vcount] = array(
860 'class' => $selected,
862 'href' => $this->mTitle
->getLocalURL( '', $code )
868 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
870 wfProfileOut( __METHOD__
);
871 return $content_actions;
875 * build array of common navigation links
879 function buildNavUrls() {
880 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
881 global $wgEnableUploads, $wgUploadNavigationUrl;
883 wfProfileIn( __METHOD__
);
885 $action = $wgRequest->getVal( 'action', 'view' );
888 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
889 if( $wgUploadNavigationUrl ) {
890 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
891 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
892 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
894 $nav_urls['upload'] = false;
896 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
898 // default permalink to being off, will override it as required below.
899 $nav_urls['permalink'] = false;
901 // A print stylesheet is attached to all pages, but nobody ever
902 // figures that out. :) Add a link...
903 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
904 if ( !$wgRequest->getBool( 'printable' ) ) {
905 $nav_urls['print'] = array(
906 'text' => wfMsg( 'printableversion' ),
907 'href' => $wgRequest->appendQuery( 'printable=yes' )
911 // Also add a "permalink" while we're at it
912 if ( $this->mRevisionId
) {
913 $nav_urls['permalink'] = array(
914 'text' => wfMsg( 'permalink' ),
915 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
919 // Copy in case this undocumented, shady hook tries to mess with internals
920 $revid = $this->mRevisionId
;
921 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
924 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
925 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
926 $nav_urls['whatlinkshere'] = array(
927 'href' => $wlhTitle->getLocalUrl()
929 if( $this->mTitle
->getArticleId() ) {
930 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
931 $nav_urls['recentchangeslinked'] = array(
932 'href' => $rclTitle->getLocalUrl()
935 $nav_urls['recentchangeslinked'] = false;
937 if( $wgUseTrackbacks )
938 $nav_urls['trackbacklink'] = array(
939 'href' => $wgOut->getTitle()->trackbackURL()
943 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
944 $id = User
::idFromName( $this->mTitle
->getText() );
945 $ip = User
::isIP( $this->mTitle
->getText() );
951 if( $id ||
$ip ) { # both anons and non-anons have contribs list
952 $nav_urls['contributions'] = array(
953 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
957 $logPage = SpecialPage
::getTitleFor( 'Log' );
958 $nav_urls['log'] = array(
959 'href' => $logPage->getLocalUrl(
961 'user' => $this->mTitle
->getText()
966 $nav_urls['log'] = false;
969 if ( $wgUser->isAllowed( 'block' ) ) {
970 $nav_urls['blockip'] = array(
971 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
974 $nav_urls['blockip'] = false;
977 $nav_urls['contributions'] = false;
978 $nav_urls['log'] = false;
979 $nav_urls['blockip'] = false;
981 $nav_urls['emailuser'] = false;
982 if( $this->showEmailUser( $id ) ) {
983 $nav_urls['emailuser'] = array(
984 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
987 wfProfileOut( __METHOD__
);
992 * Generate strings used for xml 'id' names
996 function getNameSpaceKey() {
997 return $this->mTitle
->getNamespaceKey();
1003 function setupUserJs( $allowUserJs ) {
1004 global $wgRequest, $wgJsMimeType;
1005 wfProfileIn( __METHOD__
);
1007 $action = $wgRequest->getVal( 'action', 'view' );
1009 if( $allowUserJs && $this->loggedin
) {
1010 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1011 # XXX: additional security check/prompt?
1012 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1014 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1017 wfProfileOut( __METHOD__
);
1021 * Code for extensions to hook into to provide per-page CSS, see
1022 * extensions/PageCSS/PageCSS.php for an implementation of this.
1026 function setupPageCss() {
1027 wfProfileIn( __METHOD__
);
1029 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1030 wfProfileOut( __METHOD__
);
1034 public function commonPrintStylesheet() {
1040 * Generic wrapper for template functions, with interface
1041 * compatible with what we use of PHPTAL 0.7.
1044 abstract class QuickTemplate
{
1048 public function QuickTemplate() {
1049 $this->data
= array();
1050 $this->translator
= new MediaWiki_I18N();
1054 * Sets the value $value to $name
1058 public function set( $name, $value ) {
1059 $this->data
[$name] = $value;
1066 public function setRef( $name, &$value ) {
1067 $this->data
[$name] =& $value;
1073 public function setTranslator( &$t ) {
1074 $this->translator
= &$t;
1078 * Main function, used by classes that subclass QuickTemplate
1079 * to show the actual HTML output
1081 abstract public function execute();
1086 function text( $str ) {
1087 echo htmlspecialchars( $this->data
[$str] );
1093 function jstext( $str ) {
1094 echo Xml
::escapeJsString( $this->data
[$str] );
1100 function html( $str ) {
1101 echo $this->data
[$str];
1107 function msg( $str ) {
1108 echo htmlspecialchars( $this->translator
->translate( $str ) );
1114 function msgHtml( $str ) {
1115 echo $this->translator
->translate( $str );
1119 * An ugly, ugly hack.
1122 function msgWiki( $str ) {
1123 global $wgParser, $wgOut;
1125 $text = $this->translator
->translate( $str );
1126 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1127 $wgOut->parserOptions(), true );
1128 echo $parserOutput->getText();
1134 function haveData( $str ) {
1135 return isset( $this->data
[$str] );
1141 function haveMsg( $str ) {
1142 $msg = $this->translator
->translate( $str );
1143 return ( $msg != '-' ) && ( $msg != '' ); # ????