Fix exception in ApiPageSet
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 22 Jul 2013 17:08:31 +0000 (13:08 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 22 Jul 2013 18:12:38 +0000 (14:12 -0400)
ApiPageSet is calling $this->profileOut(), then calling a function that
calls $this->profileDBIn(). Move that function to after a new
$this->profileIn().

Also, add a unit test for this situation.

Bug: 51821
Change-Id: Ib4dbfb567faadcd5e3d7d058ca6bdf8b4c83f634

includes/api/ApiPageSet.php
tests/phpunit/includes/api/query/ApiQueryBasicTest.php

index 9fdad2b..b05cb2b 100644 (file)
@@ -152,7 +152,6 @@ class ApiPageSet extends ApiBase {
                        if ( !$isDryRun ) {
                                $generator->executeGenerator( $this );
                                wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$this ) );
-                               $this->resolvePendingRedirects();
                        } else {
                                // Prevent warnings from being reported on these parameters
                                $main = $this->getMain();
@@ -163,6 +162,10 @@ class ApiPageSet extends ApiBase {
                        $generator->profileOut();
                        $this->profileIn();
 
+                       if ( !$isDryRun ) {
+                               $this->resolvePendingRedirects();
+                       }
+
                        if ( !$isQuery ) {
                                // If this pageset is not part of the query, we called profileIn() above
                                $dbSource->profileOut();
index 403034b..1a2aa83 100644 (file)
@@ -320,6 +320,32 @@ class ApiQueryBasicTest extends ApiQueryTestBase {
                        self::$categorymembers ) );
        }
 
+       /**
+        * Test bug 51821
+        */
+       public function testGeneratorRedirects() {
+               $this->editPage( 'AQBT-Target', 'test' );
+               $this->editPage( 'AQBT-Redir', '#REDIRECT [[AQBT-Target]]' );
+               $this->check( array(
+                       array( 'generator' => 'backlinks', 'gbltitle' => 'AQBT-Target', 'redirects' => '1' ),
+                       array(
+                               'redirects' => array(
+                                       array(
+                                               'from' => 'AQBT-Redir',
+                                               'to' => 'AQBT-Target',
+                                       )
+                               ),
+                               'pages' => array(
+                                       '6' => array(
+                                               'pageid' => 6,
+                                               'ns' => 0,
+                                               'title' => 'AQBT-Target',
+                                       )
+                               ),
+                       )
+               ) );
+       }
+
        /**
         * Recursively merges the expected values in the $item into the $all
         */