Skip to content

Commit

Permalink
Work around deprecated Output::addWikiText() method (see #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Mar 18, 2020
1 parent c91d10c commit c945c75
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 22 deletions.
41 changes: 33 additions & 8 deletions specials/SpecialRDFIOAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
class RDFIOAdmin extends RDFIOSpecialPage {

private $wOut;

function __construct() {
parent::__construct( 'RDFIOAdmin', 'rdfio-admin' );
}
Expand All @@ -26,13 +28,13 @@ function execute( $par ) {

$wUser = $this->getUser();
$wRequest = $this->getRequest();
$wOut = $this->getOutput();
$this->wOut = $this->getOutput();

$this->setHeaders();

$rdfiogAction = $wRequest->getText( 'rdfio-action', '' );

$wOut->addHTML('<h3>' . wfMessage( 'rdfio-triplestore-setup' )->parse() . '</h3>' );
$this->addHTML('<h3>' . wfMessage( 'rdfio-triplestore-setup' )->parse() . '</h3>' );

$arc2StoreConfig = array(
'db_host' => $wgDBserver,
Expand All @@ -42,6 +44,7 @@ function execute( $par ) {
'store_name' => $wgDBprefix . 'arc2store', // Determines table prefix
);
$store = ARC2::getStore( $arc2StoreConfig );

if ( $store->isSetUp() ) {
$this->infoMsg( wfMessage( 'rdfio-triplestore-is-already-setup' )->parse() );
} else {
Expand All @@ -60,22 +63,22 @@ function execute( $par ) {
Html::Hidden( 'rdfio-action', 'setup' ) .
Html::Hidden( 'token', $wUser->getEditToken() ) .
'</form>';
$wOut->addHTML( $setupStoreForm );
$this->addHTML( $setupStoreForm );
}
}

$wOut->addWikiText( "\n===" . wfMessage( 'rdfio-data-sources' )->parse() . "===\n" );
$wOut->addWikiText( "\n{{#ask: [[Category:RDFIO Data Source]]
$this->addWikiText( "\n===" . wfMessage( 'rdfio-data-sources' )->parse() . "===\n" );
$this->addWikiText( "\n{{#ask: [[Category:RDFIO Data Source]]
|?Equivalent URI
|?RDFIO Import Type
|format=table
|mainlabel=Data Source
|limit=10
}}\n" );

$wOut->addWikiText( "\n===" . wfMessage( 'rdfio-pages-and-templates' )->parse() . "===\n" );
$wOut->addHTML( wfMessage( 'rdfio-associate-template-with-category-howto' )->parse() );
$wOut->addWikiText( "{{#ask: [[:Category:+]]
$this->addWikiText( "\n===" . wfMessage( 'rdfio-pages-and-templates' )->parse() . "===\n" );
$this->addHTML( wfMessage( 'rdfio-associate-template-with-category-howto' )->parse() );
$this->addWikiText( "{{#ask: [[:Category:+]]
|?Equivalent URI
|?Has template
|format=table
Expand All @@ -84,6 +87,28 @@ function execute( $par ) {
}}" );
}

/**
* Add wiki text to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The wiki text to add.
*/
private function addWikiText( $text ) {
if ( method_exists( $this->wOut, 'addWikiTextAsInterface' ) ) {
$this->wOut->addWikiTextAsInterface( $text );
} else {
$this->wOut->addWikiText( $text );
}
}

/**
* Add HTML content to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The HTML content to add.
*/
private function addHTML( $html ) {
$this->wOut->addHTML( $html );
}

/**
* Check permissions and set up the ARC2 store if allowed.
* @param $store
Expand Down
37 changes: 30 additions & 7 deletions specials/SpecialRDFImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class RDFImport extends RDFIOSpecialPage {

private $wOut;

function __construct() {
parent::__construct( 'RDFImport', 'rdfio-import' );
}
Expand All @@ -18,7 +20,7 @@ function execute( $par ) {
throw new PermissionsError( 'rdfio-import', array( 'rdfio-specialpage-access-permission-missing' ) );
}

$wOut = $this->getOutput();
$this->wOut = $this->getOutput();

// Set HTML headers sent to the browser
$this->setHeaders();
Expand All @@ -41,7 +43,7 @@ function execute( $par ) {

// Show imported triples
$rdfImporter = new RDFIORDFImporter();
$wOut->addHTML( $rdfImporter->showImportedTriples( $triples ) );
$this->addHTML( $rdfImporter->showImportedTriples( $triples ) );

if ( $requestData->externalRdfUrl ) {
$rdfImporter->addDataSource( $requestData->externalRdfUrl, 'RDF' );
Expand All @@ -58,6 +60,28 @@ function execute( $par ) {
$this->showHTMLFormAndInfo( $requestData );
}

/**
* Add wiki text to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The wiki text to add.
*/
private function addWikiText( $text ) {
if ( method_exists( $this->wOut, 'addWikiTextAsInterface' ) ) {
$this->wOut->addWikiTextAsInterface( $text );
} else {
$this->wOut->addWikiText( $text );
}
}

/**
* Add HTML content to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The HTML content to add.
*/
private function addHTML( $html ) {
$this->wOut->addHTML( $html );
}

/**
* Import data into wiki pages
*/
Expand Down Expand Up @@ -116,13 +140,12 @@ function getRequestData() {
* Show the RDF Import Form HTML, and some additional info HTML
*/
function showHTMLFormAndInfo( $requestData ) {
$wOut = $this->getOutput();
$wUser = $this->getUser();

$wOut->addHTML( $this->getHTMLForm( $requestData, $wUser ) );
$wOut->addHTML( '<div id=sources style="display:none">' );
$wOut->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::RDF]] |format=list }}' );
$wOut->addHTML( '</div>' );
$this->addHTML( $this->getHTMLForm( $requestData, $wUser ) );
$this->addHTML( '<div id=sources style="display:none">' );
$this->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::RDF]] |format=list }}' );
$this->addHTML( '</div>' );
}

