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" . '' . "\n"; $html .= '

' . wfMessage( 'smw_smwadmin_db' )->text() . "

\n" . '

' . wfMessage( 'smw_smwadmin_dbdocu' )->text() . "

\n"; $html .= '

' . wfMessage( 'smw_smwadmin_permissionswarn' )->text() . "

\n" . '' . '
' . "\n"; $html .= '

' . wfMessage( 'smw_smwadmin_datarefresh' )->text() . "

\n" . '

' . wfMessage( 'smw_smwadmin_datarefreshdocu' )->text() . "

\n"; if ( !is_null( $refreshjob ) ) { $prog = $refreshjob->getProgress(); $html .= '

' . wfMessage( 'smw_smwadmin_datarefreshprogress' )->text() . "

\n" . '

 ' . round( $prog * 100, 4 ) . '%



'; if ( $GLOBALS['smwgAdminRefreshStore'] ) { $html .= '
' . '' . ' ' . ' ' . wfMessage( 'smw_smwadmin_datarefreshstopconfirm' )->escaped() . '
' . "\n"; } } elseif ( $GLOBALS['smwgAdminRefreshStore'] ) { $html .= '
' . '' . '' . '' . '
' . "\n"; } $html .= $this->getSettingsSection(); $html .= $this->getIdLookupSection(); $html .= $this->getAnnounceSection(); $html .= $this->getSupportSection(); $this->getOutput()->addHTML( $html ); } protected function getSettingsSection() { return '

' . $this->msg( 'smw-sp-admin-settings-title' )->text() . "

\n" . '

' . $this->msg( 'smw-sp-admin-settings-docu' )->parse() . "

\n". '
' . '' . '' . '
' . "\n"; } protected function getAnnounceSection() { return '

' . wfMessage( 'smw_smwadmin_announce' )->text() . "

\n" . '

' . wfMessage( 'smw_smwadmin_announcedocu' )->text() . "

\n" . '

' . wfMessage( 'smw_smwadmin_announcebutton' )->text() . "

\n" . '
' . '' . '' . '
' . "\n"; } protected function getSupportSection() { return '

' . wfMessage( 'smw_smwadmin_support' )->text() . "

\n" . '

' . wfMessage( 'smw_smwadmin_supportdocu' )->text() . "

\n" . "\n"; } protected function getIdLookupSection() { return '
' . Html::element( 'h2', array(), $this->msg( 'smw-sp-admin-idlookup-title' )->text() ) . "\n" . Html::element( 'p', array(), $this->msg( 'smw-sp-admin-idlookup-docu' )->text() ) . "\n" . Xml::tags( 'form', array( 'method' => 'get', 'action' => $GLOBALS['wgScript'] ), Html::hidden( 'title', $this->getContext()->getTitle()->getPrefixedText() ) . Html::hidden( 'action', 'idlookup' ) . Xml::inputLabel( $this->msg( 'smw-sp-admin-idlookup-objectid' )->text(), 'objectId', 'objectId', 20, null ) . ' ' . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) ); } protected function actionUpdateTables() { if ( $GLOBALS['wgRequest']->getText( 'udsure' ) == 'yes' ) { $this->printRawOutput( function() { $result = SMWStore::setupStore(); if ( $result === true ) { print '

' . 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\nSemantic MediaWiki

";
		// 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 ); } }