Skip to content

Commit

Permalink
Replace usages of globals (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega committed Mar 9, 2022
1 parent c37cda4 commit cd764c2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
12 changes: 6 additions & 6 deletions includes/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,31 +995,31 @@ public function _scroll( $option ) {

// If scrolling is active we adjust the values for certain other parameters based on URL arguments
if ( $option === true ) {
global $wgRequest;
$request = RequestContext::getMain()->getRequest();

// The 'findTitle' option has argument over the 'fromTitle' argument.
$titlegt = $wgRequest->getVal( 'DPL_findTitle', '' );
$titlegt = $request->getVal( 'DPL_findTitle', '' );

if ( !empty( $titlegt ) ) {
$titlegt = '=_' . ucfirst( $titlegt );
} else {
$titlegt = $wgRequest->getVal( 'DPL_fromTitle', '' );
$titlegt = $request->getVal( 'DPL_fromTitle', '' );
$titlegt = ucfirst( $titlegt );
}

$this->setParameter( 'titlegt', str_replace( ' ', '_', $titlegt ) );

// Lets get the 'toTitle' argument.
$titlelt = $wgRequest->getVal( 'DPL_toTitle', '' );
$titlelt = $request->getVal( 'DPL_toTitle', '' );
$titlelt = ucfirst( $titlelt );

$this->setParameter( 'titlelt', str_replace( ' ', '_', $titlelt ) );

// Make sure the 'scrollDir' arugment is captured. This is mainly used for the Variables extension and in the header/footer replacements.
$this->setParameter( 'scrolldir', $wgRequest->getVal( 'DPL_scrollDir', '' ) );
$this->setParameter( 'scrolldir', $request->getVal( 'DPL_scrollDir', '' ) );

// Also set count limit from URL if not otherwise set.
$this->_count( $wgRequest->getInt( 'DPL_count' ) );
$this->_count( $request->getInt( 'DPL_count' ) );
}

// We do not return false since they could have just left it out. Who knows why they put the parameter in the list in the first place.
Expand Down
5 changes: 2 additions & 3 deletions includes/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MediaWiki\MediaWikiServices;
use MWException;
use Parser;
use RequestContext;
use Title;
use WebRequest;
use Wikimedia\Rdbms\IDatabase;
Expand Down Expand Up @@ -97,13 +98,11 @@ class Parse {
];

public function __construct() {
global $wgRequest;

$this->DB = wfGetDB( DB_REPLICA, 'dpl' );
$this->parameters = new Parameters();
$this->logger = new Logger();
$this->tableNames = Query::getTableNames();
$this->request = $wgRequest;
$this->request = RequestContext::getMain()->getRequest();
}

/**
Expand Down
37 changes: 20 additions & 17 deletions includes/UpdateArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ public static function updateArticleByRule( $title, $text, $rulesText ) {
}

// deal with template parameters =================================================

global $wgRequest;

$user = RequestContext::getMain()->getUser();

if ( $template != '' ) {
Expand Down Expand Up @@ -331,7 +328,9 @@ public static function updateArticleByRule( $title, $text, $rulesText ) {
if ( $call >= $matchCount ) {
break;
}
$myValue = $wgRequest->getVal( urlencode( $call . '_' . $parm ), '' );

$request = RequestContext::getMain()->getRequest();
$myValue = $request->getVal( urlencode( $call . '_' . $parm ), '' );
}

$myOptional = array_key_exists( $nr, $optional );
Expand All @@ -354,7 +353,9 @@ public static function updateArticleByRule( $title, $text, $rulesText ) {
if ( $exec == 'set' ) {
return self::doUpdateArticle( $title, $text, $summary );
} elseif ( $exec == 'preview' ) {
global $wgScriptPath, $wgRequest;
global $wgScriptPath;

$request = RequestContext::getMain()->getRequest();

$titleX = Title::newFromText( $title );
$articleX = new Article( $titleX );
Expand All @@ -371,7 +372,7 @@ public static function updateArticleByRule( $title, $text, $rulesText ) {
<input type="hidden" name="wpSummary value="' . $summary . '" id="wpSummary" />
<input name="wpAutoSummary" type="hidden" value="" />
<input id="wpSave" name="wpSave" type="submit" value="Save page" accesskey="s" title="Save your changes [s]" />
<input type="hidden" value="' . $wgRequest->getVal( 'token' ) . '" name="wpEditToken" />
<input type="hidden" value="' . $request->getVal( 'token' ) . '" name="wpEditToken" />
</form>
</html>';
return $form;
Expand All @@ -381,12 +382,13 @@ public static function updateArticleByRule( $title, $text, $rulesText ) {
}

private static function doUpdateArticle( $title, $text, $summary ) {
global $wgRequest, $wgOut;
$context = RequestContext::getMain();
$request = $context->getRequest();
$out = $context->getOutput();
$user = $context->getUser();

$user = RequestContext::getMain()->getUser();

if ( !$user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
$wgOut->addWikiMsg( 'sessionfailure' );
if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
$out->addWikiMsg( 'sessionfailure' );

return 'session failure';
}
Expand Down Expand Up @@ -415,11 +417,11 @@ private static function doUpdateArticle( $title, $text, $summary ) {
EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY
);

$wgOut->redirect( $titleX->getFullUrl( $page->isRedirect() ? 'redirect=no' : '' ) );
$out->redirect( $titleX->getFullUrl( $page->isRedirect() ? 'redirect=no' : '' ) );

return '';
} else {
$wgOut->showPermissionsErrorPage( $permission_errors );
$out->showPermissionsErrorPage( $permission_errors );

return 'permission error';
}
Expand Down Expand Up @@ -666,8 +668,6 @@ private static function updateTemplateCall( &$matchCount, $text, $template, $cal
}

public static function deleteArticleByRule( $title, $text, $rulesText ) {
global $wgOut;

// return "deletion of articles by DPL is disabled.";

// we use ; as command delimiter; \; stands for a semicolon
Expand Down Expand Up @@ -711,14 +711,17 @@ public static function deleteArticleByRule( $title, $text, $rulesText ) {
$titleX = Title::newFromText( $title );

if ( $exec ) {
$user = RequestContext::getMain()->getUser();
$context = RequestContext::getMain();
$out = $context->getOutput();
$user = $context->getUser();

# Check permissions
$permission_errors = MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors( 'delete', $user, $titleX );
$isReadOnly = MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly();

if ( count( $permission_errors ) > 0 ) {
$wgOut->showPermissionsErrorPage( $permission_errors );
$out->showPermissionsErrorPage( $permission_errors );

return 'permission error';
} elseif ( $isReadOnly ) {
throw new ReadOnlyError;
Expand Down
7 changes: 4 additions & 3 deletions includes/lister/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DPL\UpdateArticle;
use MediaWiki\MediaWikiServices;
use Parser;
use RequestContext;
use Sanitizer;
use Title;

Expand Down Expand Up @@ -624,7 +625,7 @@ public function formatList( $articles, $start, $count ) {
* @return string
*/
public function formatItem( Article $article, $pageText = null ) {
global $wgLang;
$lang = RequestContext::getMain()->getLanguage();

$item = '';

Expand All @@ -644,14 +645,14 @@ public function formatItem( Article $article, $pageText = null ) {

if ( $article->mSize != null ) {
$byte = 'B';
$pageLength = $wgLang->formatNum( $article->mSize );
$pageLength = $lang->formatNum( $article->mSize );
$item .= " [{$pageLength} {$byte}]";
}

if ( $article->mCounter !== null ) {
$contLang = MediaWikiServices::getInstance()->getContentLanguage();

$item .= ' ' . $contLang->getDirMark() . '(' . wfMessage( 'hitcounters-nviews', $wgLang->formatNum( $article->mCounter ) )->escaped() . ')';
$item .= ' ' . $contLang->getDirMark() . '(' . wfMessage( 'hitcounters-nviews', $lang->formatNum( $article->mCounter ) )->escaped() . ')';
}

if ( $article->mUserLink !== null ) {
Expand Down

0 comments on commit cd764c2

Please sign in to comment.