2161962cc4d3d92d43f49d2e5975c3781074e2ff
2 if ( ! defined( 'MEDIAWIKI' ) )
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
27 class MediaWiki_I18N
{
28 var $_context = array();
30 function set( $varName, $value ) {
31 $this->_context
[$varName] = $value;
34 function translate( $value ) {
35 wfProfileIn( __METHOD__
);
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
40 $value = wfMsg( $value );
41 // interpolate variables
43 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
44 list( $src, $var ) = $m;
46 $varValue = $this->_context
[$var];
48 $value = str_replace( $src, $varValue, $value );
50 wfProfileOut( __METHOD__
);
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
67 class SkinTemplate
extends Skin
{
73 * Name of our skin, it probably needs to be all lower case. Child classes
74 * should override the default.
76 var $skinname = 'monobook';
79 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
80 * are located. Child classes should override the default.
82 var $stylename = 'monobook';
85 * For QuickTemplate, the name of the subclass which will actually fill the
86 * template. Child classes should override the default.
88 var $template = 'QuickTemplate';
93 * Add specific styles for this skin
95 * @param $out OutputPage
97 function setupSkinUserCss( OutputPage
$out ){
98 $out->addStyle( 'common/shared.css', 'screen' );
99 $out->addStyle( 'common/commonPrint.css', 'print' );
101 /* add specific javascript the base Skin class */
102 function setupSkinUserJs( OutputPage
$out ){
106 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
107 $siteGenScriptFile = self
::makeUrl( '-',
108 "action=raw$jsCache&gen=js&useskin=" .
109 urlencode( $this->getSkinName() ) ) ;
110 $this->jsvarurl
= $siteGenScriptFile;
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
119 * @param $callback string (or file)
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
130 * initialize various variables and generate the template
132 * @param $out OutputPage
134 function outputPage( OutputPage
$out ) {
135 global $wgArticle, $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
145 wfProfileIn( __METHOD__
);
147 $oldid = $wgRequest->getVal( 'oldid' );
148 $diff = $wgRequest->getVal( 'diff' );
149 $action = $wgRequest->getVal( 'action', 'view' );
151 wfProfileIn( __METHOD__
. '-init' );
152 $this->initPage( $out );
155 $tpl = $this->setupTemplate( $this->template
, 'skins' );
157 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
158 $tpl->setTranslator( new MediaWiki_I18N() );
160 wfProfileOut( __METHOD__
. '-init' );
162 wfProfileIn( __METHOD__
. '-stuff' );
163 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
164 $this->thisurl
= $this->mTitle
->getPrefixedURL();
166 if ( !$wgRequest->wasPosted() ) {
167 $query = $wgRequest->getValues();
168 unset( $query['title'] );
169 unset( $query['returnto'] );
170 unset( $query['returntoquery'] );
172 $this->thisquery
= wfUrlencode( wfArrayToCGI( $query ) );
173 $this->loggedin
= $wgUser->isLoggedIn();
174 $this->iscontent
= ( $this->mTitle
->getNamespace() != NS_SPECIAL
);
175 $this->iseditable
= ( $this->iscontent
and !( $action == 'edit' or $action == 'submit' ) );
176 $this->username
= $wgUser->getName();
178 if ( $wgUser->isLoggedIn() ||
$this->showIPinHeader() ) {
179 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
181 # This won't be used in the standard skins, but we define it to preserve the interface
182 # To save time, we check for existence
183 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
186 $this->userjs
= $this->userjsprev
= false;
187 $this->setupUserCss( $out );
188 $this->setupUserJs( $out->isUserJsAllowed() );
189 $this->titletxt
= $this->mTitle
->getPrefixedText();
190 wfProfileOut( __METHOD__
. '-stuff' );
192 wfProfileIn( __METHOD__
. '-stuff2' );
193 $tpl->set( 'title', $out->getPageTitle() );
194 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
195 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
196 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
197 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
199 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
200 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
201 $this->mTitle
->getNsText();
203 $tpl->set( 'nscanonical', $nsname );
204 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
205 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
206 $tpl->set( 'titletext', $this->mTitle
->getText() );
207 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
208 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
210 $tpl->set( 'isarticle', $out->isArticle() );
212 $tpl->setRef( 'thispage', $this->thispage
);
213 $subpagestr = $this->subPageSubtitle();
215 'subtitle', !empty( $subpagestr ) ?
216 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
219 $undelete = $this->getUndeleteLink();
221 'undelete', !empty( $undelete ) ?
222 '<span class="subpages">'.$undelete.'</span>' :
226 $tpl->set( 'catlinks', $this->getCategories() );
227 if( $out->isSyndicated() ) {
229 foreach( $out->getSyndicationLinks() as $format => $link ) {
230 $feeds[$format] = array(
231 'text' => wfMsg( "feed-$format" ),
235 $tpl->setRef( 'feeds', $feeds );
237 $tpl->set( 'feeds', false );
239 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
240 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
242 $tpl->set( 'trackbackhtml', null );
245 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
246 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
247 $tpl->setRef( 'mimetype', $wgMimeType );
248 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
249 $tpl->setRef( 'charset', $wgOutputEncoding );
250 $tpl->set( 'headlinks', $out->getHeadLinks() );
252 //moved headscripts to near end of template header output
254 $tpl->set( 'csslinks', $out->buildCssLinks() );
255 $tpl->setRef( 'wgScript', $wgScript );
256 $tpl->setRef( 'skinname', $this->skinname
);
257 $tpl->set( 'skinclass', get_class( $this ) );
258 $tpl->setRef( 'stylename', $this->stylename
);
259 $tpl->set( 'printable', $out->isPrintable() );
260 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
261 $tpl->setRef( 'loggedin', $this->loggedin
);
262 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
263 /* XXX currently unused, might get useful later
264 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
265 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
266 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
267 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
268 $tpl->set( "helppage", wfMsg('helppage'));
270 $tpl->set( 'searchaction', $this->escapeSearchLink() );
271 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
272 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
273 $tpl->setRef( 'stylepath', $wgStylePath );
274 $tpl->setRef( 'articlepath', $wgArticlePath );
275 $tpl->setRef( 'scriptpath', $wgScriptPath );
276 $tpl->setRef( 'serverurl', $wgServer );
277 $tpl->setRef( 'logopath', $wgLogo );
278 $tpl->setRef( 'lang', $wgContLanguageCode );
279 $tpl->set( 'dir', $wgContLang->getDir() );
280 $tpl->set( 'rtl', $wgContLang->isRTL() );
281 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
282 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
283 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
284 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
285 $tpl->setRef( 'userpage', $this->userpage
);
286 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
287 $tpl->set( 'userlang', $wgLang->getCode() );
288 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
289 $tpl->set( 'pagecss', $this->setupPageCss() );
290 $tpl->setRef( 'usercss', $this->usercss
);
291 $tpl->setRef( 'userjs', $this->userjs
);
292 $tpl->setRef( 'userjsprev', $this->userjsprev
);
294 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
295 $tpl->set( 'jsvarurl',
297 "action=raw$jsCache&gen=js&useskin=" .
298 urlencode( $this->getSkinName() ) ) );
300 $tpl->set( 'jsvarurl', false );
303 $newtalks = $wgUser->getNewMessageLinks();
305 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
306 $usertitle = $this->mUser
->getUserPage();
307 $usertalktitle = $usertitle->getTalkPage();
309 if( !$usertalktitle->equals( $this->mTitle
) ) {
310 $newmessageslink = $this->link(
312 wfMsgHtml( 'newmessageslink' ),
314 array( 'redirect' => 'no' ),
315 array( 'known', 'noclasses' )
318 $newmessagesdifflink = $this->link(
320 wfMsgHtml( 'newmessagesdifflink' ),
322 array( 'diff' => 'cur' ),
323 array( 'known', 'noclasses' )
327 'youhavenewmessages',
332 $out->setSquidMaxage( 0 );
334 } else if( count( $newtalks ) ) {
335 // _>" " for BC <= 1.16
336 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
338 foreach( $newtalks as $newtalk ) {
339 $msgs[] = Xml
::element('a',
340 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
342 $parts = implode( $sep, $msgs );
343 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
344 $out->setSquidMaxage( 0 );
348 wfProfileOut( __METHOD__
. '-stuff2' );
350 wfProfileIn( __METHOD__
. '-stuff3' );
351 $tpl->setRef( 'newtalk', $ntl );
352 $tpl->setRef( 'skin', $this );
353 $tpl->set( 'logo', $this->logoText() );
354 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
355 $wgArticle and 0 != $wgArticle->getID() ){
356 if ( !$wgDisableCounters ) {
357 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
359 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
361 $tpl->set( 'viewcount', false );
364 $tpl->set( 'viewcount', false );
367 if( $wgPageShowWatchingUsers ) {
368 $dbr = wfGetDB( DB_SLAVE
);
369 $watchlist = $dbr->tableName( 'watchlist' );
370 $res = $dbr->select( 'watchlist',
371 array( 'COUNT(*) AS n' ),
372 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
375 $x = $dbr->fetchObject( $res );
376 $numberofwatchingusers = $x->n
;
377 if( $numberofwatchingusers > 0 ) {
378 $tpl->set( 'numberofwatchingusers',
379 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
380 $wgLang->formatNum( $numberofwatchingusers ) )
383 $tpl->set( 'numberofwatchingusers', false );
386 $tpl->set( 'numberofwatchingusers', false );
389 $tpl->set( 'copyright', $this->getCopyright() );
391 $this->credits
= false;
393 if( $wgMaxCredits != 0 ){
394 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
396 $tpl->set( 'lastmod', $this->lastModified() );
399 $tpl->setRef( 'credits', $this->credits
);
401 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
402 $tpl->set( 'copyright', $this->getCopyright() );
403 $tpl->set( 'viewcount', false );
404 $tpl->set( 'lastmod', false );
405 $tpl->set( 'credits', false );
406 $tpl->set( 'numberofwatchingusers', false );
408 $tpl->set( 'copyright', false );
409 $tpl->set( 'viewcount', false );
410 $tpl->set( 'lastmod', false );
411 $tpl->set( 'credits', false );
412 $tpl->set( 'numberofwatchingusers', false );
414 wfProfileOut( __METHOD__
. '-stuff3' );
416 wfProfileIn( __METHOD__
. '-stuff4' );
417 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
418 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
419 $tpl->set( 'disclaimer', $this->disclaimerLink() );
420 $tpl->set( 'privacy', $this->privacyLink() );
421 $tpl->set( 'about', $this->aboutLink() );
423 $tpl->setRef( 'debug', $out->mDebugtext
);
424 $tpl->set( 'reporttime', wfReportTime() );
425 $tpl->set( 'sitenotice', wfGetSiteNotice() );
426 $tpl->set( 'bottomscripts', $this->bottomScripts() );
428 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
429 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
430 $tpl->setRef( 'bodytext', $out->mBodytext
);
433 $language_urls = array();
435 if ( !$wgHideInterlanguageLinks ) {
436 foreach( $out->getLanguageLinks() as $l ) {
437 $tmp = explode( ':', $l, 2 );
438 $class = 'interwiki-' . $tmp[0];
440 $nt = Title
::newFromText( $l );
442 $language_urls[] = array(
443 'href' => $nt->getFullURL(),
444 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
445 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
451 if( count( $language_urls ) ) {
452 $tpl->setRef( 'language_urls', $language_urls );
454 $tpl->set( 'language_urls', false );
456 wfProfileOut( __METHOD__
. '-stuff4' );
458 wfProfileIn( __METHOD__
. '-stuff5' );
460 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
461 $content_actions = $this->buildContentActionUrls();
462 $tpl->setRef( 'content_actions', $content_actions );
464 // XXX: attach this from javascript, same with section editing
465 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
466 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
467 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
469 $tpl->set( 'body_ondblclick', false );
471 $tpl->set( 'body_onload', false );
472 $tpl->set( 'sidebar', $this->buildSidebar() );
473 $tpl->set( 'nav_urls', $this->buildNavUrls() );
475 //set the head script near the end (in case above actions result in adding scripts)
476 $tpl->set( 'headscripts', $out->getScript() );
478 // original version by hansm
479 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
480 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
483 // allow extensions adding stuff after the page content.
484 // See Skin::afterContentHook() for further documentation.
485 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
486 wfProfileOut( __METHOD__
. '-stuff5' );
489 wfProfileIn( __METHOD__
. '-execute' );
490 $res = $tpl->execute();
491 wfProfileOut( __METHOD__
. '-execute' );
493 // result may be an error
494 $this->printOrError( $res );
495 wfProfileOut( __METHOD__
);
499 * Output the string, or print error message if it's
500 * an error object of the appropriate type.
501 * For the base class, assume strings all around.
506 function printOrError( $str ) {
511 * build array of urls for personal toolbar
515 function buildPersonalUrls() {
516 global $wgOut, $wgRequest;
518 $title = $wgOut->getTitle();
519 $pageurl = $title->getLocalURL();
520 wfProfileIn( __METHOD__
);
522 /* set up the default links for the personal toolbar */
523 $personal_urls = array();
524 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
525 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
526 $returnto = "returnto=$page";
527 if( $this->thisquery
!= '' )
528 $returnto .= "&returntoquery=$query";
529 if( $this->loggedin
) {
530 $personal_urls['userpage'] = array(
531 'text' => $this->username
,
532 'href' => &$this->userpageUrlDetails
['href'],
533 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
534 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
536 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
537 $personal_urls['mytalk'] = array(
538 'text' => wfMsg( 'mytalk' ),
539 'href' => &$usertalkUrlDetails['href'],
540 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
541 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
543 $href = self
::makeSpecialUrl( 'Preferences' );
544 $personal_urls['preferences'] = array(
545 'text' => wfMsg( 'mypreferences' ),
547 'active' => ( $href == $pageurl )
549 $href = self
::makeSpecialUrl( 'Watchlist' );
550 $personal_urls['watchlist'] = array(
551 'text' => wfMsg( 'mywatchlist' ),
553 'active' => ( $href == $pageurl )
556 # We need to do an explicit check for Special:Contributions, as we
557 # have to match both the title, and the target (which could come
558 # from request values or be specified in "sub page" form. The plot
559 # thickens, because $wgTitle is altered for special pages, so doesn't
560 # contain the original alias-with-subpage.
561 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
562 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
563 list( $spName, $spPar ) =
564 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
565 $active = $spName == 'Contributions'
566 && ( ( $spPar && $spPar == $this->username
)
567 ||
$wgRequest->getText( 'target' ) == $this->username
);
572 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
573 $personal_urls['mycontris'] = array(
574 'text' => wfMsg( 'mycontris' ),
578 $personal_urls['logout'] = array(
579 'text' => wfMsg( 'userlogout' ),
580 'href' => self
::makeSpecialUrl( 'Userlogout',
581 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
587 $loginlink = $wgUser->isAllowed( 'createaccount' )
588 ?
'nav-login-createaccount'
590 if( $this->showIPinHeader() ) {
591 $href = &$this->userpageUrlDetails
['href'];
592 $personal_urls['anonuserpage'] = array(
593 'text' => $this->username
,
595 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
596 'active' => ( $pageurl == $href )
598 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
599 $href = &$usertalkUrlDetails['href'];
600 $personal_urls['anontalk'] = array(
601 'text' => wfMsg( 'anontalk' ),
603 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
604 'active' => ( $pageurl == $href )
606 $personal_urls['anonlogin'] = array(
607 'text' => wfMsg( $loginlink ),
608 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
609 'active' => $title->isSpecial( 'Userlogin' )
612 $personal_urls['login'] = array(
613 'text' => wfMsg( $loginlink ),
614 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
615 'active' => $title->isSpecial( 'Userlogin' )
620 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
621 wfProfileOut( __METHOD__
);
622 return $personal_urls;
625 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
628 $classes[] = 'selected';
630 if( $checkEdit && !$title->isKnown() ) {
632 $query = 'action=edit&redlink=1';
635 $text = wfMsg( $message );
636 if ( wfEmptyMsg( $message, $text ) ) {
638 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
642 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
643 $title, $message, $selected, $checkEdit,
644 &$classes, &$query, &$text, &$result ) ) ) {
649 'class' => implode( ' ', $classes ),
651 'href' => $title->getLocalUrl( $query ) );
654 function makeTalkUrlDetails( $name, $urlaction = '' ) {
655 $title = Title
::newFromText( $name );
656 if( !is_object( $title ) ) {
657 throw new MWException( __METHOD__
. " given invalid pagename $name" );
659 $title = $title->getTalkPage();
660 self
::checkTitle( $title, $name );
662 'href' => $title->getLocalURL( $urlaction ),
663 'exists' => $title->getArticleID() != 0 ?
true : false
667 function makeArticleUrlDetails( $name, $urlaction = '' ) {
668 $title = Title
::newFromText( $name );
669 $title= $title->getSubjectPage();
670 self
::checkTitle( $title, $name );
672 'href' => $title->getLocalURL( $urlaction ),
673 'exists' => $title->getArticleID() != 0 ?
true : false
678 * an array of edit links by default used for the tabs
682 function buildContentActionUrls() {
683 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
685 wfProfileIn( __METHOD__
);
687 $action = $wgRequest->getVal( 'action', 'view' );
688 $section = $wgRequest->getVal( 'section' );
689 $content_actions = array();
691 $prevent_active_tabs = false;
692 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
694 if( $this->iscontent
) {
695 $subjpage = $this->mTitle
->getSubjectPage();
696 $talkpage = $this->mTitle
->getTalkPage();
698 $nskey = $this->mTitle
->getNamespaceKey();
699 $content_actions[$nskey] = $this->tabAction(
702 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
706 $content_actions['talk'] = $this->tabAction(
709 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
714 wfProfileIn( __METHOD__
. '-edit' );
715 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
716 $istalk = $this->mTitle
->isTalkPage();
717 $istalkclass = $istalk?
' istalk':'';
718 $content_actions['edit'] = array(
719 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
720 'text' => $this->mTitle
->exists()
723 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
726 // adds new section link if page is a current revision of a talk page or
727 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
728 if ( !$wgOut->forceHideNewSectionLink() ) {
729 $content_actions['addsection'] = array(
730 'class' => $section == 'new' ?
'selected' : false,
731 'text' => wfMsg( 'addsection' ),
732 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
736 } elseif ( $this->mTitle
->isKnown() ) {
737 $content_actions['viewsource'] = array(
738 'class' => ($action == 'edit') ?
'selected' : false,
739 'text' => wfMsg( 'viewsource' ),
740 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
743 wfProfileOut( __METHOD__
. '-edit' );
745 wfProfileIn( __METHOD__
. '-live' );
746 if ( $this->mTitle
->exists() ) {
748 $content_actions['history'] = array(
749 'class' => ($action == 'history') ?
'selected' : false,
750 'text' => wfMsg( 'history_short' ),
751 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
755 if( $wgUser->isAllowed( 'delete' ) ) {
756 $content_actions['delete'] = array(
757 'class' => ($action == 'delete') ?
'selected' : false,
758 'text' => wfMsg( 'delete' ),
759 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
762 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
763 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
764 $content_actions['move'] = array(
765 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
766 'text' => wfMsg( 'move' ),
767 'href' => $moveTitle->getLocalUrl()
771 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
772 if( !$this->mTitle
->isProtected() ){
773 $content_actions['protect'] = array(
774 'class' => ($action == 'protect') ?
'selected' : false,
775 'text' => wfMsg( 'protect' ),
776 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
780 $content_actions['unprotect'] = array(
781 'class' => ($action == 'unprotect') ?
'selected' : false,
782 'text' => wfMsg( 'unprotect' ),
783 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
788 //article doesn't exist or is deleted
789 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
790 if( $n = $this->mTitle
->isDeleted() ) {
791 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
792 $content_actions['undelete'] = array(
794 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
795 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
796 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
801 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
802 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
803 $content_actions['protect'] = array(
804 'class' => ($action == 'protect') ?
'selected' : false,
805 'text' => wfMsg( 'protect' ),
806 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
810 $content_actions['unprotect'] = array(
811 'class' => ($action == 'unprotect') ?
'selected' : false,
812 'text' => wfMsg( 'unprotect' ),
813 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
819 wfProfileOut( __METHOD__
. '-live' );
821 if( $this->loggedin
) {
822 if( !$this->mTitle
->userIsWatching()) {
823 $content_actions['watch'] = array(
824 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
825 'text' => wfMsg( 'watch' ),
826 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
829 $content_actions['unwatch'] = array(
830 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
831 'text' => wfMsg( 'unwatch' ),
832 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
838 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
840 /* show special page tab */
842 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
843 'class' => 'selected',
844 'text' => wfMsg('nstab-special'),
845 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
848 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
851 /* show links to different language variants */
852 global $wgDisableLangConversion;
853 $variants = $wgContLang->getVariants();
854 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
855 $preferred = $wgContLang->getPreferredVariant();
857 foreach( $variants as $code ) {
858 $varname = $wgContLang->getVariantname( $code );
859 if( $varname == 'disable' )
861 $selected = ( $code == $preferred )?
'selected' : false;
862 $content_actions['varlang-' . $vcount] = array(
863 'class' => $selected,
865 'href' => $this->mTitle
->getLocalURL( '', $code )
871 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
873 wfProfileOut( __METHOD__
);
874 return $content_actions;
878 * build array of common navigation links
882 function buildNavUrls() {
883 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
884 global $wgEnableUploads, $wgUploadNavigationUrl;
886 wfProfileIn( __METHOD__
);
888 $action = $wgRequest->getVal( 'action', 'view' );
891 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
892 if( $wgUploadNavigationUrl ) {
893 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
894 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
895 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
897 $nav_urls['upload'] = false;
899 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
901 // default permalink to being off, will override it as required below.
902 $nav_urls['permalink'] = false;
904 // A print stylesheet is attached to all pages, but nobody ever
905 // figures that out. :) Add a link...
906 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
907 if ( !$wgOut->isPrintable() ) {
908 $nav_urls['print'] = array(
909 'text' => wfMsg( 'printableversion' ),
910 'href' => $wgRequest->appendQuery( 'printable=yes' )
914 // Also add a "permalink" while we're at it
915 if ( $this->mRevisionId
) {
916 $nav_urls['permalink'] = array(
917 'text' => wfMsg( 'permalink' ),
918 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
922 // Copy in case this undocumented, shady hook tries to mess with internals
923 $revid = $this->mRevisionId
;
924 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
927 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
928 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
929 $nav_urls['whatlinkshere'] = array(
930 'href' => $wlhTitle->getLocalUrl()
932 if( $this->mTitle
->getArticleId() ) {
933 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
934 $nav_urls['recentchangeslinked'] = array(
935 'href' => $rclTitle->getLocalUrl()
938 $nav_urls['recentchangeslinked'] = false;
940 if( $wgUseTrackbacks )
941 $nav_urls['trackbacklink'] = array(
942 'href' => $wgOut->getTitle()->trackbackURL()
946 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
947 $id = User
::idFromName( $this->mTitle
->getText() );
948 $ip = User
::isIP( $this->mTitle
->getText() );
954 if( $id ||
$ip ) { # both anons and non-anons have contribs list
955 $nav_urls['contributions'] = array(
956 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
960 $logPage = SpecialPage
::getTitleFor( 'Log' );
961 $nav_urls['log'] = array(
962 'href' => $logPage->getLocalUrl(
964 'user' => $this->mTitle
->getText()
969 $nav_urls['log'] = false;
972 if ( $wgUser->isAllowed( 'block' ) ) {
973 $nav_urls['blockip'] = array(
974 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
977 $nav_urls['blockip'] = false;
980 $nav_urls['contributions'] = false;
981 $nav_urls['log'] = false;
982 $nav_urls['blockip'] = false;
984 $nav_urls['emailuser'] = false;
985 if( $this->showEmailUser( $id ) ) {
986 $nav_urls['emailuser'] = array(
987 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
990 wfProfileOut( __METHOD__
);
995 * Generate strings used for xml 'id' names
999 function getNameSpaceKey() {
1000 return $this->mTitle
->getNamespaceKey();
1006 function setupUserJs( $allowUserJs ) {
1007 global $wgRequest, $wgJsMimeType;
1008 wfProfileIn( __METHOD__
);
1010 $action = $wgRequest->getVal( 'action', 'view' );
1012 if( $allowUserJs && $this->loggedin
) {
1013 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1014 # XXX: additional security check/prompt?
1015 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1017 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1020 wfProfileOut( __METHOD__
);
1024 * Code for extensions to hook into to provide per-page CSS, see
1025 * extensions/PageCSS/PageCSS.php for an implementation of this.
1029 function setupPageCss() {
1030 wfProfileIn( __METHOD__
);
1032 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1033 wfProfileOut( __METHOD__
);
1037 public function commonPrintStylesheet() {
1043 * Generic wrapper for template functions, with interface
1044 * compatible with what we use of PHPTAL 0.7.
1047 abstract class QuickTemplate
{
1051 public function QuickTemplate() {
1052 $this->data
= array();
1053 $this->translator
= new MediaWiki_I18N();
1057 * Sets the value $value to $name
1061 public function set( $name, $value ) {
1062 $this->data
[$name] = $value;
1069 public function setRef( $name, &$value ) {
1070 $this->data
[$name] =& $value;
1076 public function setTranslator( &$t ) {
1077 $this->translator
= &$t;
1081 * Main function, used by classes that subclass QuickTemplate
1082 * to show the actual HTML output
1084 abstract public function execute();
1089 function text( $str ) {
1090 echo htmlspecialchars( $this->data
[$str] );
1096 function jstext( $str ) {
1097 echo Xml
::escapeJsString( $this->data
[$str] );
1103 function html( $str ) {
1104 echo $this->data
[$str];
1110 function msg( $str ) {
1111 echo htmlspecialchars( $this->translator
->translate( $str ) );
1117 function msgHtml( $str ) {
1118 echo $this->translator
->translate( $str );
1122 * An ugly, ugly hack.
1125 function msgWiki( $str ) {
1126 global $wgParser, $wgOut;
1128 $text = $this->translator
->translate( $str );
1129 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1130 $wgOut->parserOptions(), true );
1131 echo $parserOutput->getText();
1137 function haveData( $str ) {
1138 return isset( $this->data
[$str] );
1144 function haveMsg( $str ) {
1145 $msg = $this->translator
->translate( $str );
1146 return ( $msg != '-' ) && ( $msg != '' ); # ????