9b4a28783956064583c2c3cde3686040ef847eb8
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, $wgProfiler;
139 wfProfileIn( __METHOD__
);
140 if ( is_object( $wgProfiler ) ) {
141 $wgProfiler->setTemplated( true );
144 $oldid = $wgRequest->getVal( 'oldid' );
145 $diff = $wgRequest->getVal( 'diff' );
146 $action = $wgRequest->getVal( 'action', 'view' );
148 wfProfileIn( __METHOD__
. '-init' );
149 $this->initPage( $out );
152 $tpl = $this->setupTemplate( $this->template
, 'skins' );
154 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
155 $tpl->setTranslator( new MediaWiki_I18N() );
157 wfProfileOut( __METHOD__
. '-init' );
159 wfProfileIn( __METHOD__
. '-stuff' );
160 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
161 $this->thisurl
= $this->mTitle
->getPrefixedURL();
163 if ( !$wgRequest->wasPosted() ) {
164 $query = $wgRequest->getValues();
165 unset( $query['title'] );
166 unset( $query['returnto'] );
167 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->titletxt
= $this->mTitle
->getPrefixedText();
184 wfProfileOut( __METHOD__
. '-stuff' );
186 wfProfileIn( __METHOD__
. '-stuff-head' );
187 if ( $this->useHeadElement
) {
188 $pagecss = $this->setupPageCss();
190 $out->addInlineStyle( $pagecss );
192 $this->setupUserCss( $out );
194 $tpl->set( 'pagecss', $this->setupPageCss() );
195 $tpl->setRef( 'usercss', $this->usercss
);
197 $this->userjs
= $this->userjsprev
= false;
198 $this->setupUserJs( $out->isUserJsAllowed() );
199 $tpl->setRef( 'userjs', $this->userjs
);
200 $tpl->setRef( 'userjsprev', $this->userjsprev
);
203 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
204 $tpl->set( 'jsvarurl',
206 "action=raw$jsCache&gen=js&useskin=" .
207 urlencode( $this->getSkinName() ) ) );
209 $tpl->set( 'jsvarurl', false );
212 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
213 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
214 $tpl->set( 'html5version', $wgHtml5Version );
215 $tpl->set( 'headlinks', $out->getHeadLinks() );
216 $tpl->set( 'csslinks', $out->buildCssLinks() );
218 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
219 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
221 $tpl->set( 'trackbackhtml', null );
224 wfProfileOut( __METHOD__
. '-stuff-head' );
226 wfProfileIn( __METHOD__
. '-stuff2' );
227 $tpl->set( 'title', $out->getPageTitle() );
228 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
229 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
230 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
231 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
233 $nsname = MWNamespace
::exists( $this->mTitle
->getNamespace() ) ?
234 MWNamespace
::getCanonicalName( $this->mTitle
->getNamespace() ) :
235 $this->mTitle
->getNsText();
237 $tpl->set( 'nscanonical', $nsname );
238 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
239 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
240 $tpl->set( 'titletext', $this->mTitle
->getText() );
241 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
242 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
244 $tpl->set( 'isarticle', $out->isArticle() );
246 $tpl->setRef( 'thispage', $this->thispage
);
247 $subpagestr = $this->subPageSubtitle();
249 'subtitle', !empty( $subpagestr ) ?
250 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
253 $undelete = $this->getUndeleteLink();
255 'undelete', !empty( $undelete ) ?
256 '<span class="subpages">'.$undelete.'</span>' :
260 $tpl->set( 'catlinks', $this->getCategories() );
261 if( $out->isSyndicated() ) {
263 foreach( $out->getSyndicationLinks() as $format => $link ) {
264 $feeds[$format] = array(
265 'text' => wfMsg( "feed-$format" ),
269 $tpl->setRef( 'feeds', $feeds );
271 $tpl->set( 'feeds', false );
274 $tpl->setRef( 'mimetype', $wgMimeType );
275 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
276 $tpl->setRef( 'charset', $wgOutputEncoding );
277 $tpl->setRef( 'wgScript', $wgScript );
278 $tpl->setRef( 'skinname', $this->skinname
);
279 $tpl->set( 'skinclass', get_class( $this ) );
280 $tpl->setRef( 'stylename', $this->stylename
);
281 $tpl->set( 'printable', $out->isPrintable() );
282 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
283 $tpl->setRef( 'loggedin', $this->loggedin
);
284 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
285 /* XXX currently unused, might get useful later
286 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
287 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
288 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
289 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
290 $tpl->set( "helppage", wfMsg('helppage'));
292 $tpl->set( 'searchaction', $this->escapeSearchLink() );
293 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
294 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
295 $tpl->setRef( 'stylepath', $wgStylePath );
296 $tpl->setRef( 'articlepath', $wgArticlePath );
297 $tpl->setRef( 'scriptpath', $wgScriptPath );
298 $tpl->setRef( 'serverurl', $wgServer );
299 $tpl->setRef( 'logopath', $wgLogo );
300 $tpl->setRef( 'lang', $wgContLanguageCode );
301 $tpl->set( 'dir', $wgContLang->getDir() );
302 $tpl->set( 'rtl', $wgContLang->isRTL() );
303 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
304 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
305 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
306 $tpl->set( 'username', $wgUser->isAnon() ?
null : $this->username
);
307 $tpl->setRef( 'userpage', $this->userpage
);
308 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
309 $tpl->set( 'userlang', $wgLang->getCode() );
311 // Users can have their language set differently than the
312 // content of the wiki. For these users, tell the web browser
313 // that interface elements are in a different language.
314 $tpl->set( 'userlangattributes', '');
315 $tpl->set( 'specialpageattributes', '');
317 $lang = $wgLang->getCode();
318 $dir = $wgLang->getDir();
319 if ( $lang !== $wgContLang->getCode() ||
$dir !== $wgContLang->getDir() ) {
320 $attrs = " lang='$lang' dir='$dir'";
322 $tpl->set( 'userlangattributes', $attrs );
324 // The content of SpecialPages should be presented in the
325 // user's language. Content of regular pages should not be touched.
326 if($this->mTitle
->isSpecialPage()) {
327 $tpl->set( 'specialpageattributes', $attrs );
331 $newtalks = $wgUser->getNewMessageLinks();
333 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
334 $usertitle = $this->mUser
->getUserPage();
335 $usertalktitle = $usertitle->getTalkPage();
337 if( !$usertalktitle->equals( $this->mTitle
) ) {
338 $newmessageslink = $this->link(
340 wfMsgHtml( 'newmessageslink' ),
342 array( 'redirect' => 'no' ),
343 array( 'known', 'noclasses' )
346 $newmessagesdifflink = $this->link(
348 wfMsgHtml( 'newmessagesdifflink' ),
350 array( 'diff' => 'cur' ),
351 array( 'known', 'noclasses' )
355 'youhavenewmessages',
360 $out->setSquidMaxage( 0 );
362 } else if( count( $newtalks ) ) {
363 // _>" " for BC <= 1.16
364 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
366 foreach( $newtalks as $newtalk ) {
367 $msgs[] = Xml
::element('a',
368 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
370 $parts = implode( $sep, $msgs );
371 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
372 $out->setSquidMaxage( 0 );
376 wfProfileOut( __METHOD__
. '-stuff2' );
378 wfProfileIn( __METHOD__
. '-stuff3' );
379 $tpl->setRef( 'newtalk', $ntl );
380 $tpl->setRef( 'skin', $this );
381 $tpl->set( 'logo', $this->logoText() );
382 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
383 $wgArticle and 0 != $wgArticle->getID() ){
384 if ( !$wgDisableCounters ) {
385 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
387 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
389 $tpl->set( 'viewcount', false );
392 $tpl->set( 'viewcount', false );
395 if( $wgPageShowWatchingUsers ) {
396 $dbr = wfGetDB( DB_SLAVE
);
397 $watchlist = $dbr->tableName( 'watchlist' );
398 $res = $dbr->select( 'watchlist',
399 array( 'COUNT(*) AS n' ),
400 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
403 $x = $dbr->fetchObject( $res );
404 $numberofwatchingusers = $x->n
;
405 if( $numberofwatchingusers > 0 ) {
406 $tpl->set( 'numberofwatchingusers',
407 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
408 $wgLang->formatNum( $numberofwatchingusers ) )
411 $tpl->set( 'numberofwatchingusers', false );
414 $tpl->set( 'numberofwatchingusers', false );
417 $tpl->set( 'copyright', $this->getCopyright() );
419 $this->credits
= false;
421 if( $wgMaxCredits != 0 ){
422 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
424 $tpl->set( 'lastmod', $this->lastModified() );
427 $tpl->setRef( 'credits', $this->credits
);
429 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
430 $tpl->set( 'copyright', $this->getCopyright() );
431 $tpl->set( 'viewcount', false );
432 $tpl->set( 'lastmod', false );
433 $tpl->set( 'credits', false );
434 $tpl->set( 'numberofwatchingusers', false );
436 $tpl->set( 'copyright', false );
437 $tpl->set( 'viewcount', false );
438 $tpl->set( 'lastmod', false );
439 $tpl->set( 'credits', false );
440 $tpl->set( 'numberofwatchingusers', false );
442 wfProfileOut( __METHOD__
. '-stuff3' );
444 wfProfileIn( __METHOD__
. '-stuff4' );
445 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
446 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
447 $tpl->set( 'disclaimer', $this->disclaimerLink() );
448 $tpl->set( 'privacy', $this->privacyLink() );
449 $tpl->set( 'about', $this->aboutLink() );
451 if ( $wgDebugComments ) {
452 $tpl->setRef( 'debug', $out->mDebugtext
);
454 $tpl->set( 'debug', '' );
457 $tpl->set( 'reporttime', wfReportTime() );
458 $tpl->set( 'sitenotice', wfGetSiteNotice() );
459 $tpl->set( 'bottomscripts', $this->bottomScripts() );
461 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
462 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
463 $tpl->setRef( 'bodytext', $out->mBodytext
);
466 $language_urls = array();
468 if ( !$wgHideInterlanguageLinks ) {
469 foreach( $out->getLanguageLinks() as $l ) {
470 $tmp = explode( ':', $l, 2 );
471 $class = 'interwiki-' . $tmp[0];
473 $nt = Title
::newFromText( $l );
475 $language_urls[] = array(
476 'href' => $nt->getFullURL(),
477 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
478 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
484 if( count( $language_urls ) ) {
485 $tpl->setRef( 'language_urls', $language_urls );
487 $tpl->set( 'language_urls', false );
489 wfProfileOut( __METHOD__
. '-stuff4' );
491 wfProfileIn( __METHOD__
. '-stuff5' );
493 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
494 $content_actions = $this->buildContentActionUrls();
495 $tpl->setRef( 'content_actions', $content_actions );
497 $tpl->set( 'sidebar', $this->buildSidebar() );
498 $tpl->set( 'nav_urls', $this->buildNavUrls() );
500 // Set the head scripts near the end, in case the above actions resulted in added scripts
501 if ( $this->useHeadElement
) {
502 $tpl->set( 'headelement', $out->headElement( $this ) );
504 $tpl->set( 'headscripts', $out->getScript() );
507 // original version by hansm
508 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
509 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
512 // allow extensions adding stuff after the page content.
513 // See Skin::afterContentHook() for further documentation.
514 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
515 wfProfileOut( __METHOD__
. '-stuff5' );
518 wfProfileIn( __METHOD__
. '-execute' );
519 $res = $tpl->execute();
520 wfProfileOut( __METHOD__
. '-execute' );
522 // result may be an error
523 $this->printOrError( $res );
524 wfProfileOut( __METHOD__
);
528 * Output the string, or print error message if it's
529 * an error object of the appropriate type.
530 * For the base class, assume strings all around.
535 function printOrError( $str ) {
540 * build array of urls for personal toolbar
544 function buildPersonalUrls() {
545 global $wgOut, $wgRequest;
547 $title = $wgOut->getTitle();
548 $pageurl = $title->getLocalURL();
549 wfProfileIn( __METHOD__
);
551 /* set up the default links for the personal toolbar */
552 $personal_urls = array();
553 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
554 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
555 $returnto = "returnto=$page";
556 if( $this->thisquery
!= '' )
557 $returnto .= "&returntoquery=$query";
558 if( $this->loggedin
) {
559 $personal_urls['userpage'] = array(
560 'text' => $this->username
,
561 'href' => &$this->userpageUrlDetails
['href'],
562 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
563 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
565 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
566 $personal_urls['mytalk'] = array(
567 'text' => wfMsg( 'mytalk' ),
568 'href' => &$usertalkUrlDetails['href'],
569 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
570 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
572 $href = self
::makeSpecialUrl( 'Preferences' );
573 $personal_urls['preferences'] = array(
574 'text' => wfMsg( 'mypreferences' ),
576 'active' => ( $href == $pageurl )
578 $href = self
::makeSpecialUrl( 'Watchlist' );
579 $personal_urls['watchlist'] = array(
580 'text' => wfMsg( 'mywatchlist' ),
582 'active' => ( $href == $pageurl )
585 # We need to do an explicit check for Special:Contributions, as we
586 # have to match both the title, and the target (which could come
587 # from request values or be specified in "sub page" form. The plot
588 # thickens, because $wgTitle is altered for special pages, so doesn't
589 # contain the original alias-with-subpage.
590 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
591 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
592 list( $spName, $spPar ) =
593 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
594 $active = $spName == 'Contributions'
595 && ( ( $spPar && $spPar == $this->username
)
596 ||
$wgRequest->getText( 'target' ) == $this->username
);
601 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
602 $personal_urls['mycontris'] = array(
603 'text' => wfMsg( 'mycontris' ),
607 $personal_urls['logout'] = array(
608 'text' => wfMsg( 'userlogout' ),
609 'href' => self
::makeSpecialUrl( 'Userlogout',
610 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
616 $loginlink = $wgUser->isAllowed( 'createaccount' )
617 ?
'nav-login-createaccount'
619 if( $this->showIPinHeader() ) {
620 $href = &$this->userpageUrlDetails
['href'];
621 $personal_urls['anonuserpage'] = array(
622 'text' => $this->username
,
624 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
625 'active' => ( $pageurl == $href )
627 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
628 $href = &$usertalkUrlDetails['href'];
629 $personal_urls['anontalk'] = array(
630 'text' => wfMsg( 'anontalk' ),
632 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
633 'active' => ( $pageurl == $href )
635 $personal_urls['anonlogin'] = array(
636 'text' => wfMsg( $loginlink ),
637 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
638 'active' => $title->isSpecial( 'Userlogin' )
641 $personal_urls['login'] = array(
642 'text' => wfMsg( $loginlink ),
643 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
644 'active' => $title->isSpecial( 'Userlogin' )
649 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
650 wfProfileOut( __METHOD__
);
651 return $personal_urls;
654 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
657 $classes[] = 'selected';
659 if( $checkEdit && !$title->isKnown() ) {
661 $query = 'action=edit&redlink=1';
664 $text = wfMsg( $message );
665 if ( wfEmptyMsg( $message, $text ) ) {
667 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
671 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
672 $title, $message, $selected, $checkEdit,
673 &$classes, &$query, &$text, &$result ) ) ) {
678 'class' => implode( ' ', $classes ),
680 'href' => $title->getLocalUrl( $query ) );
683 function makeTalkUrlDetails( $name, $urlaction = '' ) {
684 $title = Title
::newFromText( $name );
685 if( !is_object( $title ) ) {
686 throw new MWException( __METHOD__
. " given invalid pagename $name" );
688 $title = $title->getTalkPage();
689 self
::checkTitle( $title, $name );
691 'href' => $title->getLocalURL( $urlaction ),
692 'exists' => $title->getArticleID() != 0 ?
true : false
696 function makeArticleUrlDetails( $name, $urlaction = '' ) {
697 $title = Title
::newFromText( $name );
698 $title= $title->getSubjectPage();
699 self
::checkTitle( $title, $name );
701 'href' => $title->getLocalURL( $urlaction ),
702 'exists' => $title->getArticleID() != 0 ?
true : false
707 * an array of edit links by default used for the tabs
711 function buildContentActionUrls() {
712 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
714 wfProfileIn( __METHOD__
);
716 $action = $wgRequest->getVal( 'action', 'view' );
717 $section = $wgRequest->getVal( 'section' );
718 $content_actions = array();
720 $prevent_active_tabs = false;
721 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
723 if( $this->iscontent
) {
724 $subjpage = $this->mTitle
->getSubjectPage();
725 $talkpage = $this->mTitle
->getTalkPage();
727 $nskey = $this->mTitle
->getNamespaceKey();
728 $content_actions[$nskey] = $this->tabAction(
731 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
735 $content_actions['talk'] = $this->tabAction(
738 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
743 wfProfileIn( __METHOD__
. '-edit' );
744 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
745 $istalk = $this->mTitle
->isTalkPage();
746 $istalkclass = $istalk?
' istalk':'';
747 $content_actions['edit'] = array(
748 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
749 'text' => $this->mTitle
->exists()
752 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
755 // adds new section link if page is a current revision of a talk page or
756 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
757 if ( !$wgOut->forceHideNewSectionLink() ) {
758 $content_actions['addsection'] = array(
759 'class' => $section == 'new' ?
'selected' : false,
760 'text' => wfMsg( 'addsection' ),
761 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
765 } elseif ( $this->mTitle
->isKnown() ) {
766 $content_actions['viewsource'] = array(
767 'class' => ($action == 'edit') ?
'selected' : false,
768 'text' => wfMsg( 'viewsource' ),
769 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
772 wfProfileOut( __METHOD__
. '-edit' );
774 wfProfileIn( __METHOD__
. '-live' );
775 if ( $this->mTitle
->exists() ) {
777 $content_actions['history'] = array(
778 'class' => ($action == 'history') ?
'selected' : false,
779 'text' => wfMsg( 'history_short' ),
780 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
784 if( $wgUser->isAllowed( 'delete' ) ) {
785 $content_actions['delete'] = array(
786 'class' => ($action == 'delete') ?
'selected' : false,
787 'text' => wfMsg( 'delete' ),
788 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
791 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
792 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
793 $content_actions['move'] = array(
794 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
795 'text' => wfMsg( 'move' ),
796 'href' => $moveTitle->getLocalUrl()
800 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
801 if( !$this->mTitle
->isProtected() ){
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' )
817 //article doesn't exist or is deleted
818 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
819 if( $n = $this->mTitle
->isDeleted() ) {
820 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
821 $content_actions['undelete'] = array(
823 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
824 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
825 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
830 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
831 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
832 $content_actions['protect'] = array(
833 'class' => ($action == 'protect') ?
'selected' : false,
834 'text' => wfMsg( 'protect' ),
835 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
839 $content_actions['unprotect'] = array(
840 'class' => ($action == 'unprotect') ?
'selected' : false,
841 'text' => wfMsg( 'unprotect' ),
842 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
848 wfProfileOut( __METHOD__
. '-live' );
850 if( $this->loggedin
) {
851 if( !$this->mTitle
->userIsWatching()) {
852 $content_actions['watch'] = array(
853 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
854 'text' => wfMsg( 'watch' ),
855 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
858 $content_actions['unwatch'] = array(
859 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
860 'text' => wfMsg( 'unwatch' ),
861 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
867 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
869 /* show special page tab */
871 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
872 'class' => 'selected',
873 'text' => wfMsg('nstab-special'),
874 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
877 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
880 /* show links to different language variants */
881 global $wgDisableLangConversion;
882 $variants = $wgContLang->getVariants();
883 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
884 $preferred = $wgContLang->getPreferredVariant();
886 foreach( $variants as $code ) {
887 $varname = $wgContLang->getVariantname( $code );
888 if( $varname == 'disable' )
890 $selected = ( $code == $preferred )?
'selected' : false;
891 $content_actions['varlang-' . $vcount] = array(
892 'class' => $selected,
894 'href' => $this->mTitle
->getLocalURL( '', $code )
900 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
902 wfProfileOut( __METHOD__
);
903 return $content_actions;
907 * build array of common navigation links
911 function buildNavUrls() {
912 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
913 global $wgEnableUploads, $wgUploadNavigationUrl;
915 wfProfileIn( __METHOD__
);
917 $action = $wgRequest->getVal( 'action', 'view' );
920 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
921 if( $wgUploadNavigationUrl ) {
922 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
923 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
924 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
926 $nav_urls['upload'] = false;
928 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
930 // default permalink to being off, will override it as required below.
931 $nav_urls['permalink'] = false;
933 // A print stylesheet is attached to all pages, but nobody ever
934 // figures that out. :) Add a link...
935 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
936 if ( !$wgOut->isPrintable() ) {
937 $nav_urls['print'] = array(
938 'text' => wfMsg( 'printableversion' ),
939 'href' => $wgRequest->appendQuery( 'printable=yes' )
943 // Also add a "permalink" while we're at it
944 if ( $this->mRevisionId
) {
945 $nav_urls['permalink'] = array(
946 'text' => wfMsg( 'permalink' ),
947 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
951 // Copy in case this undocumented, shady hook tries to mess with internals
952 $revid = $this->mRevisionId
;
953 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
956 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
957 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
958 $nav_urls['whatlinkshere'] = array(
959 'href' => $wlhTitle->getLocalUrl()
961 if( $this->mTitle
->getArticleId() ) {
962 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
963 $nav_urls['recentchangeslinked'] = array(
964 'href' => $rclTitle->getLocalUrl()
967 $nav_urls['recentchangeslinked'] = false;
969 if( $wgUseTrackbacks )
970 $nav_urls['trackbacklink'] = array(
971 'href' => $wgOut->getTitle()->trackbackURL()
975 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
976 $id = User
::idFromName( $this->mTitle
->getText() );
977 $ip = User
::isIP( $this->mTitle
->getText() );
983 if( $id ||
$ip ) { # both anons and non-anons have contribs list
984 $nav_urls['contributions'] = array(
985 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
989 $logPage = SpecialPage
::getTitleFor( 'Log' );
990 $nav_urls['log'] = array(
991 'href' => $logPage->getLocalUrl(
993 'user' => $this->mTitle
->getText()
998 $nav_urls['log'] = false;
1001 if ( $wgUser->isAllowed( 'block' ) ) {
1002 $nav_urls['blockip'] = array(
1003 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
1006 $nav_urls['blockip'] = false;
1009 $nav_urls['contributions'] = false;
1010 $nav_urls['log'] = false;
1011 $nav_urls['blockip'] = false;
1013 $nav_urls['emailuser'] = false;
1014 if( $this->showEmailUser( $id ) ) {
1015 $nav_urls['emailuser'] = array(
1016 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
1019 wfProfileOut( __METHOD__
);
1024 * Generate strings used for xml 'id' names
1028 function getNameSpaceKey() {
1029 return $this->mTitle
->getNamespaceKey();
1035 function setupUserJs( $allowUserJs ) {
1036 global $wgRequest, $wgJsMimeType;
1037 wfProfileIn( __METHOD__
);
1039 $action = $wgRequest->getVal( 'action', 'view' );
1041 if( $allowUserJs && $this->loggedin
) {
1042 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1043 # XXX: additional security check/prompt?
1044 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1046 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1049 wfProfileOut( __METHOD__
);
1053 * Code for extensions to hook into to provide per-page CSS, see
1054 * extensions/PageCSS/PageCSS.php for an implementation of this.
1058 function setupPageCss() {
1059 wfProfileIn( __METHOD__
);
1061 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1062 wfProfileOut( __METHOD__
);
1066 public function commonPrintStylesheet() {
1072 * Generic wrapper for template functions, with interface
1073 * compatible with what we use of PHPTAL 0.7.
1076 abstract class QuickTemplate
{
1080 public function QuickTemplate() {
1081 $this->data
= array();
1082 $this->translator
= new MediaWiki_I18N();
1086 * Sets the value $value to $name
1090 public function set( $name, $value ) {
1091 $this->data
[$name] = $value;
1098 public function setRef( $name, &$value ) {
1099 $this->data
[$name] =& $value;
1105 public function setTranslator( &$t ) {
1106 $this->translator
= &$t;
1110 * Main function, used by classes that subclass QuickTemplate
1111 * to show the actual HTML output
1113 abstract public function execute();
1118 function text( $str ) {
1119 echo htmlspecialchars( $this->data
[$str] );
1125 function jstext( $str ) {
1126 echo Xml
::escapeJsString( $this->data
[$str] );
1132 function html( $str ) {
1133 echo $this->data
[$str];
1139 function msg( $str ) {
1140 echo htmlspecialchars( $this->translator
->translate( $str ) );
1146 function msgHtml( $str ) {
1147 echo $this->translator
->translate( $str );
1151 * An ugly, ugly hack.
1154 function msgWiki( $str ) {
1155 global $wgParser, $wgOut;
1157 $text = $this->translator
->translate( $str );
1158 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1159 $wgOut->parserOptions(), true );
1160 echo $parserOutput->getText();
1166 function haveData( $str ) {
1167 return isset( $this->data
[$str] );
1173 function haveMsg( $str ) {
1174 $msg = $this->translator
->translate( $str );
1175 return ( $msg != '-' ) && ( $msg != '' ); # ????