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, set in initPage()
74 * It probably need to be all lower case.
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
97 * @param $out OutputPage
99 function initPage( OutputPage
$out ) {
100 parent
::initPage( $out );
101 $this->skinname
= 'monobook';
102 $this->stylename
= 'monobook';
103 $this->template
= 'QuickTemplate';
107 * Add specific styles for this skin
109 * @param $out OutputPage
111 function setupSkinUserCss( OutputPage
$out ){
112 $out->addStyle( 'common/shared.css', 'screen' );
113 $out->addStyle( 'common/commonPrint.css', 'print' );
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
121 * @param $callback string (or file)
122 * @param $repository string: subdirectory where we keep template files
123 * @param $cache_dir string
127 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
128 return new $classname();
132 * initialize various variables and generate the template
134 * @param $out OutputPage
136 function outputPage( OutputPage
$out ) {
137 global $wgArticle, $wgUser, $wgLang, $wgContLang;
138 global $wgScript, $wgStylePath, $wgContLanguageCode;
139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
141 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
142 global $wgMaxCredits, $wgShowCreditsIfMax;
143 global $wgPageShowWatchingUsers;
144 global $wgUseTrackbacks, $wgUseSiteJs;
145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
147 wfProfileIn( __METHOD__
);
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151 $action = $wgRequest->getVal( 'action', 'view' );
153 wfProfileIn( __METHOD__
. '-init' );
154 $this->initPage( $out );
157 $tpl = $this->setupTemplate( $this->template
, 'skins' );
159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
160 $tpl->setTranslator( new MediaWiki_I18N() );
162 wfProfileOut( __METHOD__
. '-init' );
164 wfProfileIn( __METHOD__
. '-stuff' );
165 $this->thispage
= $this->mTitle
->getPrefixedDBkey();
166 $this->thisurl
= $this->mTitle
->getPrefixedURL();
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->userjs
= $this->userjsprev
= false;
181 $this->setupUserCss( $out );
182 $this->setupUserJs( $out->isUserJsAllowed() );
183 $this->titletxt
= $this->mTitle
->getPrefixedText();
184 wfProfileOut( __METHOD__
. '-stuff' );
186 wfProfileIn( __METHOD__
. '-stuff2' );
187 $tpl->set( 'title', $out->getPageTitle() );
188 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
189 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
190 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle
) );
191 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] ) ?
194 $wgCanonicalNamespaceNames[ $this->mTitle
->getNamespace() ] :
195 $this->mTitle
->getNsText();
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle
->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle
->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle
->getText() );
201 $tpl->set( 'articleid', $this->mTitle
->getArticleId() );
202 $tpl->set( 'currevisionid', isset( $wgArticle ) ?
$wgArticle->getLatest() : 0 );
204 $tpl->set( 'isarticle', $out->isArticle() );
206 $tpl->setRef( 'thispage', $this->thispage
);
207 $subpagestr = $this->subPageSubtitle();
209 'subtitle', !empty( $subpagestr ) ?
210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
213 $undelete = $this->getUndeleteLink();
215 'undelete', !empty( $undelete ) ?
216 '<span class="subpages">'.$undelete.'</span>' :
220 $tpl->set( 'catlinks', $this->getCategories() );
221 if( $out->isSyndicated() ) {
223 foreach( $out->getSyndicationLinks() as $format => $link ) {
224 $feeds[$format] = array(
225 'text' => wfMsg( "feed-$format" ),
229 $tpl->setRef( 'feeds', $feeds );
231 $tpl->set( 'feeds', false );
233 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
234 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
236 $tpl->set( 'trackbackhtml', null );
239 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
240 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
241 $tpl->setRef( 'mimetype', $wgMimeType );
242 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
243 $tpl->setRef( 'charset', $wgOutputEncoding );
244 $tpl->set( 'headlinks', $out->getHeadLinks() );
245 $tpl->set( 'headscripts', $out->getScript() );
246 $tpl->set( 'csslinks', $out->buildCssLinks() );
247 $tpl->setRef( 'wgScript', $wgScript );
248 $tpl->setRef( 'skinname', $this->skinname
);
249 $tpl->set( 'skinclass', get_class( $this ) );
250 $tpl->setRef( 'stylename', $this->stylename
);
251 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
252 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
253 $tpl->setRef( 'loggedin', $this->loggedin
);
254 $tpl->set( 'notspecialpage', $this->mTitle
->getNamespace() != NS_SPECIAL
);
255 /* XXX currently unused, might get useful later
256 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
257 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
258 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
259 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
260 $tpl->set( "helppage", wfMsg('helppage'));
262 $tpl->set( 'searchaction', $this->escapeSearchLink() );
263 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBKey() );
264 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
265 $tpl->setRef( 'stylepath', $wgStylePath );
266 $tpl->setRef( 'articlepath', $wgArticlePath );
267 $tpl->setRef( 'scriptpath', $wgScriptPath );
268 $tpl->setRef( 'serverurl', $wgServer );
269 $tpl->setRef( 'logopath', $wgLogo );
270 $tpl->setRef( 'lang', $wgContLanguageCode );
271 $tpl->set( 'dir', $wgContLang->isRTL() ?
'rtl' : 'ltr' );
272 $tpl->set( 'rtl', $wgContLang->isRTL() );
273 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
274 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
275 $tpl->set( 'username', $wgUser->isAnon() ?
NULL : $this->username
);
276 $tpl->setRef( 'userpage', $this->userpage
);
277 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
278 $tpl->set( 'userlang', $wgLang->getCode() );
279 $tpl->set( 'pagecss', $this->setupPageCss() );
280 $tpl->setRef( 'usercss', $this->usercss
);
281 $tpl->setRef( 'userjs', $this->userjs
);
282 $tpl->setRef( 'userjsprev', $this->userjsprev
);
284 $jsCache = $this->loggedin ?
'&smaxage=0' : '';
285 $tpl->set( 'jsvarurl',
287 "action=raw$jsCache&gen=js&useskin=" .
288 urlencode( $this->getSkinName() ) ) );
290 $tpl->set( 'jsvarurl', false );
292 $newtalks = $wgUser->getNewMessageLinks();
294 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
295 $usertitle = $this->mUser
->getUserPage();
296 $usertalktitle = $usertitle->getTalkPage();
297 if( !$usertalktitle->equals( $this->mTitle
) ) {
298 $ntl = wfMsg( 'youhavenewmessages',
299 $this->makeKnownLinkObj(
301 wfMsgHtml( 'newmessageslink' ),
304 $this->makeKnownLinkObj(
306 wfMsgHtml( 'newmessagesdifflink' ),
311 $out->setSquidMaxage( 0 );
313 } else if( count( $newtalks ) ) {
314 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
316 foreach( $newtalks as $newtalk ) {
317 $msgs[] = Xml
::element('a',
318 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
320 $parts = implode( $sep, $msgs );
321 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
322 $out->setSquidMaxage( 0 );
326 wfProfileOut( __METHOD__
. '-stuff2' );
328 wfProfileIn( __METHOD__
. '-stuff3' );
329 $tpl->setRef( 'newtalk', $ntl );
330 $tpl->setRef( 'skin', $this );
331 $tpl->set( 'logo', $this->logoText() );
332 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
333 $wgArticle and 0 != $wgArticle->getID() ){
334 if ( !$wgDisableCounters ) {
335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
337 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
339 $tpl->set( 'viewcount', false );
342 $tpl->set( 'viewcount', false );
345 if( $wgPageShowWatchingUsers ) {
346 $dbr = wfGetDB( DB_SLAVE
);
347 $watchlist = $dbr->tableName( 'watchlist' );
348 $res = $dbr->select( 'watchlist',
349 array( 'COUNT(*) AS n' ),
350 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
353 $x = $dbr->fetchObject( $res );
354 $numberofwatchingusers = $x->n
;
355 if( $numberofwatchingusers > 0 ) {
356 $tpl->set( 'numberofwatchingusers',
357 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
358 $wgLang->formatNum( $numberofwatchingusers ) )
361 $tpl->set( 'numberofwatchingusers', false );
364 $tpl->set( 'numberofwatchingusers', false );
367 $tpl->set( 'copyright', $this->getCopyright() );
369 $this->credits
= false;
371 if( $wgMaxCredits != 0 ){
372 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
374 $tpl->set( 'lastmod', $this->lastModified() );
377 $tpl->setRef( 'credits', $this->credits
);
379 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
380 $tpl->set( 'copyright', $this->getCopyright() );
381 $tpl->set( 'viewcount', false );
382 $tpl->set( 'lastmod', false );
383 $tpl->set( 'credits', false );
384 $tpl->set( 'numberofwatchingusers', false );
386 $tpl->set( 'copyright', false );
387 $tpl->set( 'viewcount', false );
388 $tpl->set( 'lastmod', false );
389 $tpl->set( 'credits', false );
390 $tpl->set( 'numberofwatchingusers', false );
392 wfProfileOut( __METHOD__
. '-stuff3' );
394 wfProfileIn( __METHOD__
. '-stuff4' );
395 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
396 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
397 $tpl->set( 'disclaimer', $this->disclaimerLink() );
398 $tpl->set( 'privacy', $this->privacyLink() );
399 $tpl->set( 'about', $this->aboutLink() );
401 $tpl->setRef( 'debug', $out->mDebugtext
);
402 $tpl->set( 'reporttime', wfReportTime() );
403 $tpl->set( 'sitenotice', wfGetSiteNotice() );
404 $tpl->set( 'bottomscripts', $this->bottomScripts() );
406 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
407 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
408 $tpl->setRef( 'bodytext', $out->mBodytext
);
411 $language_urls = array();
413 if ( !$wgHideInterlanguageLinks ) {
414 foreach( $out->getLanguageLinks() as $l ) {
415 $tmp = explode( ':', $l, 2 );
416 $class = 'interwiki-' . $tmp[0];
418 $nt = Title
::newFromText( $l );
420 $language_urls[] = array(
421 'href' => $nt->getFullURL(),
422 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
423 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
429 if( count( $language_urls ) ) {
430 $tpl->setRef( 'language_urls', $language_urls );
432 $tpl->set( 'language_urls', false );
434 wfProfileOut( __METHOD__
. '-stuff4' );
436 wfProfileIn( __METHOD__
. '-stuff5' );
438 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
439 $content_actions = $this->buildContentActionUrls();
440 $tpl->setRef( 'content_actions', $content_actions );
442 // XXX: attach this from javascript, same with section editing
443 if( $this->iseditable
&& $wgUser->getOption( 'editondblclick' ) ){
444 $encEditUrl = Xml
::escapeJsString( $this->mTitle
->getLocalUrl( $this->editUrlOptions() ) );
445 $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' );
447 $tpl->set( 'body_ondblclick', false );
449 $tpl->set( 'body_onload', false );
450 $tpl->set( 'sidebar', $this->buildSidebar() );
451 $tpl->set( 'nav_urls', $this->buildNavUrls() );
453 // original version by hansm
454 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
455 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
458 // allow extensions adding stuff after the page content.
459 // See Skin::afterContentHook() for further documentation.
460 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
461 wfProfileOut( __METHOD__
. '-stuff5' );
464 wfProfileIn( __METHOD__
. '-execute' );
465 $res = $tpl->execute();
466 wfProfileOut( __METHOD__
. '-execute' );
468 // result may be an error
469 $this->printOrError( $res );
470 wfProfileOut( __METHOD__
);
474 * Output the string, or print error message if it's
475 * an error object of the appropriate type.
476 * For the base class, assume strings all around.
481 function printOrError( $str ) {
486 * build array of urls for personal toolbar
490 function buildPersonalUrls() {
491 global $wgOut, $wgRequest;
493 $title = $wgOut->getTitle();
494 $pageurl = $title->getLocalURL();
495 wfProfileIn( __METHOD__
);
497 /* set up the default links for the personal toolbar */
498 $personal_urls = array();
499 if( $this->loggedin
) {
500 $personal_urls['userpage'] = array(
501 'text' => $this->username
,
502 'href' => &$this->userpageUrlDetails
['href'],
503 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
504 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
506 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
507 $personal_urls['mytalk'] = array(
508 'text' => wfMsg( 'mytalk' ),
509 'href' => &$usertalkUrlDetails['href'],
510 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
511 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
513 $href = self
::makeSpecialUrl( 'Preferences' );
514 $personal_urls['preferences'] = array(
515 'text' => wfMsg( 'mypreferences' ),
517 'active' => ( $href == $pageurl )
519 $href = self
::makeSpecialUrl( 'Watchlist' );
520 $personal_urls['watchlist'] = array(
521 'text' => wfMsg( 'mywatchlist' ),
523 'active' => ( $href == $pageurl )
526 # We need to do an explicit check for Special:Contributions, as we
527 # have to match both the title, and the target (which could come
528 # from request values or be specified in "sub page" form. The plot
529 # thickens, because $wgTitle is altered for special pages, so doesn't
530 # contain the original alias-with-subpage.
531 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
532 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
533 list( $spName, $spPar ) =
534 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
535 $active = $spName == 'Contributions'
536 && ( ( $spPar && $spPar == $this->username
)
537 ||
$wgRequest->getText( 'target' ) == $this->username
);
542 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
543 $personal_urls['mycontris'] = array(
544 'text' => wfMsg( 'mycontris' ),
548 $personal_urls['logout'] = array(
549 'text' => wfMsg( 'userlogout' ),
550 'href' => self
::makeSpecialUrl( 'Userlogout',
551 $title->isSpecial( 'Preferences' ) ?
'' : "returnto={$this->thisurl}"
557 $loginlink = $wgUser->isAllowed( 'createaccount' )
558 ?
'nav-login-createaccount'
560 if( $this->showIPinHeader() ) {
561 $href = &$this->userpageUrlDetails
['href'];
562 $personal_urls['anonuserpage'] = array(
563 'text' => $this->username
,
565 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
566 'active' => ( $pageurl == $href )
568 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
569 $href = &$usertalkUrlDetails['href'];
570 $personal_urls['anontalk'] = array(
571 'text' => wfMsg( 'anontalk' ),
573 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
574 'active' => ( $pageurl == $href )
576 $personal_urls['anonlogin'] = array(
577 'text' => wfMsg( $loginlink ),
578 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
579 'active' => $title->isSpecial( 'Userlogin' )
582 $personal_urls['login'] = array(
583 'text' => wfMsg( $loginlink ),
584 'href' => self
::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl
),
585 'active' => $title->isSpecial( 'Userlogin' )
590 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
591 wfProfileOut( __METHOD__
);
592 return $personal_urls;
595 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
598 $classes[] = 'selected';
600 if( $checkEdit && !$title->isKnown() ) {
602 $query = 'action=edit&redlink=1';
605 $text = wfMsg( $message );
606 if ( wfEmptyMsg( $message, $text ) ) {
608 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
612 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
613 $title, $message, $selected, $checkEdit,
614 &$classes, &$query, &$text, &$result ) ) ) {
619 'class' => implode( ' ', $classes ),
621 'href' => $title->getLocalUrl( $query ) );
624 function makeTalkUrlDetails( $name, $urlaction = '' ) {
625 $title = Title
::newFromText( $name );
626 if( !is_object( $title ) ) {
627 throw new MWException( __METHOD__
. " given invalid pagename $name" );
629 $title = $title->getTalkPage();
630 self
::checkTitle( $title, $name );
632 'href' => $title->getLocalURL( $urlaction ),
633 'exists' => $title->getArticleID() != 0 ?
true : false
637 function makeArticleUrlDetails( $name, $urlaction = '' ) {
638 $title = Title
::newFromText( $name );
639 $title= $title->getSubjectPage();
640 self
::checkTitle( $title, $name );
642 'href' => $title->getLocalURL( $urlaction ),
643 'exists' => $title->getArticleID() != 0 ?
true : false
648 * an array of edit links by default used for the tabs
652 function buildContentActionUrls() {
653 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
655 wfProfileIn( __METHOD__
);
657 $action = $wgRequest->getVal( 'action', 'view' );
658 $section = $wgRequest->getVal( 'section' );
659 $content_actions = array();
661 $prevent_active_tabs = false;
662 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
664 if( $this->iscontent
) {
665 $subjpage = $this->mTitle
->getSubjectPage();
666 $talkpage = $this->mTitle
->getTalkPage();
668 $nskey = $this->mTitle
->getNamespaceKey();
669 $content_actions[$nskey] = $this->tabAction(
672 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
676 $content_actions['talk'] = $this->tabAction(
679 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
684 wfProfileIn( __METHOD__
. '-edit' );
685 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
686 $istalk = $this->mTitle
->isTalkPage();
687 $istalkclass = $istalk?
' istalk':'';
688 $content_actions['edit'] = array(
689 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
690 'text' => $this->mTitle
->exists()
693 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
696 if ( $istalk ||
$wgOut->showNewSectionLink() ) {
697 if ( !$wgOut->forceHideNewSectionLink() ) {
698 $content_actions['addsection'] = array(
699 'class' => $section == 'new' ?
'selected' : false,
700 'text' => wfMsg( 'addsection' ),
701 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
705 } elseif ( $this->mTitle
->isKnown() ) {
706 $content_actions['viewsource'] = array(
707 'class' => ($action == 'edit') ?
'selected' : false,
708 'text' => wfMsg( 'viewsource' ),
709 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
712 wfProfileOut( __METHOD__
. '-edit' );
714 wfProfileIn( __METHOD__
. '-live' );
715 if ( $this->mTitle
->exists() ) {
717 $content_actions['history'] = array(
718 'class' => ($action == 'history') ?
'selected' : false,
719 'text' => wfMsg( 'history_short' ),
720 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
724 if( $wgUser->isAllowed( 'delete' ) ) {
725 $content_actions['delete'] = array(
726 'class' => ($action == 'delete') ?
'selected' : false,
727 'text' => wfMsg( 'delete' ),
728 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
731 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
732 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
733 $content_actions['move'] = array(
734 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
735 'text' => wfMsg( 'move' ),
736 'href' => $moveTitle->getLocalUrl()
740 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
741 if( !$this->mTitle
->isProtected() ){
742 $content_actions['protect'] = array(
743 'class' => ($action == 'protect') ?
'selected' : false,
744 'text' => wfMsg( 'protect' ),
745 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
749 $content_actions['unprotect'] = array(
750 'class' => ($action == 'unprotect') ?
'selected' : false,
751 'text' => wfMsg( 'unprotect' ),
752 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
757 //article doesn't exist or is deleted
758 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
759 if( $n = $this->mTitle
->isDeleted() ) {
760 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
761 $content_actions['undelete'] = array(
763 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
764 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
765 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
770 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
771 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
772 $content_actions['protect'] = array(
773 'class' => ($action == 'protect') ?
'selected' : false,
774 'text' => wfMsg( 'protect' ),
775 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
779 $content_actions['unprotect'] = array(
780 'class' => ($action == 'unprotect') ?
'selected' : false,
781 'text' => wfMsg( 'unprotect' ),
782 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
788 wfProfileOut( __METHOD__
. '-live' );
790 if( $this->loggedin
) {
791 if( !$this->mTitle
->userIsWatching()) {
792 $content_actions['watch'] = array(
793 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
794 'text' => wfMsg( 'watch' ),
795 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
798 $content_actions['unwatch'] = array(
799 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
800 'text' => wfMsg( 'unwatch' ),
801 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
807 wfRunHooks( 'SkinTemplateTabs', array( &$this, &$content_actions ) );
809 /* show special page tab */
811 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
812 'class' => 'selected',
813 'text' => wfMsg('nstab-special'),
814 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
817 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
820 /* show links to different language variants */
821 global $wgDisableLangConversion;
822 $variants = $wgContLang->getVariants();
823 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
824 $preferred = $wgContLang->getPreferredVariant();
826 foreach( $variants as $code ) {
827 $varname = $wgContLang->getVariantname( $code );
828 if( $varname == 'disable' )
830 $selected = ( $code == $preferred )?
'selected' : false;
831 $content_actions['varlang-' . $vcount] = array(
832 'class' => $selected,
834 'href' => $this->mTitle
->getLocalURL( '', $code )
840 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
842 wfProfileOut( __METHOD__
);
843 return $content_actions;
847 * build array of common navigation links
851 function buildNavUrls() {
852 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
853 global $wgEnableUploads, $wgUploadNavigationUrl;
855 wfProfileIn( __METHOD__
);
857 $action = $wgRequest->getVal( 'action', 'view' );
860 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
861 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
862 if( $wgUploadNavigationUrl ) {
863 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
865 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
868 if( $wgUploadNavigationUrl )
869 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
871 $nav_urls['upload'] = false;
873 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
875 // default permalink to being off, will override it as required below.
876 $nav_urls['permalink'] = false;
878 // A print stylesheet is attached to all pages, but nobody ever
879 // figures that out. :) Add a link...
880 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
881 $nav_urls['print'] = array(
882 'text' => wfMsg( 'printableversion' ),
883 'href' => $wgRequest->appendQuery( 'printable=yes' )
886 // Also add a "permalink" while we're at it
887 if ( $this->mRevisionId
) {
888 $nav_urls['permalink'] = array(
889 'text' => wfMsg( 'permalink' ),
890 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
894 // Copy in case this undocumented, shady hook tries to mess with internals
895 $revid = $this->mRevisionId
;
896 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
899 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
900 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
901 $nav_urls['whatlinkshere'] = array(
902 'href' => $wlhTitle->getLocalUrl()
904 if( $this->mTitle
->getArticleId() ) {
905 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
906 $nav_urls['recentchangeslinked'] = array(
907 'href' => $rclTitle->getLocalUrl()
910 $nav_urls['recentchangeslinked'] = false;
912 if( $wgUseTrackbacks )
913 $nav_urls['trackbacklink'] = array(
914 'href' => $wgOut->getTitle()->trackbackURL()
918 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
919 $id = User
::idFromName( $this->mTitle
->getText() );
920 $ip = User
::isIP( $this->mTitle
->getText() );
926 if( $id ||
$ip ) { # both anons and non-anons have contribs list
927 $nav_urls['contributions'] = array(
928 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
932 $logPage = SpecialPage
::getTitleFor( 'Log' );
933 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
934 . $this->mTitle
->getPartialUrl() ) );
936 $nav_urls['log'] = false;
939 if ( $wgUser->isAllowed( 'block' ) ) {
940 $nav_urls['blockip'] = array(
941 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
944 $nav_urls['blockip'] = false;
947 $nav_urls['contributions'] = false;
948 $nav_urls['log'] = false;
949 $nav_urls['blockip'] = false;
951 $nav_urls['emailuser'] = false;
952 if( $this->showEmailUser( $id ) ) {
953 $nav_urls['emailuser'] = array(
954 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
957 wfProfileOut( __METHOD__
);
962 * Generate strings used for xml 'id' names
966 function getNameSpaceKey() {
967 return $this->mTitle
->getNamespaceKey();
973 function setupUserJs( $allowUserJs ) {
974 global $wgRequest, $wgJsMimeType;
976 wfProfileIn( __METHOD__
);
978 $action = $wgRequest->getVal( 'action', 'view' );
980 if( $allowUserJs && $this->loggedin
) {
981 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
982 # XXX: additional security check/prompt?
983 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
985 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
988 wfProfileOut( __METHOD__
);
992 * Code for extensions to hook into to provide per-page CSS, see
993 * extensions/PageCSS/PageCSS.php for an implementation of this.
997 function setupPageCss() {
998 wfProfileIn( __METHOD__
);
1000 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1001 wfProfileOut( __METHOD__
);
1007 * Generic wrapper for template functions, with interface
1008 * compatible with what we use of PHPTAL 0.7.
1011 class QuickTemplate
{
1015 public function QuickTemplate() {
1016 $this->data
= array();
1017 $this->translator
= new MediaWiki_I18N();
1021 * Sets the value $value to $name
1025 public function set( $name, $value ) {
1026 $this->data
[$name] = $value;
1033 public function setRef( $name, &$value ) {
1034 $this->data
[$name] =& $value;
1040 public function setTranslator( &$t ) {
1041 $this->translator
= &$t;
1045 * Main function, used by classes that subclass QuickTemplate
1046 * to show the actual HTML output
1048 public function execute() {
1049 echo 'Override this function.';
1055 function text( $str ) {
1056 echo htmlspecialchars( $this->data
[$str] );
1062 function jstext( $str ) {
1063 echo Xml
::escapeJsString( $this->data
[$str] );
1069 function html( $str ) {
1070 echo $this->data
[$str];
1076 function msg( $str ) {
1077 echo htmlspecialchars( $this->translator
->translate( $str ) );
1083 function msgHtml( $str ) {
1084 echo $this->translator
->translate( $str );
1088 * An ugly, ugly hack.
1091 function msgWiki( $str ) {
1092 global $wgParser, $wgOut;
1094 $text = $this->translator
->translate( $str );
1095 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1096 $wgOut->parserOptions(), true );
1097 echo $parserOutput->getText();
1103 function haveData( $str ) {
1104 return isset( $this->data
[$str] );
1110 function haveMsg( $str ) {
1111 $msg = $this->translator
->translate( $str );
1112 return ( $msg != '-' ) && ( $msg != '' ); # ????