Replace rc_patrolled values with contants, part I
authorAmir Sarabadani <ladsgroup@gmail.com>
Wed, 11 Apr 2018 20:20:55 +0000 (22:20 +0200)
committerAmir Sarabadani <ladsgroup@gmail.com>
Wed, 11 Apr 2018 20:35:31 +0000 (22:35 +0200)
This constants has been recently introduced and it's good to use them

Change-Id: I8ce56dc95de3e49610dca71c00965ca1ac74bcf0

includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryUserContributions.php
includes/api/ApiQueryWatchlist.php
includes/changes/RecentChange.php
includes/diff/DifferenceEngine.php
includes/logging/LogEntry.php
includes/page/WikiPage.php

index 9ff4149..326debc 100644 (file)
@@ -235,15 +235,21 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        if ( isset( $show['unpatrolled'] ) ) {
                                // See ChangesList::isUnpatrolled
                                if ( $user->useRCPatrol() ) {
-                                       $this->addWhere( 'rc_patrolled = 0' );
+                                       $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
                                } elseif ( $user->useNPPatrol() ) {
-                                       $this->addWhere( 'rc_patrolled = 0' );
+                                       $this->addWhere( 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
                                        $this->addWhereFld( 'rc_type', RC_NEW );
                                }
                        }
 
-                       $this->addWhereIf( 'rc_patrolled != 2', isset( $show['!autopatrolled'] ) );
-                       $this->addWhereIf( 'rc_patrolled = 2', isset( $show['autopatrolled'] ) );
+                       $this->addWhereIf(
+                               'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
+                               isset( $show['!autopatrolled'] )
+                       );
+                       $this->addWhereIf(
+                               'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
+                               isset( $show['autopatrolled'] )
+                       );
 
                        // Don't throw log entries out the window here
                        $this->addWhereIf(
@@ -552,9 +558,9 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
 
                /* Add the patrolled flag */
                if ( $this->fld_patrolled ) {
-                       $vals['patrolled'] = $row->rc_patrolled != 0;
+                       $vals['patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
                        $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
-                       $vals['autopatrolled'] = $row->rc_patrolled == 2;
+                       $vals['autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
                }
 
                if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
index f6bc8cb..12f42ed 100644 (file)
@@ -540,10 +540,22 @@ class ApiQueryContributions extends ApiQueryBase {
 
                        $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) );
                        $this->addWhereIf( 'rev_minor_edit != 0', isset( $show['minor'] ) );
-                       $this->addWhereIf( 'rc_patrolled = 0', isset( $show['!patrolled'] ) );
-                       $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
-                       $this->addWhereIf( 'rc_patrolled != 2', isset( $show['!autopatrolled'] ) );
-                       $this->addWhereIf( 'rc_patrolled = 2', isset( $show['autopatrolled'] ) );
+                       $this->addWhereIf(
+                               'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
+                               isset( $show['!patrolled'] )
+                       );
+                       $this->addWhereIf(
+                               'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
+                               isset( $show['patrolled'] )
+                       );
+                       $this->addWhereIf(
+                               'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
+                               isset( $show['!autopatrolled'] )
+                       );
+                       $this->addWhereIf(
+                               'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
+                               isset( $show['autopatrolled'] )
+                       );
                        $this->addWhereIf( $idField . ' != page_latest', isset( $show['!top'] ) );
                        $this->addWhereIf( $idField . ' = page_latest', isset( $show['top'] ) );
                        $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
index 52ad26c..bb09838 100644 (file)
@@ -375,9 +375,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
 
                /* Add the patrolled flag */
                if ( $this->fld_patrol ) {
-                       $vals['patrolled'] = $recentChangeInfo['rc_patrolled'] != 0;
+                       $vals['patrolled'] = $recentChangeInfo['rc_patrolled'] != RecentChange::PRC_UNPATROLLED;
                        $vals['unpatrolled'] = ChangesList::isUnpatrolled( (object)$recentChangeInfo, $user );
-                       $vals['autopatrolled'] = $recentChangeInfo['rc_patrolled'] == 2;
+                       $vals['autopatrolled'] = $recentChangeInfo['rc_patrolled'] == RecentChange::PRC_AUTOPATROLLED;
                }
 
                if ( $this->fld_loginfo && $recentChangeInfo['rc_type'] == RC_LOG ) {
index b051120..2f41905 100644 (file)
@@ -622,7 +622,7 @@ class RecentChange {
                $dbw->update(
                        'recentchanges',
                        [
-                               'rc_patrolled' => 1
+                               'rc_patrolled' => self::PRC_PATROLLED
                        ],
                        [
                                'rc_id' => $this->getAttribute( 'rc_id' )
@@ -890,7 +890,7 @@ class RecentChange {
                        'rc_last_oldid' => 0,
                        'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
                        'rc_ip' => self::checkIPAddress( $ip ),
-                       'rc_patrolled' => $markPatrolled ? 1 : 0,
+                       'rc_patrolled' => $markPatrolled ? self::PRC_PATROLLED : self::PRC_UNPATROLLED,
                        'rc_new' => 0, # obsolete
                        'rc_old_len' => null,
                        'rc_new_len' => null,
@@ -976,7 +976,7 @@ class RecentChange {
                        'rc_last_oldid' => $oldRevId,
                        'rc_bot' => $bot ? 1 : 0,
                        'rc_ip' => self::checkIPAddress( $ip ),
-                       'rc_patrolled' => 1, // Always patrolled, just like log entries
+                       'rc_patrolled' => self::PRC_PATROLLED, // Always patrolled, just like log entries
                        'rc_new' => 0, # obsolete
                        'rc_old_len' => null,
                        'rc_new_len' => null,
index 037a80f..8f57c57 100644 (file)
@@ -542,7 +542,7 @@ class DifferenceEngine extends ContextSource {
                                [
                                        'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
                                        'rc_this_oldid' => $this->mNewid,
-                                       'rc_patrolled' => 0
+                                       'rc_patrolled' => RecentChange::PRC_UNPATROLLED
                                ],
                                __METHOD__
                        );
index c672ef7..97dadba 100644 (file)
@@ -785,7 +785,7 @@ class ManualLogEntry extends LogEntryBase {
 
                                        // Log the autopatrol if the log entry is patrollable
                                        if ( $this->getIsPatrollable() &&
-                                               $rc->getAttribute( 'rc_patrolled' ) === 2
+                                               $rc->getAttribute( 'rc_patrolled' ) === RecentChange::PRC_AUTOPATROLLED
                                        ) {
                                                PatrolLog::record( $rc, true, $this->getPerformer() );
                                        }
index f45036c..e5232d3 100644 (file)
@@ -3269,7 +3269,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                if ( $wgUseRCPatrol ) {
                        // Mark all reverted edits as patrolled
-                       $set['rc_patrolled'] = 1;
+                       $set['rc_patrolled'] = RecentChange::PRC_PATROLLED;
                }
 
                if ( count( $set ) ) {