Part of fix/workaround to bug 26163. API calls to get language links and categories...
authorPriyanka Dhanda <pdhanda@users.mediawiki.org>
Mon, 6 Dec 2010 18:31:09 +0000 (18:31 +0000)
committerPriyanka Dhanda <pdhanda@users.mediawiki.org>
Mon, 6 Dec 2010 18:31:09 +0000 (18:31 +0000)
includes/api/ApiParse.php

index 9a88631..81a0e0c 100644 (file)
@@ -219,9 +219,19 @@ class ApiParse extends ApiBase {
                if ( isset( $prop['langlinks'] ) ) {
                        $result_array['langlinks'] = $this->formatLangLinks( $p_result->getLanguageLinks() );
                }
+               if ( isset( $prop['languageshtml'] ) ) {
+                       $languagesHtml = $this->languagesHtml( $p_result->getLanguageLinks() );
+                       $result_array['languageshtml'] = array();
+                       $result->setContent( $result_array['languageshtml'], $languagesHtml );
+               }
                if ( isset( $prop['categories'] ) ) {
                        $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
                }
+               if ( isset( $prop['categorieshtml'] ) ) {
+                       $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
+                       $result_array['categorieshtml'] = array();
+                       $result->setContent( $result_array['categorieshtml'], $categoriesHtml );
+               }
                if ( isset( $prop['links'] ) ) {
                        $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
                }
@@ -326,6 +336,20 @@ class ApiParse extends ApiBase {
                return $result;
        }
 
+       private function categoriesHtml( $categories ) {
+               global $wgOut, $wgUser;
+               $wgOut->addCategoryLinks( $categories );
+               $sk = $wgUser->getSkin();
+               return $sk->getCategories();
+       }
+
+       private function languagesHtml( $languages ) {
+               global $wgOut, $wgUser;
+               $wgOut->setLanguageLinks( $languages );
+               $sk = $wgUser->getSkin();
+               return $sk->otherLanguages();
+       }
+
        private function formatLinks( $links ) {
                $result = array();
                foreach ( $links as $ns => $nslinks ) {
@@ -408,7 +432,9 @@ class ApiParse extends ApiBase {
                                ApiBase::PARAM_TYPE => array(
                                        'text',
                                        'langlinks',
+                                       'languageshtml',
                                        'categories',
+                                       'categorieshtml',
                                        'links',
                                        'templates',
                                        'images',
@@ -444,6 +470,8 @@ class ApiParse extends ApiBase {
                                ' text           - Gives the parsed text of the wikitext',
                                ' langlinks      - Gives the langlinks the parsed wikitext',
                                ' categories     - Gives the categories of the parsed wikitext',
+                               ' categorieshtml - Gives the html version of the categories',
+                               ' languageshtml  - Gives the html version of the languagelinks',
                                ' links          - Gives the internal links in the parsed wikitext',
                                ' templates      - Gives the templates in the parsed wikitext',
                                ' images         - Gives the images in the parsed wikitext',