Add option to show only creations in Special:Contribs, API
[lhc/web/wiklou.git] / includes / api / ApiQueryUserContributions.php
index 7896a2c..9ad77d4 100644 (file)
@@ -207,10 +207,16 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
 
                $show = $this->params['show'];
+               if ( $this->params['toponly'] ) { // deprecated/old param
+                       $show[] = 'top';
+               }
                if ( !is_null( $show ) ) {
                        $show = array_flip( $show );
+
                        if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) )
                                || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
+                               || ( isset( $show['top'] ) && isset( $show['!top'] ) )
+                               || ( isset( $show['new'] ) && isset( $show['!new'] ) )
                        ) {
                                $this->dieUsageMsg( 'show' );
                        }
@@ -219,6 +225,10 @@ class ApiQueryContributions extends ApiQueryBase {
                        $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( 'rev_id != page_latest', isset( $show['!top'] ) );
+                       $this->addWhereIf( 'rev_id = page_latest', isset( $show['top'] ) );
+                       $this->addWhereIf( 'rev_parent_id != 0', isset( $show['!new'] ) );
+                       $this->addWhereIf( 'rev_parent_id = 0', isset( $show['new'] ) );
                }
                $this->addOption( 'LIMIT', $this->params['limit'] + 1 );
                $index = array( 'revision' => 'usertext_timestamp' );
@@ -294,10 +304,6 @@ class ApiQueryContributions extends ApiQueryBase {
                        $this->addWhereFld( 'ct_tag', $this->params['tag'] );
                }
 
-               if ( $this->params['toponly'] ) {
-                       $this->addWhere( 'rev_id = page_latest' );
-               }
-
                $this->addOption( 'USE INDEX', $index );
        }
 
@@ -360,7 +366,13 @@ class ApiQueryContributions extends ApiQueryBase {
                                $vals['commenthidden'] = '';
                                $anyHidden = true;
                        }
-                       if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_COMMENT, $this->getUser() ) ) {
+
+                       $userCanView = Revision::userCanBitfield(
+                               $row->rev_deleted,
+                               Revision::DELETED_COMMENT, $this->getUser()
+                       );
+
+                       if ( $userCanView ) {
                                if ( $this->fld_comment ) {
                                        $vals['comment'] = $row->rev_comment;
                                }
@@ -471,10 +483,17 @@ class ApiQueryContributions extends ApiQueryBase {
                                        '!minor',
                                        'patrolled',
                                        '!patrolled',
+                                       'top',
+                                       '!top',
+                                       'new',
+                                       '!new',
                                )
                        ),
                        'tag' => null,
-                       'toponly' => false,
+                       'toponly' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                );
        }