Add show=unpatrolled to the recentchanges API
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 25 Oct 2013 10:11:08 +0000 (12:11 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 18 Nov 2013 05:03:32 +0000 (10:33 +0530)
Adding it only in the API because SpecialRecentChanges only shows
"Hide patrolled edits" option if rcpatrol is enabled.

show=!patrolled returns results that include changes that can't
be patrolled which technically correct (they aren't correct)
but probably not what you're looking for when looking for
unpatrolled changes.

Change-Id: I356a8625c7126b90aa7e7a23efe3bef7d448b502

includes/api/ApiQueryRecentChanges.php

index 7848853..50a3352 100644 (file)
@@ -192,12 +192,14 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                || ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
                                || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
                                || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
+                               || ( isset( $show['patrolled'] ) && isset( $show['unpatrolled'] ) )
+                               || ( isset( $show['!patrolled'] ) && isset( $show['unpatrolled'] ) )
                        ) {
                                $this->dieUsageMsg( 'show' );
                        }
 
                        // Check permissions
-                       if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
+                       if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) || isset( $show['unpatrolled'] ) ) {
                                if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
                                        $this->dieUsage(
                                                'You need the patrol right to request the patrolled flag',
@@ -217,6 +219,16 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        $this->addWhereIf( 'rc_patrolled != 0', isset( $show['patrolled'] ) );
                        $this->addWhereIf( 'page_is_redirect = 1', isset( $show['redirect'] ) );
 
+                       if ( isset( $show['unpatrolled'] ) ) {
+                               // See ChangesList:isUnpatrolled
+                               if ( $user->useRCPatrol() ) {
+                                       $this->addWhere( 'rc_patrolled = 0' );
+                               } elseif ( $user->useNPPatrol() ) {
+                                       $this->addWhere( 'rc_patrolled = 0' );
+                                       $this->addWhereFld( 'rc_type', RC_NEW );
+                               }
+                       }
+
                        // Don't throw log entries out the window here
                        $this->addWhereIf(
                                'page_is_redirect = 0 OR page_is_redirect IS NULL',
@@ -639,7 +651,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                        'redirect',
                                        '!redirect',
                                        'patrolled',
-                                       '!patrolled'
+                                       '!patrolled',
+                                       'unpatrolled'
                                )
                        ),
                        'limit' => array(