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';
91 * Whether this skin use OutputPage::headElement() to generate the <head>
94 var $useHeadElement = false;
99 * Add specific styles for this skin
101 * @param $out OutputPage
103 function setupSkinUserCss( OutputPage
$out ){
104 $out->addStyle( 'common/shared.css', 'screen' );
105 $out->addStyle( 'common/commonPrint.css', 'print' );
109 * Create the template engine object; we feed it a bunch of data
110 * and eventually it spits out some HTML. Should have interface
111 * roughly equivalent to PHPTAL 0.7.
113 * @param $callback string (or file)
114 * @param $repository string: subdirectory where we keep template files
115 * @param $cache_dir string
119 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
120 return new $classname();
124 * initialize various variables and generate the template
126 * @param $out OutputPage
128 function outputPage( OutputPage
$out ) {
129 global $wgArticle, $wgUser, $wgLang, $wgContLang;
130 global $wgScript, $wgStylePath, $wgContLanguageCode;
131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
133 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
134 global $wgMaxCredits, $wgShowCreditsIfMax;
135 global $wgPageShowWatchingUsers;
136 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
137 global $wgArticlePath, $wgScriptPath, $wgServer;
139 wfProfileIn( __METHOD__
);
141 $oldid = $wgRequest->getVal( 'oldid' );
142 $diff = $wgRequest->getVal( 'diff' );
143 $action = $wgRequest->getVal( 'action', 'view' );
145 wfProfileIn( __METHOD__
. '-init' );
146 $this->initPage( $out );
149 $tpl = $this->setupTemplate( $this->template
, 'skins' );
151 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
152 $tpl->setTranslator( new MediaWiki_I18N() );
154 wfProfileOut( __METHOD__
. '-init' );
156 wfProfileIn( __METHOD__
. '-stuff' );
157 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
158 $this->thisurl
= $this->mTitle
->getPrefixedURL();
160 if ( !$wgRequest->wasPosted() ) {
161 $query = $wgRequest->getValues();
162 unset( $query['title'] );
163 unset( $query['returnto'] );
164 unset( $query['returntoquery'] );
166 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
167 $this->loggedin
= $wgUser->isLoggedIn();
168 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
169 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
170 $this->username
= $wgUser->getName();
172 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
173 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
175 # This won't be used in the standard skins, but we define it to preserve the interface
176 # To save time, we check for existence
177 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
180 $this->titletxt
= $this->mTitle
->getPrefixedText();
181 wfProfileOut( __METHOD__
. '-stuff' );
183 wfProfileIn( __METHOD__
. '-stuff-head' );
184 if ( $this->useHeadElement
) {
185 $pagecss = $this->setupPageCss();
187 $out->addInlineStyle( $pagecss );
189 $this->setupUserCss( $out );
191 $tpl->set( 'pagecss', $this->setupPageCss() );
192 $tpl->setRef( 'usercss', $this->usercss
);
194 $this->userjs
= $this->userjsprev
= false;
195 $this->setupUserJs( $out->isUserJsAllowed() );
196 $tpl->setRef( 'userjs', $this->userjs
);
197 $tpl->setRef( 'userjsprev', $this->userjsprev
);
200 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
201 $tpl->set( 'jsvarurl',
203 "action=raw$jsCache&gen=js&useskin=" .
204 urlencode( $this->getSkinName() ) ) );
206 $tpl->set( 'jsvarurl', false );
209 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
210 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
211 $tpl->set( 'html5version', $wgHtml5Version );
212 $tpl->set( 'headlinks', $out->getHeadLinks() );
213 $tpl->set( 'csslinks', $out->buildCssLinks() );
215 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
216 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
218 $tpl->set( 'trackbackhtml', null );
221 wfProfileOut( __METHOD__
. '-stuff-head' );
223 wfProfileIn( __METHOD__
. '-stuff2' );
224 $tpl->set( 'title', $out->getPageTitle() );
225 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
226 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
227 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
228 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
230 $nsname = MWNamespace
::exists( $this->mTitle
->getNamespace() ) ?
231 MWNamespace
::getCanonicalName( $this->mTitle
->getNamespace() ) :
232 $this->mTitle
->getNsText();
234 $tpl->set( 'nscanonical', $nsname );
235 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
236 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
237 $tpl->set( 'titletext', $this->mTitle
->getText() );
238 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
239 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
241 $tpl->set( 'isarticle', $out->isArticle() );
243 $tpl->setRef( 'thispage', $this->thispage
);
244 $subpagestr = $this->subPageSubtitle();
246 'subtitle', !empty( $subpagestr ) ?
247 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
250 $undelete = $this->getUndeleteLink();
252 'undelete', !empty( $undelete ) ?
253 '<span class="subpages">'.$undelete.'</span>' :
257 $tpl->set( 'catlinks', $this->getCategories() );
258 if( $out->isSyndicated() ) {
260 foreach( $out->getSyndicationLinks() as $format => $link ) {
261 $feeds[$format] = array(
262 'text' => wfMsg( "feed-$format" ),
266 $tpl->setRef( 'feeds', $feeds );
268 $tpl->set( 'feeds', false );
271 $tpl->setRef( 'mimetype', $wgMimeType );
272 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
273 $tpl->setRef( 'charset', $wgOutputEncoding );
274 $tpl->setRef( 'wgScript', $wgScript );
275 $tpl->setRef( 'skinname', $this->skinname
);
276 $tpl->set( 'skinclass', get_class( $this ) );
277 $tpl->setRef( 'stylename', $this->stylename
);
278 $tpl->set( 'printable', $out->isPrintable() );
279 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
280 $tpl->setRef( 'loggedin', $this->loggedin
);
281 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
282 /* XXX currently unused, might get useful later
283 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
284 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
285 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
286 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
287 $tpl->set( "helppage", wfMsg('helppage'));
289 $tpl->set( 'searchaction', $this->escapeSearchLink() );
290 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
291 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
292 $tpl->setRef( 'stylepath', $wgStylePath );
293 $tpl->setRef( 'articlepath', $wgArticlePath );
294 $tpl->setRef( 'scriptpath', $wgScriptPath );
295 $tpl->setRef( 'serverurl', $wgServer );
296 $tpl->setRef( 'logopath', $wgLogo );
297 $tpl->setRef( 'lang', $wgContLanguageCode );
298 $tpl->set( 'dir', $wgContLang->getDir() );
299 $tpl->set( 'rtl', $wgContLang->isRTL() );
300 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
301 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
302 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
303 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
304 $tpl->setRef( 'userpage', $this->userpage
);
305 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
306 $tpl->set( 'userlang', $wgLang->getCode() );
308 // Users can have their language set differently than the
309 // content of the wiki. For these users, tell the web browser
310 // that interface elements are in a different language.
311 $tpl->set( 'userlangattributes', '');
312 $tpl->set( 'specialpageattributes', '');
314 $lang = $wgLang->getCode();
315 $dir = $wgLang->getDir();
316 if ( $lang !== $wgContLang->getCode() ||
$dir !== $wgContLang->getDir() ) {
317 $attrs = "lang='$lang' xml:lang='$lang' dir='$dir'";
319 $tpl->set( 'userlangattributes', $attrs );
321 // The content of SpecialPages should be presented in the
322 // user's language. Content of regular pages should not be touched.
323 if($this->mTitle
->isSpecialPage()) {
324 $tpl->set( 'specialpageattributes', $attrs );
328 $newtalks = $wgUser->getNewMessageLinks();
330 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
331 $usertitle = $this->mUser
->getUserPage();
332 $usertalktitle = $usertitle->getTalkPage();
334 if( !$usertalktitle->equals( $this->mTitle
) ) {
335 $newmessageslink = $this->link(
337 wfMsgHtml( 'newmessageslink' ),
339 array( 'redirect' => 'no' ),
340 array( 'known', 'noclasses' )
343 $newmessagesdifflink = $this->link(
345 wfMsgHtml( 'newmessagesdifflink' ),
347 array( 'diff' => 'cur' ),
348 array( 'known', 'noclasses' )
352 'youhavenewmessages',
357 $out->setSquidMaxage( 0 );
359 } else if( count( $newtalks ) ) {
360 // _>" " for BC <= 1.16
361 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
363 foreach( $newtalks as $newtalk ) {
364 $msgs[] = Xml
::element('a',
365 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
367 $parts = implode( $sep, $msgs );
368 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
369 $out->setSquidMaxage( 0 );
373 wfProfileOut( __METHOD__
. '-stuff2' );
375 wfProfileIn( __METHOD__
. '-stuff3' );
376 $tpl->setRef( 'newtalk', $ntl );
377 $tpl->setRef( 'skin', $this );
378 $tpl->set( 'logo', $this->logoText() );
379 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
380 $wgArticle and 0 != $wgArticle->getID() ){
381 if ( !$wgDisableCounters ) {
382 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
384 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
386 $tpl->set( 'viewcount', false );
389 $tpl->set( 'viewcount', false );
392 if( $wgPageShowWatchingUsers ) {
393 $dbr = wfGetDB( DB_SLAVE
);
394 $watchlist = $dbr->tableName( 'watchlist' );
395 $res = $dbr->select( 'watchlist',
396 array( 'COUNT(*) AS n' ),
397 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
400 $x = $dbr->fetchObject( $res );
401 $numberofwatchingusers = $x->n
;
402 if( $numberofwatchingusers > 0 ) {
403 $tpl->set( 'numberofwatchingusers',
404 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
405 $wgLang->formatNum( $numberofwatchingusers ) )
408 $tpl->set( 'numberofwatchingusers', false );
411 $tpl->set( 'numberofwatchingusers', false );
414 $tpl->set( 'copyright', $this->getCopyright() );
416 $this->credits
= false;
418 if( $wgMaxCredits != 0 ){
419 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
421 $tpl->set( 'lastmod', $this->lastModified() );
424 $tpl->setRef( 'credits', $this->credits
);
427 $tpl->set( 'copyright', false );
428 $tpl->set( 'viewcount', false );
429 $tpl->set( 'lastmod', false );
430 $tpl->set( 'credits', false );
431 $tpl->set( 'numberofwatchingusers', false );
433 wfProfileOut( __METHOD__
. '-stuff3' );
435 wfProfileIn( __METHOD__
. '-stuff4' );
436 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
437 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
438 $tpl->set( 'disclaimer', $this->disclaimerLink() );
439 $tpl->set( 'privacy', $this->privacyLink() );
440 $tpl->set( 'about', $this->aboutLink() );
442 if ( $wgDebugComments ) {
443 $tpl->setRef( 'debug', $out->mDebugtext
);
445 $tpl->set( 'debug', '' );
448 $tpl->set( 'reporttime', wfReportTime() );
449 $tpl->set( 'sitenotice', wfGetSiteNotice() );
450 $tpl->set( 'bottomscripts', $this->bottomScripts() );
452 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
453 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
454 $tpl->setRef( 'bodytext', $out->mBodytext
);
457 $language_urls = array();
459 if ( !$wgHideInterlanguageLinks ) {
460 foreach( $out->getLanguageLinks() as $l ) {
461 $tmp = explode( ':', $l, 2 );
462 $class = 'interwiki-' . $tmp[0];
464 $nt = Title
::newFromText( $l );
466 $language_urls[] = array(
467 'href' => $nt->getFullURL(),
468 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
469 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
475 if( count( $language_urls ) ) {
476 $tpl->setRef( 'language_urls', $language_urls );
478 $tpl->set( 'language_urls', false );
480 wfProfileOut( __METHOD__
. '-stuff4' );
482 wfProfileIn( __METHOD__
. '-stuff5' );
484 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
485 $content_actions = $this->buildContentActionUrls();
486 $tpl->setRef( 'content_actions', $content_actions );
488 // XXX: attach this from javascript, same with section editing
489 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
490 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
491 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
493 $tpl->set( 'body_ondblclick', false );
495 $tpl->set( 'body_onload', false );
496 $tpl->set( 'sidebar', $this->buildSidebar() );
497 $tpl->set( 'nav_urls', $this->buildNavUrls() );
499 // Set the head scripts near the end, in case the above actions resulted in added scripts
500 if ( $this->useHeadElement
) {
501 $tpl->set( 'headelement', $out->headElement( $this ) );
503 $tpl->set( 'headscripts', $out->getScript() );
506 // original version by hansm
507 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
508 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
511 // allow extensions adding stuff after the page content.
512 // See Skin::afterContentHook() for further documentation.
513 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
514 wfProfileOut( __METHOD__
. '-stuff5' );
517 wfProfileIn( __METHOD__
. '-execute' );
518 $res = $tpl->execute();
519 wfProfileOut( __METHOD__
. '-execute' );
521 // result may be an error
522 $this->printOrError( $res );
523 wfProfileOut( __METHOD__
);
527 * Output the string, or print error message if it's
528 * an error object of the appropriate type.
529 * For the base class, assume strings all around.
534 function printOrError( $str ) {
539 * build array of urls for personal toolbar
543 function buildPersonalUrls() {
544 global $wgOut, $wgRequest;
546 $title = $wgOut->getTitle();
547 $pageurl = $title->getLocalURL();
548 wfProfileIn( __METHOD__
);
550 /* set up the default links for the personal toolbar */
551 $personal_urls = array();
552 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
553 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
554 $returnto = "returnto=$page";
555 if( $this->thisquery
!= '' )
556 $returnto .= "&returntoquery=$query";
557 if( $this->loggedin
) {
558 $personal_urls['userpage'] = array(
559 'text' => $this->username
,
560 'href' => &$this->userpageUrlDetails
['href'],
561 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
562 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
564 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
565 $personal_urls['mytalk'] = array(
566 'text' => wfMsg( 'mytalk' ),
567 'href' => &$usertalkUrlDetails['href'],
568 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
569 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
571 $href = self
::makeSpecialUrl( 'Preferences' );
572 $personal_urls['preferences'] = array(
573 'text' => wfMsg( 'mypreferences' ),
575 'active' => ( $href == $pageurl )
577 $href = self
::makeSpecialUrl( 'Watchlist' );
578 $personal_urls['watchlist'] = array(
579 'text' => wfMsg( 'mywatchlist' ),
581 'active' => ( $href == $pageurl )
584 # We need to do an explicit check for Special:Contributions, as we
585 # have to match both the title, and the target (which could come
586 # from request values or be specified in "sub page" form. The plot
587 # thickens, because $wgTitle is altered for special pages, so doesn't
588 # contain the original alias-with-subpage.
589 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
590 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
591 list( $spName, $spPar ) =
592 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
593 $active = $spName == 'Contributions'
594 && ( ( $spPar && $spPar == $this->username
)
595 ||
$wgRequest->getText( 'target' ) == $this->username
);
600 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
601 $personal_urls['mycontris'] = array(
602 'text' => wfMsg( 'mycontris' ),
606 $personal_urls['logout'] = array(
607 'text' => wfMsg( 'userlogout' ),
608 'href' => self
::makeSpecialUrl( 'Userlogout',
609 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
615 $loginlink = $wgUser->isAllowed( 'createaccount' )
616 ?
'nav-login-createaccount'
618 if( $this->showIPinHeader() ) {
619 $href = &$this->userpageUrlDetails
['href'];
620 $personal_urls['anonuserpage'] = array(
621 'text' => $this->username
,
623 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
624 'active' => ( $pageurl == $href )
626 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
627 $href = &$usertalkUrlDetails['href'];
628 $personal_urls['anontalk'] = array(
629 'text' => wfMsg( 'anontalk' ),
631 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
632 'active' => ( $pageurl == $href )
634 $personal_urls['anonlogin'] = array(
635 'text' => wfMsg( $loginlink ),
636 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
637 'active' => $title->isSpecial( 'Userlogin' )
640 $personal_urls['login'] = array(
641 'text' => wfMsg( $loginlink ),
642 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
643 'active' => $title->isSpecial( 'Userlogin' )
648 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
649 wfProfileOut( __METHOD__
);
650 return $personal_urls;
653 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
656 $classes[] = 'selected';
658 if( $checkEdit && !$title->isKnown() ) {
660 $query = 'action=edit&redlink=1';
663 $text = wfMsg( $message );
664 if ( wfEmptyMsg( $message, $text ) ) {
666 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
670 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
671 $title, $message, $selected, $checkEdit,
672 &$classes, &$query, &$text, &$result ) ) ) {
677 'class' => implode( ' ', $classes ),
679 'href' => $title->getLocalUrl( $query ) );
682 function makeTalkUrlDetails( $name, $urlaction = '' ) {
683 $title = Title
::newFromText( $name );
684 if( !is_object( $title ) ) {
685 throw new MWException( __METHOD__
. " given invalid pagename $name" );
687 $title = $title->getTalkPage();
688 self
::checkTitle( $title, $name );
690 'href' => $title->getLocalURL( $urlaction ),
691 'exists' => $title->getArticleID() != 0 ?
true : false
695 function makeArticleUrlDetails( $name, $urlaction = '' ) {
696 $title = Title
::newFromText( $name );
697 $title= $title->getSubjectPage();
698 self
::checkTitle( $title, $name );
700 'href' => $title->getLocalURL( $urlaction ),
701 'exists' => $title->getArticleID() != 0 ?
true : false
706 * an array of edit links by default used for the tabs
710 function buildContentActionUrls() {
711 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
713 wfProfileIn( __METHOD__
);
715 $action = $wgRequest->getVal( 'action', 'view' );
716 $section = $wgRequest->getVal( 'section' );
717 $content_actions = array();
719 $prevent_active_tabs = false;
720 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
722 if( $this->iscontent
) {
723 $subjpage = $this->mTitle
->getSubjectPage();
724 $talkpage = $this->mTitle
->getTalkPage();
726 $nskey = $this->mTitle
->getNamespaceKey();
727 $content_actions[$nskey] = $this->tabAction(
730 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
734 $content_actions['talk'] = $this->tabAction(
737 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
742 wfProfileIn( __METHOD__
. '-edit' );
743 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
744 $istalk = $this->mTitle
->isTalkPage();
745 $istalkclass = $istalk?
' istalk':'';
746 $content_actions['edit'] = array(
747 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
748 'text' => $this->mTitle
->exists()
751 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
754 // adds new section link if page is a current revision of a talk page or
755 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
756 if ( !$wgOut->forceHideNewSectionLink() ) {
757 $content_actions['addsection'] = array(
758 'class' => $section == 'new' ?
'selected' : false,
759 'text' => wfMsg( 'addsection' ),
760 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
764 } elseif ( $this->mTitle
->isKnown() ) {
765 $content_actions['viewsource'] = array(
766 'class' => ($action == 'edit') ?
'selected' : false,
767 'text' => wfMsg( 'viewsource' ),
768 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
771 wfProfileOut( __METHOD__
. '-edit' );
773 wfProfileIn( __METHOD__
. '-live' );
774 if ( $this->mTitle
->exists() ) {
776 $content_actions['history'] = array(
777 'class' => ($action == 'history') ?
'selected' : false,
778 'text' => wfMsg( 'history_short' ),
779 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
783 if( $wgUser->isAllowed( 'delete' ) ) {
784 $content_actions['delete'] = array(
785 'class' => ($action == 'delete') ?
'selected' : false,
786 'text' => wfMsg( 'delete' ),
787 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
790 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
791 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
792 $content_actions['move'] = array(
793 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
794 'text' => wfMsg( 'move' ),
795 'href' => $moveTitle->getLocalUrl()
799 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
800 if( !$this->mTitle
->isProtected() ){
801 $content_actions['protect'] = array(
802 'class' => ($action == 'protect') ?
'selected' : false,
803 'text' => wfMsg( 'protect' ),
804 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
808 $content_actions['unprotect'] = array(
809 'class' => ($action == 'unprotect') ?
'selected' : false,
810 'text' => wfMsg( 'unprotect' ),
811 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
816 //article doesn't exist or is deleted
817 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
818 if( $n = $this->mTitle
->isDeleted() ) {
819 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
820 $content_actions['undelete'] = array(
822 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
823 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
824 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
829 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
830 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
831 $content_actions['protect'] = array(
832 'class' => ($action == 'protect') ?
'selected' : false,
833 'text' => wfMsg( 'protect' ),
834 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
838 $content_actions['unprotect'] = array(
839 'class' => ($action == 'unprotect') ?
'selected' : false,
840 'text' => wfMsg( 'unprotect' ),
841 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
847 wfProfileOut( __METHOD__
. '-live' );
849 if( $this->loggedin
) {
850 if( !$this->mTitle
->userIsWatching()) {
851 $content_actions['watch'] = array(
852 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
853 'text' => wfMsg( 'watch' ),
854 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
857 $content_actions['unwatch'] = array(
858 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
859 'text' => wfMsg( 'unwatch' ),
860 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
866 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
868 /* show special page tab */
870 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
871 'class' => 'selected',
872 'text' => wfMsg('nstab-special'),
873 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
876 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
879 /* show links to different language variants */
880 global $wgDisableLangConversion;
881 $variants = $wgContLang->getVariants();
882 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
883 $preferred = $wgContLang->getPreferredVariant();
885 foreach( $variants as $code ) {
886 $varname = $wgContLang->getVariantname( $code );
887 if( $varname == 'disable' )
889 $selected = ( $code == $preferred )?
'selected' : false;
890 $content_actions['varlang-' . $vcount] = array(
891 'class' => $selected,
893 'href' => $this->mTitle
->getLocalURL( '', $code )
899 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
901 wfProfileOut( __METHOD__
);
902 return $content_actions;
906 * build array of common navigation links
910 function buildNavUrls() {
911 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
912 global $wgEnableUploads, $wgUploadNavigationUrl;
914 wfProfileIn( __METHOD__
);
916 $action = $wgRequest->getVal( 'action', 'view' );
919 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
920 if( $wgUploadNavigationUrl ) {
921 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
922 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
923 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
925 $nav_urls['upload'] = false;
927 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
929 // default permalink to being off, will override it as required below.
930 $nav_urls['permalink'] = false;
932 // A print stylesheet is attached to all pages, but nobody ever
933 // figures that out. :) Add a link...
934 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
935 if ( !$wgOut->isPrintable() ) {
936 $nav_urls['print'] = array(
937 'text' => wfMsg( 'printableversion' ),
938 'href' => $wgRequest->appendQuery( 'printable=yes' )
942 // Also add a "permalink" while we're at it
943 if ( $this->mRevisionId
) {
944 $nav_urls['permalink'] = array(
945 'text' => wfMsg( 'permalink' ),
946 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
950 // Copy in case this undocumented, shady hook tries to mess with internals
951 $revid = $this->mRevisionId
;
952 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
955 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
956 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
957 $nav_urls['whatlinkshere'] = array(
958 'href' => $wlhTitle->getLocalUrl()
960 if( $this->mTitle
->getArticleId() ) {
961 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
962 $nav_urls['recentchangeslinked'] = array(
963 'href' => $rclTitle->getLocalUrl()
966 $nav_urls['recentchangeslinked'] = false;
968 if( $wgUseTrackbacks )
969 $nav_urls['trackbacklink'] = array(
970 'href' => $wgOut->getTitle()->trackbackURL()
974 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
975 $id = User
::idFromName( $this->mTitle
->getText() );
976 $ip = User
::isIP( $this->mTitle
->getText() );
982 if( $id ||
$ip ) { # both anons and non-anons have contribs list
983 $nav_urls['contributions'] = array(
984 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
988 $logPage = SpecialPage
::getTitleFor( 'Log' );
989 $nav_urls['log'] = array(
990 'href' => $logPage->getLocalUrl(
992 'user' => $this->mTitle
->getText()
997 $nav_urls['log'] = false;
1000 if ( $wgUser->isAllowed( 'block' ) ) {
1001 $nav_urls['blockip'] = array(
1002 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
1005 $nav_urls['blockip'] = false;
1008 $nav_urls['contributions'] = false;
1009 $nav_urls['log'] = false;
1010 $nav_urls['blockip'] = false;
1012 $nav_urls['emailuser'] = false;
1013 if( $this->showEmailUser( $id ) ) {
1014 $nav_urls['emailuser'] = array(
1015 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
1018 wfProfileOut( __METHOD__
);
1023 * Generate strings used for xml 'id' names
1027 function getNameSpaceKey() {
1028 return $this->mTitle
->getNamespaceKey();
1034 function setupUserJs( $allowUserJs ) {
1035 global $wgRequest, $wgJsMimeType;
1036 wfProfileIn( __METHOD__
);
1038 $action = $wgRequest->getVal( 'action', 'view' );
1040 if( $allowUserJs && $this->loggedin
) {
1041 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1042 # XXX: additional security check/prompt?
1043 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1045 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1048 wfProfileOut( __METHOD__
);
1052 * Code for extensions to hook into to provide per-page CSS, see
1053 * extensions/PageCSS/PageCSS.php for an implementation of this.
1057 function setupPageCss() {
1058 wfProfileIn( __METHOD__
);
1060 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1061 wfProfileOut( __METHOD__
);
1065 public function commonPrintStylesheet() {
1071 * Generic wrapper for template functions, with interface
1072 * compatible with what we use of PHPTAL 0.7.
1075 abstract class QuickTemplate
{
1079 public function QuickTemplate() {
1080 $this->data
= array();
1081 $this->translator
= new MediaWiki_I18N();
1085 * Sets the value $value to $name
1089 public function set( $name, $value ) {
1090 $this->data
[$name] = $value;
1097 public function setRef( $name, &$value ) {
1098 $this->data
[$name] =& $value;
1104 public function setTranslator( &$t ) {
1105 $this->translator
= &$t;
1109 * Main function, used by classes that subclass QuickTemplate
1110 * to show the actual HTML output
1112 abstract public function execute();
1117 function text( $str ) {
1118 echo htmlspecialchars( $this->data
[$str] );
1124 function jstext( $str ) {
1125 echo Xml
::escapeJsString( $this->data
[$str] );
1131 function html( $str ) {
1132 echo $this->data
[$str];
1138 function msg( $str ) {
1139 echo htmlspecialchars( $this->translator
->translate( $str ) );
1145 function msgHtml( $str ) {
1146 echo $this->translator
->translate( $str );
1150 * An ugly, ugly hack.
1153 function msgWiki( $str ) {
1154 global $wgParser, $wgOut;
1156 $text = $this->translator
->translate( $str );
1157 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1158 $wgOut->parserOptions(), true );
1159 echo $parserOutput->getText();
1165 function haveData( $str ) {
1166 return isset( $this->data
[$str] );
1172 function haveMsg( $str ) {
1173 $msg = $this->translator
->translate( $str );
1174 return ( $msg != '-' ) && ( $msg != '' ); # ????