/**
Expand Down
38 changes: 31 additions & 7 deletions specials/SpecialSPARQLImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class SPARQLImport extends RDFIOSpecialPage {

private $wOut;

function __construct() {
parent::__construct( 'SPARQLImport', 'rdfio-import' );
}
Expand All @@ -18,7 +20,7 @@ function execute( $par ) {
throw new PermissionsError( 'rdfio-import', array( 'rdfio-specialpage-access-permission-missing' ) );
}

$wOut = $this->getOutput();
$this->wOut = $this->getOutput();
$wRequest = $this->getRequest();
$wUser = $this->getUser();

Expand All @@ -36,7 +38,7 @@ function execute( $par ) {
}

$submitButtonText = wfMessage( 'rdfio-import-next-batch-of-triples' )->parse();
$wOut->addHTML( $this->getHTMLForm( $submitButtonText, $limit, $offset + $limit ) );
$this->addHTML( $this->getHTMLForm( $submitButtonText, $limit, $offset + $limit ) );

try {
$importInfo = $this->import( $limit, $offset );
Expand All @@ -51,10 +53,32 @@ function execute( $par ) {
return;
}

$wOut->addHTML( $this->getHTMLForm( $submitButtonText, $limit, $offset ) );
$wOut->addHTML( '<div id=sources style="display:none">' );
$wOut->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::SPARQL]] |format=list }}' );
$wOut->addHTML( '</div>' );
$this->addHTML( $this->getHTMLForm( $submitButtonText, $limit, $offset ) );
$this->addHTML( '<div id=sources style="display:none">' );
$this->addWikiText( '{{#ask: [[Category:RDFIO Data Source]] [[RDFIO Import Type::SPARQL]] |format=list }}' );
$this->addHTML( '</div>' );
}

/**
* Add wiki text to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The wiki text to add.
*/
private function addWikiText( $text ) {
if ( method_exists( $this->wOut, 'addWikiTextAsInterface' ) ) {
$this->wOut->addWikiTextAsInterface( $text );
} else {
$this->wOut->addWikiText( $text );
}
}

/**
* Add HTML content to output. Requires that $this->wOut is already
* initialized to $this->getOutput();
* @param $text The HTML content to add.
*/
private function addHTML( $html ) {
$this->wOut->addHTML( $html );
}

function resourceType( $resourceStr ) {
Expand Down Expand Up @@ -114,7 +138,7 @@ protected function import( $limit = 25, $offset = 0 ) {

$rdfImporter = new RDFIORDFImporter();
$rdfImporter->importTriples( $triples );
$wOut->addHTML( $rdfImporter->showImportedTriples( $triples ) );
$this->addHTML( $rdfImporter->showImportedTriples( $triples ) );

return array( 'externalSparqlUrl' => $externalSparqlUrl );
}
Expand Down

0 comments on commit c945c75

Please sign in to comment.