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 = $this->getNewtalks();
333 wfProfileOut( __METHOD__
. '-stuff2' );
335 wfProfileIn( __METHOD__
. '-stuff3' );
336 $tpl->setRef( 'newtalk', $newtalks );
337 $tpl->setRef( 'skin', $this );
338 $tpl->set( 'logo', $this->logoText() );
339 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
340 $wgArticle and 0 != $wgArticle->getID() ){
341 if ( !$wgDisableCounters ) {
342 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
344 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
346 $tpl->set( 'viewcount', false );
349 $tpl->set( 'viewcount', false );
352 if( $wgPageShowWatchingUsers ) {
353 $dbr = wfGetDB( DB_SLAVE
);
354 $watchlist = $dbr->tableName( 'watchlist' );
355 $res = $dbr->select( 'watchlist',
356 array( 'COUNT(*) AS n' ),
357 array( 'wl_title' => $dbr->strencode( $this->mTitle
->getDBkey() ), 'wl_namespace' => $this->mTitle
->getNamespace() ),
360 $x = $dbr->fetchObject( $res );
361 $numberofwatchingusers = $x->n
;
362 if( $numberofwatchingusers > 0 ) {
363 $tpl->set( 'numberofwatchingusers',
364 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
365 $wgLang->formatNum( $numberofwatchingusers ) )
368 $tpl->set( 'numberofwatchingusers', false );
371 $tpl->set( 'numberofwatchingusers', false );
374 $tpl->set( 'copyright', $this->getCopyright() );
376 $this->credits
= false;
378 if( $wgMaxCredits != 0 ){
379 $this->credits
= Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
381 $tpl->set( 'lastmod', $this->lastModified() );
384 $tpl->setRef( 'credits', $this->credits
);
386 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
387 $tpl->set( 'copyright', $this->getCopyright() );
388 $tpl->set( 'viewcount', false );
389 $tpl->set( 'lastmod', false );
390 $tpl->set( 'credits', false );
391 $tpl->set( 'numberofwatchingusers', false );
393 $tpl->set( 'copyright', false );
394 $tpl->set( 'viewcount', false );
395 $tpl->set( 'lastmod', false );
396 $tpl->set( 'credits', false );
397 $tpl->set( 'numberofwatchingusers', false );
399 wfProfileOut( __METHOD__
. '-stuff3' );
401 wfProfileIn( __METHOD__
. '-stuff4' );
402 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
403 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
404 $tpl->set( 'disclaimer', $this->disclaimerLink() );
405 $tpl->set( 'privacy', $this->privacyLink() );
406 $tpl->set( 'about', $this->aboutLink() );
408 if ( $wgDebugComments ) {
409 $tpl->setRef( 'debug', $out->mDebugtext
);
411 $tpl->set( 'debug', '' );
414 $tpl->set( 'reporttime', wfReportTime() );
415 $tpl->set( 'sitenotice', wfGetSiteNotice() );
416 $tpl->set( 'bottomscripts', $this->bottomScripts() );
418 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
419 $out->mBodytext
.= $printfooter . $this->generateDebugHTML();
420 $tpl->setRef( 'bodytext', $out->mBodytext
);
423 $language_urls = array();
425 if ( !$wgHideInterlanguageLinks ) {
426 foreach( $out->getLanguageLinks() as $l ) {
427 $tmp = explode( ':', $l, 2 );
428 $class = 'interwiki-' . $tmp[0];
430 $nt = Title
::newFromText( $l );
432 $language_urls[] = array(
433 'href' => $nt->getFullURL(),
434 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
435 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
441 if( count( $language_urls ) ) {
442 $tpl->setRef( 'language_urls', $language_urls );
444 $tpl->set( 'language_urls', false );
446 wfProfileOut( __METHOD__
. '-stuff4' );
448 wfProfileIn( __METHOD__
. '-stuff5' );
450 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
451 $content_actions = $this->buildContentActionUrls();
452 $tpl->setRef( 'content_actions', $content_actions );
454 $tpl->set( 'sidebar', $this->buildSidebar() );
455 $tpl->set( 'nav_urls', $this->buildNavUrls() );
457 // Set the head scripts near the end, in case the above actions resulted in added scripts
458 if ( $this->useHeadElement
) {
459 $tpl->set( 'headelement', $out->headElement( $this ) );
461 $tpl->set( 'headscripts', $out->getScript() );
464 // original version by hansm
465 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
466 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
469 // allow extensions adding stuff after the page content.
470 // See Skin::afterContentHook() for further documentation.
471 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
472 wfProfileOut( __METHOD__
. '-stuff5' );
475 wfProfileIn( __METHOD__
. '-execute' );
476 $res = $tpl->execute();
477 wfProfileOut( __METHOD__
. '-execute' );
479 // result may be an error
480 $this->printOrError( $res );
481 wfProfileOut( __METHOD__
);
485 * Output the string, or print error message if it's
486 * an error object of the appropriate type.
487 * For the base class, assume strings all around.
492 function printOrError( $str ) {
497 * build array of urls for personal toolbar
501 function buildPersonalUrls() {
502 global $wgOut, $wgRequest;
504 $title = $wgOut->getTitle();
505 $pageurl = $title->getLocalURL();
506 wfProfileIn( __METHOD__
);
508 /* set up the default links for the personal toolbar */
509 $personal_urls = array();
510 $page = $wgRequest->getVal( 'returnto', $this->thisurl
);
511 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery
);
512 $returnto = "returnto=$page";
513 if( $this->thisquery
!= '' )
514 $returnto .= "&returntoquery=$query";
515 if( $this->loggedin
) {
516 $personal_urls['userpage'] = array(
517 'text' => $this->username
,
518 'href' => &$this->userpageUrlDetails
['href'],
519 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
520 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl )
522 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
523 $personal_urls['mytalk'] = array(
524 'text' => wfMsg( 'mytalk' ),
525 'href' => &$usertalkUrlDetails['href'],
526 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
527 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
529 $href = self
::makeSpecialUrl( 'Preferences' );
530 $personal_urls['preferences'] = array(
531 'text' => wfMsg( 'mypreferences' ),
533 'active' => ( $href == $pageurl )
535 $href = self
::makeSpecialUrl( 'Watchlist' );
536 $personal_urls['watchlist'] = array(
537 'text' => wfMsg( 'mywatchlist' ),
539 'active' => ( $href == $pageurl )
542 # We need to do an explicit check for Special:Contributions, as we
543 # have to match both the title, and the target (which could come
544 # from request values or be specified in "sub page" form. The plot
545 # thickens, because $wgTitle is altered for special pages, so doesn't
546 # contain the original alias-with-subpage.
547 $origTitle = Title
::newFromText( $wgRequest->getText( 'title' ) );
548 if( $origTitle instanceof Title
&& $origTitle->getNamespace() == NS_SPECIAL
) {
549 list( $spName, $spPar ) =
550 SpecialPage
::resolveAliasWithSubpage( $origTitle->getText() );
551 $active = $spName == 'Contributions'
552 && ( ( $spPar && $spPar == $this->username
)
553 ||
$wgRequest->getText( 'target' ) == $this->username
);
558 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
559 $personal_urls['mycontris'] = array(
560 'text' => wfMsg( 'mycontris' ),
564 $personal_urls['logout'] = array(
565 'text' => wfMsg( 'userlogout' ),
566 'href' => self
::makeSpecialUrl( 'Userlogout',
567 $title->isSpecial( 'Preferences' ) ?
'' : $returnto
573 $loginlink = $wgUser->isAllowed( 'createaccount' )
574 ?
'nav-login-createaccount'
576 if( $this->showIPinHeader() ) {
577 $href = &$this->userpageUrlDetails
['href'];
578 $personal_urls['anonuserpage'] = array(
579 'text' => $this->username
,
581 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
582 'active' => ( $pageurl == $href )
584 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
585 $href = &$usertalkUrlDetails['href'];
586 $personal_urls['anontalk'] = array(
587 'text' => wfMsg( 'anontalk' ),
589 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
590 'active' => ( $pageurl == $href )
592 $personal_urls['anonlogin'] = array(
593 'text' => wfMsg( $loginlink ),
594 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
595 'active' => $title->isSpecial( 'Userlogin' )
598 $personal_urls['login'] = array(
599 'text' => wfMsg( $loginlink ),
600 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
601 'active' => $title->isSpecial( 'Userlogin' )
606 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
607 wfProfileOut( __METHOD__
);
608 return $personal_urls;
611 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
614 $classes[] = 'selected';
616 if( $checkEdit && !$title->isKnown() ) {
618 $query = 'action=edit&redlink=1';
621 $text = wfMsg( $message );
622 if ( wfEmptyMsg( $message, $text ) ) {
624 $text = $wgContLang->getFormattedNsText( MWNamespace
::getSubject( $title->getNamespace() ) );
628 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
629 $title, $message, $selected, $checkEdit,
630 &$classes, &$query, &$text, &$result ) ) ) {
635 'class' => implode( ' ', $classes ),
637 'href' => $title->getLocalUrl( $query ) );
640 function makeTalkUrlDetails( $name, $urlaction = '' ) {
641 $title = Title
::newFromText( $name );
642 if( !is_object( $title ) ) {
643 throw new MWException( __METHOD__
. " given invalid pagename $name" );
645 $title = $title->getTalkPage();
646 self
::checkTitle( $title, $name );
648 'href' => $title->getLocalURL( $urlaction ),
649 'exists' => $title->getArticleID() != 0 ?
true : false
653 function makeArticleUrlDetails( $name, $urlaction = '' ) {
654 $title = Title
::newFromText( $name );
655 $title= $title->getSubjectPage();
656 self
::checkTitle( $title, $name );
658 'href' => $title->getLocalURL( $urlaction ),
659 'exists' => $title->getArticleID() != 0 ?
true : false
664 * an array of edit links by default used for the tabs
668 function buildContentActionUrls() {
669 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
671 wfProfileIn( __METHOD__
);
673 $action = $wgRequest->getVal( 'action', 'view' );
674 $section = $wgRequest->getVal( 'section' );
675 $content_actions = array();
677 $prevent_active_tabs = false;
678 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
680 if( $this->iscontent
) {
681 $subjpage = $this->mTitle
->getSubjectPage();
682 $talkpage = $this->mTitle
->getTalkPage();
684 $nskey = $this->mTitle
->getNamespaceKey();
685 $content_actions[$nskey] = $this->tabAction(
688 !$this->mTitle
->isTalkPage() && !$prevent_active_tabs,
692 $content_actions['talk'] = $this->tabAction(
695 $this->mTitle
->isTalkPage() && !$prevent_active_tabs,
700 wfProfileIn( __METHOD__
. '-edit' );
701 if ( $this->mTitle
->quickUserCan( 'edit' ) && ( $this->mTitle
->exists() ||
$this->mTitle
->quickUserCan( 'create' ) ) ) {
702 $istalk = $this->mTitle
->isTalkPage();
703 $istalkclass = $istalk?
' istalk':'';
704 $content_actions['edit'] = array(
705 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ?
'selected' : '' ) . $istalkclass,
706 'text' => $this->mTitle
->exists()
709 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
712 // adds new section link if page is a current revision of a talk page or
713 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) ||
$wgOut->showNewSectionLink() ) {
714 if ( !$wgOut->forceHideNewSectionLink() ) {
715 $content_actions['addsection'] = array(
716 'class' => $section == 'new' ?
'selected' : false,
717 'text' => wfMsg( 'addsection' ),
718 'href' => $this->mTitle
->getLocalUrl( 'action=edit§ion=new' )
722 } elseif ( $this->mTitle
->isKnown() ) {
723 $content_actions['viewsource'] = array(
724 'class' => ($action == 'edit') ?
'selected' : false,
725 'text' => wfMsg( 'viewsource' ),
726 'href' => $this->mTitle
->getLocalUrl( $this->editUrlOptions() )
729 wfProfileOut( __METHOD__
. '-edit' );
731 wfProfileIn( __METHOD__
. '-live' );
732 if ( $this->mTitle
->exists() ) {
734 $content_actions['history'] = array(
735 'class' => ($action == 'history') ?
'selected' : false,
736 'text' => wfMsg( 'history_short' ),
737 'href' => $this->mTitle
->getLocalUrl( 'action=history' ),
741 if( $wgUser->isAllowed( 'delete' ) ) {
742 $content_actions['delete'] = array(
743 'class' => ($action == 'delete') ?
'selected' : false,
744 'text' => wfMsg( 'delete' ),
745 'href' => $this->mTitle
->getLocalUrl( 'action=delete' )
748 if ( $this->mTitle
->quickUserCan( 'move' ) ) {
749 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $this->thispage
);
750 $content_actions['move'] = array(
751 'class' => $this->mTitle
->isSpecial( 'Movepage' ) ?
'selected' : false,
752 'text' => wfMsg( 'move' ),
753 'href' => $moveTitle->getLocalUrl()
757 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
758 if( !$this->mTitle
->isProtected() ){
759 $content_actions['protect'] = array(
760 'class' => ($action == 'protect') ?
'selected' : false,
761 'text' => wfMsg( 'protect' ),
762 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
766 $content_actions['unprotect'] = array(
767 'class' => ($action == 'unprotect') ?
'selected' : false,
768 'text' => wfMsg( 'unprotect' ),
769 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
774 //article doesn't exist or is deleted
775 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
776 if( $n = $this->mTitle
->isDeleted() ) {
777 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
778 $content_actions['undelete'] = array(
780 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
781 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage
) )
782 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
787 if ( $this->mTitle
->getNamespace() !== NS_MEDIAWIKI
&& $wgUser->isAllowed( 'protect' ) ) {
788 if( !$this->mTitle
->getRestrictions( 'create' ) ) {
789 $content_actions['protect'] = array(
790 'class' => ($action == 'protect') ?
'selected' : false,
791 'text' => wfMsg( 'protect' ),
792 'href' => $this->mTitle
->getLocalUrl( 'action=protect' )
796 $content_actions['unprotect'] = array(
797 'class' => ($action == 'unprotect') ?
'selected' : false,
798 'text' => wfMsg( 'unprotect' ),
799 'href' => $this->mTitle
->getLocalUrl( 'action=unprotect' )
805 wfProfileOut( __METHOD__
. '-live' );
807 if( $this->loggedin
) {
808 if( !$this->mTitle
->userIsWatching()) {
809 $content_actions['watch'] = array(
810 'class' => ($action == 'watch' or $action == 'unwatch') ?
'selected' : false,
811 'text' => wfMsg( 'watch' ),
812 'href' => $this->mTitle
->getLocalUrl( 'action=watch' )
815 $content_actions['unwatch'] = array(
816 'class' => ($action == 'unwatch' or $action == 'watch') ?
'selected' : false,
817 'text' => wfMsg( 'unwatch' ),
818 'href' => $this->mTitle
->getLocalUrl( 'action=unwatch' )
824 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
826 /* show special page tab */
828 $content_actions[$this->mTitle
->getNamespaceKey()] = array(
829 'class' => 'selected',
830 'text' => wfMsg('nstab-special'),
831 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
834 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
837 /* show links to different language variants */
838 global $wgDisableLangConversion;
839 $variants = $wgContLang->getVariants();
840 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
841 $preferred = $wgContLang->getPreferredVariant();
843 foreach( $variants as $code ) {
844 $varname = $wgContLang->getVariantname( $code );
845 if( $varname == 'disable' )
847 $selected = ( $code == $preferred )?
'selected' : false;
848 $content_actions['varlang-' . $vcount] = array(
849 'class' => $selected,
851 'href' => $this->mTitle
->getLocalURL( '', $code )
857 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
859 wfProfileOut( __METHOD__
);
860 return $content_actions;
864 * build array of common navigation links
868 function buildNavUrls() {
869 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
870 global $wgEnableUploads, $wgUploadNavigationUrl;
872 wfProfileIn( __METHOD__
);
874 $action = $wgRequest->getVal( 'action', 'view' );
877 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
878 if( $wgUploadNavigationUrl ) {
879 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
880 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
881 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
883 $nav_urls['upload'] = false;
885 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
887 // default permalink to being off, will override it as required below.
888 $nav_urls['permalink'] = false;
890 // A print stylesheet is attached to all pages, but nobody ever
891 // figures that out. :) Add a link...
892 if( $this->iscontent
&& ( $action == 'view' ||
$action == 'purge' ) ) {
893 if ( !$wgOut->isPrintable() ) {
894 $nav_urls['print'] = array(
895 'text' => wfMsg( 'printableversion' ),
896 'href' => $wgRequest->appendQuery( 'printable=yes' )
900 // Also add a "permalink" while we're at it
901 if ( $this->mRevisionId
) {
902 $nav_urls['permalink'] = array(
903 'text' => wfMsg( 'permalink' ),
904 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
908 // Copy in case this undocumented, shady hook tries to mess with internals
909 $revid = $this->mRevisionId
;
910 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
913 if( $this->mTitle
->getNamespace() != NS_SPECIAL
) {
914 $wlhTitle = SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
);
915 $nav_urls['whatlinkshere'] = array(
916 'href' => $wlhTitle->getLocalUrl()
918 if( $this->mTitle
->getArticleId() ) {
919 $rclTitle = SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
);
920 $nav_urls['recentchangeslinked'] = array(
921 'href' => $rclTitle->getLocalUrl()
924 $nav_urls['recentchangeslinked'] = false;
926 if( $wgUseTrackbacks )
927 $nav_urls['trackbacklink'] = array(
928 'href' => $wgOut->getTitle()->trackbackURL()
932 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
933 $id = User
::idFromName( $this->mTitle
->getText() );
934 $ip = User
::isIP( $this->mTitle
->getText() );
940 if( $id ||
$ip ) { # both anons and non-anons have contribs list
941 $nav_urls['contributions'] = array(
942 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $this->mTitle
->getText() )
946 $logPage = SpecialPage
::getTitleFor( 'Log' );
947 $nav_urls['log'] = array(
948 'href' => $logPage->getLocalUrl(
950 'user' => $this->mTitle
->getText()
955 $nav_urls['log'] = false;
958 if ( $wgUser->isAllowed( 'block' ) ) {
959 $nav_urls['blockip'] = array(
960 'href' => self
::makeSpecialUrlSubpage( 'Blockip', $this->mTitle
->getText() )
963 $nav_urls['blockip'] = false;
966 $nav_urls['contributions'] = false;
967 $nav_urls['log'] = false;
968 $nav_urls['blockip'] = false;
970 $nav_urls['emailuser'] = false;
971 if( $this->showEmailUser( $id ) ) {
972 $nav_urls['emailuser'] = array(
973 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle
->getText() )
976 wfProfileOut( __METHOD__
);
981 * Generate strings used for xml 'id' names
985 function getNameSpaceKey() {
986 return $this->mTitle
->getNamespaceKey();
992 function setupUserJs( $allowUserJs ) {
993 global $wgRequest, $wgJsMimeType;
994 wfProfileIn( __METHOD__
);
996 $action = $wgRequest->getVal( 'action', 'view' );
998 if( $allowUserJs && $this->loggedin
) {
999 if( $this->mTitle
->isJsSubpage() and $this->userCanPreview( $action ) ) {
1000 # XXX: additional security check/prompt?
1001 $this->userjsprev
= '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1003 $this->userjs
= self
::makeUrl( $this->userpage
. '/' . $this->skinname
. '.js', 'action=raw&ctype=' . $wgJsMimeType );
1006 wfProfileOut( __METHOD__
);
1010 * Code for extensions to hook into to provide per-page CSS, see
1011 * extensions/PageCSS/PageCSS.php for an implementation of this.
1015 function setupPageCss() {
1016 wfProfileIn( __METHOD__
);
1018 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1019 wfProfileOut( __METHOD__
);
1023 public function commonPrintStylesheet() {
1029 * Generic wrapper for template functions, with interface
1030 * compatible with what we use of PHPTAL 0.7.
1033 abstract class QuickTemplate
{
1037 public function QuickTemplate() {
1038 $this->data
= array();
1039 $this->translator
= new MediaWiki_I18N();
1043 * Sets the value $value to $name
1047 public function set( $name, $value ) {
1048 $this->data
[$name] = $value;
1055 public function setRef( $name, &$value ) {
1056 $this->data
[$name] =& $value;
1062 public function setTranslator( &$t ) {
1063 $this->translator
= &$t;
1067 * Main function, used by classes that subclass QuickTemplate
1068 * to show the actual HTML output
1070 abstract public function execute();
1075 function text( $str ) {
1076 echo htmlspecialchars( $this->data
[$str] );
1082 function jstext( $str ) {
1083 echo Xml
::escapeJsString( $this->data
[$str] );
1089 function html( $str ) {
1090 echo $this->data
[$str];
1096 function msg( $str ) {
1097 echo htmlspecialchars( $this->translator
->translate( $str ) );
1103 function msgHtml( $str ) {
1104 echo $this->translator
->translate( $str );
1108 * An ugly, ugly hack.
1111 function msgWiki( $str ) {
1112 global $wgParser, $wgOut;
1114 $text = $this->translator
->translate( $str );
1115 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1116 $wgOut->parserOptions(), true );
1117 echo $parserOutput->getText();
1123 function haveData( $str ) {
1124 return isset( $this->data
[$str] );
1130 function haveMsg( $str ) {
1131 $msg = $this->translator
->translate( $str );
1132 return ( $msg != '-' ) && ( $msg != '' ); # ????