/// Stores a Title object (of the current page).
protected $mTitle = null;
+ /// Stores a User object (the one the page is being rendered for)
+ protected $mUser = null;
+
/**
* An array of stylesheet filenames (relative from skins path), with options
* for CSS media, IE conditions, and RTL/LTR direction.
* @return Boolean: true iff cache-ok headers was sent.
*/
public function checkLastModified( $timestamp ) {
- global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
+ global $wgCachePages, $wgCacheEpoch, $wgRequest;
if ( !$timestamp || $timestamp == '19700101000000' ) {
wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
return false;
}
- if( $wgUser->getOption( 'nocache' ) ) {
+ if( $this->getUser()->getOption( 'nocache' ) ) {
wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
return false;
}
$timestamp = wfTimestamp( TS_MW, $timestamp );
$modifiedTimes = array(
'page' => $timestamp,
- 'user' => $wgUser->getTouched(),
+ 'user' => $this->getUser()->getTouched(),
'epoch' => $wgCacheEpoch
);
wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
}
}
+ /**
+ * Set the User object to use
+ *
+ * @param $u User object
+ */
+ public function setUser( $u ) {
+ $this->mUser = $u;
+ }
+
+ /**
+ * Get the User object used in this instance
+ *
+ * @return User
+ */
+ public function getUser() {
+ if ( !isset($this->mUser) ) {
+ wfDebug( __METHOD__ . " called and \$mUser is null. Return \$wgUser for sanity\n" );
+ global $wgUser;
+ return $wgUser;
+ }
+ return $this->mUser;
+ }
+
+ /**
+ * Get the Skin object used to render this instance
+ *
+ * @return Skin
+ */
+ public function getSkin() {
+ // For now we'll just proxy to the user. In the future a saner location for
+ // organizing what skin to use may be chosen
+ return $this->getUser()->getSkin();
+ }
+
/**
* Replace the subtile with $str
*
* @param $categories Array mapping category name => sort key
*/
public function addCategoryLinks( $categories ) {
- global $wgUser, $wgContLang;
+ global $wgContLang;
if ( !is_array( $categories ) || count( $categories ) == 0 ) {
return;
# Add the remaining categories to the skin
if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
- $sk = $wgUser->getSkin();
foreach ( $categories as $category => $type ) {
$origcategory = $category;
$title = Title::makeTitleSafe( NS_CATEGORY, $category );
}
$text = $wgContLang->convertHtml( $title->getText() );
$this->mCategories[] = $title->getText();
- $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
+ $this->mCategoryLinks[$type][] = $this->getSkin()->link( $title, $text );
}
}
}
* the object, let's actually output it:
*/
public function output() {
- global $wgUser, $wgOutputEncoding, $wgRequest;
+ global $wgOutputEncoding, $wgRequest;
global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
if( $this->mDoNothing ) {
} else {
$this->addDefaultModules();
- $sk = $wgUser->getSkin( $this->getTitle() );
+ $sk = $this->getSkin( $this->getTitle() );
// Hook that allows last minute changes to the output page, e.g.
// adding of CSS or Javascript by extensions.
* @return nothing
*/
function blockedPage( $return = true ) {
- global $wgUser, $wgContLang, $wgLang;
+ global $wgContLang, $wgLang;
$this->setPageTitle( wfMsg( 'blockedtitle' ) );
$this->setRobotPolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
- $name = $wgUser->blockedBy();
- $reason = $wgUser->blockedFor();
+ $name = $this->getUser()->blockedBy();
+ $reason = $this->getUser()->blockedFor();
if( $reason == '' ) {
$reason = wfMsg( 'blockednoreason' );
}
$blockTimestamp = $wgLang->timeanddate(
- wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true
+ wfTimestamp( TS_MW, $this->getUser()->mBlock->mTimestamp ), true
);
$ip = wfGetIP();
$link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
- $blockid = $wgUser->mBlock->getId();
+ $blockid = $this->getUser()->mBlock->getId();
- $blockExpiry = $wgLang->formatExpiry( $wgUser->mBlock->mExpiry );
+ $blockExpiry = $wgLang->formatExpiry( $this->getUser()->mBlock->mExpiry );
- if ( $wgUser->mBlock->mAuto ) {
+ if ( $this->getUser()->mBlock->mAuto ) {
$msg = 'autoblockedtext';
} else {
$msg = 'blockedtext';
/* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
* This could be a username, an IP range, or a single IP. */
- $intended = $wgUser->mBlock->getTarget();
+ $intended = $this->getUser()->mBlock->getTarget();
$this->addWikiMsg(
$msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
* Produce the stock "please login to use the wiki" page
*/
public function loginToUse() {
- global $wgUser;
-
- if( $wgUser->isLoggedIn() ) {
+ if( $this->getUser()->isLoggedIn() ) {
$this->permissionRequired( 'read' );
return;
}
- $skin = $wgUser->getSkin();
-
$this->setPageTitle( wfMsg( 'loginreqtitle' ) );
$this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
$this->setRobotPolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
$loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
- $loginLink = $skin->link(
+ $loginLink = $this->getSkin()->link(
$loginTitle,
wfMsgHtml( 'loginreqlink' ),
array(),
* @param $action String: action that was denied or null if unknown
*/
public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
- global $wgUser;
- $skin = $wgUser->getSkin();
-
$this->setRobotPolicy( 'noindex,nofollow' );
$this->setArticleRelated( false );
if( $source ) {
$this->setPageTitle( wfMsg( 'viewsource' ) );
$this->setSubtitle(
- wfMsg( 'viewsourcefor', $skin->linkKnown( $this->getTitle() ) )
+ wfMsg( 'viewsourcefor', $this->getSkin()->linkKnown( $this->getTitle() ) )
);
} else {
$this->setPageTitle( wfMsg( 'badaccess' ) );
$params = array(
'id' => 'wpTextbox1',
'name' => 'wpTextbox1',
- 'cols' => $wgUser->getOption( 'cols' ),
- 'rows' => $wgUser->getOption( 'rows' ),
+ 'cols' => $this->getUser()->getOption( 'cols' ),
+ 'rows' => $this->getUser()->getOption( 'rows' ),
'readonly' => 'readonly'
);
$this->addHTML( Html::element( 'textarea', $params, $source ) );
// Show templates used by this article
- $skin = $wgUser->getSkin();
+ $skin = $this->getSkin();
$article = new Article( $this->getTitle() );
$this->addHTML( "<div class='templatesUsed'>
{$skin->formatTemplates( $article->getUsedTemplates() )}
* @param $text String text of the link (input is not escaped)
*/
public function addReturnTo( $title, $query = array(), $text = null ) {
- global $wgUser;
$this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
$link = wfMsgHtml(
'returnto',
- $wgUser->getSkin()->link( $title, $text, array(), $query )
+ $this->getSkin()->link( $title, $text, array(), $query )
);
$this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
}
public function headElement( Skin $sk, $includeStyle = true ) {
global $wgOutputEncoding, $wgMimeType;
global $wgUseTrackbacks, $wgHtml5;
- global $wgUser, $wgRequest, $wgLang;
+ global $wgRequest, $wgLang;
if ( $sk->commonPrintStylesheet() ) {
$this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
if (
$this->getTitle()->getNamespace() != NS_SPECIAL &&
in_array( $action, array( 'view', 'purge' ) ) &&
- $wgUser->getOption( 'editondblclick' )
+ $this->getUser()->getOption( 'editondblclick' )
)
{
$bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
* Add the default ResourceLoader modules to this object
*/
private function addDefaultModules() {
- global $wgUser, $wgIncludeLegacyJavaScript,
+ global $wgIncludeLegacyJavaScript,
$wgUseAjax, $wgAjaxWatch, $wgEnableMWSuggest;
// Add base resources
wfRunHooks( 'AjaxAddScript', array( &$this ) );
- if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
+ if( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
$this->addModules( 'mediawiki.action.watch.ajax' );
}
- if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
+ if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
$this->addModules( 'mediawiki.legacy.mwsuggest' );
}
}
- if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
+ if( $this->getUser()->getBoolOption( 'editsectiononrightclick' ) ) {
$this->addModules( 'mediawiki.action.view.rightClickEdit' );
}
}
* @return string html <script> and <style> tags
*/
protected function makeResourceLoaderLink( Skin $skin, $modules, $only, $useESI = false ) {
- global $wgUser, $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
+ global $wgLang, $wgLoadScript, $wgResourceLoaderUseESI,
$wgResourceLoaderInlinePrivateModules, $wgRequest;
// Lazy-load ResourceLoader
// TODO: Should this be a static function of ResourceLoader instead?
foreach ( $groups as $group => $modules ) {
$query = $baseQuery;
// Special handling for user-specific groups
- if ( ( $group === 'user' || $group === 'private' ) && $wgUser->isLoggedIn() ) {
- $query['user'] = $wgUser->getName();
+ if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) {
+ $query['user'] = $this->getUser()->getName();
}
// Create a fake request based on the one we are about to make so modules return
* @return String: HTML fragment
*/
function getHeadScripts( Skin $sk ) {
- global $wgUser, $wgRequest, $wgUseSiteJs, $wgAllowUserJs;
+ global $wgRequest, $wgUseSiteJs, $wgAllowUserJs;
// Startup - this will immediately load jquery and mediawiki modules
$scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
// Add site JS if enabled
if ( $wgUseSiteJs ) {
$scripts .= $this->makeResourceLoaderLink( $sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS );
- if( $wgUser->isLoggedIn() ){
+ if( $this->getUser()->isLoggedIn() ){
$userScripts[] = 'user.groups';
}
}
// Add user JS if enabled
- if ( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
+ if ( $wgAllowUserJs && $this->getUser()->isLoggedIn() ) {
$action = $wgRequest->getVal( 'action', 'view' );
if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
# XXX: additional security check/prompt?
* have to be purged on configuration changes.
*/
protected function getJSVars() {
- global $wgUser, $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
+ global $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
$title = $this->getTitle();
$ns = $title->getNamespace();
'wgArticleId' => $title->getArticleId(),
'wgIsArticle' => $this->isArticle(),
'wgAction' => $wgRequest->getText( 'action', 'view' ),
- 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
- 'wgUserGroups' => $wgUser->getEffectiveGroups(),
+ 'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(),
+ 'wgUserGroups' => $this->getUser()->getEffectiveGroups(),
'wgCategories' => $this->getCategories(),
'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
);
foreach ( $title->getRestrictionTypes() as $type ) {
$vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
}
- if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
- $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
+ if ( $wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
+ $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $this->getUser() );
}
// Allow extensions to add their custom variables to the global JS variables