/** * Return html table of the current work underway * - called from both special page and statically by ajax handler */ function wfWikidAdminRenderWork() { global $wgWikidWork, $wgWikidAdminWikiPattern; if (!is_array($wgWikidWork)) { wfWikidAdminLoadWork(); } if (count($wgWikidWork) > 0) { $unset = "<i>unset</i>"; $title = Title::makeTitle(NS_SPECIAL, 'WikidAdmin'); $class = ''; $cols = array('Job ID', 'Wiki', 'Type', 'Start', 'Progress', 'State', 'Status'); $html = "<table class=\"changes\"><tr>\n"; foreach ($cols as $col) { $html .= "<th id=\"wa-work-" . strtolower($col) . "\">{$col}</th>\n"; } $html .= "</tr>\n"; foreach ($wgWikidWork as $job) { $class = $class == 'odd' ? 'even' : 'odd'; $id = isset($job['id']) ? $job['id'] : $unset; $wiki = preg_replace($wgWikidAdminWikiPattern, "\$1", $job['wiki']); $type = isset($job['type']) ? $job['type'] : $unset; $start = isset($job['start']) ? wfTimestamp(TS_DB, $job['start']) : $unset; $len = isset($job['length']) ? $job['length'] : $unset; $wptr = isset($job['wptr']) ? $job['wptr'] : $unset; $paused = isset($job['paused']) ? $job['paused'] : false; $status = isset($job['status']) ? $job['status'] : $unset; $plink = $title->getLocalUrl("id={$id}&action=pause"); $plink = "<a href=\"{$plink}\">" . ($paused ? "continue" : "pause") . "</a>"; $slink = $title->getLocalUrl("id={$id}&action=stop"); $slink = "<a href=\"{$slink}\">cancel</a>"; $state = ($paused ? "Paused" : "Running") . " <small>({$plink}|{$slink})</small>"; $progress = $wptr == $unset || $len == $unset ? $unset : "{$wptr} of {$len}"; $html .= "<tr class=\"mw-line-{$class}\">"; $html .= "<td>{$id}</td><td>{$wiki}</td><td>{$type}</td><td>{$start}</td><td>{$progress}</td><td>{$state}</td><td>{$status}</td>"; $html .= "</tr>\n"; } $html .= "</table>\n"; } else { $html = "<i>There are currently no active jobs</i>\n"; } return $html; }
function execute($param) { global $wgWikidWork, $wgWikidTypes, $wgParser, $wgOut, $wgHooks, $wgRequest, $wgJsMimeType; $wgParser->disableCache(); $this->setHeaders(); wfWikidAdminLoadWork(); # Add some script for auto updating the job info $wgOut->addScript("<script type='{$wgJsMimeType}'>\n\t\t\tfunction wikidAdminCurrentTimer() {\n\t\t\t\tsetTimeout('wikidAdminCurrentTimer()',1000);\n\t\t\t\tsajax_do_call('wfWikidAdminRenderWork',[],document.getElementById('current-work'));\n\t\t\t}\n\t\t\tfunction wikidAdminHistoryTimer() {\n\t\t\t\tsetTimeout('wikidAdminHistoryTimer()',10000);\n\t\t\t\tsajax_do_call('wfWikidAdminRenderWorkHistory',[],document.getElementById('work-history'));\n\t\t\t}</script>"); # Start a new job instance if wpStart & wpType posted if ($wgRequest->getText('wpStart')) { $type = $wgRequest->getText('wpType'); $start = true; $args = array(); wfRunHooks("WikidAdminTypeFormProcess_{$type}", array(&$args, &$start)); if ($start) { $this->startJob($type, $args); } } # Cancel a job if ($wgRequest->getText('action') == 'stop') { $this->stopJob($wgRequest->getText('id')); } # Pause/continue a job if ($wgRequest->getText('action') == 'pause') { $this->pauseJob($wgRequest->getText('id')); } # Render ability to start a new job and supply optional args $wgOut->addWikiText("== Start a new job ==\n"); if (count($wgWikidTypes)) { $url = Title::newFromText('WikidAdmin', NS_SPECIAL)->getLocalUrl(); $html = "<form action=\"{$url}\" method=\"POST\" enctype=\"multipart/form-data\">"; $html .= "<table><tr valign=\"top\">\n"; $html .= '<td>Type: <select name="wpType" id="wpType" onchange="wikidAdminShowTypeForm()" ><option />'; foreach ($wgWikidTypes as $type) { $html .= "<option>{$type}</option>"; } $html .= "</select></td><td>"; # Render forms for types $forms = array(); foreach ($wgWikidTypes as $type) { $hook = "WikidAdminTypeFormRender_{$type}"; if (isset($wgHooks[$hook])) { $form = ''; wfRunHooks($hook, array(&$form)); $html .= "<div id=\"form-{$type}\" style=\"display:none\" >{$form}</div>"; $forms[] = "'{$type}'"; } } # and the script to switch the visible one $forms = join(',', $forms); $wgOut->addScript("<script type='{$wgJsMimeType}'>\n\t\t\tfunction wikidAdminShowTypeForm() {\n\t\t\t\tvar type = document.getElementById('wpType').value;\n\t\t\t\tvar forms = [{$forms}];\n\t\t\t\tfor( i in forms ) document.getElementById('form-'+forms[i]).style.display = forms[i] == type ? '' : 'none';\n\t\t\t}</script>"); $html .= '</td><td><input name="wpStart" type="submit" value="Start" /></td>'; $html .= '</tr></table></form><br />'; $wgOut->addHtml($html); } else { $wgOut->addHtml('<i>There are no job types defined</i><br />'); } # Render as a table with pause/continue/cancel for each $wgOut->addWikiText("\n== Currently executing work ==\n"); $wgOut->addHtml('<div id="current-work">' . wfWikidAdminRenderWork() . '</div>'); $wgOut->addHtml("<script type='{$wgJsMimeType}'>wikidAdminCurrentTimer();</script><br />"); # Render a list of previously run jobs from the job log $wgOut->addWikiText("== Work history ==\n"); $wgOut->addHtml('<div id="work-history">' . wfWikidAdminRenderWorkHistory() . '</div>'); $wgOut->addHtml("<script type='{$wgJsMimeType}'>wikidAdminHistoryTimer();</script>"); }