Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiParsoidUtilsFlow
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
6
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Flow\Api;
4
5use Flow\Conversion\Utils;
6use Flow\Exception\WikitextException;
7use MediaWiki\Api\ApiBase;
8use Wikimedia\ParamValidator\ParamValidator;
9
10class ApiParsoidUtilsFlow extends ApiBase {
11
12    public function execute() {
13        $params = $this->extractRequestParams();
14        $page = $this->getTitleOrPageId( $params );
15
16        try {
17            $content = Utils::convert(
18                $params['from'],
19                $params['to'],
20                $params['content'],
21                $page->getTitle()
22            );
23        } catch ( WikitextException $e ) {
24            $code = $e->getErrorCode();
25            $this->dieWithError( $code, $code,
26                [ 'detail' => $e->getMessage() ]
27            );
28        }
29
30        $result = [
31            'format' => $params['to'],
32            'content' => $content,
33        ];
34        $this->getResult()->addValue( null, $this->getModuleName(), $result );
35    }
36
37    public function getAllowedParams() {
38        return [
39            'from' => [
40                ParamValidator::PARAM_REQUIRED => true,
41                ParamValidator::PARAM_TYPE => [ 'html', 'wikitext' ],
42            ],
43            'to' => [
44                ParamValidator::PARAM_REQUIRED => true,
45                ParamValidator::PARAM_TYPE => [ 'html', 'wikitext' ],
46            ],
47            'content' => [
48                ParamValidator::PARAM_REQUIRED => true,
49            ],
50            'title' => null,
51            'pageid' => [
52                ParamValidator::PARAM_ISMULTI => false,
53                ParamValidator::PARAM_TYPE => 'integer'
54            ],
55        ];
56    }
57
58    /**
59     * @inheritDoc
60     */
61    protected function getExamplesMessages() {
62        return [
63            "action=flow-parsoid-utils&from=wikitext&to=html&content='''lorem'''+''blah''&title=Main_Page"
64                => 'apihelp-flow-parsoid-utils-example-1',
65        ];
66    }
67}