Part of bug 23254 - Add interwiki links to parse output
authorSam Reed <reedy@users.mediawiki.org>
Tue, 25 May 2010 13:47:22 +0000 (13:47 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Tue, 25 May 2010 13:47:22 +0000 (13:47 +0000)
includes/api/ApiParse.php

index 86cadc1..7a37a32 100644 (file)
@@ -51,7 +51,7 @@ class ApiParse extends ApiBase {
                }
                $prop = array_flip( $params['prop'] );
                $revid = false;
-               
+
                if ( isset( $params['section'] ) ) {
                        $this->section = $params['section'];
                } else {
@@ -211,6 +211,7 @@ class ApiParse extends ApiBase {
                if ( isset( $prop['sections'] ) ) {
                        $result_array['sections'] = $p_result->getSections();
                }
+
                if ( isset( $prop['displaytitle'] ) ) {
                        $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
                                                        $p_result->getDisplayTitle() :
@@ -238,6 +239,10 @@ class ApiParse extends ApiBase {
                        $result_array['headhtml'] = array();
                        $result->setContent( $result_array['headhtml'], $out->headElement( $userSkin ) );
                }
+               
+               if ( isset( $prop['iwlinks'] ) ) {
+                       $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
+               }
 
                if ( !is_null( $oldid ) ) {
                        $result_array['revid'] = intval( $oldid );
@@ -251,6 +256,7 @@ class ApiParse extends ApiBase {
                        'templates' => 'tl',
                        'images' => 'img',
                        'externallinks' => 'el',
+                       'iwlinks' => 'iw',
                        'sections' => 's',
                        'headitems' => 'hi',
                );
@@ -310,6 +316,19 @@ class ApiParse extends ApiBase {
                return $result;
        }
 
+       private function formatIWLinks( $iw ) {
+               $result = array();
+               foreach ( $iw as $prefix => $titles ) {
+                       foreach ( $titles as $title => $id ) {
+                               $entry = array();
+                               $entry['prefix'] = $prefix;
+                               $this->getResult()->setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
+                               $result[] = $entry;
+                       }
+               }
+               return $result;
+       }
+
        private function formatHeadItems( $headItems ) {
                $result = array();
                foreach ( $headItems as $tag => $content ) {
@@ -366,7 +385,8 @@ class ApiParse extends ApiBase {
                                        'revid',
                                        'displaytitle',
                                        'headitems',
-                                       'headhtml'
+                                       'headhtml',
+                                       'iwlinks',
                                )
                        ),
                        'pst' => false,