Matěj Suchánek has uploaded a new change for review. ( 
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.

(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, 30 insertions(+), 144 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter 
refs/changes/29/370629/1

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..9488aa4 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",
diff --git a/includes/AbuseFilter.class.php b/includes/AbuseFilter.class.php
index f0af762..6ea294d 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 b102341..2e9ab97 100644
--- a/includes/AbuseFilter.hooks.php
+++ b/includes/AbuseFilter.hooks.php
@@ -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 $oldTitle Title
-        * @param $newTitle Title
-        * @param $user User
-        * @param $error
-        * @param $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();
        }
 
        /**
@@ -730,28 +694,19 @@
         * @param $id
         * @param $nt Title
         * @param $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;
        }
 
        /**
@@ -786,28 +741,6 @@
                array $props, &$error
        ) {
                return self::filterUpload( 'stashupload', $upload, $user, 
$props, null, null, $error );
-       }
-
-       /**
-        * @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 );
        }
 
        /**
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: newchange
Gerrit-Change-Id: Iec237b2887f72b115fdcef78d2d7a944ba82c784
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchane...@gmail.com>

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

Reply via email to