(bug 28952) Add tofragment to the redirect resolution info.
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 14 May 2011 12:48:07 +0000 (12:48 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 14 May 2011 12:48:07 +0000 (12:48 +0000)
Changes the format of ApiPageSet::getRedirectTitles() from returning prefixed text strings to returning title objects so we can obtain the fragment info

includes/api/ApiPageSet.php
includes/api/ApiQuery.php

index dc7ea95..fdee6fe 100644 (file)
@@ -212,7 +212,7 @@ class ApiPageSet extends ApiQueryBase {
        /**
         * Get a list of redirect resolutions - maps a title to its redirect
         * target.
-        * @return array prefixed_title (string) => prefixed_title (string)
+        * @return array prefixed_title (string) => Title object
         */
        public function getRedirectTitles() {
                return $this->mRedirectTitles;
@@ -610,16 +610,17 @@ class ApiPageSet extends ApiQueryBase {
                        array(
                                'rd_from',
                                'rd_namespace',
+                               'rd_fragment',
+                               'rd_interwiki',
                                'rd_title'
                        ), array( 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ),
                        __METHOD__
                );
                $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 )->getPrefixedText();
+                       $to = Title::makeTitle( $row->rd_namespace, $row->rd_title, $row->rd_fragment, $row->rd_interwiki );
                        unset( $this->mPendingRedirectIDs[$rdfrom] );
                        if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
                                $lb->add( $row->rd_namespace, $row->rd_title );
@@ -638,7 +639,7 @@ class ApiPageSet extends ApiQueryBase {
                                        continue;
                                }
                                $lb->addObj( $rt );
-                               $this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText();
+                               $this->mRedirectTitles[$title->getPrefixedText()] = $rt;
                                unset( $this->mPendingRedirectIDs[$id] );
                        }
                }
index 1292f75..f621041 100644 (file)
@@ -381,11 +381,15 @@ class ApiQuery extends ApiBase {
 
                // Show redirect information
                $redirValues = array();
-               foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo ) {
-                       $redirValues[] = array(
+               foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleTo ) {
+                       $r = array(
                                'from' => strval( $titleStrFrom ),
-                               'to' => $titleStrTo
+                               'to' => $titleTo->getPrefixedText(),
                        );
+                       if ( $titleTo->getFragment() !== '' ) {
+                               $r['tofragment'] = $titleTo->getFragment();
+                       }
+                       $redirValues[] = $r;
                }
 
                if ( count( $redirValues ) ) {