jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/370629 )

Change subject: Require MediaWiki 1.29
......................................................................


Require MediaWiki 1.29

After I544cdfa75c7472f2d98b2561bc6f6f9c2d2ad639 (dieWithError
and checkUserRightsAny), this is the oldest MediaWiki version
AbuseFilter can be run on.

AbortMove was removed from MediaWiki in 1.25, UploadVerifyFile
is only relevant for 1.27 and older.

(Replaces I1e962217c3b20d901a5742cf76339a3f488a6e97.)

Change-Id: Iec237b2887f72b115fdcef78d2d7a944ba82c784
---
M AbuseFilter.php
M extension.json
M includes/AbuseFilter.class.php
M includes/AbuseFilter.hooks.php
M includes/api/ApiQueryAbuseLog.php
5 files changed, 33 insertions(+), 167 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AbuseFilter.php b/AbuseFilter.php
index 72dfb8b..4a06b06 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -25,7 +25,7 @@
        ); */
        return;
 } else {
-       die( 'This version of the AbuseFilter extension requires MediaWiki 
1.25+' );
+       die( 'This version of the AbuseFilter extension requires MediaWiki 
1.29+' );
 }
 
 // Global declarations and documentation kept for IDEs and PHP documentors.
diff --git a/extension.json b/extension.json
index 9cd5ab9..cc81984 100644
--- a/extension.json
+++ b/extension.json
@@ -11,7 +11,7 @@
        "license-name": "GPL-2.0+",
        "type": "antispam",
        "requires": {
-               "MediaWiki": ">= 1.25.0"
+               "MediaWiki": ">= 1.29.0"
        },
        "AvailableRights": [
                "abusefilter-modify",
@@ -181,7 +181,6 @@
        "Hooks": {
                "EditFilterMergedContent": 
"AbuseFilterHooks::onEditFilterMergedContent",
                "GetAutoPromoteGroups": 
"AbuseFilterHooks::onGetAutoPromoteGroups",
-               "AbortMove": "AbuseFilterHooks::onAbortMove",
                "MovePageCheckPermissions": 
"AbuseFilterHooks::onMovePageCheckPermissions",
                "ArticleDelete": "AbuseFilterHooks::onArticleDelete",
                "RecentChange_save": "AbuseFilterHooks::onRecentChangeSave",
@@ -189,7 +188,6 @@
                "ChangeTagsListActive": 
"AbuseFilterHooks::onChangeTagsListActive",
                "LoadExtensionSchemaUpdates": 
"AbuseFilterHooks::onLoadExtensionSchemaUpdates",
                "ContributionsToolLinks": 
"AbuseFilterHooks::onContributionsToolLinks",
-               "UploadVerifyFile": "AbuseFilterHooks::onUploadVerifyFile",
                "UploadVerifyUpload": "AbuseFilterHooks::onUploadVerifyUpload",
                "UploadStashFile": "AbuseFilterHooks::onUploadStashFile",
                "MakeGlobalVariablesScript": 
"AbuseFilterHooks::onMakeGlobalVariablesScript",
diff --git a/includes/AbuseFilter.class.php b/includes/AbuseFilter.class.php
index 8a91828..07736b2 100644
--- a/includes/AbuseFilter.class.php
+++ b/includes/AbuseFilter.class.php
@@ -341,11 +341,9 @@
 
                global $wgDisableCounters;
                if ( !$wgDisableCounters && !$title->isSpecialPage() ) {
-                       // Support: MediaWiki 1.24 and earlier
-                       if ( method_exists( 'WikiPage', 'getCount' ) ) {
-                               $vars->setVar( $prefix . '_VIEWS', 
WikiPage::factory( $title )->getCount() );
-                               // Support: MediaWiki 1.25+ with HitCounters 
extension
-                       } elseif ( method_exists( 'HitCounters\HitCounters', 
'getCount' ) ) {
+                       // Support: HitCounters extension
+                       // XXX: This should be part of the extension (T159069)
+                       if ( method_exists( 'HitCounters\HitCounters', 
'getCount' ) ) {
                                $vars->setVar( $prefix . '_VIEWS', 
HitCounters\HitCounters::getCount( $title ) );
                        }
                }
@@ -947,7 +945,7 @@
                } else {
                        $status = self::executeFilterActions( $matched_filters, 
$title, $vars );
 
-                       $actions_taken = $status->value; // getValue() was 
introduced only in 1.20
+                       $actions_taken = $status->getValue();
 
                        $action = $vars->getVar( 'ACTION' )->toString();
 
@@ -1136,9 +1134,7 @@
 
                        // Send data to CheckUser if installed and we
                        // aren't already sending a notification to 
recentchanges
-                       // Requires MW 1.23+
                        if ( is_callable( 'CheckUserHooks::updateCheckUserData' 
)
-                               && is_callable( 
'ManualLogEntry::getRecentChange' )
                                && strpos( $wgAbuseFilterNotifications, 'rc' ) 
=== false
                        ) {
                                $rc = $entry->getRecentChange();
@@ -1842,31 +1838,7 @@
         */
        public static function getFilterUser() {
                $username = wfMessage( 'abusefilter-blocker' 
)->inContentLanguage()->text();
-               if ( method_exists( 'User', 'newSystemUser' ) ) {
-                       $user = User::newSystemUser( $username, [ 'steal' => 
true ] );
-               } else {
-                       $user = User::newFromName( $username );
-                       $user->load();
-                       if ( $user->getId() && $user->mPassword == '' ) {
-                               // Already set up.
-                               return $user;
-                       }
-
-                       // Not set up. Create it.
-                       if ( !$user->getId() ) {
-                               print 'Trying to create account -- user id is ' 
. $user->getId();
-                               $user->addToDatabase();
-                               $user->saveSettings();
-                               // Increment site_stats.ss_users
-                               $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
-                               $ssu->doUpdate();
-                       } else {
-                               // Take over the account
-                               $user->setPassword( null );
-                               $user->setEmail( null );
-                               $user->saveSettings();
-                       }
-               }
+               $user = User::newSystemUser( $username, [ 'steal' => true ] );
 
                // Promote user to 'sysop' so it doesn't look
                // like an unprivileged account is blocking users
diff --git a/includes/AbuseFilter.hooks.php b/includes/AbuseFilter.hooks.php
index fdba9a5..dbbbdba 100644
--- a/includes/AbuseFilter.hooks.php
+++ b/includes/AbuseFilter.hooks.php
@@ -17,7 +17,7 @@
         */
        public static function onRegistration() {
                global $wgAbuseFilterAvailableActions, 
$wgAbuseFilterRestrictedActions,
-                       $wgDisableAuthManager, $wgAuthManagerAutoConfig;
+                       $wgAuthManagerAutoConfig;
 
                if ( isset( $wgAbuseFilterAvailableActions ) || isset( 
$wgAbuseFilterRestrictedActions ) ) {
                        wfWarn( '$wgAbuseFilterAvailableActions and 
$wgAbuseFilterRestrictedActions have been '
@@ -26,15 +26,10 @@
                                . 'array and the values are booleans.' );
                }
 
-               if ( class_exists( AuthManager::class ) && 
!$wgDisableAuthManager ) {
-                       
$wgAuthManagerAutoConfig['preauth'][AbuseFilterPreAuthenticationProvider::class]
 = [
-                               'class' => 
AbuseFilterPreAuthenticationProvider::class,
-                               'sort' => 5, // run after normal preauth 
providers to keep the log cleaner
-                       ];
-               } else {
-                       Hooks::register( 'AbortNewAccount', 
'AbuseFilterHooks::onAbortNewAccount' );
-                       Hooks::register( 'AbortAutoAccount', 
'AbuseFilterHooks::onAbortAutoAccount' );
-               }
+               
$wgAuthManagerAutoConfig['preauth'][AbuseFilterPreAuthenticationProvider::class]
 = [
+                       'class' => AbuseFilterPreAuthenticationProvider::class,
+                       'sort' => 5, // run after normal preauth providers to 
keep the log cleaner
+               ];
        }
 
        /**
@@ -293,14 +288,10 @@
         * @return bool
         */
        protected static function identicalPageObjects( $page1, $page2 ) {
-               if ( method_exists( 'Article', 'getPage' ) ) {
-                       $wpage1 = ( $page1 instanceof Article ) ? 
$page1->getPage() : $page1;
-                       $wpage2 = ( $page2 instanceof Article ) ? 
$page2->getPage() : $page2;
+               $wpage1 = ( $page1 instanceof Article ) ? $page1->getPage() : 
$page1;
+               $wpage2 = ( $page2 instanceof Article ) ? $page2->getPage() : 
$page2;
 
-                       return ( $wpage1 === $wpage2 );
-               } else { // b/c for before WikiPage
-                       return ( $page1 === $page2 ); // should be two Article 
objects
-               }
+               return $wpage1 === $wpage2;
        }
 
        /**
@@ -343,33 +334,6 @@
                $status->merge( $result );
 
                return $result->isOK();
-       }
-
-       /**
-        * @param Title $oldTitle
-        * @param Title $newTitle
-        * @param User $user
-        * @param string $error
-        * @param string $reason
-        * @return bool
-        */
-       public static function onAbortMove( $oldTitle, $newTitle, $user, 
&$error, $reason ) {
-               global $wgUser;
-               // HACK: This is a secret userright so system actions
-               // can bypass AbuseFilter. Should not be assigned to
-               // normal users. This should be turned into a proper
-               // userright in bug 67936.
-               if ( $wgUser->isAllowed( 'abusefilter-bypass' ) ) {
-                       return true;
-               }
-
-               $status = new Status();
-               self::onMovePageCheckPermissions( $oldTitle, $newTitle, 
$wgUser, $reason, $status );
-               if ( !$status->isOK() ) {
-                       $error = $status->getHTML();
-               }
-
-               return $status->isOK();
        }
 
        /**
@@ -704,25 +668,7 @@
                $user = User::newFromName( $username );
 
                if ( $user && !$updater->updateRowExists( 'create 
abusefilter-blocker-user' ) ) {
-                       if ( method_exists( 'User', 'newSystemUser' ) ) {
-                               $user = User::newSystemUser( $username, [ 
'steal' => true ] );
-                       } else {
-                               if ( !$user->getId() ) {
-                                       $user->addToDatabase();
-                                       $user->saveSettings();
-                                       # Increment site_stats.ss_users
-                                       $ssu = new SiteStatsUpdate( 0, 0, 0, 0, 
1 );
-                                       $ssu->doUpdate();
-                               } else {
-                                       // Sorry dude, we need this account.
-                                       $user->setPassword( null );
-                                       $user->setEmail( null );
-                                       $user->saveSettings();
-                               }
-                       }
-                       $updater->insertUpdateRow( 'create 
abusefilter-blocker-user' );
-                       # Promote user so it doesn't look too crazy.
-                       $user->addGroup( 'sysop' );
+                       $user = User::newSystemUser( $username, [ 'steal' => 
true ] );
                }
        }
 
@@ -730,28 +676,19 @@
         * @param $id
         * @param Title $nt
         * @param array $tools
-        * @param SpecialPage|null $sp for context in newer MW versions
-        * @return bool
+        * @param SpecialPage $sp for context
         */
-       public static function onContributionsToolLinks( $id, $nt, &$tools, 
SpecialPage $sp = null ) {
-               if ( $sp ) {
-                       $context = $sp->getContext();
-               } else {
-                       // Fallback to main context
-                       $context = RequestContext::getMain();
-               }
-               if ( $context->getUser()->isAllowed( 'abusefilter-log' ) ) {
-                       $linkRenderer = 
MediaWikiServices::getInstance()->getLinkRenderer();
-                       $tools[] = $linkRenderer->makeLink(
+       public static function onContributionsToolLinks( $id, $nt, &$tools, 
SpecialPage $sp ) {
+               if ( $sp->getUser()->isAllowed( 'abusefilter-log' ) ) {
+                       $linkRenderer = $sp->getLinkRenderer();
+                       $tools['abuselog'] = $linkRenderer->makeLink(
                                SpecialPage::getTitleFor( 'AbuseLog' ),
-                               $context->msg( 'abusefilter-log-linkoncontribs' 
)->text(),
-                               [ 'title' => $context->msg( 
'abusefilter-log-linkoncontribs-text',
-                                       $nt->getText() )->parse() ],
+                               $sp->msg( 'abusefilter-log-linkoncontribs' 
)->text(),
+                               [ 'title' => $sp->msg( 
'abusefilter-log-linkoncontribs-text',
+                                       $nt->getText() )->text() ],
                                [ 'wpSearchUser' => $nt->getText() ]
                        );
                }
-
-               return true;
        }
 
        /**
@@ -789,29 +726,7 @@
        }
 
        /**
-        * @param UploadBase $upload
-        * @param string $mime
-        * @param array|ApiMessage &$error
-        * @return bool
-        */
-       public static function onUploadVerifyFile( $upload, $mime, &$error ) {
-               global $wgUser, $wgVersion;
-
-               // We only use this hook on MW 1.27 and older, as it's is the 
only hook we have.
-               // On MW 1.28 and newer, we use UploadVerifyUpload to check 
file uploads, and
-               // UploadStashFile to check file uploads to stash.
-               if ( version_compare( $wgVersion, '1.28', '>=' ) ) {
-                       return;
-               }
-
-               // UploadBase makes it absolutely impossible to get these out 
of it, even though it knows them.
-               $props = FSFile::getPropsFromPath( $upload->getTempPath() );
-
-               return self::filterUpload( 'upload', $upload, $wgUser, $props, 
null, null, $error );
-       }
-
-       /**
-        * Implementation for UploadVerifyFile and UploadVerifyUpload hooks.
+        * Implementation for UploadStashFile and UploadVerifyUpload hooks.
         *
         * @param string $action 'upload' or 'stashupload'
         * @param UploadBase $upload
diff --git a/includes/api/ApiQueryAbuseLog.php 
b/includes/api/ApiQueryAbuseLog.php
index a86fbe9..3aea434 100644
--- a/includes/api/ApiQueryAbuseLog.php
+++ b/includes/api/ApiQueryAbuseLog.php
@@ -58,23 +58,11 @@
                $fld_hidden = isset( $prop['hidden'] );
                $fld_revid = isset( $prop['revid'] );
 
-               if ( is_callable( [ $this, 'checkUserRightsAny' ] ) ) {
-                       if ( $fld_ip ) {
-                               $this->checkUserRightsAny( 
'abusefilter-private' );
-                       }
-                       if ( $fld_details ) {
-                               $this->checkUserRightsAny( 
'abusefilter-log-detail' );
-                       }
-               } else {
-                       if ( $fld_ip && !$user->isAllowed( 
'abusefilter-private' ) ) {
-                               $this->dieUsage( 'You don\'t have permission to 
view IP addresses', 'permissiondenied' );
-                       }
-                       if ( $fld_details && !$user->isAllowed( 
'abusefilter-log-detail' ) ) {
-                               $this->dieUsage(
-                                       'You don\'t have permission to view 
detailed abuse log entries',
-                                       'permissiondenied'
-                               );
-                       }
+               if ( $fld_ip ) {
+                       $this->checkUserRightsAny( 'abusefilter-private' );
+               }
+               if ( $fld_details ) {
+                       $this->checkUserRightsAny( 'abusefilter-log-detail' );
                }
                // Match permissions for viewing events on private filters to 
SpecialAbuseLog (bug 42814)
                if ( $params['filter'] &&
@@ -86,16 +74,9 @@
                        }
                        foreach ( $params['filter'] as $filter ) {
                                if ( AbuseFilter::filterHidden( $filter ) ) {
-                                       if ( is_callable( [ $this, 
'dieWithError' ] ) ) {
-                                               $this->dieWithError(
-                                                       [ 
'apierror-permissiondenied', $this->msg( 'action-abusefilter-log-private' ) ]
-                                               );
-                                       } else {
-                                               $this->dieUsage(
-                                                       'You don\'t have 
permission to view log entries for private filters',
-                                                       'permissiondenied'
-                                               );
-                                       }
+                                       $this->dieWithError(
+                                               [ 'apierror-permissiondenied', 
$this->msg( 'action-abusefilter-log-private' ) ]
+                                       );
                                }
                        }
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/370629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iec237b2887f72b115fdcef78d2d7a944ba82c784
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Huji <huji.h...@gmail.com>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to