build: Update mediawiki/mediawiki-codesniffer to 0.10.1
[lhc/web/wiklou.git] / includes / changes / RecentChange.php
index 81f64a8..5fad8fd 100644 (file)
@@ -130,7 +130,7 @@ class RecentChange {
                if ( is_array( $type ) ) {
                        $retval = [];
                        foreach ( $type as $t ) {
-                               $retval[] = RecentChange::parseToRCType( $t );
+                               $retval[] = self::parseToRCType( $t );
                        }
 
                        return $retval;
@@ -329,7 +329,9 @@ class RecentChange {
                $this->mAttribs['rc_id'] = $dbw->insertId();
 
                # Notify extensions
-               Hooks::run( 'RecentChange_save', [ &$this ] );
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $rc = $this;
+               Hooks::run( 'RecentChange_save', [ &$rc ] );
 
                if ( count( $this->tags ) ) {
                        ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'],
@@ -389,8 +391,8 @@ class RecentChange {
 
                $performer = $this->getPerformer();
 
-               foreach ( $feeds as $feed ) {
-                       $feed += [
+               foreach ( $feeds as $params ) {
+                       $params += [
                                'omit_bots' => false,
                                'omit_anon' => false,
                                'omit_user' => false,
@@ -399,59 +401,48 @@ class RecentChange {
                        ];
 
                        if (
-                               ( $feed['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
-                               ( $feed['omit_anon'] && $performer->isAnon() ) ||
-                               ( $feed['omit_user'] && !$performer->isAnon() ) ||
-                               ( $feed['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
-                               ( $feed['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
+                               ( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
+                               ( $params['omit_anon'] && $performer->isAnon() ) ||
+                               ( $params['omit_user'] && !$performer->isAnon() ) ||
+                               ( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
+                               ( $params['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
                                $this->mAttribs['rc_type'] == RC_EXTERNAL
                        ) {
                                continue;
                        }
 
-                       $engine = self::getEngine( $feed['uri'] );
-
                        if ( isset( $this->mExtra['actionCommentIRC'] ) ) {
                                $actionComment = $this->mExtra['actionCommentIRC'];
                        } else {
                                $actionComment = null;
                        }
 
-                       /** @var $formatter RCFeedFormatter */
-                       $formatter = is_object( $feed['formatter'] ) ? $feed['formatter'] : new $feed['formatter']();
-                       $line = $formatter->getLine( $feed, $this, $actionComment );
-                       if ( !$line ) {
-                               // T109544
-                               // If a feed formatter returns null, this will otherwise cause an
-                               // error in at least RedisPubSubFeedEngine.
-                               // Not sure where/how this should best be handled.
-                               continue;
-                       }
-
-                       $engine->send( $feed, $line );
+                       $feed = RCFeed::factory( $params );
+                       $feed->notify( $this, $actionComment );
                }
        }
 
        /**
-        * Gets the stream engine object for a given URI from $wgRCEngines
-        *
+        * @since 1.22
+        * @deprecated since 1.29 Use RCFeed::factory() instead
         * @param string $uri URI to get the engine object for
-        * @throws MWException
         * @return RCFeedEngine The engine object
+        * @throws MWException
         */
-       public static function getEngine( $uri ) {
+       public static function getEngine( $uri, $params = [] ) {
+               // TODO: Merge into RCFeed::factory().
                global $wgRCEngines;
-
                $scheme = parse_url( $uri, PHP_URL_SCHEME );
                if ( !$scheme ) {
-                       throw new MWException( __FUNCTION__ . ": Invalid stream logger URI: '$uri'" );
+                       throw new MWException( "Invalid RCFeed uri: '$uri'" );
                }
-
                if ( !isset( $wgRCEngines[$scheme] ) ) {
-                       throw new MWException( __FUNCTION__ . ": Unknown stream logger URI scheme: $scheme" );
+                       throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
                }
-
-               return new $wgRCEngines[$scheme];
+               if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
+                       return $wgRCEngines[$scheme];
+               }
+               return new $wgRCEngines[$scheme]( $params );
        }
 
        /**
@@ -468,7 +459,7 @@ class RecentChange {
 
                $change = $change instanceof RecentChange
                        ? $change
-                       : RecentChange::newFromId( $change );
+                       : self::newFromId( $change );
 
                if ( !$change instanceof RecentChange ) {
                        return null;
@@ -883,7 +874,7 @@ class RecentChange {
                        'rc_logid' => 0,
                        'rc_log_type' => null,
                        'rc_log_action' => '',
-                       'rc_params' =>  serialize( [
+                       'rc_params' => serialize( [
                                'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
                        ] )
                ];
@@ -920,7 +911,16 @@ class RecentChange {
        public function loadFromRow( $row ) {
                $this->mAttribs = get_object_vars( $row );
                $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
-               $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
+               // rc_deleted MUST be set
+               $this->mAttribs['rc_deleted'] = $row->rc_deleted;
+
+               if ( isset( $this->mAttribs['rc_ip'] ) ) {
+                       // Clean up CIDRs for Postgres per T164898. ("127.0.0.1" casts to "127.0.0.1/32")
+                       $n = strpos( $this->mAttribs['rc_ip'], '/' );
+                       if ( $n !== false ) {
+                               $this->mAttribs['rc_ip'] = substr( $this->mAttribs['rc_ip'], 0, $n );
+                       }
+               }
        }
 
        /**