raise timeout for CdbTest::testCdb()
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index bee8046..e2f4dae 100644 (file)
@@ -624,43 +624,10 @@ class ApiPageSet extends ApiQueryBase {
         * @return LinkBatch
         */
        private function getRedirectTargets() {
-               $redirectTitles = $this->resolveIdsToRedirectTargets( array_keys( $this->mPendingRedirectIDs ), 'profileDB' );
-
                $lb = new LinkBatch();
-               foreach( $this->mPendingRedirectIDs as $rdfrom => $from ) {
-                       if( !isset( $redirectTitles[$rdfrom] ) ) {
-                               continue;
-                       }
-                       $to = $redirectTitles[$rdfrom];
-                       if ( $to && !isset( $this->mAllPages[$to->getNamespace()][$to->getText()] ) ) {
-                               $lb->addObj( $to );
-                       }
-                       $this->mRedirectTitles[$from->getPrefixedText()] = $to;
-               }
-               return $lb;
-       }
-
-       /**
-        * Get the targets of redirects from the database
-        *
-        * Also creates entries in the redirect table for redirects that don't
-        * have one.
-        *
-        * @param $redirectIDs array The array of pageids to resolve
-        * @param $profileDB string if profileDBIn should called
-        * @return array id => redirect target as title
-        * @since 1.21
-        */
-       public function resolveIdsToRedirectTargets( $redirectIDs, $profileDB = '' ) {
-               if( !$redirectIDs ) {
-                       return array();
-               }
-
                $db = $this->getDB();
 
-               if( $profileDB ) {
-                       $this->profileDBIn();
-               }
+               $this->profileDBIn();
                $res = $db->select(
                        'redirect',
                        array(
@@ -669,38 +636,37 @@ class ApiPageSet extends ApiQueryBase {
                                'rd_fragment',
                                'rd_interwiki',
                                'rd_title'
-                       ), array( 'rd_from' => $redirectIDs ),
+                       ), array( 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ),
                        __METHOD__
                );
-               if( $profileDB ) {
-                       $this->profileDBOut();
-               }
-
-               $redirectTitles = array();
+               $this->profileDBOut();
                foreach ( $res as $row ) {
                        $rdfrom = intval( $row->rd_from );
+                       $from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
                        $to = Title::makeTitle( $row->rd_namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki );
-                       $redirectTitles[$rdfrom] = $to;
+                       unset( $this->mPendingRedirectIDs[$rdfrom] );
+                       if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
+                               $lb->add( $row->rd_namespace, $row->rd_title );
+                       }
+                       $this->mRedirectTitles[$from] = $to;
                }
 
-               $unresolvedRedirectIDs = array_diff( $redirectIDs, array_keys( $redirectTitles ) );
-               if ( $unresolvedRedirectIDs ) {
+               if ( $this->mPendingRedirectIDs ) {
                        // We found pages that aren't in the redirect table
                        // Add them
-                       foreach ( $unresolvedRedirectIDs as $id ) {
-                               $page = WikiPage::newFromID( $id );
-                               if ( !$page ) {
-                                       continue;
-                               }
+                       foreach ( $this->mPendingRedirectIDs as $id => $title ) {
+                               $page = WikiPage::factory( $title );
                                $rt = $page->insertRedirect();
                                if ( !$rt ) {
                                        // What the hell. Let's just ignore this
                                        continue;
                                }
-                               $redirectTitles[$id] = $rt;
+                               $lb->addObj( $rt );
+                               $this->mRedirectTitles[$title->getPrefixedText()] = $rt;
+                               unset( $this->mPendingRedirectIDs[$id] );
                        }
                }
-               return $redirectTitles;
+               return $lb;
        }
 
        /**
@@ -739,9 +705,10 @@ class ApiPageSet extends ApiQueryBase {
                                if ( $this->mConvertTitles &&
                                                count( $wgContLang->getVariants() ) > 1  &&
                                                !$titleObj->exists() ) {
-                                       // Language::findVariantLink will modify titleObj into
+                                       // Language::findVariantLink will modify titleText and titleObj into
                                        // the canonical variant if possible
-                                       $wgContLang->findVariantLink( $title, $titleObj );
+                                       $titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText();
+                                       $wgContLang->findVariantLink( $titleText, $titleObj );
                                        $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
                                }
 
@@ -762,7 +729,11 @@ class ApiPageSet extends ApiQueryBase {
                        // namespace is localized or the capitalization is
                        // different
                        if ( $titleWasConverted ) {
-                               $this->mConvertedTitles[$title] = $titleObj->getPrefixedText();
+                               $this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
+                               // In this case the page can't be Special.
+                               if ( is_string( $title ) && $title !== $unconvertedTitle ) {
+                                       $this->mNormalizedTitles[$title] = $unconvertedTitle;
+                               }
                        } elseif ( is_string( $title ) && $title !== $titleObj->getPrefixedText() ) {
                                $this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
                        }
@@ -820,8 +791,4 @@ class ApiPageSet extends ApiQueryBase {
                        array( 'code' => 'multisource', 'info' => "Cannot use 'revids' at the same time as 'dataSource'" ),
                ) );
        }
-
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }
 }