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