store = StoreFactory::getStore(); } public function setStore( Store $store ) { $this->store = $store; } public function getStore() { return $this->store; } public function execute( $par ) { if ( !$this->userCanExecute( $this->getUser() ) ) { // If the user is not authorized, show an error. $this->displayRestrictionError(); return; } $this->setHeaders(); // FIXME Searching the job table needs to be fixed // // SMW shouldn't expose itself to an internal MW DB table at // this level. If an official Api doesn't provide needed // functionality, the DB call should be encapsulate within its // own class /**** Get status of refresh job, if any ****/ $dbr = wfGetDB( DB_SLAVE ); $row = $dbr->selectRow( 'job', '*', array( 'job_cmd' => 'SMW\RefreshJob' ), __METHOD__ ); if ( $row !== false ) { // similar to Job::pop_type, but without deleting the job $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title ); $blob = (string)$row->job_params !== '' ? unserialize( $row->job_params ) : false; $refreshjob = Job::factory( $row->job_cmd, $title, $blob, $row->job_id ); } else { $refreshjob = null; } /**** Execute actions if any ****/ switch ( $this->getRequest()->getText( 'action' ) ) { case 'listsettings': return $this->actionListSettings(); case 'idlookup': return $this->actionIdLookup( $this->getRequest()->getVal( 'objectId' ) ); case 'updatetables': return $this->actionUpdateTables(); case 'refreshstore': return $this->actionRefreshStore( $refreshjob ); } /**** Normal output ****/ $html = '
' . wfMessage( 'smw_smwadmin_docu' )->text() . "
\n"; // creating tables and converting contents from older versions $html .= '' . "\n"; $html .= '' . wfMessage( 'smw_smwadmin_datarefreshdocu' )->text() . "
\n"; if ( !is_null( $refreshjob ) ) { $prog = $refreshjob->getProgress(); $html .= '' . wfMessage( 'smw_smwadmin_datarefreshprogress' )->text() . "
\n" . '' . $this->msg( 'smw-sp-admin-settings-docu' )->parse() . "
\n". '' . "\n"; } protected function getAnnounceSection() { return '' . wfMessage( 'smw_smwadmin_announcedocu' )->text() . "
\n" . '' . wfMessage( 'smw_smwadmin_announcebutton' )->text() . "
\n" . '' . "\n"; } protected function getSupportSection() { return '' . wfMessage( 'smw_smwadmin_supportdocu' )->text() . "
\n" . "' . wfMessage( 'smw_smwadmin_setupsuccess' )->text() . "
\n"; } } ); } } protected function actionRefreshStore( $refreshjob ) { if ( $GLOBALS['smwgAdminRefreshStore'] ) { $sure = $GLOBALS['wgRequest']->getText( 'rfsure' ); $title = SpecialPage::getTitleFor( 'SMWAdmin' ); if ( $sure == 'yes' ) { if ( is_null( $refreshjob ) ) { // careful, there might be race conditions here $newjob = new RefreshJob( $title, array( 'spos' => 1, 'prog' => 0, 'rc' => 2 ) ); $newjob->insert(); $this->getOutput()->addHTML( '' . wfMessage( 'smw_smwadmin_updatestarted', 'Special:SMWAdmin' )->text() . '
' ); } else { $this->getOutput()->addHTML( '' . wfMessage( 'smw_smwadmin_updatenotstarted', 'Special:SMWAdmin' )->text() . '
' ); } } elseif ( $sure == 'stop' ) { // FIXME See above comments !! $dbw = wfGetDB( DB_MASTER ); // delete (all) existing iteration jobs $dbw->delete( 'job', array( 'job_cmd' => 'SMW\RefreshJob' ), __METHOD__ ); $this->getOutput()->addHTML( '' . wfMessage( 'smw_smwadmin_updatestopped', 'Special:SMWAdmin' )->text() . '
' ); } else { $this->getOutput()->addHTML( '' . wfMessage( 'smw_smwadmin_updatenotstopped', 'Special:SMWAdmin' )->text() . '
' ); } } } protected function actionListSettings() { $this->printRawOutput( function( $instance ) { print '' . $instance->encodeJson( Settings::newFromGlobals()->toArray() ) . ''; } ); } protected function actionIdLookup( $objectId ) { $objectId = (int)$objectId; $this->printRawOutput( function( $instance ) use ( $objectId ) { $tableName = $instance->getStore()->getObjectIds()->getIdTable(); $row = $instance->getStore()->getDatabase()->selectRow( $tableName, array( 'smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject' ), 'smw_id=' . $objectId, __METHOD__ ); print '
' . $instance->encodeJson( array( $objectId, $row ) ) . ''; } ); } protected function printRawOutput( $text ) { $this->getOutput()->disable(); // raw output ob_start(); print "\n\n
"; // header( "Content-type: text/html; charset=UTF-8" ); is_callable( $text ) ? $text( $this ) : $text; print ''; print ' ' . wfMessage( 'smw_smwadmin_return', 'Special:SMWAdmin' )->text() . "\n"; print ''; ob_flush(); flush(); } /** * @note JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and * JSON_UNESCAPED_UNICOD were only added with 5.4 */ public function encodeJson( array $input ) { if ( defined( 'JSON_PRETTY_PRINT' ) ) { return json_encode( $input, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); } return FormatJson::encode( $input, true ); } }