jenkins-bot has submitted this change and it was merged.
Change subject: Add download functionality
......................................................................
Add download functionality
Participants and admins must be able to download the submitted runs.
Change-Id: I684b36521b6cbd885a99257357388abce780be64
---
M MathSearch.alias.php
M MathSearch.hooks.php
M MathSearch.php
A SpecialMathDownloadResult.php
M SpecialUploadResult.php
M i18n/en.json
M i18n/qqq.json
7 files changed, 93 insertions(+), 21 deletions(-)
Approvals:
Physikerwelt: Looks good to me, approved
Raimond Spekking: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/MathSearch.alias.php b/MathSearch.alias.php
index 586c1d2..9b2fc0b 100644
--- a/MathSearch.alias.php
+++ b/MathSearch.alias.php
@@ -17,6 +17,7 @@
'GetEquationsByQuery' => array( 'GetEquationsByQuery', 'Get Formulae by
Query' ),
'MathIndex' => array( 'MathIndex', 'Math Index' ),
'MathUpload' => array( 'MathUpload', 'Math Upload' ),
+ 'MathDownload' => array( 'MathDownload', 'Math Download' ),
);
/** Arabic (العربية) */
diff --git a/MathSearch.hooks.php b/MathSearch.hooks.php
index 12cd3c5..b691fb2 100644
--- a/MathSearch.hooks.php
+++ b/MathSearch.hooks.php
@@ -39,6 +39,8 @@
$updater->addExtensionTable( 'mathperformance', $dir .
'mathperformance.sql' );
if ( $wgMathWmcServer ){
$updater->addExtensionTable( 'math_wmc_ref',
$dir . "math_wmc_ref.sql");
+ $updater->addExtensionTable( 'math_wmc_runs',
$dir . "math_wmc_runs.sql");
+ $updater->addExtensionTable(
'math_wmc_results', $dir . "math_wmc_results.sql");
}
$updater->addExtensionTable( 'mathidentifier', $dir .
'mathidentifier.sql' );
} else {
diff --git a/MathSearch.php b/MathSearch.php
index 2db52e8..532c7eb 100644
--- a/MathSearch.php
+++ b/MathSearch.php
@@ -98,4 +98,7 @@
$wgAutoloadClasses['SpecialUploadResult'] = $dir . 'SpecialUploadResult.php';
$wgSpecialPages['MathUpload'] = 'SpecialUploadResult';
$wgSpecialPageGroups['MathUpload'] = 'mathsearch';
-$wgMathUploadEnabled = false;
\ No newline at end of file
+$wgMathUploadEnabled = false;
+$wgAutoloadClasses['SpecialMathDownloadResult'] = $dir .
'SpecialMathDownloadResult.php';
+$wgSpecialPages['MathDownload'] = 'SpecialMathDownloadResult';
+$wgSpecialPageGroups['MathDownload'] = 'mathsearch';
\ No newline at end of file
diff --git a/SpecialMathDownloadResult.php b/SpecialMathDownloadResult.php
new file mode 100644
index 0000000..81559f9
--- /dev/null
+++ b/SpecialMathDownloadResult.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Lets the user download a CSV file with the results
+ *
+ * @author Moritz Schubotz
+ */
+class SpecialMathDownloadResult extends SpecialUploadResult {
+ public function __construct( $name = 'MathDownload' ) {
+ parent::__construct( $name );
+ }
+
+ public static function run2CSV( $runId ){
+ $out = SpecialUploadResult::getCsvColumnHeader() . "\n";
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'math_wmc_results',
+ array( 'qId' , 'oldId' , 'fId' ),
+ array( 'runId' => $runId ) ,
+ __METHOD__,
+ array( 'ORDER BY' => array( 'qId' , 'rank' ) ) );
+ if ( $res !== false ) {
+ foreach ( $res as $row ) {
+ $fId = $row->fId == null ? 0 : $row->fId;
+ $out .=
"{$row->qId},math.{$row->oldId}.{$fId}\n";
+ }
+ }
+ return $out;
+ }
+
+ function execute( $query ) {
+ $this->setHeaders();
+ if ( ! ( $this->getUser()->isAllowed( 'mathwmcsubmit' ) ) ) {
+ throw new PermissionsError( 'mathwmcsubmit' );
+ }
+
+ $this->getOutput()->addWikiText( wfMessage(
'math-wmc-download-intro' )->text() );
+ $formDescriptor = $this->printRunSelector( 'select' );
+ $formDescriptor['run']['help-message'] = '';
+ $htmlForm = new HTMLForm( $formDescriptor, $this->getContext()
);
+ $htmlForm->setSubmitCallback( array( $this, 'processInput' ) );
+ $htmlForm->setSubmitTextMsg( 'math-wmc-download-button' );
+ $htmlForm->show();
+
+ }
+
+ function processInput( ) {
+ $this->getOutput()->disable();
+ header( 'Content-Type: text/csv');
+ header( 'Content-Disposition: attachment; filename="run' .
$this->runId . '.csv"');
+ print(self::run2CSV( $this->runId ));
+ return true;
+ }
+
+
+}
diff --git a/SpecialUploadResult.php b/SpecialUploadResult.php
index 3d0727c..c16da70 100644
--- a/SpecialUploadResult.php
+++ b/SpecialUploadResult.php
@@ -7,12 +7,15 @@
* @author Yaron Koren (This class is baaed on DT_ImportCSV from the
DataTransfer extension)
*/
class SpecialUploadResult extends SpecialPage {
- private $columnHeaders = array( 'queryId', 'formulaId' );
+ private static $columnHeaders = array( 'queryId', 'formulaId' );
private $warnings = array();
private $results = array();
- private $runID = false;
+ protected $runId = false;
private $validQIds = array();
+ public static function getCsvColumnHeader(){
+ return implode( ',', self::$columnHeaders );
+ }
public function __construct( $name = 'MathUpload' ) {
parent::__construct( $name );
}
@@ -54,7 +57,7 @@
}
- protected function printRunSelector() {
+ protected function printRunSelector( $type = 'selectorother' ) {
$dbr = wfGetDB( DB_SLAVE );
$formFields = array();
$options = array();
@@ -64,8 +67,8 @@
foreach ( $res as $row ) {
$options[ $row->runName . " (" . $row->runId . ")" ] =
$row->runId;
}
- //Probably we want to add more field in the future
- $formFields['run'] = array( 'type' => 'selectorother',
+ //Probably we want to add more fields in the future
+ $formFields['run'] = array( 'type' => $type,
'label-message' => 'math-wmc-SelectRun',
'options' => $options,
'required' => true,
@@ -92,18 +95,18 @@
$success = $dbw->insert( 'math_wmc_runs',
array( 'isDraft' => true, 'userID' =>
$uID, 'runName' => $run ) );
if ( $success ) {
- $this->runID = $dbw->insertId();
- $this->getOutput()->addWikiMsg(
'math-wmc-RunAdded', $run, $this->runID );
+ $this->runId = $dbw->insertId();
+ $this->getOutput()->addWikiMsg(
'math-wmc-RunAdded', $run, $this->runId );
} else {
- $this->runID = false;
+ $this->runId = false;
$this->getOutput()->addWikiMsg(
'math-wmc-RunAddError', $run );
}
} else {
$this->getOutput()->addWikiMsg(
'math-wmc-RunAddExist', $run, $exists );
- $this->runID = false;
+ $this->runId = false;
}
} else {
- $this->runID = $run;
+ $this->runId = $run;
}
return $run;
}
@@ -112,7 +115,7 @@
$dbr = wfGetDB( DB_SLAVE );
$uID = $this->getUser()->getId();
$res = $dbr->selectField( 'math_wmc_runs', 'runName',
- array( 'isDraft' => true, 'userID' => $uID, 'runId' =>
$this->runID ) );
+ array( 'isDraft' => true, 'userID' => $uID, 'runId' =>
$this->runId ) );
if ( ! $res ) {
return wfMessage( 'math-wmc-SelectRunHelp' )->text();
} else {
@@ -155,7 +158,7 @@
function processInput( ) {
$this->getOutput()->addWikiMsg( "math-wmc-SubmissionSuccess" );
- $this->deleteRun( $this->runID );
+ $this->deleteRun( $this->runId );
$dbw = wfGetDB( DB_MASTER );
//TODO: Find adequate API call
$this->getOutput()->addHTML('<table border="1"
style="width:100%">
@@ -166,7 +169,7 @@
<th>rendering</th>
</tr>');
foreach ( $this->results as $result ) {
- $result['runId'] = $this->runID; //make sure that runId
is correct
+ $result['runId'] = $this->runId; //make sure that runId
is correct
$dbw->insert( 'math_wmc_results', $result );
$this->printResultRow( $result );
}
@@ -190,7 +193,7 @@
}
$formulaId = MathSearchHooks::generateMathAnchorString(
$row['oldId'], $row['fId'] );
$link=Revision::newFromId( $row['oldId']
)->getTitle()->getCanonicalURL().$formulaId;
- $this->getOutput()->addHTML("<tr><td>${row['qId']}</td><td><a
href=\"${link}\">$formulaId</a></td>
+ $this->getOutput()->addHTML("<tr><td>${row['qId']}</td><td><a
href=\"${link}\" >$formulaId</a></td>
<td>${row['rank']}</td><td>$renderedMath</td></tr>");
}
@@ -253,7 +256,7 @@
// check header line
$uploadedHeaders = $table[0];
- if ( $uploadedHeaders != $this->columnHeaders ) {
+ if ( $uploadedHeaders != self::columnHeaders ) {
$error_msg = wfMessage( 'math-wmc-bad-header' )->text();
return $error_msg;
}
@@ -301,7 +304,7 @@
private function addValidatedResult( $qId, $pId, $eId, $fHash, $rank ) {
$this->results[] = array(
- 'runId' => $this->runID,
+ 'runId' => $this->runId,
'qId' => $qId,
'oldId' => $pId,
'fId' => $eId,
@@ -310,7 +313,7 @@
}
private function displayFeedback(){
- $runId=$this->runID;
+ $runId=$this->runId;
$dbr=wfGetDB(DB_SLAVE);
$res = $dbr->select(
array('l'=>'math_wmc_rank_levels','r'=>'math_wmc_ref','math_wmc_results'),
@@ -349,8 +352,11 @@
$this->getOutput()->addHTML('</table>');
}
+ /**
+ * @throws MWException
+ */
private function displayFormulaFeedback(){
- $runId=$this->runID;
+ $runId=$this->runId;
$dbr=wfGetDB(DB_SLAVE);
$res = $dbr->select(
array('l'=>'math_wmc_rank_levels','r'=>'math_wmc_ref','math_wmc_results'),
diff --git a/i18n/en.json b/i18n/en.json
index 06e196a..9ae9aa7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -6,6 +6,7 @@
},
"mathsearch": "Math search",
"formulainfo": "Formula info",
+ "mathdownload": "Download math search results",
"mathindex": "Math index",
"mathupload": "Submit math search results",
"specialpages-group-mathsearch": "Math search",
@@ -22,8 +23,10 @@
"mathmode_6": "MW_MATH_MATHJAX",
"mathmode_7": "MW_MATH_LATEXML",
"mathmode_7+": "MW_MATH_LATEXML_JAX",
- "math-wmc-attach-results-help": "Sometimes a single run contains to
many results for one file upload. In that case the upload has to be split into
several files.",
- "math-wmc-attach-results-label":"Attach more results to existing run",
+ "math-wmc-attach-results-help": "Sometimes a single run contains to many
results for one file upload. In that case the upload has to be split into
several files.",
+ "math-wmc-attach-results-label":"Attach more results to existing run",
+ "math-wmc-download-intro": "Download your previously submitted runs here.
The file contains only valid hits. All invalid hits have been removed.",
+ "math-wmc-download-button": "Download",
"math-wmc-Introduction":"Upload your submission to the current NTCIR
Wikipedia Math Search Task here:",
"math-wmc-SectionRun" : "Submission information",
"math-wmc-SelectRun": "Name",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index e090aad..af1d754 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -10,6 +10,7 @@
"mathsearch": "{{doc-special|MathSearch}}\n\"Math Search\" is the name
of the MediaWiki extension which integrates the [http://search.mathweb.org/
MathWeb Search] engine.\n\nMath Search is used to search for a formula based on
their MathML representation.\n{{Identical|Math search}}",
"formulainfo": "{{doc-special|FormulaInfo}}\nThe special page displays
technical information about the formula, e.g. the variables it contains and
information about rendering etc.",
"mathindex": "{{doc-special|MathIndex}}\nThe special page provides a
user interface to the maintenance scripts to maintain the index for
mathematical formulae.",
+ "mathdownload": "{{doc-special|MathDownload}}\nUsers and admins can
download submissions to the wmc math search search challenge for archival.",
"specialpages-group-mathsearch": "{{doc-special-group|that=are related
to the extension MathSearch|like=[[Special:MathSearch]],
[[Special:FormulaInfo]], [[Special:GetEquationsByQuery]],
[[Special:XQueryGenerator]]}}\n\"Math Search\" is also the name of the
MediaWiki extension which integrates the [http://search.mathweb.org/ MathWeb
Search] engine.\n{{Identical|Math search}}",
"mathsearch-desc": "{{desc|name=Math
Search|http://www.mediawiki.org/wiki/Extension:MathSearch}}",
"getequationsbyquery": "{{doc-special|GetEquationByQuery}}",
@@ -17,6 +18,8 @@
"mathdebug": "{{doc-special|MathDebug}}",
"math-wmc-attach-results-help": "Form label help text",
"math-wmc-attach-results-label": "Form label",
+ "math-wmc-download-intro": "Introductory text for MathDownload special
page.",
+ "math-wmc-download-button": "Button label for submit button.",
"math-wmc-Introduction": "Used as introduction for the upload form",
"math-wmc-SectionRun": "Form group name",
"math-wmc-SelectRun": "Form label\n{{Identical|Name}}",
--
To view, visit https://gerrit.wikimedia.org/r/181264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I684b36521b6cbd885a99257357388abce780be64
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
Gerrit-Reviewer: Raimond Spekking <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits