Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialMathDownloadResult
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 5
90
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
 run2CSV
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 processInput
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 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\MediaWikiServices;
5
6/**
7 * Lets the user download a CSV file with the results
8 *
9 * @author Moritz Schubotz
10 */
11class SpecialMathDownloadResult extends SpecialUploadResult {
12
13    public function __construct( $name = 'MathDownload' ) {
14        parent::__construct( $name );
15    }
16
17    public static function run2CSV( $runId ) {
18        $out = ImportCsv::getCsvColumnHeader() . "\n";
19        $dbr = MediaWikiServices::getInstance()
20            ->getConnectionProvider()
21            ->getReplicaDatabase();
22        $res = $dbr->select( 'math_wmc_results',
23            [ 'qId', 'oldId', 'fId' ],
24            [ 'runId' => $runId ],
25            __METHOD__,
26            [ 'ORDER BY' => [ 'qId', 'rank' ] ] );
27        if ( $res !== false ) {
28            foreach ( $res as $row ) {
29                $fId = $row->fId == null ? 0 : $row->fId;
30                $out .= "{$row->qId},math.{$row->oldId}.{$fId}\n";
31            }
32        }
33        return $out;
34    }
35
36    function execute( $query ) {
37        $this->setHeaders();
38        if ( !$this->getUser()->isAllowed( 'mathwmcsubmit' ) ) {
39            throw new PermissionsError( 'mathwmcsubmit' );
40        }
41
42        $this->getOutput()->addWikiTextAsInterface( wfMessage( 'math-wmc-download-intro' )->text() );
43        $formDescriptor = $this->printRunSelector( 'select' );
44        $formDescriptor['run']['help-message'] = '';
45        $htmlForm = new HTMLForm( $formDescriptor, $this->getContext() );
46        $htmlForm->setSubmitCallback( [ $this, 'processInput' ] );
47        $htmlForm->setSubmitTextMsg( 'math-wmc-download-button' );
48        $htmlForm->show();
49    }
50
51    function processInput() {
52        $this->getOutput()->disable();
53        header( 'Content-Type: text/csv' );
54        header( 'Content-Disposition: attachment; filename="run' . $this->runId . '.csv"' );
55        print ( self::run2CSV( $this->runId ) );
56        return true;
57    }
58
59    protected function getGroupName() {
60        return 'mathsearch';
61    }
62}