Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
SpecialMathIndex | |
0.00% |
0 / 52 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setHeaders | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
testIndex | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
processInput | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | class SpecialMathIndex extends SpecialPage { |
4 | |
5 | private const SCRIPT_UPDATE_MATH = 0; |
6 | private const SCRIPT_WRITE_INDEX = 1; |
7 | |
8 | function __construct() { |
9 | parent::__construct( 'MathIndex', 'edit', true ); |
10 | } |
11 | |
12 | /** |
13 | * Sets headers - this should be called from the execute() method of all derived classes! |
14 | */ |
15 | function setHeaders() { |
16 | $out = $this->getOutput(); |
17 | $out->setArticleRelated( false ); |
18 | $out->setRobotPolicy( "noindex,nofollow" ); |
19 | $out->setPageTitle( $this->getDescription() ); |
20 | } |
21 | |
22 | /** @inheritDoc */ |
23 | function execute( $par ) { |
24 | $output = $this->getOutput(); |
25 | $this->setHeaders(); |
26 | if ( $this->getConfig()->get( 'MathDebug' ) ) { |
27 | if ( !$this->userCanExecute( $this->getUser() ) ) { |
28 | $this->displayRestrictionError(); |
29 | } else { |
30 | $this->testIndex(); |
31 | } |
32 | } else { |
33 | $output->addWikiTextAsInterface( |
34 | '\'\'\'This page is avaliblible in math debug mode only.\'\'\'' . "\n\n" . |
35 | 'Enable the math debug mode by setting <code> $wgMathDebug = true</code> .' |
36 | ); |
37 | } |
38 | } |
39 | |
40 | function testIndex() { |
41 | $out = $this->getOutput(); |
42 | $out->addWikiTextAsInterface( 'This is a test.' ); |
43 | $formDescriptor = [ |
44 | 'script' => [ |
45 | 'label' => 'Script', # What's the label of the field |
46 | 'type' => 'select', # What's the input type |
47 | 'help' => 'for example: \sin(?x^2)', |
48 | 'default' => 0, |
49 | 'options' => [ # The options available within the menu (displayed => value) |
50 | # depends on how you see it but keys and values are kind of mixed here |
51 | 'UpdateMath' => self::SCRIPT_UPDATE_MATH, |
52 | # "Option 1" is the displayed content, "1" is the value |
53 | 'ExportIndex' => self::SCRIPT_WRITE_INDEX, |
54 | # Hmtl Result = <option value="option2id">Option 2</option> |
55 | 'something else' => 'option2id' |
56 | ] |
57 | ] |
58 | ]; |
59 | $htmlForm = new HTMLForm( $formDescriptor, $this->getContext() ); # We build the HTMLForm object |
60 | $htmlForm->setSubmitText( 'Search' ); |
61 | $htmlForm->setSubmitCallback( [ get_class( $this ), 'processInput' ] ); |
62 | $htmlForm->setHeaderText( "<h2>Select script to run</h2>" ); |
63 | $htmlForm->show(); # Displaying the form |
64 | } |
65 | |
66 | /** |
67 | * OnSubmit Callback, here we do all the logic we want to do... |
68 | * @param array $formData |
69 | */ |
70 | public static function processInput( $formData ) { |
71 | switch ( $formData['script'] ) { |
72 | case self::SCRIPT_UPDATE_MATH: |
73 | require_once __DIR__ . '/../../maintenance/UpdateMath.php'; |
74 | $updater = new UpdateMath(); |
75 | $updater->loadParamsAndArgs( null, [ "max" => 1 ], null ); |
76 | $updater->execute(); |
77 | break; |
78 | case self::SCRIPT_WRITE_INDEX: |
79 | require_once __DIR__ . '/../../maintenance/CreateMathIndex.php'; |
80 | $updater = new CreateMathIndex(); |
81 | $updater->loadParamsAndArgs( null, [ "mwsns" => 'mws:' ], |
82 | [ __DIR__ . '/mws/data/wiki' ] |
83 | ); |
84 | $updater->execute(); |
85 | break; |
86 | default: |
87 | break; |
88 | } |
89 | } |
90 | |
91 | protected function getGroupName() { |
92 | return 'mathsearch'; |
93 | } |
94 | |
95 | } |