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