🚧 This instance is under construction; expect occasional downtime. Runners available in /repos. Questions? Ask in #wikimedia-gitlab on libera.chat, or under GitLab on Phabricator.

Commit 7dbdf3eb authored by Wolfgang Fahl's avatar Wolfgang Fahl
Browse files

preparese local service alternative

parent 51784368
......@@ -23,6 +23,10 @@
"DiagramsServiceUrl": {
"description": "URL of the diagram-rendering service.",
"value": "https://example.org/diagrams/"
},
"DiagramsServiceLocal": {
"description": "should the diagrams be rendered locally via command line calls?",
"value": false
}
},
"Hooks": {
......
......@@ -8,6 +8,7 @@
"diagrams-desc": "Render Graphviz, Mscgen, and PlantUML diagrams in wiki pages. See [[Special:Diagrams]].",
"diagrams-special-title": "Special:Diagrams",
"diagrams-wiki-desc": "The Diagrams extension needs java, plantuml and graphviz to be installed. Below you find the results for the check of the installation.",
"diagrams-error-no-response": "Diagrams error: no response received from remote service.",
"diagrams-error-no-response": "Diagrams error: no response received from remote service at $1.",
"diagrams-error-local": "Diagrams error: local rendering $1",
"diagrams-error-returned-0": "Diagrams service error:"
}
......@@ -51,8 +51,39 @@ class Hooks {
* @param string|null $type
* @return string
*/
protected static function render( $generator, $input, $type = null ) {
protected static function render(string $generator, string $input,string $type = null ):string {
$localService= MediaWikiServices::getInstance()->getMainConfig()->get( 'DiagramsServiceLocal' );
$baseUrl = MediaWikiServices::getInstance()->getMainConfig()->get( 'DiagramsServiceUrl' );
$result=null;
if (!$localService) {
$result=static::renderWithService($generator,$input,$baseUrl,$type);
} else {
$result=static::renderLocal($generator,$input,$type);
}
return $result;
}
/**
* render on the local host using command line calls
* @param string $generator
* @param string $input
* @param string $type
* @return string
*/
protected static function renderLocal(string $generator, string $input,string $type = null ):string {
return static::formatError( wfMessage( 'diagrams-error-local' , 'not implemented yet') );
}
/**
* render with the given service baseUrl
* @param string $generator
* @param string $input
* @param string $baseUrl
* @param string $type
* @return unknown
*/
protected static function renderWithService(string $generator, string $input,string $baseUrl, string $type = null): string {
$url = trim( $baseUrl, '/' ) . '/render';
$params = [
'postData' => http_build_query( [
......@@ -63,9 +94,18 @@ class Hooks {
];
$result = Http::request( 'POST', $url, $params, __METHOD__ );
if ( $result === false ) {
return static::formatError( wfMessage( 'diagrams-error-no-response' ) );
return static::formatError( wfMessage( 'diagrams-error-no-response' , $baseUrl) );
}
$response = json_decode( $result );
return static::renderResponse($reponse);
}
/**
* render the given response
* @param mixed $response
* @return string
*/
protected static function renderResponse(mixed $response):string {
if ( isset( $response->error ) ) {
$error = wfMessage( 'diagrams-error-returned-' . $response->error );
if ( isset( $response->message ) ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment