MediaWiki扩展Math渲染失败

来自姬鸿昌的知识库
Jihongchang讨论 | 贡献2022年8月10日 (三) 12:12的版本 (建立内容为“万恶的墙! 需要墙外代理才能调用 Wiki 提供的 Restbase 和 Mathoid 服务,LocalSettings.php 中的<syntaxhighlight lang="properties"> // Set Ma…”的新页面)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

万恶的墙!

需要墙外代理才能调用 Wiki 提供的 Restbase 和 Mathoid 服务,LocalSettings.php 中的

// Set MathML as default rendering option
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL = 'https://wikimedia.org/api/rest_';
$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org';

修改 Math 扩展中的接口调用:MathRestbaseInterface.php 修改函数 getCheckRequest:

        /** 
         * @return array
         * @throws MWException
         */
        public function getCheckRequest() {
                $request = [ 
                                'method' => 'POST',
                                'body'   => [
                                        'type' => $this->type,
                                        'q'    => $this->tex
                                ],  
                                'proxy' => '172.17.0.1:10808',
                                'url'    => $this->getUrl( "media/math/check/{$this->type}" )
                ];  
                return $request;
        }

修改函数 getContentRequest:

        /**
         * @return string
         */
        public function getMathoidStyle() {
                return $this->mathoidStyle;
        }

        /**
         * @param string $type
         * @return array
         * @throws MWException
         */
        private function getContentRequest( $type ) {
                $this->calculateHash();
                $request = [
                        'method' => 'GET',
                        'proxy' => '172.17.0.1:10808',
                        'url' => $this->getUrl( "media/math/render/$type/{$this->hash}" )
                ];
                if ( $this->purge ) {
                        $request['headers'] = [
                                'Cache-Control' => 'no-cache'
                        ];
                        $this->purge = false;
                }
                return $request;
        }

其中的 proxy 声明就是新增的代码