Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
TwigExtension | |
0.00% |
0 / 13 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFunctions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getFilters | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
qsMerge | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
wikitextFilterCallback | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @section LICENSE |
4 | * This file is part of Wikimedia Slim application library |
5 | * |
6 | * Wikimedia Slim application library is free software: you can |
7 | * redistribute it and/or modify it under the terms of the GNU General Public |
8 | * License as published by the Free Software Foundation, either version 3 of |
9 | * the License, or (at your option) any later version. |
10 | * |
11 | * Wikimedia Slim application library is distributed in the hope that it |
12 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with Wikimedia Grants Review application. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
20 | * @file |
21 | * @copyright © 2015 Bryan Davis, Wikimedia Foundation and contributors. |
22 | */ |
23 | |
24 | namespace Wikimedia\Slimapp; |
25 | |
26 | use Twig_Extension; |
27 | use Twig_SimpleFilter; |
28 | use Twig_SimpleFunction; |
29 | |
30 | /** |
31 | * @author Bryan Davis <bd808@wikimedia.org> |
32 | * @copyright © 2015 Bryan Davis, Wikimedia Foundation and contributors. |
33 | */ |
34 | class TwigExtension extends Twig_Extension { |
35 | |
36 | /** |
37 | * @var ParsoidClient |
38 | */ |
39 | protected $parsoid; |
40 | |
41 | /** |
42 | * @param ParsoidClient $parsoid ParsoidClient |
43 | */ |
44 | public function __construct( ParsoidClient $parsoid ) { |
45 | $this->parsoid = $parsoid; |
46 | } |
47 | |
48 | /** |
49 | * @return string Extension name |
50 | */ |
51 | public function getName() { |
52 | return 'wikimedia-slimapp'; |
53 | } |
54 | |
55 | /** |
56 | * @return array Extension functions |
57 | */ |
58 | public function getFunctions() { |
59 | return [ |
60 | new Twig_SimpleFunction( 'qsMerge', [ $this, 'qsMerge' ] ), |
61 | ]; |
62 | } |
63 | |
64 | /** |
65 | * @return array Extension filters |
66 | */ |
67 | public function getFilters() { |
68 | return [ |
69 | new Twig_SimpleFilter( |
70 | 'wikitext', [ $this, 'wikitextFilterCallback' ], |
71 | [ 'is_safe' => [ 'html' ] ] |
72 | ), |
73 | ]; |
74 | } |
75 | |
76 | /** |
77 | * @param array $parms Parameter array |
78 | * @return string URL-encoded message body |
79 | */ |
80 | public function qsMerge( $parms ) { |
81 | return Form::qsMerge( $parms ); |
82 | } |
83 | |
84 | /** |
85 | * @param string $text Wikitext |
86 | * @return string Parsed wikitext |
87 | */ |
88 | public function wikitextFilterCallback( $text ) { |
89 | return $this->parsoid->parse( $text ); |
90 | } |
91 | } |