Skip to content

Commit

Permalink
trying to use wikipedia api to parse the wiki text.
Browse files Browse the repository at this point in the history
It works but the performance is a big concerns.
We will not use it for now. Commit here as a reference.
  • Loading branch information
seanchen committed Mar 7, 2013
1 parent 58c9e50 commit 0887951
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion wp-trac-client/admin-testing.php
Expand Up @@ -4,7 +4,7 @@
$_POST['wptc_testing_form_submit'] === 'Y') {

$functionName = $_POST['wptc_function'];
$functionInputs = $_POST['wptc_function_params'];
$functionInputs = stripslashes($_POST['wptc_function_params']);
$functionParams = explode(',', $functionInputs);

//switch($functionName) {
Expand Down Expand Up @@ -55,6 +55,9 @@
<option>wptc_remove_ticket_meta</option>
<option>wptc_widget_ticket_defaults</option>
<option>wptc_widget_version_nav</option>
<option>get_wiki_client</option>
<option>wptc_widget_parse_content</option>
<option>wptc_widget_mw_parse_content</option>
</select>
</td>
</tr>
Expand Down
22 changes: 19 additions & 3 deletions wp-trac-client/widgets.php
Expand Up @@ -15,15 +15,31 @@ function wptc_widget_clean_textarea($input) {
return apply_filters('wptc_widget_clean_textarea', $ret);
}

/**
* using mediawiki api to parse wiki content
*/
function wptc_widget_mw_parse_content($wiki) {

$wiki_client = get_wiki_client();
$wiki_client->setParameterGet('action', 'parse');
$wiki_client->setParameterGet('format', 'xml');
$wiki_client->setParameterGet('text', $wiki);
$response = $wiki_client->request('GET');
$result = simplexml_load_string(trim($response->getBody()));
//print_r($result);

//echo $result->text();
return (string)$result->parse->text;
}

/**
* parse wiki format to prepare HTML.
*/
function wptc_widget_parse_content($wiki) {

//$ret = Markdown($wiki);
$wkr = new WikiRenderer('trac_to_xhtml');
$ret = $wkr->render($wiki);
//$ret = $wiki;
//$ret = wptc_widget_mw_parse_content($wiki);

// apply filters to allow user to tweak.
return apply_filters('wptc_widget_parse_content', $ret);
Expand Down Expand Up @@ -820,7 +836,7 @@ function wptc_widget_ticket_info($ticket) {
Description
<a class="anchor" href="#comment:description" title="Link to this section"> ¶</a></h3>
<div class="searchable">
<p>{$ticket_description}<br></p>
{$ticket_description}
</div>
</div><!-- END ticket-description -->
Expand Down
12 changes: 12 additions & 0 deletions wp-trac-client/wp-trac-client.php
Expand Up @@ -130,6 +130,18 @@ function get_wptc_client() {
return $wptc_client;
}

/**
* retrun a rest wiki ckient.
*/
function get_wiki_client() {

require_once 'Zend/Http/Client.php';
$wikiApiUrl = 'http://en.wikipedia.org/w/api.php';
$wiki_client = new Zend_Http_Client($wikiApiUrl);

return $wiki_client;
}

function wptc_is_debug() {

$debug = get_site_option('wptc_debug');
Expand Down

0 comments on commit 0887951

Please sign in to comment.