Revert r70703 and followup r70715: broke &redirect for API edit with a fatal error
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 23 Oct 2010 17:48:08 +0000 (17:48 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 23 Oct 2010 17:48:08 +0000 (17:48 +0000)
includes/api/ApiEditPage.php

index 83d9c16..fac787a 100644 (file)
@@ -57,16 +57,36 @@ class ApiEditPage extends ApiBase {
                if ( !$titleObj || $titleObj->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                }
+               
+               if( $params['redirect'] ) {
+                       if( $titleObj->isRedirect() ) {
+                               $oldTitle = $titleObj;
+                               
+                               $titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
+                               //array_shift( $titles );
+                               
+                               $this->getResult()->addValue( null, 'foo', $titles );
+                               
+                               
+                               $redirValues = array();
+                               foreach ( $titles as $id => $newTitle ) {
+                                       
+                                       if( !isset( $titles[ $id - 1 ] ) ) {
+                                               $titles[ $id - 1 ] = $oldTitle;
+                                       }
+                                       
+                                       $redirValues[] = array(
+                                               'from' => $titles[ $id - 1 ]->getPrefixedText(),
+                                               'to' => $newTitle->getPrefixedText()
+                                       );
+                                       
+                                       $titleObj = $newTitle;
+                               }
+               
+                               $this->getResult()->setIndexedTagName( $redirValues, 'r' );
+                               $this->getResult()->addValue( null, 'redirects', $redirValues );
 
-               if( $params['redirect'] && $titleObj->isRedirect() ) {
-                       $pageSet = new ApiPageSet( $this->getQuery(), true ); // Or true, true to also do variant conversion of titles
-                       $pageSet->populateFromTitles( array( $titleObj ) );
-                       foreach ( $pageSet->getRedirectTitles() as $from => $to ) {
-                               $redirsValues[] = array( 'from' => $from, 'to' => $to );
                        }
-
-                       $this->getResult()->setIndexedTagName( $redirValues, 'r' );
-                       $this->getResult()->addValue( null, 'redirects', $redirValues );
                }
 
                // Some functions depend on $wgTitle == $ep->mTitle