00001 <?php
00002 if ( ! defined( 'MEDIAWIKI' ) )
00003 die( 1 );
00004
00005 # This program is free software; you can redistribute it and/or modify
00006 # it under the terms of the GNU General Public License as published by
00007 # the Free Software Foundation; either version 2 of the License, or
00008 # (at your option) any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 # GNU General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program; if not, write to the Free Software Foundation, Inc.,
00017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 # http://www.gnu.org/copyleft/gpl.html
00019
00027 class MediaWiki_I18N {
00028 var $_context = array();
00029
00030 function set($varName, $value) {
00031 $this->_context[$varName] = $value;
00032 }
00033
00034 function translate($value) {
00035 wfProfileIn( __METHOD__ );
00036
00037
00038 $value = preg_replace( '/^string:/', '', $value );
00039
00040 $value = wfMsg( $value );
00041
00042 $m = array();
00043 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
00044 list($src, $var) = $m;
00045 wfSuppressWarnings();
00046 $varValue = $this->_context[$var];
00047 wfRestoreWarnings();
00048 $value = str_replace($src, $varValue, $value);
00049 }
00050 wfProfileOut( __METHOD__ );
00051 return $value;
00052 }
00053 }
00054
00067 class SkinTemplate extends Skin {
00076 var $skinname;
00077
00082 var $stylename;
00083
00088 var $template;
00089
00099 function initPage( OutputPage $out ) {
00100 parent::initPage( $out );
00101 $this->skinname = 'monobook';
00102 $this->stylename = 'monobook';
00103 $this->template = 'QuickTemplate';
00104 }
00105
00111 function setupSkinUserCss( OutputPage $out ){
00112 $out->addStyle( 'common/shared.css', 'screen' );
00113 $out->addStyle( 'common/commonPrint.css', 'print' );
00114 }
00115
00127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
00128 return new $classname();
00129 }
00130
00136 function outputPage( OutputPage $out ) {
00137 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang;
00138 global $wgScript, $wgStylePath, $wgContLanguageCode;
00139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
00140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
00141 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
00142 global $wgMaxCredits, $wgShowCreditsIfMax;
00143 global $wgPageShowWatchingUsers;
00144 global $wgUseTrackbacks, $wgUseSiteJs;
00145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
00146
00147 wfProfileIn( __METHOD__ );
00148
00149 $oldid = $wgRequest->getVal( 'oldid' );
00150 $diff = $wgRequest->getVal( 'diff' );
00151 $action = $wgRequest->getVal( 'action', 'view' );
00152
00153 wfProfileIn( __METHOD__."-init" );
00154 $this->initPage( $out );
00155
00156 $this->setMembers();
00157 $tpl = $this->setupTemplate( $this->template, 'skins' );
00158
00159 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
00160 $tpl->setTranslator(new MediaWiki_I18N());
00161 #}
00162 wfProfileOut( __METHOD__."-init" );
00163
00164 wfProfileIn( __METHOD__."-stuff" );
00165 $this->thispage = $this->mTitle->getPrefixedDbKey();
00166 $this->thisurl = $this->mTitle->getPrefixedURL();
00167 $this->loggedin = $wgUser->isLoggedIn();
00168 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
00169 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
00170 $this->username = $wgUser->getName();
00171
00172 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
00173 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
00174 } else {
00175 # This won't be used in the standard skins, but we define it to preserve the interface
00176 # To save time, we check for existence
00177 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
00178 }
00179
00180 $this->userjs = $this->userjsprev = false;
00181 $this->setupUserCss( $out );
00182 $this->setupUserJs( $out->isUserJsAllowed() );
00183 $this->titletxt = $this->mTitle->getPrefixedText();
00184 wfProfileOut( __METHOD__."-stuff" );
00185
00186 wfProfileIn( __METHOD__."-stuff2" );
00187 $tpl->set( 'title', $out->getPageTitle() );
00188 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
00189 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
00190 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
00191 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
00192
00193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
00194 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
00195 $this->mTitle->getNsText();
00196
00197 $tpl->set( 'nscanonical', $nsname );
00198 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
00199 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
00200 $tpl->set( 'titletext', $this->mTitle->getText() );
00201 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
00202 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
00203
00204 $tpl->set( 'isarticle', $out->isArticle() );
00205
00206 $tpl->setRef( "thispage", $this->thispage );
00207 $subpagestr = $this->subPageSubtitle();
00208 $tpl->set(
00209 'subtitle', !empty($subpagestr)?
00210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
00211 $out->getSubtitle()
00212 );
00213 $undelete = $this->getUndeleteLink();
00214 $tpl->set(
00215 "undelete", !empty($undelete)?
00216 '<span class="subpages">'.$undelete.'</span>':
00217 ''
00218 );
00219
00220 $tpl->set( 'catlinks', $this->getCategories());
00221 if( $out->isSyndicated() ) {
00222 $feeds = array();
00223 foreach( $out->getSyndicationLinks() as $format => $link ) {
00224 $feeds[$format] = array(
00225 'text' => wfMsg( "feed-$format" ),
00226 'href' => $link );
00227 }
00228 $tpl->setRef( 'feeds', $feeds );
00229 } else {
00230 $tpl->set( 'feeds', false );
00231 }
00232 if ($wgUseTrackbacks && $out->isArticleRelated()) {
00233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
00234 } else {
00235 $tpl->set( 'trackbackhtml', null );
00236 }
00237
00238 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
00239 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
00240 $tpl->setRef( 'mimetype', $wgMimeType );
00241 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
00242 $tpl->setRef( 'charset', $wgOutputEncoding );
00243 $tpl->set( 'headlinks', $out->getHeadLinks() );
00244 $tpl->set( 'headscripts', $out->getScript() );
00245 $tpl->set( 'csslinks', $out->buildCssLinks() );
00246 $tpl->setRef( 'wgScript', $wgScript );
00247 $tpl->setRef( 'skinname', $this->skinname );
00248 $tpl->set( 'skinclass', get_class( $this ) );
00249 $tpl->setRef( 'stylename', $this->stylename );
00250 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
00251 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
00252 $tpl->setRef( 'loggedin', $this->loggedin );
00253 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
00254
00255
00256
00257
00258
00259
00260
00261 $tpl->set( 'searchaction', $this->escapeSearchLink() );
00262 $tpl->set( 'searchtitle', SpecialPage::getTitleFor('search')->getPrefixedDBKey() );
00263 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
00264 $tpl->setRef( 'stylepath', $wgStylePath );
00265 $tpl->setRef( 'articlepath', $wgArticlePath );
00266 $tpl->setRef( 'scriptpath', $wgScriptPath );
00267 $tpl->setRef( 'serverurl', $wgServer );
00268 $tpl->setRef( 'logopath', $wgLogo );
00269 $tpl->setRef( "lang", $wgContLanguageCode );
00270 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
00271 $tpl->set( 'rtl', $wgContLang->isRTL() );
00272 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
00273 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
00274 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
00275 $tpl->setRef( 'userpage', $this->userpage);
00276 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
00277 $tpl->set( 'userlang', $wgLang->getCode() );
00278 $tpl->set( 'pagecss', $this->setupPageCss() );
00279 $tpl->setRef( 'usercss', $this->usercss);
00280 $tpl->setRef( 'userjs', $this->userjs);
00281 $tpl->setRef( 'userjsprev', $this->userjsprev);
00282 if( $wgUseSiteJs ) {
00283 $jsCache = $this->loggedin ? '&smaxage=0' : '';
00284 $tpl->set( 'jsvarurl',
00285 self::makeUrl('-',
00286 "action=raw$jsCache&gen=js&useskin=" .
00287 urlencode( $this->getSkinName() ) ) );
00288 } else {
00289 $tpl->set('jsvarurl', false);
00290 }
00291 $newtalks = $wgUser->getNewMessageLinks();
00292
00293 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
00294 $usertitle = $this->mUser->getUserPage();
00295 $usertalktitle = $usertitle->getTalkPage();
00296 if( !$usertalktitle->equals( $this->mTitle ) ) {
00297 $ntl = wfMsg( 'youhavenewmessages',
00298 $this->makeKnownLinkObj(
00299 $usertalktitle,
00300 wfMsgHtml( 'newmessageslink' ),
00301 'redirect=no'
00302 ),
00303 $this->makeKnownLinkObj(
00304 $usertalktitle,
00305 wfMsgHtml( 'newmessagesdifflink' ),
00306 'diff=cur'
00307 )
00308 );
00309 # Disable Cache
00310 $out->setSquidMaxage(0);
00311 }
00312 } else if (count($newtalks)) {
00313 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
00314 $msgs = array();
00315 foreach ($newtalks as $newtalk) {
00316 $msgs[] = Xml::element("a",
00317 array('href' => $newtalk["link"]), $newtalk["wiki"]);
00318 }
00319 $parts = implode($sep, $msgs);
00320 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
00321 $out->setSquidMaxage(0);
00322 } else {
00323 $ntl = '';
00324 }
00325 wfProfileOut( __METHOD__."-stuff2" );
00326
00327 wfProfileIn( __METHOD__."-stuff3" );
00328 $tpl->setRef( 'newtalk', $ntl );
00329 $tpl->setRef( 'skin', $this );
00330 $tpl->set( 'logo', $this->logoText() );
00331 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
00332 $wgArticle and 0 != $wgArticle->getID() )
00333 {
00334 if ( !$wgDisableCounters ) {
00335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
00336 if ( $viewcount ) {
00337 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
00338 } else {
00339 $tpl->set('viewcount', false);
00340 }
00341 } else {
00342 $tpl->set('viewcount', false);
00343 }
00344
00345 if ($wgPageShowWatchingUsers) {
00346 $dbr = wfGetDB( DB_SLAVE );
00347 $watchlist = $dbr->tableName( 'watchlist' );
00348 $sql = "SELECT COUNT(*) AS n FROM $watchlist
00349 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
00350 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
00351 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
00352 $x = $dbr->fetchObject( $res );
00353 $numberofwatchingusers = $x->n;
00354 if ($numberofwatchingusers > 0) {
00355 $tpl->set('numberofwatchingusers',
00356 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
00357 $wgLang->formatNum($numberofwatchingusers))
00358 );
00359 } else {
00360 $tpl->set('numberofwatchingusers', false);
00361 }
00362 } else {
00363 $tpl->set('numberofwatchingusers', false);
00364 }
00365
00366 $tpl->set('copyright',$this->getCopyright());
00367
00368 $this->credits = false;
00369
00370 if( $wgMaxCredits != 0 ){
00371 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
00372 } else {
00373 $tpl->set( 'lastmod', $this->lastModified() );
00374 }
00375
00376 $tpl->setRef( 'credits', $this->credits );
00377
00378 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
00379 $tpl->set('copyright', $this->getCopyright());
00380 $tpl->set('viewcount', false);
00381 $tpl->set('lastmod', false);
00382 $tpl->set('credits', false);
00383 $tpl->set('numberofwatchingusers', false);
00384 } else {
00385 $tpl->set('copyright', false);
00386 $tpl->set('viewcount', false);
00387 $tpl->set('lastmod', false);
00388 $tpl->set('credits', false);
00389 $tpl->set('numberofwatchingusers', false);
00390 }
00391 wfProfileOut( __METHOD__."-stuff3" );
00392
00393 wfProfileIn( __METHOD__."-stuff4" );
00394 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
00395 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
00396 $tpl->set( 'disclaimer', $this->disclaimerLink() );
00397 $tpl->set( 'privacy', $this->privacyLink() );
00398 $tpl->set( 'about', $this->aboutLink() );
00399
00400 $tpl->setRef( 'debug', $out->mDebugtext );
00401 $tpl->set( 'reporttime', wfReportTime() );
00402 $tpl->set( 'sitenotice', wfGetSiteNotice() );
00403 $tpl->set( 'bottomscripts', $this->bottomScripts() );
00404
00405 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
00406 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
00407 $tpl->setRef( 'bodytext', $out->mBodytext );
00408
00409 # Language links
00410 $language_urls = array();
00411
00412 if ( !$wgHideInterlanguageLinks ) {
00413 foreach( $out->getLanguageLinks() as $l ) {
00414 $tmp = explode( ':', $l, 2 );
00415 $class = 'interwiki-' . $tmp[0];
00416 unset($tmp);
00417 $nt = Title::newFromText( $l );
00418 if ( $nt ) {
00419 $language_urls[] = array(
00420 'href' => $nt->getFullURL(),
00421 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
00422 'class' => $class
00423 );
00424 }
00425 }
00426 }
00427 if(count($language_urls)) {
00428 $tpl->setRef( 'language_urls', $language_urls);
00429 } else {
00430 $tpl->set('language_urls', false);
00431 }
00432 wfProfileOut( __METHOD__."-stuff4" );
00433
00434 wfProfileIn( __METHOD__."-stuff5" );
00435 # Personal toolbar
00436 $tpl->set('personal_urls', $this->buildPersonalUrls());
00437 $content_actions = $this->buildContentActionUrls();
00438 $tpl->setRef('content_actions', $content_actions);
00439
00440
00441 if($this->iseditable && $wgUser->getOption("editondblclick") )
00442 {
00443 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
00444 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
00445 } else {
00446 $tpl->set('body_ondblclick', false);
00447 }
00448 $tpl->set( 'body_onload', false );
00449 $tpl->set( 'sidebar', $this->buildSidebar() );
00450 $tpl->set( 'nav_urls', $this->buildNavUrls() );
00451
00452
00453 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
00454 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
00455 }
00456
00457
00458
00459 $tpl->set ('dataAfterContent', $this->afterContentHook());
00460 wfProfileOut( __METHOD__."-stuff5" );
00461
00462
00463 wfProfileIn( __METHOD__."-execute" );
00464 $res = $tpl->execute();
00465 wfProfileOut( __METHOD__."-execute" );
00466
00467
00468 $this->printOrError( $res );
00469 wfProfileOut( __METHOD__ );
00470 }
00471
00480 function printOrError( $str ) {
00481 echo $str;
00482 }
00483
00489 function buildPersonalUrls() {
00490 global $wgTitle, $wgRequest;
00491
00492 $pageurl = $wgTitle->getLocalURL();
00493 wfProfileIn( __METHOD__ );
00494
00495
00496 $personal_urls = array();
00497 if ($this->loggedin) {
00498 $personal_urls['userpage'] = array(
00499 'text' => $this->username,
00500 'href' => &$this->userpageUrlDetails['href'],
00501 'class' => $this->userpageUrlDetails['exists']?false:'new',
00502 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
00503 );
00504 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
00505 $personal_urls['mytalk'] = array(
00506 'text' => wfMsg('mytalk'),
00507 'href' => &$usertalkUrlDetails['href'],
00508 'class' => $usertalkUrlDetails['exists']?false:'new',
00509 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
00510 );
00511 $href = self::makeSpecialUrl( 'Preferences' );
00512 $personal_urls['preferences'] = array(
00513 'text' => wfMsg( 'mypreferences' ),
00514 'href' => $href,
00515 'active' => ( $href == $pageurl )
00516 );
00517 $href = self::makeSpecialUrl( 'Watchlist' );
00518 $personal_urls['watchlist'] = array(
00519 'text' => wfMsg( 'mywatchlist' ),
00520 'href' => $href,
00521 'active' => ( $href == $pageurl )
00522 );
00523
00524 # We need to do an explicit check for Special:Contributions, as we
00525 # have to match both the title, and the target (which could come
00526 # from request values or be specified in "sub page" form. The plot
00527 # thickens, because $wgTitle is altered for special pages, so doesn't
00528 # contain the original alias-with-subpage.
00529 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
00530 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
00531 list( $spName, $spPar ) =
00532 SpecialPage::resolveAliasWithSubpage( $title->getText() );
00533 $active = $spName == 'Contributions'
00534 && ( ( $spPar && $spPar == $this->username )
00535 || $wgRequest->getText( 'target' ) == $this->username );
00536 } else {
00537 $active = false;
00538 }
00539
00540 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
00541 $personal_urls['mycontris'] = array(
00542 'text' => wfMsg( 'mycontris' ),
00543 'href' => $href,
00544 'active' => $active
00545 );
00546 $personal_urls['logout'] = array(
00547 'text' => wfMsg( 'userlogout' ),
00548 'href' => self::makeSpecialUrl( 'Userlogout',
00549 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
00550 ),
00551 'active' => false
00552 );
00553 } else {
00554 global $wgUser;
00555 $loginlink = $wgUser->isAllowed( 'createaccount' )
00556 ? 'nav-login-createaccount'
00557 : 'login';
00558 if( $this->showIPinHeader() ) {
00559 $href = &$this->userpageUrlDetails['href'];
00560 $personal_urls['anonuserpage'] = array(
00561 'text' => $this->username,
00562 'href' => $href,
00563 'class' => $this->userpageUrlDetails['exists']?false:'new',
00564 'active' => ( $pageurl == $href )
00565 );
00566 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
00567 $href = &$usertalkUrlDetails['href'];
00568 $personal_urls['anontalk'] = array(
00569 'text' => wfMsg('anontalk'),
00570 'href' => $href,
00571 'class' => $usertalkUrlDetails['exists']?false:'new',
00572 'active' => ( $pageurl == $href )
00573 );
00574 $personal_urls['anonlogin'] = array(
00575 'text' => wfMsg( $loginlink ),
00576 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
00577 'active' => $wgTitle->isSpecial( 'Userlogin' )
00578 );
00579 } else {
00580
00581 $personal_urls['login'] = array(
00582 'text' => wfMsg( $loginlink ),
00583 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
00584 'active' => $wgTitle->isSpecial( 'Userlogin' )
00585 );
00586 }
00587 }
00588
00589 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
00590 wfProfileOut( __METHOD__ );
00591 return $personal_urls;
00592 }
00593
00594 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
00595 $classes = array();
00596 if( $selected ) {
00597 $classes[] = 'selected';
00598 }
00599 if( $checkEdit && !$title->isKnown() ) {
00600 $classes[] = 'new';
00601 $query = 'action=edit&redlink=1';
00602 }
00603
00604 $text = wfMsg( $message );
00605 if ( wfEmptyMsg( $message, $text ) ) {
00606 global $wgContLang;
00607 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
00608 }
00609
00610 $result = array();
00611 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
00612 $title, $message, $selected, $checkEdit,
00613 &$classes, &$query, &$text, &$result)) ) {
00614 return $result;
00615 }
00616
00617 return array(
00618 'class' => implode( ' ', $classes ),
00619 'text' => $text,
00620 'href' => $title->getLocalUrl( $query ) );
00621 }
00622
00623 function makeTalkUrlDetails( $name, $urlaction = '' ) {
00624 $title = Title::newFromText( $name );
00625 if( !is_object($title) ) {
00626 throw new MWException( __METHOD__." given invalid pagename $name" );
00627 }
00628 $title = $title->getTalkPage();
00629 self::checkTitle( $title, $name );
00630 return array(
00631 'href' => $title->getLocalURL( $urlaction ),
00632 'exists' => $title->getArticleID() != 0 ? true : false
00633 );
00634 }
00635
00636 function makeArticleUrlDetails( $name, $urlaction = '' ) {
00637 $title = Title::newFromText( $name );
00638 $title= $title->getSubjectPage();
00639 self::checkTitle( $title, $name );
00640 return array(
00641 'href' => $title->getLocalURL( $urlaction ),
00642 'exists' => $title->getArticleID() != 0 ? true : false
00643 );
00644 }
00645
00651 function buildContentActionUrls() {
00652 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
00653
00654 wfProfileIn( __METHOD__ );
00655
00656 $action = $wgRequest->getVal( 'action', 'view' );
00657 $section = $wgRequest->getVal( 'section' );
00658 $content_actions = array();
00659
00660 $prevent_active_tabs = false ;
00661 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
00662
00663 if( $this->iscontent ) {
00664 $subjpage = $this->mTitle->getSubjectPage();
00665 $talkpage = $this->mTitle->getTalkPage();
00666
00667 $nskey = $this->mTitle->getNamespaceKey();
00668 $content_actions[$nskey] = $this->tabAction(
00669 $subjpage,
00670 $nskey,
00671 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
00672 '', true);
00673
00674 $content_actions['talk'] = $this->tabAction(
00675 $talkpage,
00676 'talk',
00677 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
00678 '',
00679 true);
00680
00681 wfProfileIn( __METHOD__."-edit" );
00682 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
00683 $istalk = $this->mTitle->isTalkPage();
00684 $istalkclass = $istalk?' istalk':'';
00685 $content_actions['edit'] = array(
00686 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
00687 'text' => $this->mTitle->exists()
00688 ? wfMsg( 'edit' )
00689 : wfMsg( 'create' ),
00690 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
00691 );
00692
00693 if ( $istalk || $wgOut->showNewSectionLink() ) {
00694 if ( !$wgOut->forceHideNewSectionLink() ) {
00695 $content_actions['addsection'] = array(
00696 'class' => $section == 'new' ? 'selected' : false,
00697 'text' => wfMsg('addsection'),
00698 'href' => $this->mTitle->getLocalUrl( 'action=edit§ion=new' )
00699 );
00700 }
00701 }
00702 } elseif ( $this->mTitle->isKnown() ) {
00703 $content_actions['viewsource'] = array(
00704 'class' => ($action == 'edit') ? 'selected' : false,
00705 'text' => wfMsg('viewsource'),
00706 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
00707 );
00708 }
00709 wfProfileOut( __METHOD__."-edit" );
00710
00711 wfProfileIn( __METHOD__."-live" );
00712 if ( $this->mTitle->exists() ) {
00713
00714 $content_actions['history'] = array(
00715 'class' => ($action == 'history') ? 'selected' : false,
00716 'text' => wfMsg('history_short'),
00717 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
00718 'rel' => 'archives',
00719 );
00720
00721 if( $wgUser->isAllowed('delete') ) {
00722 $content_actions['delete'] = array(
00723 'class' => ($action == 'delete') ? 'selected' : false,
00724 'text' => wfMsg('delete'),
00725 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
00726 );
00727 }
00728 if ( $this->mTitle->quickUserCan( 'move' ) ) {
00729 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
00730 $content_actions['move'] = array(
00731 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
00732 'text' => wfMsg('move'),
00733 'href' => $moveTitle->getLocalUrl()
00734 );
00735 }
00736
00737 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
00738 if( !$this->mTitle->isProtected() ){
00739 $content_actions['protect'] = array(
00740 'class' => ($action == 'protect') ? 'selected' : false,
00741 'text' => wfMsg('protect'),
00742 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
00743 );
00744
00745 } else {
00746 $content_actions['unprotect'] = array(
00747 'class' => ($action == 'unprotect') ? 'selected' : false,
00748 'text' => wfMsg('unprotect'),
00749 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
00750 );
00751 }
00752 }
00753 } else {
00754
00755 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
00756 if( $n = $this->mTitle->isDeleted() ) {
00757 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
00758 $content_actions['undelete'] = array(
00759 'class' => false,
00760 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
00761 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
00762 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
00763 );
00764 }
00765 }
00766
00767 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
00768 if( !$this->mTitle->getRestrictions( 'create' ) ) {
00769 $content_actions['protect'] = array(
00770 'class' => ($action == 'protect') ? 'selected' : false,
00771 'text' => wfMsg('protect'),
00772 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
00773 );
00774
00775 } else {
00776 $content_actions['unprotect'] = array(
00777 'class' => ($action == 'unprotect') ? 'selected' : false,
00778 'text' => wfMsg('unprotect'),
00779 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
00780 );
00781 }
00782 }
00783 }
00784
00785 wfProfileOut( __METHOD__."-live" );
00786
00787 if( $this->loggedin ) {
00788 if( !$this->mTitle->userIsWatching()) {
00789 $content_actions['watch'] = array(
00790 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
00791 'text' => wfMsg('watch'),
00792 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
00793 );
00794 } else {
00795 $content_actions['unwatch'] = array(
00796 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
00797 'text' => wfMsg('unwatch'),
00798 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
00799 );
00800 }
00801 }
00802
00803
00804 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
00805 } else {
00806
00807
00808 $content_actions[$this->mTitle->getNamespaceKey()] = array(
00809 'class' => 'selected',
00810 'text' => wfMsg('nstab-special'),
00811 'href' => $wgRequest->getRequestURL(),
00812 );
00813
00814 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
00815 }
00816
00817
00818 global $wgDisableLangConversion;
00819 $variants = $wgContLang->getVariants();
00820 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
00821 $preferred = $wgContLang->getPreferredVariant();
00822 $vcount=0;
00823 foreach( $variants as $code ) {
00824 $varname = $wgContLang->getVariantname( $code );
00825 if( $varname == 'disable' )
00826 continue;
00827 $selected = ( $code == $preferred )? 'selected' : false;
00828 $content_actions['varlang-' . $vcount] = array(
00829 'class' => $selected,
00830 'text' => $varname,
00831 'href' => $this->mTitle->getLocalURL('',$code)
00832 );
00833 $vcount ++;
00834 }
00835 }
00836
00837 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
00838
00839 wfProfileOut( __METHOD__ );
00840 return $content_actions;
00841 }
00842
00843
00844
00850 function buildNavUrls() {
00851 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
00852 global $wgEnableUploads, $wgUploadNavigationUrl;
00853
00854 wfProfileIn( __METHOD__ );
00855
00856 $action = $wgRequest->getVal( 'action', 'view' );
00857
00858 $nav_urls = array();
00859 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
00860 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
00861 if ($wgUploadNavigationUrl) {
00862 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
00863 } else {
00864 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
00865 }
00866 } else {
00867 if ($wgUploadNavigationUrl)
00868 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
00869 else
00870 $nav_urls['upload'] = false;
00871 }
00872 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
00873
00874
00875 $nav_urls['permalink'] = false;
00876
00877
00878
00879 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
00880 $nav_urls['print'] = array(
00881 'text' => wfMsg( 'printableversion' ),
00882 'href' => $wgRequest->appendQuery( 'printable=yes' )
00883 );
00884
00885
00886 if ( $this->mRevisionId ) {
00887 $nav_urls['permalink'] = array(
00888 'text' => wfMsg( 'permalink' ),
00889 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
00890 );
00891 }
00892
00893
00894 $revid = $this->mRevisionId;
00895 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
00896 }
00897
00898 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
00899 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
00900 $nav_urls['whatlinkshere'] = array(
00901 'href' => $wlhTitle->getLocalUrl()
00902 );
00903 if( $this->mTitle->getArticleId() ) {
00904 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
00905 $nav_urls['recentchangeslinked'] = array(
00906 'href' => $rclTitle->getLocalUrl()
00907 );
00908 } else {
00909 $nav_urls['recentchangeslinked'] = false;
00910 }
00911 if ($wgUseTrackbacks)
00912 $nav_urls['trackbacklink'] = array(
00913 'href' => $wgTitle->trackbackURL()
00914 );
00915 }
00916
00917 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
00918 $id = User::idFromName($this->mTitle->getText());
00919 $ip = User::isIP($this->mTitle->getText());
00920 } else {
00921 $id = 0;
00922 $ip = false;
00923 }
00924
00925 if($id || $ip) { # both anons and non-anons have contribs list
00926 $nav_urls['contributions'] = array(
00927 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
00928 );
00929
00930 if( $id ) {
00931 $logPage = SpecialPage::getTitleFor( 'Log' );
00932 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
00933 . $this->mTitle->getPartialUrl() ) );
00934 } else {
00935 $nav_urls['log'] = false;
00936 }
00937
00938 if ( $wgUser->isAllowed( 'block' ) ) {
00939 $nav_urls['blockip'] = array(
00940 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
00941 );
00942 } else {
00943 $nav_urls['blockip'] = false;
00944 }
00945 } else {
00946 $nav_urls['contributions'] = false;
00947 $nav_urls['log'] = false;
00948 $nav_urls['blockip'] = false;
00949 }
00950 $nav_urls['emailuser'] = false;
00951 if( $this->showEmailUser( $id ) ) {
00952 $nav_urls['emailuser'] = array(
00953 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
00954 );
00955 }
00956 wfProfileOut( __METHOD__ );
00957 return $nav_urls;
00958 }
00959
00965 function getNameSpaceKey() {
00966 return $this->mTitle->getNamespaceKey();
00967 }
00968
00972 function setupUserJs( $allowUserJs ) {
00973 global $wgRequest, $wgJsMimeType;
00974
00975 wfProfileIn( __METHOD__ );
00976
00977 $action = $wgRequest->getVal( 'action', 'view' );
00978
00979 if( $allowUserJs && $this->loggedin ) {
00980 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
00981 # XXX: additional security check/prompt?
00982 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
00983 } else {
00984 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
00985 }
00986 }
00987 wfProfileOut( __METHOD__ );
00988 }
00989
00996 function setupPageCss() {
00997 wfProfileIn( __METHOD__ );
00998 $out = false;
00999 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
01000 wfProfileOut( __METHOD__ );
01001 return $out;
01002 }
01003 }
01004
01010 class QuickTemplate {
01014 function QuickTemplate() {
01015 $this->data = array();
01016 $this->translator = new MediaWiki_I18N();
01017 }
01018
01022 function set( $name, $value ) {
01023 $this->data[$name] = $value;
01024 }
01025
01029 function setRef($name, &$value) {
01030 $this->data[$name] =& $value;
01031 }
01032
01036 function setTranslator( &$t ) {
01037 $this->translator = &$t;
01038 }
01039
01043 function execute() {
01044 echo "Override this function.";
01045 }
01046
01047
01051 function text( $str ) {
01052 echo htmlspecialchars( $this->data[$str] );
01053 }
01054
01058 function jstext( $str ) {
01059 echo Xml::escapeJsString( $this->data[$str] );
01060 }
01061
01065 function html( $str ) {
01066 echo $this->data[$str];
01067 }
01068
01072 function msg( $str ) {
01073 echo htmlspecialchars( $this->translator->translate( $str ) );
01074 }
01075
01079 function msgHtml( $str ) {
01080 echo $this->translator->translate( $str );
01081 }
01082
01087 function msgWiki( $str ) {
01088 global $wgParser, $wgTitle, $wgOut;
01089
01090 $text = $this->translator->translate( $str );
01091 $parserOutput = $wgParser->parse( $text, $wgTitle,
01092 $wgOut->parserOptions(), true );
01093 echo $parserOutput->getText();
01094 }
01095
01099 function haveData( $str ) {
01100 return isset( $this->data[$str] );
01101 }
01102
01106 function haveMsg( $str ) {
01107 $msg = $this->translator->translate( $str );
01108 return ($msg != '-') && ($msg != ''); # ????
01109 }
01110 }