Skip to content

Commit 9cfdf04

Browse files
committed
Clean up main logic of RDF Import form, to show better error msg on lack of write access etc
1 parent fd2551e commit 9cfdf04

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

specials/SpecialRDFImport.php

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,42 @@ function execute( $par ) {
1515
$wOut = $this->getOutput();
1616
$wUser = $this->getUser();
1717

18-
try {
19-
# Set HTML headers sent to the browser
20-
$this->setHeaders();
18+
// Set HTML headers sent to the browser
19+
$this->setHeaders();
2120

22-
# The main code
23-
$requestData = $this->getRequestData();
24-
if ( $requestData->hasWriteAccess && $requestData->action === 'import' ) {
21+
// The main code
22+
$requestData = $this->getRequestData();
23+
if ( $requestData->action === 'import' ) {
24+
if ( !$requestData->hasWriteAccess ) {
25+
$this->errorMsg( "The current user does not have write access in the wiki" );
26+
return;
27+
}
28+
29+
try {
2530
$importInfo = $this->importData( $requestData );
2631
$triples = $importInfo['triples'];
2732
if ( $triples ) {
28-
$rdfImporter = new RDFIORDFImporter();
29-
$wOut->addHTML( $this->getHTMLForm( $requestData, $wUser ) );
33+
$this->showHTMLFormAndInfo( $requestData );
34+
3035
$this->successMsg('Successfully imported ' . count( $triples ) . ' triples!' );
36+
37+
// Show imported triples
38+
$rdfImporter = new RDFIORDFImporter();
3139
$wOut->addHTML( $rdfImporter->showImportedTriples( $triples ) );
40+
3241
if ( $requestData->externalRdfUrl ) {
3342
$rdfImporter->addDataSource( $requestData->externalRdfUrl, 'RDF' );
3443
}
44+
return;
45+
3546
} else if ( !$triples ) {
36-
throw new RDFIOException ( "No new triples to import" );
47+
$this->errorMsg( 'No new triples to import, in in-data' );
3748
}
38-
} else {
39-
$wOut->addHTML( $this->getHTMLForm( $requestData, $wUser ) );
40-
$wOut->addHTML( '<div id=sources style="display:none">' );
41-
$wOut->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::RDF]] |format=list }}' );
42-
$wOut->addHTML( '</div>' );
49+
} catch ( MWException $e ) {
50+
$this->errorMsg( $e->getMessage() );
4351
}
44-
} catch ( MWException $e ) {
45-
$this->errorMsg( $e->getMessage() );
4652
}
53+
$this->showHTMLFormAndInfo( $requestData );
4754
}
4855

4956
/**
@@ -100,6 +107,18 @@ function getRequestData() {
100107
return $requestData;
101108
}
102109

110+
/**
111+
* Show the RDF Import Form HTML, and some additional info HTML
112+
*/
113+
function showHTMLFormAndInfo( $requestData ) {
114+
$wOut = $this->getOutput();
115+
$wUser = $this->getUser();
116+
117+
$wOut->addHTML( $this->getHTMLForm( $requestData, $wUser ) );
118+
$wOut->addHTML( '<div id=sources style="display:none">' );
119+
$wOut->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::RDF]] |format=list }}' );
120+
$wOut->addHTML( '</div>' );
121+
}
103122

104123
/**
105124
* Output the HTML for the form, to the user

0 commit comments

Comments
 (0)