X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fchanges%2FRecentChange.php;h=5fad8fd9ea5b6fe8c4b4158e298a747eea06107d;hp=13a5fc7b80b3faa3cfc4180c55958277901113fc;hb=d1cf48a397edbbe9c6a63d6f83861d676f686d07;hpb=58f10b2598e0b456e92eb8068b7e424af95ec2e2 diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 13a5fc7b80..5fad8fd9ea 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -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,62 +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'" ); } - if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) { return $wgRCEngines[$scheme]; } - return new $wgRCEngines[$scheme]; + return new $wgRCEngines[$scheme]( $params ); } /** @@ -471,7 +459,7 @@ class RecentChange { $change = $change instanceof RecentChange ? $change - : RecentChange::newFromId( $change ); + : self::newFromId( $change ); if ( !$change instanceof RecentChange ) { return null; @@ -886,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() ] ) ]; @@ -923,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 ); + } + } } /**