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 = 'monobook';
00077
00082 var $stylename = 'monobook';
00083
00088 var $template = 'QuickTemplate';
00089
00094 var $useHeadElement = false;
00095
00103 function setupSkinUserCss( OutputPage $out ){
00104 $out->addStyle( 'common/shared.css', 'screen' );
00105 $out->addStyle( 'common/commonPrint.css', 'print' );
00106 }
00107
00119 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
00120 return new $classname();
00121 }
00122
00128 function outputPage( OutputPage $out ) {
00129 global $wgArticle, $wgUser, $wgLang, $wgContLang;
00130 global $wgScript, $wgStylePath, $wgContLanguageCode;
00131 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
00132 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
00133 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
00134 global $wgMaxCredits, $wgShowCreditsIfMax;
00135 global $wgPageShowWatchingUsers;
00136 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
00137 global $wgArticlePath, $wgScriptPath, $wgServer;
00138
00139 wfProfileIn( __METHOD__ );
00140
00141 $oldid = $wgRequest->getVal( 'oldid' );
00142 $diff = $wgRequest->getVal( 'diff' );
00143 $action = $wgRequest->getVal( 'action', 'view' );
00144
00145 wfProfileIn( __METHOD__ . '-init' );
00146 $this->initPage( $out );
00147
00148 $this->setMembers();
00149 $tpl = $this->setupTemplate( $this->template, 'skins' );
00150
00151 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
00152 $tpl->setTranslator( new MediaWiki_I18N() );
00153 #}
00154 wfProfileOut( __METHOD__ . '-init' );
00155
00156 wfProfileIn( __METHOD__ . '-stuff' );
00157 $this->thispage = $this->mTitle->getPrefixedDBkey();
00158 $this->thisurl = $this->mTitle->getPrefixedURL();
00159 $query = array();
00160 if ( !$wgRequest->wasPosted() ) {
00161 $query = $wgRequest->getValues();
00162 unset( $query['title'] );
00163 unset( $query['returnto'] );
00164 unset( $query['returntoquery'] );
00165 }
00166 $this->thisquery = wfUrlencode( wfArrayToCGI( $query ) );
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->titletxt = $this->mTitle->getPrefixedText();
00181 wfProfileOut( __METHOD__ . '-stuff' );
00182
00183 wfProfileIn( __METHOD__ . '-stuff-head' );
00184 if ( $this->useHeadElement ) {
00185 $pagecss = $this->setupPageCss();
00186 if( $pagecss )
00187 $out->addInlineStyle( $pagecss );
00188 } else {
00189 $this->setupUserCss( $out );
00190
00191 $tpl->set( 'pagecss', $this->setupPageCss() );
00192 $tpl->setRef( 'usercss', $this->usercss );
00193
00194 $this->userjs = $this->userjsprev = false;
00195 $this->setupUserJs( $out->isUserJsAllowed() );
00196 $tpl->setRef( 'userjs', $this->userjs );
00197 $tpl->setRef( 'userjsprev', $this->userjsprev );
00198
00199 if( $wgUseSiteJs ) {
00200 $jsCache = $this->loggedin ? '&smaxage=0' : '';
00201 $tpl->set( 'jsvarurl',
00202 self::makeUrl( '-',
00203 "action=raw$jsCache&gen=js&useskin=" .
00204 urlencode( $this->getSkinName() ) ) );
00205 } else {
00206 $tpl->set( 'jsvarurl', false );
00207 }
00208
00209 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
00210 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
00211 $tpl->set( 'html5version', $wgHtml5Version );
00212 $tpl->set( 'headlinks', $out->getHeadLinks() );
00213 $tpl->set( 'csslinks', $out->buildCssLinks() );
00214
00215 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
00216 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
00217 } else {
00218 $tpl->set( 'trackbackhtml', null );
00219 }
00220 }
00221 wfProfileOut( __METHOD__ . '-stuff-head' );
00222
00223 wfProfileIn( __METHOD__ . '-stuff2' );
00224 $tpl->set( 'title', $out->getPageTitle() );
00225 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
00226 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
00227 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
00228 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
00229
00230 $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
00231 MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
00232 $this->mTitle->getNsText();
00233
00234 $tpl->set( 'nscanonical', $nsname );
00235 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
00236 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
00237 $tpl->set( 'titletext', $this->mTitle->getText() );
00238 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
00239 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
00240
00241 $tpl->set( 'isarticle', $out->isArticle() );
00242
00243 $tpl->setRef( 'thispage', $this->thispage );
00244 $subpagestr = $this->subPageSubtitle();
00245 $tpl->set(
00246 'subtitle', !empty( $subpagestr ) ?
00247 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() :
00248 $out->getSubtitle()
00249 );
00250 $undelete = $this->getUndeleteLink();
00251 $tpl->set(
00252 'undelete', !empty( $undelete ) ?
00253 '<span class="subpages">'.$undelete.'</span>' :
00254 ''
00255 );
00256
00257 $tpl->set( 'catlinks', $this->getCategories() );
00258 if( $out->isSyndicated() ) {
00259 $feeds = array();
00260 foreach( $out->getSyndicationLinks() as $format => $link ) {
00261 $feeds[$format] = array(
00262 'text' => wfMsg( "feed-$format" ),
00263 'href' => $link
00264 );
00265 }
00266 $tpl->setRef( 'feeds', $feeds );
00267 } else {
00268 $tpl->set( 'feeds', false );
00269 }
00270
00271 $tpl->setRef( 'mimetype', $wgMimeType );
00272 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
00273 $tpl->setRef( 'charset', $wgOutputEncoding );
00274 $tpl->setRef( 'wgScript', $wgScript );
00275 $tpl->setRef( 'skinname', $this->skinname );
00276 $tpl->set( 'skinclass', get_class( $this ) );
00277 $tpl->setRef( 'stylename', $this->stylename );
00278 $tpl->set( 'printable', $out->isPrintable() );
00279 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
00280 $tpl->setRef( 'loggedin', $this->loggedin );
00281 $tpl->set( 'notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL );
00282
00283
00284
00285
00286
00287
00288
00289 $tpl->set( 'searchaction', $this->escapeSearchLink() );
00290 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
00291 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
00292 $tpl->setRef( 'stylepath', $wgStylePath );
00293 $tpl->setRef( 'articlepath', $wgArticlePath );
00294 $tpl->setRef( 'scriptpath', $wgScriptPath );
00295 $tpl->setRef( 'serverurl', $wgServer );
00296 $tpl->setRef( 'logopath', $wgLogo );
00297 $tpl->setRef( 'lang', $wgContLanguageCode );
00298 $tpl->set( 'dir', $wgContLang->getDir() );
00299 $tpl->set( 'rtl', $wgContLang->isRTL() );
00300 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
00301 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
00302 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
00303 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
00304 $tpl->setRef( 'userpage', $this->userpage );
00305 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
00306 $tpl->set( 'userlang', $wgLang->getCode() );
00307
00308
00309
00310
00311 $tpl->set( 'userlangattributes', '');
00312 $tpl->set( 'specialpageattributes', '');
00313
00314 $lang = $wgLang->getCode();
00315 $dir = $wgLang->getDir();
00316 if ( $lang !== $wgContLang->getCode() || $dir !== $wgContLang->getDir() ) {
00317 $attrs = " lang='$lang' dir='$dir'";
00318
00319 $tpl->set( 'userlangattributes', $attrs );
00320
00321
00322
00323 if($this->mTitle->isSpecialPage()) {
00324 $tpl->set( 'specialpageattributes', $attrs );
00325 }
00326 }
00327
00328 $newtalks = $wgUser->getNewMessageLinks();
00329 $ntl = '';
00330
00331 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
00332 $usertitle = $this->mUser->getUserPage();
00333 $usertalktitle = $usertitle->getTalkPage();
00334
00335 if( !$usertalktitle->equals( $this->mTitle ) ) {
00336 $newmessageslink = $this->link(
00337 $usertalktitle,
00338 wfMsgHtml( 'newmessageslink' ),
00339 array(),
00340 array( 'redirect' => 'no' ),
00341 array( 'known', 'noclasses' )
00342 );
00343
00344 $newmessagesdifflink = $this->link(
00345 $usertalktitle,
00346 wfMsgHtml( 'newmessagesdifflink' ),
00347 array(),
00348 array( 'diff' => 'cur' ),
00349 array( 'known', 'noclasses' )
00350 );
00351
00352 $ntl = wfMsg(
00353 'youhavenewmessages',
00354 $newmessageslink,
00355 $newmessagesdifflink
00356 );
00357 # Disable Cache
00358 $out->setSquidMaxage( 0 );
00359 }
00360 } else if( count( $newtalks ) ) {
00361
00362 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
00363 $msgs = array();
00364 foreach( $newtalks as $newtalk ) {
00365 $msgs[] = Xml::element('a',
00366 array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
00367 }
00368 $parts = implode( $sep, $msgs );
00369 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
00370 $out->setSquidMaxage( 0 );
00371 }
00372 wfProfileOut( __METHOD__ . '-stuff2' );
00373
00374 wfProfileIn( __METHOD__ . '-stuff3' );
00375 $tpl->setRef( 'newtalk', $ntl );
00376 $tpl->setRef( 'skin', $this );
00377 $tpl->set( 'logo', $this->logoText() );
00378 if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and
00379 $wgArticle and 0 != $wgArticle->getID() ){
00380 if ( !$wgDisableCounters ) {
00381 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
00382 if ( $viewcount ) {
00383 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
00384 } else {
00385 $tpl->set( 'viewcount', false );
00386 }
00387 } else {
00388 $tpl->set( 'viewcount', false );
00389 }
00390
00391 if( $wgPageShowWatchingUsers ) {
00392 $dbr = wfGetDB( DB_SLAVE );
00393 $watchlist = $dbr->tableName( 'watchlist' );
00394 $res = $dbr->select( 'watchlist',
00395 array( 'COUNT(*) AS n' ),
00396 array( 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ), 'wl_namespace' => $this->mTitle->getNamespace() ),
00397 __METHOD__
00398 );
00399 $x = $dbr->fetchObject( $res );
00400 $numberofwatchingusers = $x->n;
00401 if( $numberofwatchingusers > 0 ) {
00402 $tpl->set( 'numberofwatchingusers',
00403 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
00404 $wgLang->formatNum( $numberofwatchingusers ) )
00405 );
00406 } else {
00407 $tpl->set( 'numberofwatchingusers', false );
00408 }
00409 } else {
00410 $tpl->set( 'numberofwatchingusers', false );
00411 }
00412
00413 $tpl->set( 'copyright', $this->getCopyright() );
00414
00415 $this->credits = false;
00416
00417 if( $wgMaxCredits != 0 ){
00418 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
00419 } else {
00420 $tpl->set( 'lastmod', $this->lastModified() );
00421 }
00422
00423 $tpl->setRef( 'credits', $this->credits );
00424
00425 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
00426 $tpl->set( 'copyright', $this->getCopyright() );
00427 $tpl->set( 'viewcount', false );
00428 $tpl->set( 'lastmod', false );
00429 $tpl->set( 'credits', false );
00430 $tpl->set( 'numberofwatchingusers', false );
00431 } else {
00432 $tpl->set( 'copyright', false );
00433 $tpl->set( 'viewcount', false );
00434 $tpl->set( 'lastmod', false );
00435 $tpl->set( 'credits', false );
00436 $tpl->set( 'numberofwatchingusers', false );
00437 }
00438 wfProfileOut( __METHOD__ . '-stuff3' );
00439
00440 wfProfileIn( __METHOD__ . '-stuff4' );
00441 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
00442 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
00443 $tpl->set( 'disclaimer', $this->disclaimerLink() );
00444 $tpl->set( 'privacy', $this->privacyLink() );
00445 $tpl->set( 'about', $this->aboutLink() );
00446
00447 if ( $wgDebugComments ) {
00448 $tpl->setRef( 'debug', $out->mDebugtext );
00449 } else {
00450 $tpl->set( 'debug', '' );
00451 }
00452
00453 $tpl->set( 'reporttime', wfReportTime() );
00454 $tpl->set( 'sitenotice', wfGetSiteNotice() );
00455 $tpl->set( 'bottomscripts', $this->bottomScripts() );
00456
00457 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
00458 $out->mBodytext .= $printfooter . $this->generateDebugHTML();
00459 $tpl->setRef( 'bodytext', $out->mBodytext );
00460
00461 # Language links
00462 $language_urls = array();
00463
00464 if ( !$wgHideInterlanguageLinks ) {
00465 foreach( $out->getLanguageLinks() as $l ) {
00466 $tmp = explode( ':', $l, 2 );
00467 $class = 'interwiki-' . $tmp[0];
00468 unset( $tmp );
00469 $nt = Title::newFromText( $l );
00470 if ( $nt ) {
00471 $language_urls[] = array(
00472 'href' => $nt->getFullURL(),
00473 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
00474 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
00475 'class' => $class
00476 );
00477 }
00478 }
00479 }
00480 if( count( $language_urls ) ) {
00481 $tpl->setRef( 'language_urls', $language_urls );
00482 } else {
00483 $tpl->set( 'language_urls', false );
00484 }
00485 wfProfileOut( __METHOD__ . '-stuff4' );
00486
00487 wfProfileIn( __METHOD__ . '-stuff5' );
00488 # Personal toolbar
00489 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
00490 $content_actions = $this->buildContentActionUrls();
00491 $tpl->setRef( 'content_actions', $content_actions );
00492
00493 $tpl->set( 'sidebar', $this->buildSidebar() );
00494 $tpl->set( 'nav_urls', $this->buildNavUrls() );
00495
00496
00497 if ( $this->useHeadElement ) {
00498 $tpl->set( 'headelement', $out->headElement( $this ) );
00499 } else {
00500 $tpl->set( 'headscripts', $out->getScript() );
00501 }
00502
00503
00504 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
00505 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
00506 }
00507
00508
00509
00510 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
00511 wfProfileOut( __METHOD__ . '-stuff5' );
00512
00513
00514 wfProfileIn( __METHOD__ . '-execute' );
00515 $res = $tpl->execute();
00516 wfProfileOut( __METHOD__ . '-execute' );
00517
00518
00519 $this->printOrError( $res );
00520 wfProfileOut( __METHOD__ );
00521 }
00522
00531 function printOrError( $str ) {
00532 echo $str;
00533 }
00534
00540 function buildPersonalUrls() {
00541 global $wgOut, $wgRequest;
00542
00543 $title = $wgOut->getTitle();
00544 $pageurl = $title->getLocalURL();
00545 wfProfileIn( __METHOD__ );
00546
00547
00548 $personal_urls = array();
00549 $page = $wgRequest->getVal( 'returnto', $this->thisurl );
00550 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
00551 $returnto = "returnto=$page";
00552 if( $this->thisquery != '' )
00553 $returnto .= "&returntoquery=$query";
00554 if( $this->loggedin ) {
00555 $personal_urls['userpage'] = array(
00556 'text' => $this->username,
00557 'href' => &$this->userpageUrlDetails['href'],
00558 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
00559 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
00560 );
00561 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
00562 $personal_urls['mytalk'] = array(
00563 'text' => wfMsg( 'mytalk' ),
00564 'href' => &$usertalkUrlDetails['href'],
00565 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
00566 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
00567 );
00568 $href = self::makeSpecialUrl( 'Preferences' );
00569 $personal_urls['preferences'] = array(
00570 'text' => wfMsg( 'mypreferences' ),
00571 'href' => $href,
00572 'active' => ( $href == $pageurl )
00573 );
00574 $href = self::makeSpecialUrl( 'Watchlist' );
00575 $personal_urls['watchlist'] = array(
00576 'text' => wfMsg( 'mywatchlist' ),
00577 'href' => $href,
00578 'active' => ( $href == $pageurl )
00579 );
00580
00581 # We need to do an explicit check for Special:Contributions, as we
00582 # have to match both the title, and the target (which could come
00583 # from request values or be specified in "sub page" form. The plot
00584 # thickens, because $wgTitle is altered for special pages, so doesn't
00585 # contain the original alias-with-subpage.
00586 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
00587 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
00588 list( $spName, $spPar ) =
00589 SpecialPage::resolveAliasWithSubpage( $origTitle->getText() );
00590 $active = $spName == 'Contributions'
00591 && ( ( $spPar && $spPar == $this->username )
00592 || $wgRequest->getText( 'target' ) == $this->username );
00593 } else {
00594 $active = false;
00595 }
00596
00597 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
00598 $personal_urls['mycontris'] = array(
00599 'text' => wfMsg( 'mycontris' ),
00600 'href' => $href,
00601 'active' => $active
00602 );
00603 $personal_urls['logout'] = array(
00604 'text' => wfMsg( 'userlogout' ),
00605 'href' => self::makeSpecialUrl( 'Userlogout',
00606 $title->isSpecial( 'Preferences' ) ? '' : $returnto
00607 ),
00608 'active' => false
00609 );
00610 } else {
00611 global $wgUser;
00612 $loginlink = $wgUser->isAllowed( 'createaccount' )
00613 ? 'nav-login-createaccount'
00614 : 'login';
00615 if( $this->showIPinHeader() ) {
00616 $href = &$this->userpageUrlDetails['href'];
00617 $personal_urls['anonuserpage'] = array(
00618 'text' => $this->username,
00619 'href' => $href,
00620 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
00621 'active' => ( $pageurl == $href )
00622 );
00623 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
00624 $href = &$usertalkUrlDetails['href'];
00625 $personal_urls['anontalk'] = array(
00626 'text' => wfMsg( 'anontalk' ),
00627 'href' => $href,
00628 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
00629 'active' => ( $pageurl == $href )
00630 );
00631 $personal_urls['anonlogin'] = array(
00632 'text' => wfMsg( $loginlink ),
00633 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
00634 'active' => $title->isSpecial( 'Userlogin' )
00635 );
00636 } else {
00637 $personal_urls['login'] = array(
00638 'text' => wfMsg( $loginlink ),
00639 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
00640 'active' => $title->isSpecial( 'Userlogin' )
00641 );
00642 }
00643 }
00644
00645 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
00646 wfProfileOut( __METHOD__ );
00647 return $personal_urls;
00648 }
00649
00650 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
00651 $classes = array();
00652 if( $selected ) {
00653 $classes[] = 'selected';
00654 }
00655 if( $checkEdit && !$title->isKnown() ) {
00656 $classes[] = 'new';
00657 $query = 'action=edit&redlink=1';
00658 }
00659
00660 $text = wfMsg( $message );
00661 if ( wfEmptyMsg( $message, $text ) ) {
00662 global $wgContLang;
00663 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
00664 }
00665
00666 $result = array();
00667 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
00668 $title, $message, $selected, $checkEdit,
00669 &$classes, &$query, &$text, &$result ) ) ) {
00670 return $result;
00671 }
00672
00673 return array(
00674 'class' => implode( ' ', $classes ),
00675 'text' => $text,
00676 'href' => $title->getLocalUrl( $query ) );
00677 }
00678
00679 function makeTalkUrlDetails( $name, $urlaction = '' ) {
00680 $title = Title::newFromText( $name );
00681 if( !is_object( $title ) ) {
00682 throw new MWException( __METHOD__ . " given invalid pagename $name" );
00683 }
00684 $title = $title->getTalkPage();
00685 self::checkTitle( $title, $name );
00686 return array(
00687 'href' => $title->getLocalURL( $urlaction ),
00688 'exists' => $title->getArticleID() != 0 ? true : false
00689 );
00690 }
00691
00692 function makeArticleUrlDetails( $name, $urlaction = '' ) {
00693 $title = Title::newFromText( $name );
00694 $title= $title->getSubjectPage();
00695 self::checkTitle( $title, $name );
00696 return array(
00697 'href' => $title->getLocalURL( $urlaction ),
00698 'exists' => $title->getArticleID() != 0 ? true : false
00699 );
00700 }
00701
00707 function buildContentActionUrls() {
00708 global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
00709
00710 wfProfileIn( __METHOD__ );
00711
00712 $action = $wgRequest->getVal( 'action', 'view' );
00713 $section = $wgRequest->getVal( 'section' );
00714 $content_actions = array();
00715
00716 $prevent_active_tabs = false;
00717 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$prevent_active_tabs ) );
00718
00719 if( $this->iscontent ) {
00720 $subjpage = $this->mTitle->getSubjectPage();
00721 $talkpage = $this->mTitle->getTalkPage();
00722
00723 $nskey = $this->mTitle->getNamespaceKey();
00724 $content_actions[$nskey] = $this->tabAction(
00725 $subjpage,
00726 $nskey,
00727 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
00728 '', true
00729 );
00730
00731 $content_actions['talk'] = $this->tabAction(
00732 $talkpage,
00733 'talk',
00734 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
00735 '',
00736 true
00737 );
00738
00739 wfProfileIn( __METHOD__ . '-edit' );
00740 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
00741 $istalk = $this->mTitle->isTalkPage();
00742 $istalkclass = $istalk?' istalk':'';
00743 $content_actions['edit'] = array(
00744 'class' => ( ( ( $action == 'edit' or $action == 'submit' ) and $section != 'new' ) ? 'selected' : '' ) . $istalkclass,
00745 'text' => $this->mTitle->exists()
00746 ? wfMsg( 'edit' )
00747 : wfMsg( 'create' ),
00748 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
00749 );
00750
00751
00752 if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
00753 if ( !$wgOut->forceHideNewSectionLink() ) {
00754 $content_actions['addsection'] = array(
00755 'class' => $section == 'new' ? 'selected' : false,
00756 'text' => wfMsg( 'addsection' ),
00757 'href' => $this->mTitle->getLocalUrl( 'action=edit§ion=new' )
00758 );
00759 }
00760 }
00761 } elseif ( $this->mTitle->isKnown() ) {
00762 $content_actions['viewsource'] = array(
00763 'class' => ($action == 'edit') ? 'selected' : false,
00764 'text' => wfMsg( 'viewsource' ),
00765 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
00766 );
00767 }
00768 wfProfileOut( __METHOD__ . '-edit' );
00769
00770 wfProfileIn( __METHOD__ . '-live' );
00771 if ( $this->mTitle->exists() ) {
00772
00773 $content_actions['history'] = array(
00774 'class' => ($action == 'history') ? 'selected' : false,
00775 'text' => wfMsg( 'history_short' ),
00776 'href' => $this->mTitle->getLocalUrl( 'action=history' ),
00777 'rel' => 'archives',
00778 );
00779
00780 if( $wgUser->isAllowed( 'delete' ) ) {
00781 $content_actions['delete'] = array(
00782 'class' => ($action == 'delete') ? 'selected' : false,
00783 'text' => wfMsg( 'delete' ),
00784 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
00785 );
00786 }
00787 if ( $this->mTitle->quickUserCan( 'move' ) ) {
00788 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
00789 $content_actions['move'] = array(
00790 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
00791 'text' => wfMsg( 'move' ),
00792 'href' => $moveTitle->getLocalUrl()
00793 );
00794 }
00795
00796 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
00797 if( !$this->mTitle->isProtected() ){
00798 $content_actions['protect'] = array(
00799 'class' => ($action == 'protect') ? 'selected' : false,
00800 'text' => wfMsg( 'protect' ),
00801 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
00802 );
00803
00804 } else {
00805 $content_actions['unprotect'] = array(
00806 'class' => ($action == 'unprotect') ? 'selected' : false,
00807 'text' => wfMsg( 'unprotect' ),
00808 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
00809 );
00810 }
00811 }
00812 } else {
00813
00814 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'deletedtext' ) ) {
00815 if( $n = $this->mTitle->isDeleted() ) {
00816 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
00817 $content_actions['undelete'] = array(
00818 'class' => false,
00819 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum( $n ) ),
00820 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
00821 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
00822 );
00823 }
00824 }
00825
00826 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
00827 if( !$this->mTitle->getRestrictions( 'create' ) ) {
00828 $content_actions['protect'] = array(
00829 'class' => ($action == 'protect') ? 'selected' : false,
00830 'text' => wfMsg( 'protect' ),
00831 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
00832 );
00833
00834 } else {
00835 $content_actions['unprotect'] = array(
00836 'class' => ($action == 'unprotect') ? 'selected' : false,
00837 'text' => wfMsg( 'unprotect' ),
00838 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
00839 );
00840 }
00841 }
00842 }
00843
00844 wfProfileOut( __METHOD__ . '-live' );
00845
00846 if( $this->loggedin ) {
00847 if( !$this->mTitle->userIsWatching()) {
00848 $content_actions['watch'] = array(
00849 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
00850 'text' => wfMsg( 'watch' ),
00851 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
00852 );
00853 } else {
00854 $content_actions['unwatch'] = array(
00855 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
00856 'text' => wfMsg( 'unwatch' ),
00857 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
00858 );
00859 }
00860 }
00861
00862
00863 wfRunHooks( 'SkinTemplateTabs', array( $this, &$content_actions ) );
00864 } else {
00865
00866
00867 $content_actions[$this->mTitle->getNamespaceKey()] = array(
00868 'class' => 'selected',
00869 'text' => wfMsg('nstab-special'),
00870 'href' => $wgRequest->getRequestURL(),
00871 );
00872
00873 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
00874 }
00875
00876
00877 global $wgDisableLangConversion;
00878 $variants = $wgContLang->getVariants();
00879 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
00880 $preferred = $wgContLang->getPreferredVariant();
00881 $vcount=0;
00882 foreach( $variants as $code ) {
00883 $varname = $wgContLang->getVariantname( $code );
00884 if( $varname == 'disable' )
00885 continue;
00886 $selected = ( $code == $preferred )? 'selected' : false;
00887 $content_actions['varlang-' . $vcount] = array(
00888 'class' => $selected,
00889 'text' => $varname,
00890 'href' => $this->mTitle->getLocalURL( '', $code )
00891 );
00892 $vcount ++;
00893 }
00894 }
00895
00896 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
00897
00898 wfProfileOut( __METHOD__ );
00899 return $content_actions;
00900 }
00901
00907 function buildNavUrls() {
00908 global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
00909 global $wgEnableUploads, $wgUploadNavigationUrl;
00910
00911 wfProfileIn( __METHOD__ );
00912
00913 $action = $wgRequest->getVal( 'action', 'view' );
00914
00915 $nav_urls = array();
00916 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
00917 if( $wgUploadNavigationUrl ) {
00918 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
00919 } elseif( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
00920 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
00921 } else {
00922 $nav_urls['upload'] = false;
00923 }
00924 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
00925
00926
00927 $nav_urls['permalink'] = false;
00928
00929
00930
00931 if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
00932 if ( !$wgOut->isPrintable() ) {
00933 $nav_urls['print'] = array(
00934 'text' => wfMsg( 'printableversion' ),
00935 'href' => $wgRequest->appendQuery( 'printable=yes' )
00936 );
00937 }
00938
00939
00940 if ( $this->mRevisionId ) {
00941 $nav_urls['permalink'] = array(
00942 'text' => wfMsg( 'permalink' ),
00943 'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
00944 );
00945 }
00946
00947
00948 $revid = $this->mRevisionId;
00949 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
00950 }
00951
00952 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
00953 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
00954 $nav_urls['whatlinkshere'] = array(
00955 'href' => $wlhTitle->getLocalUrl()
00956 );
00957 if( $this->mTitle->getArticleId() ) {
00958 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
00959 $nav_urls['recentchangeslinked'] = array(
00960 'href' => $rclTitle->getLocalUrl()
00961 );
00962 } else {
00963 $nav_urls['recentchangeslinked'] = false;
00964 }
00965 if( $wgUseTrackbacks )
00966 $nav_urls['trackbacklink'] = array(
00967 'href' => $wgOut->getTitle()->trackbackURL()
00968 );
00969 }
00970
00971 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
00972 $id = User::idFromName( $this->mTitle->getText() );
00973 $ip = User::isIP( $this->mTitle->getText() );
00974 } else {
00975 $id = 0;
00976 $ip = false;
00977 }
00978
00979 if( $id || $ip ) { # both anons and non-anons have contribs list
00980 $nav_urls['contributions'] = array(
00981 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
00982 );
00983
00984 if( $id ) {
00985 $logPage = SpecialPage::getTitleFor( 'Log' );
00986 $nav_urls['log'] = array(
00987 'href' => $logPage->getLocalUrl(
00988 array(
00989 'user' => $this->mTitle->getText()
00990 )
00991 )
00992 );
00993 } else {
00994 $nav_urls['log'] = false;
00995 }
00996
00997 if ( $wgUser->isAllowed( 'block' ) ) {
00998 $nav_urls['blockip'] = array(
00999 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
01000 );
01001 } else {
01002 $nav_urls['blockip'] = false;
01003 }
01004 } else {
01005 $nav_urls['contributions'] = false;
01006 $nav_urls['log'] = false;
01007 $nav_urls['blockip'] = false;
01008 }
01009 $nav_urls['emailuser'] = false;
01010 if( $this->showEmailUser( $id ) ) {
01011 $nav_urls['emailuser'] = array(
01012 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
01013 );
01014 }
01015 wfProfileOut( __METHOD__ );
01016 return $nav_urls;
01017 }
01018
01024 function getNameSpaceKey() {
01025 return $this->mTitle->getNamespaceKey();
01026 }
01027
01031 function setupUserJs( $allowUserJs ) {
01032 global $wgRequest, $wgJsMimeType;
01033 wfProfileIn( __METHOD__ );
01034
01035 $action = $wgRequest->getVal( 'action', 'view' );
01036
01037 if( $allowUserJs && $this->loggedin ) {
01038 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
01039 # XXX: additional security check/prompt?
01040 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
01041 } else {
01042 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
01043 }
01044 }
01045 wfProfileOut( __METHOD__ );
01046 }
01047
01054 function setupPageCss() {
01055 wfProfileIn( __METHOD__ );
01056 $out = false;
01057 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
01058 wfProfileOut( __METHOD__ );
01059 return $out;
01060 }
01061
01062 public function commonPrintStylesheet() {
01063 return false;
01064 }
01065 }
01066
01072 abstract class QuickTemplate {
01076 public function QuickTemplate() {
01077 $this->data = array();
01078 $this->translator = new MediaWiki_I18N();
01079 }
01080
01086 public function set( $name, $value ) {
01087 $this->data[$name] = $value;
01088 }
01089
01094 public function setRef( $name, &$value ) {
01095 $this->data[$name] =& $value;
01096 }
01097
01101 public function setTranslator( &$t ) {
01102 $this->translator = &$t;
01103 }
01104
01109 abstract public function execute();
01110
01114 function text( $str ) {
01115 echo htmlspecialchars( $this->data[$str] );
01116 }
01117
01121 function jstext( $str ) {
01122 echo Xml::escapeJsString( $this->data[$str] );
01123 }
01124
01128 function html( $str ) {
01129 echo $this->data[$str];
01130 }
01131
01135 function msg( $str ) {
01136 echo htmlspecialchars( $this->translator->translate( $str ) );
01137 }
01138
01142 function msgHtml( $str ) {
01143 echo $this->translator->translate( $str );
01144 }
01145
01150 function msgWiki( $str ) {
01151 global $wgParser, $wgOut;
01152
01153 $text = $this->translator->translate( $str );
01154 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
01155 $wgOut->parserOptions(), true );
01156 echo $parserOutput->getText();
01157 }
01158
01162 function haveData( $str ) {
01163 return isset( $this->data[$str] );
01164 }
01165
01169 function haveMsg( $str ) {
01170 $msg = $this->translator->translate( $str );
01171 return ( $msg != '-' ) && ( $msg != '' ); # ????
01172 }
01173 }