markerList * * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit * @see https://www.mediawiki.org/wiki/Manual:Parser_functions * @param Parser $parser * @throws \MWException */ public function onParserFirstCallInit($parser) { $parser->setHook('jsxgraph', [$this, 'parserTagJSXGraph']); } /** * After call of tidy, the required JSXGraph divs and script * tags are injected. jsxgraphcore.js is loaded only once. */ public function onParserAfterTidy($parser, &$text) { $keys = array(); $marker_count = count($this->markerList); for ($i = 0; $i < $marker_count; $i++) { $keys[] = 'jsxgraph-marker' . $i . '-jsxgraph'; } $text = str_replace($keys, $this->markerList, $text); return true; } /** * Parser hook handler for <jsxgraph>. * Called by onParserFirstCallInit * * @param string $data The content of the tag. * @param array $attribs The attributes of the tag. * @param Parser $parser Parser instance available to render * wikitext into html, or parser methods. * @param PPFrame $frame Can be used to see what template * arguments ({{{1}}}) this hook was used with. * @return string HTML to insert in the page. */ public function parserTagJSXGraph($data, $attribs, $parser, $frame) { $jsxgraph = [ 'content' => $data, 'attributes' => (object) $attribs, ]; return $this->markJSXGraphTags($jsxgraph); } /** * Here, the real work is done. The attributes of the jsxgraph tag are analyzed, * the JSXGraph divs are created, source code is stored. */ private function markJSXGraphTags($jsxgraph) { $output = ""; $attr = json_decode(json_encode($jsxgraph["attributes"]), true); $error_message = "no error"; $markercount = count($this->markerList); if ($markercount > 0) { $default_board = "brd" . $markercount; $default_box = "jxgbox" . $markercount; } else { $default_board = "brd"; $default_box = "jxgbox"; } if (!(isset($args['filename']) || isset($args['filestring']) || isset($jsxgraph["content"]))) { $error_message = "Missing parameter (width or height, filename, string or input)."; } $outputURI = '//jsxgraph.uni-bayreuth.de/~alfred/jsxgraph/distrib'; // $jsxgraph_version = ""; // $outputURICDN = 'https://cdn.jsdelivr.net/npm/jsxgraph@' . $jsxgraph_version . '/distrib'; $outputURICDN = 'https://cdn.jsdelivr.net/npm/jsxgraph/distrib'; $outputDivId = (isset($attr['box'])) ? htmlspecialchars(strip_tags($attr['box'])) : $default_box; $outputBoardId = (isset($attr['board'])) ? htmlspecialchars(strip_tags($attr['board'])) : $default_board; $width = (isset($attr['width'])) ? htmlspecialchars(strip_tags($attr['width'])) : 500; $height = (isset($attr['height'])) ? htmlspecialchars(strip_tags($attr['height'])) : 400; if ($markercount == 0) { if (FALSE && preg_match("/^132\.180/", getenv("REMOTE_ADDR"))) { // Use the local version when developing $output .= "
IP:". getenv("REMOTE_ADDR") ." - use developer version
"; $output .= ""; $output .= ""; $output .= ""; } else { $output .= ""; $output .= ""; $output .= ""; } } if (isset($attr['modules']) && trim($attr['modules']) != "") { $modules = explode(',', $attr['modules']); for ($i = 0; $i < count($modules); $i++) { $output .= ""; } } $output .= "
"; $output .= ""; if ($error_message != "no error") { $output = "

Error in MediaWiki extension (JSXGraph.php): " . $error_message . "

\n"; } $marker = "jsxgraph-marker" . $markercount . "-jsxgraph"; $this->markerList[$markercount] = $output; return $marker; } }