From f9cc3b783ae91c912fa788df27bb74274741f176 Mon Sep 17 00:00:00 2001 From: Priyanka Dhanda Date: Mon, 6 Dec 2010 18:31:09 +0000 Subject: [PATCH] Part of fix/workaround to bug 26163. API calls to get language links and categories as html --- includes/api/ApiParse.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 9a88631411..81a0e0c66f 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -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', -- 2.20.1