diff --git a/includes/Parameters.php b/includes/Parameters.php index 1702add9..cfe4c6fd 100644 --- a/includes/Parameters.php +++ b/includes/Parameters.php @@ -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. diff --git a/includes/Parse.php b/includes/Parse.php index 882fb756..60befd1b 100644 --- a/includes/Parse.php +++ b/includes/Parse.php @@ -8,6 +8,7 @@ use MediaWiki\MediaWikiServices; use MWException; use Parser; +use RequestContext; use Title; use WebRequest; use Wikimedia\Rdbms\IDatabase; @@ -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(); } /** diff --git a/includes/UpdateArticle.php b/includes/UpdateArticle.php index 04f7c029..02b4e378 100644 --- a/includes/UpdateArticle.php +++ b/includes/UpdateArticle.php @@ -218,9 +218,6 @@ public static function updateArticleByRule( $title, $text, $rulesText ) { } // deal with template parameters ================================================= - - global $wgRequest; - $user = RequestContext::getMain()->getUser(); if ( $template != '' ) { @@ -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 ); @@ -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 ); @@ -371,7 +372,7 @@ public static function updateArticleByRule( $title, $text, $rulesText ) { - + '; return $form; @@ -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'; } @@ -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'; } @@ -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 @@ -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; diff --git a/includes/lister/Lister.php b/includes/lister/Lister.php index 4063886a..8320e8c5 100644 --- a/includes/lister/Lister.php +++ b/includes/lister/Lister.php @@ -8,6 +8,7 @@ use DPL\UpdateArticle; use MediaWiki\MediaWikiServices; use Parser; +use RequestContext; use Sanitizer; use Title; @@ -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 = ''; @@ -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 ) {