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' );
103 * Add specific JavaScript the base Skin class.
104 * FIXME: not called from anywhere
106 function setupSkinUserJs( OutputPage
$out ) {
109 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
110 $siteGenScriptFile = self
::makeUrl( '-',
111 "action=raw$jsCache&gen=js&useskin=" . urlencode( $this->getSkinName() ) );
112 $this->jsvarurl
= $siteGenScriptFile;
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 $wgArticle, $wgUser, $wgLang, $wgContLang;
138 global $wgScript, $wgStylePath, $wgContLanguageCode;
139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
141 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
142 global $wgMaxCredits, $wgShowCreditsIfMax;
143 global $wgPageShowWatchingUsers;
144 global $wgUseTrackbacks, $wgUseSiteJs;
145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
147 wfProfileIn( __METHOD__
);
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151 $action = $wgRequest->getVal( 'action', 'view' );
153 wfProfileIn( __METHOD__
. '-init' );
154 $this->initPage( $out );
157 $tpl = $this->setupTemplate( $this->template
, 'skins' );
159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
160 $tpl->setTranslator( new MediaWiki_I18N() );
162 wfProfileOut( __METHOD__
. '-init' );
164 wfProfileIn( __METHOD__
. '-stuff' );
165 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
166 $this->thisurl
= $this->mTitle
->getPrefixedURL();
168 if ( !$wgRequest->wasPosted() ) {
169 $query = $wgRequest->getValues();
170 unset( $query['title'] );
171 unset( $query['returnto'] );
172 unset( $query['returntoquery'] );
174 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
175 $this->loggedin
= $wgUser->isLoggedIn();
176 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
177 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
178 $this->username
= $wgUser->getName();
180 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
181 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
183 # This won't be used in the standard skins, but we define it to preserve the interface
184 # To save time, we check for existence
185 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
188 $this->userjs
= $this->userjsprev
= false;
189 $this->setupUserCss( $out );
190 $this->setupUserJs( $out->isUserJsAllowed() );
191 $this->titletxt
= $this->mTitle
->getPrefixedText();
192 wfProfileOut( __METHOD__
. '-stuff' );
194 wfProfileIn( __METHOD__
. '-stuff2' );
195 $tpl->set( 'title', $out->getPageTitle() );
196 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
197 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
198 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
199 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
201 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
202 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
203 $this->mTitle
->getNsText();
205 $tpl->set( 'nscanonical', $nsname );
206 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
207 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
208 $tpl->set( 'titletext', $this->mTitle
->getText() );
209 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
210 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
212 $tpl->set( 'isarticle', $out->isArticle() );
214 $tpl->setRef( 'thispage', $this->thispage
);
215 $subpagestr = $this->subPageSubtitle();
217 'subtitle', !empty( $subpagestr ) ?
218 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
221 $undelete = $this->getUndeleteLink();
223 'undelete', !empty( $undelete ) ?
224 '<span class="subpages">'.$undelete.'</span>' :
228 $tpl->set( 'catlinks', $this->getCategories() );
229 if( $out->isSyndicated() ) {
231 foreach( $out->getSyndicationLinks() as $format => $link ) {
232 $feeds[$format] = array(
233 'text' => wfMsg( "feed-$format" ),
237 $tpl->setRef( 'feeds', $feeds );
239 $tpl->set( 'feeds', false );
241 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
242 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
244 $tpl->set( 'trackbackhtml', null );
247 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
248 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
249 $tpl->setRef( 'mimetype', $wgMimeType );
250 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
251 $tpl->setRef( 'charset', $wgOutputEncoding );
252 $tpl->set( 'headlinks', $out->getHeadLinks() );
253 $tpl->set( 'csslinks', $out->buildCssLinks() );
254 $tpl->setRef( 'wgScript', $wgScript );
255 $tpl->setRef( 'skinname', $this->skinname
);
256 $tpl->set( 'skinclass', get_class( $this ) );
257 $tpl->setRef( 'stylename', $this->stylename
);
258 $tpl->set( 'printable', $out->isPrintable() );
259 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
260 $tpl->setRef( 'loggedin', $this->loggedin
);
261 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
262 /* XXX currently unused, might get useful later
263 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
264 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
265 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
266 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
267 $tpl->set( "helppage", wfMsg('helppage'));
269 $tpl->set( 'searchaction', $this->escapeSearchLink() );
270 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
271 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
272 $tpl->setRef( 'stylepath', $wgStylePath );
273 $tpl->setRef( 'articlepath', $wgArticlePath );
274 $tpl->setRef( 'scriptpath', $wgScriptPath );
275 $tpl->setRef( 'serverurl', $wgServer );
276 $tpl->setRef( 'logopath', $wgLogo );
277 $tpl->setRef( 'lang', $wgContLanguageCode );
278 $tpl->set( 'dir', $wgContLang->getDir() );
279 $tpl->set( 'rtl', $wgContLang->isRTL() );
280 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
281 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
282 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
283 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
284 $tpl->setRef( 'userpage', $this->userpage
);
285 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
286 $tpl->set( 'userlang', $wgLang->getCode() );
287 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
288 $tpl->set( 'pagecss', $this->setupPageCss() );
289 $tpl->setRef( 'usercss', $this->usercss
);
290 $tpl->setRef( 'userjs', $this->userjs
);
291 $tpl->setRef( 'userjsprev', $this->userjsprev
);
293 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
294 $tpl->set( 'jsvarurl',
296 "action=raw$jsCache&gen=js&useskin=" .
297 urlencode( $this->getSkinName() ) ) );
299 $tpl->set( 'jsvarurl', false );
302 $newtalks = $wgUser->getNewMessageLinks();
304 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
305 $usertitle = $this->mUser
->getUserPage();
306 $usertalktitle = $usertitle->getTalkPage();
308 if( !$usertalktitle->equals( $this->mTitle
) ) {
309 $newmessageslink = $this->link(
311 wfMsgHtml( 'newmessageslink' ),
313 array( 'redirect' => 'no' ),
314 array( 'known', 'noclasses' )
317 $newmessagesdifflink = $this->link(
319 wfMsgHtml( 'newmessagesdifflink' ),
321 array( 'diff' => 'cur' ),
322 array( 'known', 'noclasses' )
326 'youhavenewmessages',
331 $out->setSquidMaxage( 0 );
333 } else if( count( $newtalks ) ) {
334 // _>" " for BC <= 1.16
335 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
337 foreach( $newtalks as $newtalk ) {
338 $msgs[] = Xml
::element('a',
339 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
341 $parts = implode( $sep, $msgs );
342 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
343 $out->setSquidMaxage( 0 );
347 wfProfileOut( __METHOD__
. '-stuff2' );
349 wfProfileIn( __METHOD__
. '-stuff3' );
350 $tpl->setRef( 'newtalk', $ntl );
351 $tpl->setRef( 'skin', $this );
352 $tpl->set( 'logo', $this->logoText() );
353 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
354 $wgArticle and 0 != $wgArticle->getID() ){
355 if ( !$wgDisableCounters ) {
356 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
358 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
360 $tpl->set( 'viewcount', false );
363 $tpl->set( 'viewcount', false );
366 if( $wgPageShowWatchingUsers ) {
367 $dbr = wfGetDB( DB_SLAVE
);
368 $watchlist = $dbr->tableName( 'watchlist' );
369 $res = $dbr->select( 'watchlist',
370 array( 'COUNT(*) AS n' ),
371 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
374 $x = $dbr->fetchObject( $res );
375 $numberofwatchingusers = $x->n
;
376 if( $numberofwatchingusers > 0 ) {
377 $tpl->set( 'numberofwatchingusers',
378 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
379 $wgLang->formatNum( $numberofwatchingusers ) )
382 $tpl->set( 'numberofwatchingusers', false );
385 $tpl->set( 'numberofwatchingusers', false );
388 $tpl->set( 'copyright', $this->getCopyright() );
390 $this->credits
= false;
392 if( $wgMaxCredits != 0 ){
393 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
395 $tpl->set( 'lastmod', $this->lastModified() );
398 $tpl->setRef( 'credits', $this->credits
);
400 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
401 $tpl->set( 'copyright', $this->getCopyright() );
402 $tpl->set( 'viewcount', false );
403 $tpl->set( 'lastmod', false );
404 $tpl->set( 'credits', false );
405 $tpl->set( 'numberofwatchingusers', false );
407 $tpl->set( 'copyright', false );
408 $tpl->set( 'viewcount', false );
409 $tpl->set( 'lastmod', false );
410 $tpl->set( 'credits', false );
411 $tpl->set( 'numberofwatchingusers', false );
413 wfProfileOut( __METHOD__
. '-stuff3' );
415 wfProfileIn( __METHOD__
. '-stuff4' );
416 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
417 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
418 $tpl->set( 'disclaimer', $this->disclaimerLink() );
419 $tpl->set( 'privacy', $this->privacyLink() );
420 $tpl->set( 'about', $this->aboutLink() );
422 $tpl->setRef( 'debug', $out->mDebugtext
);
423 $tpl->set( 'reporttime', wfReportTime() );
424 $tpl->set( 'sitenotice', wfGetSiteNotice() );
425 $tpl->set( 'bottomscripts', $this->bottomScripts() );
427 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
428 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
429 $tpl->setRef( 'bodytext', $out->mBodytext
);
432 $language_urls = array();
434 if ( !$wgHideInterlanguageLinks ) {
435 foreach( $out->getLanguageLinks() as $l ) {
436 $tmp = explode( ':', $l, 2 );
437 $class = 'interwiki-' . $tmp[0];
439 $nt = Title
::newFromText( $l );
441 $language_urls[] = array(
442 'href' => $nt->getFullURL(),
443 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
444 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
450 if( count( $language_urls ) ) {
451 $tpl->setRef( 'language_urls', $language_urls );
453 $tpl->set( 'language_urls', false );
455 wfProfileOut( __METHOD__
. '-stuff4' );
457 wfProfileIn( __METHOD__
. '-stuff5' );
459 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
460 $content_actions = $this->buildContentActionUrls();
461 $tpl->setRef( 'content_actions', $content_actions );
463 // XXX: attach this from javascript, same with section editing
464 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
465 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
466 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
468 $tpl->set( 'body_ondblclick', false );
470 $tpl->set( 'body_onload', false );
471 $tpl->set( 'sidebar', $this->buildSidebar() );
472 $tpl->set( 'nav_urls', $this->buildNavUrls() );
474 // Set the head scripts near the end, in case the above actions resulted in added scripts
475 $tpl->set( 'headscripts', $out->getScript() );
477 // original version by hansm
478 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
479 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
482 // allow extensions adding stuff after the page content.
483 // See Skin::afterContentHook() for further documentation.
484 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
485 wfProfileOut( __METHOD__
. '-stuff5' );
488 wfProfileIn( __METHOD__
. '-execute' );
489 $res = $tpl->execute();
490 wfProfileOut( __METHOD__
. '-execute' );
492 // result may be an error
493 $this->printOrError( $res );
494 wfProfileOut( __METHOD__
);
498 * Output the string, or print error message if it's
499 * an error object of the appropriate type.
500 * For the base class, assume strings all around.
505 function printOrError( $str ) {
510 * build array of urls for personal toolbar
514 function buildPersonalUrls() {
515 global $wgOut, $wgRequest;
517 $title = $wgOut->getTitle();
518 $pageurl = $title->getLocalURL();
519 wfProfileIn( __METHOD__
);
521 /* set up the default links for the personal toolbar */
522 $personal_urls = array();
523 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
524 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
525 $returnto = "returnto=$page";
526 if( $this->thisquery
!= '' )
527 $returnto .= "&returntoquery=$query";
528 if( $this->loggedin
) {
529 $personal_urls['userpage'] = array(
530 'text' => $this->username
,
531 'href' => &$this->userpageUrlDetails
['href'],
532 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
533 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
535 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
536 $personal_urls['mytalk'] = array(
537 'text' => wfMsg( 'mytalk' ),
538 'href' => &$usertalkUrlDetails['href'],
539 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
540 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
542 $href = self
::makeSpecialUrl( 'Preferences' );
543 $personal_urls['preferences'] = array(
544 'text' => wfMsg( 'mypreferences' ),
546 'active' => ( $href == $pageurl )
548 $href = self
::makeSpecialUrl( 'Watchlist' );
549 $personal_urls['watchlist'] = array(
550 'text' => wfMsg( 'mywatchlist' ),
552 'active' => ( $href == $pageurl )
555 # We need to do an explicit check for Special:Contributions, as we
556 # have to match both the title, and the target (which could come
557 # from request values or be specified in "sub page" form. The plot
558 # thickens, because $wgTitle is altered for special pages, so doesn't
559 # contain the original alias-with-subpage.
560 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
561 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
562 list( $spName, $spPar ) =
563 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
564 $active = $spName == 'Contributions'
565 && ( ( $spPar && $spPar == $this->username
)
566 ||
$wgRequest->getText( 'target' ) == $this->username
);
571 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
572 $personal_urls['mycontris'] = array(
573 'text' => wfMsg( 'mycontris' ),
577 $personal_urls['logout'] = array(
578 'text' => wfMsg( 'userlogout' ),
579 'href' => self
::makeSpecialUrl( 'Userlogout',
580 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
586 $loginlink = $wgUser->isAllowed( 'createaccount' )
587 ?
'nav-login-createaccount'
589 if( $this->showIPinHeader() ) {
590 $href = &$this->userpageUrlDetails
['href'];
591 $personal_urls['anonuserpage'] = array(
592 'text' => $this->username
,
594 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
595 'active' => ( $pageurl == $href )
597 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
598 $href = &$usertalkUrlDetails['href'];
599 $personal_urls['anontalk'] = array(
600 'text' => wfMsg( 'anontalk' ),
602 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
603 'active' => ( $pageurl == $href )
605 $personal_urls['anonlogin'] = array(
606 'text' => wfMsg( $loginlink ),
607 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
608 'active' => $title->isSpecial( 'Userlogin' )
611 $personal_urls['login'] = array(
612 'text' => wfMsg( $loginlink ),
613 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
614 'active' => $title->isSpecial( 'Userlogin' )
619 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
620 wfProfileOut( __METHOD__
);
621 return $personal_urls;
624 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
627 $classes[] = 'selected';
629 if( $checkEdit && !$title->isKnown() ) {
631 $query = 'action=edit&redlink=1';
634 $text = wfMsg( $message );
635 if ( wfEmptyMsg( $message, $text ) ) {
637 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
641 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
642 $title, $message, $selected, $checkEdit,
643 &$classes, &$query, &$text, &$result ) ) ) {
648 'class' => implode( ' ', $classes ),
650 'href' => $title->getLocalUrl( $query ) );
653 function makeTalkUrlDetails( $name, $urlaction = '' ) {
654 $title = Title
::newFromText( $name );
655 if( !is_object( $title ) ) {
656 throw new MWException( __METHOD__
. " given invalid pagename $name" );
658 $title = $title->getTalkPage();
659 self
::checkTitle( $title, $name );
661 'href' => $title->getLocalURL( $urlaction ),
662 'exists' => $title->getArticleID() != 0 ?
true : false
666 function makeArticleUrlDetails( $name, $urlaction = '' ) {
667 $title = Title
::newFromText( $name );
668 $title= $title->getSubjectPage();
669 self
::checkTitle( $title, $name );
671 'href' => $title->getLocalURL( $urlaction ),
672 'exists' => $title->getArticleID() != 0 ?
true : false
677 * an array of edit links by default used for the tabs
681 function buildContentActionUrls() {
682 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
684 wfProfileIn( __METHOD__
);
686 $action = $wgRequest->getVal( 'action', 'view' );
687 $section = $wgRequest->getVal( 'section' );
688 $content_actions = array();
690 $prevent_active_tabs = false;
691 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
693 if( $this->iscontent
) {
694 $subjpage = $this->mTitle
->getSubjectPage();
695 $talkpage = $this->mTitle
->getTalkPage();
697 $nskey = $this->mTitle
->getNamespaceKey();
698 $content_actions[$nskey] = $this->tabAction(
701 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
705 $content_actions['talk'] = $this->tabAction(
708 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
713 wfProfileIn( __METHOD__
. '-edit' );
714 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
715 $istalk = $this->mTitle
->isTalkPage();
716 $istalkclass = $istalk?
' istalk':'';
717 $content_actions['edit'] = array(
718 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
719 'text' => $this->mTitle
->exists()
722 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
725 // adds new section link if page is a current revision of a talk page or
726 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
727 if ( !$wgOut->forceHideNewSectionLink() ) {
728 $content_actions['addsection'] = array(
729 'class' => $section == 'new' ?
'selected' : false,
730 'text' => wfMsg( 'addsection' ),
731 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
735 } elseif ( $this->mTitle
->isKnown() ) {
736 $content_actions['viewsource'] = array(
737 'class' => ($action == 'edit') ?
'selected' : false,
738 'text' => wfMsg( 'viewsource' ),
739 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
742 wfProfileOut( __METHOD__
. '-edit' );
744 wfProfileIn( __METHOD__
. '-live' );
745 if ( $this->mTitle
->exists() ) {
747 $content_actions['history'] = array(
748 'class' => ($action == 'history') ?
'selected' : false,
749 'text' => wfMsg( 'history_short' ),
750 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
754 if( $wgUser->isAllowed( 'delete' ) ) {
755 $content_actions['delete'] = array(
756 'class' => ($action == 'delete') ?
'selected' : false,
757 'text' => wfMsg( 'delete' ),
758 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
761 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
762 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
763 $content_actions['move'] = array(
764 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
765 'text' => wfMsg( 'move' ),
766 'href' => $moveTitle->getLocalUrl()
770 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
771 if( !$this->mTitle
->isProtected() ){
772 $content_actions['protect'] = array(
773 'class' => ($action == 'protect') ?
'selected' : false,
774 'text' => wfMsg( 'protect' ),
775 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
779 $content_actions['unprotect'] = array(
780 'class' => ($action == 'unprotect') ?
'selected' : false,
781 'text' => wfMsg( 'unprotect' ),
782 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
787 //article doesn't exist or is deleted
788 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
789 if( $n = $this->mTitle
->isDeleted() ) {
790 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
791 $content_actions['undelete'] = array(
793 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
794 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
795 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
800 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
801 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
802 $content_actions['protect'] = array(
803 'class' => ($action == 'protect') ?
'selected' : false,
804 'text' => wfMsg( 'protect' ),
805 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
809 $content_actions['unprotect'] = array(
810 'class' => ($action == 'unprotect') ?
'selected' : false,
811 'text' => wfMsg( 'unprotect' ),
812 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
818 wfProfileOut( __METHOD__
. '-live' );
820 if( $this->loggedin
) {
821 if( !$this->mTitle
->userIsWatching()) {
822 $content_actions['watch'] = array(
823 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
824 'text' => wfMsg( 'watch' ),
825 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
828 $content_actions['unwatch'] = array(
829 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
830 'text' => wfMsg( 'unwatch' ),
831 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
837 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
839 /* show special page tab */
841 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
842 'class' => 'selected',
843 'text' => wfMsg('nstab-special'),
844 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
847 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
850 /* show links to different language variants */
851 global $wgDisableLangConversion;
852 $variants = $wgContLang->getVariants();
853 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
854 $preferred = $wgContLang->getPreferredVariant();
856 foreach( $variants as $code ) {
857 $varname = $wgContLang->getVariantname( $code );
858 if( $varname == 'disable' )
860 $selected = ( $code == $preferred )?
'selected' : false;
861 $content_actions['varlang-' . $vcount] = array(
862 'class' => $selected,
864 'href' => $this->mTitle
->getLocalURL( '', $code )
870 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
872 wfProfileOut( __METHOD__
);
873 return $content_actions;
877 * build array of common navigation links
881 function buildNavUrls() {
882 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
883 global $wgEnableUploads, $wgUploadNavigationUrl;
885 wfProfileIn( __METHOD__
);
887 $action = $wgRequest->getVal( 'action', 'view' );
890 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
891 if( $wgUploadNavigationUrl ) {
892 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
893 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
894 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
896 $nav_urls['upload'] = false;
898 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
900 // default permalink to being off, will override it as required below.
901 $nav_urls['permalink'] = false;
903 // A print stylesheet is attached to all pages, but nobody ever
904 // figures that out. :) Add a link...
905 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
906 if ( !$wgOut->isPrintable() ) {
907 $nav_urls['print'] = array(
908 'text' => wfMsg( 'printableversion' ),
909 'href' => $wgRequest->appendQuery( 'printable=yes' )
913 // Also add a "permalink" while we're at it
914 if ( $this->mRevisionId
) {
915 $nav_urls['permalink'] = array(
916 'text' => wfMsg( 'permalink' ),
917 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
921 // Copy in case this undocumented, shady hook tries to mess with internals
922 $revid = $this->mRevisionId
;
923 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
926 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
927 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
928 $nav_urls['whatlinkshere'] = array(
929 'href' => $wlhTitle->getLocalUrl()
931 if( $this->mTitle
->getArticleId() ) {
932 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
933 $nav_urls['recentchangeslinked'] = array(
934 'href' => $rclTitle->getLocalUrl()
937 $nav_urls['recentchangeslinked'] = false;
939 if( $wgUseTrackbacks )
940 $nav_urls['trackbacklink'] = array(
941 'href' => $wgOut->getTitle()->trackbackURL()
945 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
946 $id = User
::idFromName( $this->mTitle
->getText() );
947 $ip = User
::isIP( $this->mTitle
->getText() );
953 if( $id ||
$ip ) { # both anons and non-anons have contribs list
954 $nav_urls['contributions'] = array(
955 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
959 $logPage = SpecialPage
::getTitleFor( 'Log' );
960 $nav_urls['log'] = array(
961 'href' => $logPage->getLocalUrl(
963 'user' => $this->mTitle
->getText()
968 $nav_urls['log'] = false;
971 if ( $wgUser->isAllowed( 'block' ) ) {
972 $nav_urls['blockip'] = array(
973 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
976 $nav_urls['blockip'] = false;
979 $nav_urls['contributions'] = false;
980 $nav_urls['log'] = false;
981 $nav_urls['blockip'] = false;
983 $nav_urls['emailuser'] = false;
984 if( $this->showEmailUser( $id ) ) {
985 $nav_urls['emailuser'] = array(
986 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
989 wfProfileOut( __METHOD__
);
994 * Generate strings used for xml 'id' names
998 function getNameSpaceKey() {
999 return $this->mTitle
->getNamespaceKey();
1005 function setupUserJs( $allowUserJs ) {
1006 global $wgRequest, $wgJsMimeType;
1007 wfProfileIn( __METHOD__
);
1009 $action = $wgRequest->getVal( 'action', 'view' );
1011 if( $allowUserJs && $this->loggedin
) {
1012 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1013 # XXX: additional security check/prompt?
1014 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1016 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1019 wfProfileOut( __METHOD__
);
1023 * Code for extensions to hook into to provide per-page CSS, see
1024 * extensions/PageCSS/PageCSS.php for an implementation of this.
1028 function setupPageCss() {
1029 wfProfileIn( __METHOD__
);
1031 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1032 wfProfileOut( __METHOD__
);
1036 public function commonPrintStylesheet() {
1042 * Generic wrapper for template functions, with interface
1043 * compatible with what we use of PHPTAL 0.7.
1046 abstract class QuickTemplate
{
1050 public function QuickTemplate() {
1051 $this->data
= array();
1052 $this->translator
= new MediaWiki_I18N();
1056 * Sets the value $value to $name
1060 public function set( $name, $value ) {
1061 $this->data
[$name] = $value;
1068 public function setRef( $name, &$value ) {
1069 $this->data
[$name] =& $value;
1075 public function setTranslator( &$t ) {
1076 $this->translator
= &$t;
1080 * Main function, used by classes that subclass QuickTemplate
1081 * to show the actual HTML output
1083 abstract public function execute();
1088 function text( $str ) {
1089 echo htmlspecialchars( $this->data
[$str] );
1095 function jstext( $str ) {
1096 echo Xml
::escapeJsString( $this->data
[$str] );
1102 function html( $str ) {
1103 echo $this->data
[$str];
1109 function msg( $str ) {
1110 echo htmlspecialchars( $this->translator
->translate( $str ) );
1116 function msgHtml( $str ) {
1117 echo $this->translator
->translate( $str );
1121 * An ugly, ugly hack.
1124 function msgWiki( $str ) {
1125 global $wgParser, $wgOut;
1127 $text = $this->translator
->translate( $str );
1128 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1129 $wgOut->parserOptions(), true );
1130 echo $parserOutput->getText();
1136 function haveData( $str ) {
1137 return isset( $this->data
[$str] );
1143 function haveMsg( $str ) {
1144 $msg = $this->translator
->translate( $str );
1145 return ( $msg != '-' ) && ( $msg != '' ); # ????