* Builds trackback links for article display if $wgUseTrackbacks is set to true
*/
public function addTrackbacks() {
- global $wgOut, $wgUser;
+ global $wgOut;
$dbr = wfGetDB( DB_SLAVE );
$tbs = $dbr->select( 'trackbacks',
foreach ( $tbs as $o ) {
$rmvtxt = "";
- if ( $wgUser->isAllowed( 'trackback' ) ) {
+ if ( $wgOut->getUser()->isAllowed( 'trackback' ) ) {
$delurl = $this->mTitle->getFullURL( "action=deletetrackback&tbid=" .
- $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
+ $o->tb_id . "&token=" . urlencode( $wgOut->getUser()->editToken() ) );
$rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
}
* Removes trackback record for current article from trackbacks table
*/
public function deletetrackback() {
- global $wgUser, $wgRequest, $wgOut;
+ global $wgRequest, $wgOut;
- if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
$wgOut->addWikiMsg( 'sessionfailure' );
return;
}
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
if ( count( $permission_errors ) ) {
$wgOut->showPermissionsErrorPage( $permission_errors );
* Handle action=purge
*/
public function purge() {
- global $wgUser, $wgRequest, $wgOut;
+ global $wgRequest, $wgOut;
- if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
+ if ( $wgOut->getUser()->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
//FIXME: shouldn't this be in doPurge()?
if ( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
$this->doPurge();
* Mark this particular edit/page as patrolled
*/
public function markpatrolled() {
- global $wgOut, $wgUser, $wgRequest;
+ global $wgOut, $wgRequest;
$wgOut->setRobotPolicy( 'noindex,nofollow' );
# If we haven't been given an rc_id value, we can't do anything
$rcid = (int) $wgRequest->getVal( 'rcid' );
- if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
+ if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
$wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
return;
}
* User-interface handler for the "watch" action
*/
public function watch() {
- global $wgUser, $wgOut;
+ global $wgOut;
- if ( $wgUser->isAnon() ) {
+ if ( $wgOut->getUser()->isAnon() ) {
$wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
return;
}
* User interface handler for the "unwatch" action.
*/
public function unwatch() {
- global $wgUser, $wgOut;
+ global $wgOut;
- if ( $wgUser->isAnon() ) {
+ if ( $wgOut->getUser()->isAnon() ) {
$wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
return;
}
* UI entry point for page deletion
*/
public function delete() {
- global $wgUser, $wgOut, $wgRequest;
+ global $wgOut, $wgRequest;
$confirm = $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
+ $wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
$this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
$this->DeleteReason = $wgRequest->getText( 'wpReason' );
}
# Flag to hide all contents of the archived revisions
- $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
+ $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgOut->getUser()->isAllowed( 'suppressrevision' );
# This code desperately needs to be totally rewritten
}
# Check permissions
- $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
if ( count( $permission_errors ) > 0 ) {
$wgOut->showPermissionsErrorPage( $permission_errors );
if ( $confirm ) {
$this->doDelete( $reason, $suppress );
- if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
+ if ( $wgRequest->getCheck( 'wpWatch' ) && $wgOut->getUser()->isLoggedIn() ) {
$this->doWatch();
} elseif ( $this->mTitle->userIsWatching() ) {
$this->doUnwatch();
if ( $hasHistory && !$confirm ) {
global $wgLang;
- $skin = $wgUser->getSkin();
+ $skin = $wgOut->getSkin();
$revisions = $this->estimateRevisionCount();
//FIXME: lego
$wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
* @param $reason String: prefilled reason
*/
public function confirmDelete( $reason ) {
- global $wgOut, $wgUser;
+ global $wgOut;
wfDebug( "Article::confirmDelete\n" );
- $deleteBackLink = $wgUser->getSkin()->linkKnown( $this->mTitle );
+ $deleteBackLink = $wgOut->getSkin()->linkKnown( $this->mTitle );
$wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->addWikiMsg( 'confirmdeletetext' );
wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
- if ( $wgUser->isAllowed( 'suppressrevision' ) ) {
+ if ( $wgOut->getUser()->isAllowed( 'suppressrevision' ) ) {
$suppress = "<tr id=\"wpDeleteSuppressRow\">
<td></td>
<td class='mw-input'><strong>" .
} else {
$suppress = '';
}
- $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
+ $checkWatch = $wgOut->getUser()->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
$form = Xml::openElement( 'form', array( 'method' => 'post',
'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
</tr>";
# Disallow watching if user is not logged in
- if ( $wgUser->isLoggedIn() ) {
+ if ( $wgOut->getUser()->isLoggedIn() ) {
$form .= "
<tr>
<td></td>
</tr>" .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'fieldset' ) .
- Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
+ Html::hidden( 'wpEditToken', $wgOut->getUser()->editToken() ) .
Xml::closeElement( 'form' );
- if ( $wgUser->isAllowed( 'editinterface' ) ) {
- $skin = $wgUser->getSkin();
+ if ( $wgOut->getUser()->isAllowed( 'editinterface' ) ) {
+ $skin = $wgOut->getSkin();
$title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
$link = $skin->link(
$title,
/// 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