/** * Run job * * @return boolean success */ function run() { wfProfileIn('SMWRefreshJob::run (SMW)'); if (!array_key_exists('spos', $this->params)) { wfProfileOut('SMWRefreshJob::run (SMW)'); return true; } $run = array_key_exists('run', $this->params) ? $this->params['run'] : 1; $spos = $this->params['spos']; $namespaces = $this->params['rc'] > 1 && $run == 1 ? array(SMW_NS_PROPERTY, SMW_NS_TYPE) : false; $progress = smwfGetStore()->refreshData($spos, 20, $namespaces); $jobParams = null; if ($spos > 0) { $jobParams = array('spos' => $spos, 'prog' => $progress, 'rc' => $this->params['rc'], 'run' => $run); } elseif ($this->params['rc'] > $run) { // do another run from the beginning $jobParams = array('spos' => 1, 'prog' => 0, 'rc' => $this->params['rc'], 'run' => $run + 1); } if (!empty($jobParams)) { // wikia change start - jobqueue migration $task = new \Wikia\Tasks\Tasks\JobWrapperTask(); $task->call('SMWRefreshJob', $this->title, $jobParams); $task->queue(); // wikia change end } wfProfileOut('SMWRefreshJob::run (SMW)'); return true; }
public function execute($par) { global $wgOut, $wgRequest, $wgServer, $wgArticlePath, $wgUser, $smwgAdminRefreshStore; if (!$this->userCanExecute($wgUser)) { // If the user is not authorized, show an error. $this->displayRestrictionError(); return; } $this->setHeaders(); /**** Get status of refresh job, if any ****/ $dbr = wfGetDB(DB_SLAVE); $row = $dbr->selectRow('job', '*', array('job_cmd' => 'SMWRefreshJob'), __METHOD__); if ($row !== false) { // similar to Job::pop_type, but without deleting the job $title = Title::makeTitleSafe($row->job_namespace, $row->job_title); $refreshjob = Job::factory($row->job_cmd, $title, Job::extractBlob($row->job_params), $row->job_id); } else { $refreshjob = null; } /**** Execute actions if any ****/ $action = $wgRequest->getText('action'); if ($action == 'updatetables') { $sure = $wgRequest->getText('udsure'); if ($sure == 'yes') { $wgOut->disable(); // raw output ob_start(); print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\">\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Setting up Storage for Semantic MediaWiki</title></head><body><p><pre>"; header("Content-type: text/html; charset=UTF-8"); $result = smwfGetStore()->setup(); wfRunHooks('smwInitializeTables'); print '</pre></p>'; if ($result === true) { print '<p><b>' . wfMsg('smw_smwadmin_setupsuccess') . "</b></p>\n"; } $returntitle = SpecialPage::getTitleFor('SMWAdmin'); print '<p> ' . wfMsg('smw_smwadmin_return', '<a href="' . htmlspecialchars($returntitle->getFullURL()) . '">Special:SMWAdmin</a>') . "</p>\n"; print '</body></html>'; ob_flush(); flush(); return; } } elseif ($smwgAdminRefreshStore && $action == 'refreshstore') { // managing refresh jobs for the store $sure = $wgRequest->getText('rfsure'); if ($sure == 'yes') { if (is_null($refreshjob)) { // careful, there might be race conditions here $title = SpecialPage::getTitleFor('SMWAdmin'); $jobParams = array('spos' => 1, 'prog' => 0, 'rc' => 2); // wikia change start - jobqueue migration $task = new \Wikia\Tasks\Tasks\JobWrapperTask(); $task->call('SMWRefreshJob', $title, $jobParams); $task->queue(); // wikia change end $wgOut->addHTML('<p>' . wfMsg('smw_smwadmin_updatestarted') . '</p>'); } else { $wgOut->addHTML('<p>' . wfMsg('smw_smwadmin_updatenotstarted') . '</p>'); } } elseif ($sure == 'stop') { $dbw = wfGetDB(DB_MASTER); // delete (all) existing iteration jobs $dbw->delete('job', array('job_cmd' => 'SMWRefreshJob'), __METHOD__); $wgOut->addHTML('<p>' . wfMsg('smw_smwadmin_updatestopped') . '</p>'); } else { $wgOut->addHTML('<p>' . wfMsg('smw_smwadmin_updatenotstopped') . '</p>'); } return; } /**** Normal output ****/ $html = '<p>' . wfMsg('smw_smwadmin_docu') . "</p>\n"; // creating tables and converting contents from older versions $html .= '<form name="buildtables" action="" method="POST">' . "\n" . '<input type="hidden" name="action" value="updatetables" />' . "\n"; $html .= '<br /><h2>' . wfMsg('smw_smwadmin_db') . "</h2>\n" . '<p>' . wfMsg('smw_smwadmin_dbdocu') . "</p>\n"; $html .= '<p>' . wfMsg('smw_smwadmin_permissionswarn') . "</p>\n" . '<input type="hidden" name="udsure" value="yes"/>' . '<input type="submit" value="' . wfMsg('smw_smwadmin_dbbutton') . '"/></form>' . "\n"; $html .= '<br /><h2>' . wfMsg('smw_smwadmin_datarefresh') . "</h2>\n" . '<p>' . wfMsg('smw_smwadmin_datarefreshdocu') . "</p>\n"; if (!is_null($refreshjob)) { $prog = $refreshjob->getProgress(); $html .= '<p>' . wfMsg('smw_smwadmin_datarefreshprogress') . "</p>\n" . '<p><div style="float: left; background: #DDDDDD; border: 1px solid grey; width: 300px; "><div style="background: #AAF; width: ' . round($prog * 300) . 'px; height: 20px; "> </div></div>  ' . round($prog * 100, 4) . '%</p><br /><br />'; if ($smwgAdminRefreshStore) { $html .= '<form name="refreshwiki" action="" method="POST">' . '<input type="hidden" name="action" value="refreshstore" />' . '<input type="submit" value="' . htmlspecialchars(wfMsg('smw_smwadmin_datarefreshstop')) . '" /> ' . ' <input type="checkbox" name="rfsure" value="stop"/> ' . htmlspecialchars(wfMsg('smw_smwadmin_datarefreshstopconfirm')) . '</form>' . "\n"; } } elseif ($smwgAdminRefreshStore) { $html .= '<form name="refreshwiki" action="" method="POST">' . '<input type="hidden" name="action" value="refreshstore" />' . '<input type="hidden" name="rfsure" value="yes"/>' . '<input type="submit" value="' . wfMsg('smw_smwadmin_datarefreshbutton') . '"/>' . '</form>' . "\n"; } $html .= '<br /><h2>' . wfMsg('smw_smwadmin_announce') . "</h2>\n" . '<p>' . wfMsg('smw_smwadmin_announcedocu') . "</p>\n" . '<p>' . wfMsg('smw_smwadmin_announcebutton') . "</p>\n" . '<form name="announcewiki" action="http://semantic-mediawiki.org/wiki/Special:SMWRegistry" method="GET">' . '<input type="hidden" name="url" value="' . $wgServer . str_replace('$1', '', $wgArticlePath) . '" />' . '<input type="hidden" name="return" value="Special:SMWAdmin" />' . '<input type="submit" value="' . wfMsg('smw_smwadmin_announce') . '"/></form>' . "\n"; $html .= '<br /><h2>' . wfMsg('smw_smwadmin_support') . "</h2>\n" . '<p>' . wfMsg('smw_smwadmin_supportdocu') . "</p>\n" . "<ul>\n" . '<li>' . wfMsg('smw_smwadmin_installfile') . "</li>\n" . '<li>' . wfMsg('smw_smwadmin_smwhomepage') . "</li>\n" . '<li>' . wfMsg('smw_smwadmin_mediazilla') . "</li>\n" . '<li>' . wfMsg('smw_smwadmin_questions') . "</li>\n" . "</ul>\n"; $wgOut->addHTML($html); }
/** * Automatically creates a page that's red-linked from the page being * viewed, if there's a property pointing from anywhere to that page * that's defined with the 'Creates pages with form' special property */ static function createLinkedPage($title, $incoming_properties) { // if we're in a 'special' page, just exit - this is to prevent // constant additions being made from the 'Special:RecentChanges' // page, which shows pages that were previously deleted as red // links, even if they've since been recreated. The same might // hold true for other special pages. global $wgTitle; if (empty($wgTitle)) { return false; } if ($wgTitle->getNamespace() == NS_SPECIAL) { return false; } foreach ($incoming_properties as $property_name) { $auto_create_forms = self::getFormsThatPagePointsTo($property_name, SMW_NS_PROPERTY, self::AUTO_CREATE_FORM); if (count($auto_create_forms) > 0) { global $sfgFormPrinter; $form_name = $auto_create_forms[0]; $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); $form_article = new Article($form_title); $form_definition = $form_article->getContent(); list($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = $sfgFormPrinter->formHTML($form_definition, false, false, null, null, 'Some very long page name that will hopefully never get created ABCDEF123', null); $params = array(); global $wgUser; $params['user_id'] = $wgUser->getId(); $params['page_text'] = $data_text; // wikia change start - jobqueue migration $task = new \Wikia\Tasks\Tasks\JobWrapperTask(); $task->call('createPage', $title, $params); $task->queue(); // wikia change end return true; } } return false; }