Add ability to filter based on rc_title in API
authorAmir Sarabadani <ladsgroup@gmail.com>
Thu, 15 Mar 2018 17:03:24 +0000 (18:03 +0100)
committerAmir Sarabadani <ladsgroup@gmail.com>
Fri, 16 Mar 2018 13:58:52 +0000 (14:58 +0100)
Bug: T57377
Change-Id: I0b14bde58a4012816f2998d663d88ab035c927b7

includes/api/ApiQueryRecentChanges.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
tests/phpunit/includes/api/ApiQueryRecentChangesIntegrationTest.php

index e431202..65541db 100644 (file)
@@ -181,6 +181,16 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                        }
                }
 
+               $title = $params['title'];
+               if ( !is_null( $title ) ) {
+                       $titleObj = Title::newFromText( $title );
+                       if ( is_null( $titleObj ) ) {
+                               $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
+                       }
+                       $this->addWhereFld( 'rc_namespace', $titleObj->getNamespace() );
+                       $this->addWhereFld( 'rc_title', $titleObj->getDBkey() );
+               }
+
                if ( !is_null( $params['show'] ) ) {
                        $show = array_flip( $params['show'] );
 
@@ -710,6 +720,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
                                ApiBase::PARAM_TYPE => RecentChange::getChangeTypes()
                        ],
                        'toponly' => false,
+                       'title' => null,
                        'continue' => [
                                ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
                        ],
index 7568526..0764d8a 100644 (file)
        "apihelp-query+recentchanges-param-limit": "How many total changes to return.",
        "apihelp-query+recentchanges-param-type": "Which types of changes to show.",
        "apihelp-query+recentchanges-param-toponly": "Only list changes which are the latest revision.",
+       "apihelp-query+recentchanges-param-title": "Filter entries to those related to a page.",
        "apihelp-query+recentchanges-param-generaterevisions": "When being used as a generator, generate revision IDs rather than titles. Recent change entries without associated revision IDs (e.g. most log entries) will generate nothing.",
        "apihelp-query+recentchanges-example-simple": "List recent changes.",
        "apihelp-query+recentchanges-example-generator": "Get page info about recent unpatrolled changes.",
index fc0de4e..8b49fdc 100644 (file)
        "apihelp-query+recentchanges-param-limit": "{{doc-apihelp-param|query+recentchanges|limit}}",
        "apihelp-query+recentchanges-param-type": "{{doc-apihelp-param|query+recentchanges|type}}",
        "apihelp-query+recentchanges-param-toponly": "{{doc-apihelp-param|query+recentchanges|toponly}}",
+       "apihelp-query+recentchanges-param-title": "{{doc-apihelp-param|query+recentchanges|title}}",
        "apihelp-query+recentchanges-param-generaterevisions": "{{doc-apihelp-param|query+recentchanges|generaterevisions}}",
        "apihelp-query+recentchanges-example-simple": "{{doc-apihelp-example|query+recentchanges}}",
        "apihelp-query+recentchanges-example-generator": "{{doc-apihelp-example|query+recentchanges}}",
index 24b7500..a89c4ad 100644 (file)
@@ -860,6 +860,65 @@ class ApiQueryRecentChangesIntegrationTest extends ApiTestCase {
                );
        }
 
+       public function testTitleParams() {
+               $page1 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
+               $page2 = new TitleValue( 1, 'ApiQueryRecentChangesIntegrationTestPage2' );
+               $page3 = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage3' );
+               $this->doPageEdits(
+                       $this->getLoggedInTestUser(),
+                       [
+                               [
+                                       'target' => $page1,
+                                       'summary' => 'Create the page',
+                               ],
+                               [
+                                       'target' => $page2,
+                                       'summary' => 'Create the page',
+                               ],
+                               [
+                                       'target' => $page3,
+                                       'summary' => 'Create the page',
+                               ],
+                       ]
+               );
+
+               $result = $this->doListRecentChangesRequest(
+                       [
+                               'rctitle' => 'ApiQueryRecentChangesIntegrationTestPage',
+                               'rcprop' => 'title'
+                       ]
+               );
+
+               $result2 = $this->doListRecentChangesRequest(
+                       [
+                               'rctitle' => 'Talk:ApiQueryRecentChangesIntegrationTestPage2',
+                               'rcprop' => 'title'
+                       ]
+               );
+
+               $this->assertEquals(
+                       [
+                               [
+                                       'type' => 'new',
+                                       'ns' => $page1->getNamespace(),
+                                       'title' => $this->getPrefixedText( $page1 )
+                               ],
+                       ],
+                       $this->getItemsFromApiResponse( $result )
+               );
+
+               $this->assertEquals(
+                       [
+                               [
+                                       'type' => 'new',
+                                       'ns' => $page2->getNamespace(),
+                                       'title' => $this->getPrefixedText( $page2 )
+                               ],
+                       ],
+                       $this->getItemsFromApiResponse( $result2 )
+               );
+       }
+
        public function testStartEndParams() {
                $target = new TitleValue( 0, 'ApiQueryRecentChangesIntegrationTestPage' );
                $this->doPageEdit( $this->getLoggedInTestUser(), $target, 'Create the page' );