function showStatus() { global $wgMemc, $wgAbuseFilterConditionLimit, $wgOut, $wgLang; $overflow_count = (int) $wgMemc->get(AbuseFilter::filterLimitReachedKey()); $match_count = (int) $wgMemc->get(AbuseFilter::filterMatchesKey()); $total_count = (int) $wgMemc->get(AbuseFilter::filterUsedKey()); if ($total_count > 0) { $overflow_percent = sprintf("%.2f", 100 * $overflow_count / $total_count); $match_percent = sprintf("%.2f", 100 * $match_count / $total_count); $status = wfMsgExt('abusefilter-status', array('parseinline'), $wgLang->formatNum($total_count), $wgLang->formatNum($overflow_count), $wgLang->formatNum($overflow_percent), $wgLang->formatNum($wgAbuseFilterConditionLimit), $wgLang->formatNum($match_count), $wgLang->formatNum($match_percent)); $status = Xml::tags('div', array('class' => 'mw-abusefilter-status'), $status); $wgOut->addHTML($status); } }
function showStatus() { global $wgMemc, $wgAbuseFilterConditionLimit, $wgAbuseFilterValidGroups; $overflow_count = (int) $wgMemc->get(AbuseFilter::filterLimitReachedKey()); $match_count = (int) $wgMemc->get(AbuseFilter::filterMatchesKey()); $total_count = 0; foreach ($wgAbuseFilterValidGroups as $group) { $total_count += (int) $wgMemc->get(AbuseFilter::filterUsedKey($group)); } if ($total_count > 0) { $overflow_percent = sprintf("%.2f", 100 * $overflow_count / $total_count); $match_percent = sprintf("%.2f", 100 * $match_count / $total_count); $status = $this->msg('abusefilter-status')->numParams($total_count, $overflow_count, $overflow_percent, $wgAbuseFilterConditionLimit, $match_count, $match_percent)->parse(); $status = Xml::tags('div', array('class' => 'mw-abusefilter-status'), $status); $this->getOutput()->addHTML($status); } }
function buildFilterEditor($error, $filter, $history_id = null) { if ($filter === null) { return false; } // Build the edit form $out = $this->getOutput(); $lang = $this->getLanguage(); $user = $this->getUser(); $sk = $this->getSkin(); // Load from request OR database. list($row, $actions) = $this->loadRequest($filter, $history_id); if (!$row) { $out->addWikiMsg('abusefilter-edit-badfilter'); $out->addHTML($sk->link($this->getTitle(), wfMsg('abusefilter-return'))); return; } $out->setSubtitle(wfMsg('abusefilter-edit-subtitle', $filter, $history_id)); // Hide hidden filters. if ((isset($row->af_hidden) && $row->af_hidden || AbuseFilter::filterHidden($filter)) && !$this->canViewPrivate()) { return wfMsg('abusefilter-edit-denied'); } $output = ''; if ($error) { $out->addHTML("<span class=\"error\">{$error}</span>"); } // Read-only attribute $readOnlyAttrib = array(); $cbReadOnlyAttrib = array(); // For checkboxes if (!$this->canEdit()) { $readOnlyAttrib['readonly'] = 'readonly'; $cbReadOnlyAttrib['disabled'] = 'disabled'; } $fields = array(); $fields['abusefilter-edit-id'] = $this->mFilter == 'new' ? wfMsg('abusefilter-edit-new') : $lang->formatNum($filter); $fields['abusefilter-edit-description'] = Xml::input('wpFilterDescription', 45, isset($row->af_public_comments) ? $row->af_public_comments : '', $readOnlyAttrib); // Hit count display if (!empty($row->af_hit_count)) { $count = (int) $row->af_hit_count; $count_display = wfMsgExt('abusefilter-hitcount', array('parseinline'), $lang->formatNum($count)); $hitCount = $sk->makeKnownLinkObj(SpecialPage::getTitleFor('AbuseLog'), $count_display, 'wpSearchFilter=' . $row->af_id); $fields['abusefilter-edit-hitcount'] = $hitCount; } if ($filter !== 'new') { // Statistics global $wgMemc; $matches_count = $wgMemc->get(AbuseFilter::filterMatchesKey($filter)); $total = $wgMemc->get(AbuseFilter::filterUsedKey()); if ($total > 0) { $matches_percent = sprintf('%.2f', 100 * $matches_count / $total); list($timeProfile, $condProfile) = AbuseFilter::getFilterProfile($filter); $fields['abusefilter-edit-status-label'] = wfMsgExt('abusefilter-edit-status', array('parsemag', 'escape'), array($lang->formatNum($total), $lang->formatNum($matches_count), $lang->formatNum($matches_percent), $lang->formatNum($timeProfile), $lang->formatNum($condProfile))); } } $fields['abusefilter-edit-rules'] = AbuseFilter::buildEditBox($row->af_pattern, 'wpFilterRules', true, $this->canEdit()); $fields['abusefilter-edit-notes'] = Xml::textarea('wpFilterNotes', isset($row->af_comments) ? $row->af_comments . "\n" : "\n", 40, 5, $readOnlyAttrib); // Build checkboxen $checkboxes = array('hidden', 'enabled', 'deleted'); $flags = ''; global $wgAbuseFilterIsCentral; if ($wgAbuseFilterIsCentral) { $checkboxes[] = 'global'; } if (isset($row->af_throttled) && $row->af_throttled) { global $wgAbuseFilterEmergencyDisableThreshold; $threshold_percent = sprintf('%.2f', $wgAbuseFilterEmergencyDisableThreshold * 100); $flags .= $out->parse(wfMsg('abusefilter-edit-throttled', $lang->formatNum($threshold_percent))); } foreach ($checkboxes as $checkboxId) { $message = "abusefilter-edit-{$checkboxId}"; $dbField = "af_{$checkboxId}"; $postVar = 'wpFilter' . ucfirst($checkboxId); $checkbox = Xml::checkLabel(wfMsg($message), $postVar, $postVar, isset($row->{$dbField}) ? $row->{$dbField} : false, $cbReadOnlyAttrib); $checkbox = Xml::tags('p', null, $checkbox); $flags .= $checkbox; } $fields['abusefilter-edit-flags'] = $flags; $tools = ''; if ($filter != 'new' && $user->isAllowed('abusefilter-revert')) { $tools .= Xml::tags('p', null, $sk->link($this->getTitle('revert/' . $filter), wfMsg('abusefilter-edit-revert'))); } if ($filter != 'new') { // Test link $tools .= Xml::tags('p', null, $sk->link($this->getTitle("test/{$filter}"), wfMsgExt('abusefilter-edit-test-link', 'parseinline'))); // Last modification details $userLink = $sk->userLink($row->af_user, $row->af_user_text) . $sk->userToolLinks($row->af_user, $row->af_user_text); $userName = $row->af_user_text; $fields['abusefilter-edit-lastmod'] = wfMsgExt('abusefilter-edit-lastmod-text', array('parseinline', 'replaceafter'), array($lang->timeanddate($row->af_timestamp, true), $userLink, $lang->date($row->af_timestamp, true), $lang->time($row->af_timestamp, true), $userName)); $history_display = wfMsgExt('abusefilter-edit-viewhistory', array('parseinline')); $fields['abusefilter-edit-history'] = $sk->makeKnownLinkObj($this->getTitle('history/' . $filter), $history_display); } // Add export $exportText = json_encode(array('row' => $row, 'actions' => $actions)); $tools .= Xml::tags('a', array('href' => '#', 'id' => 'mw-abusefilter-export-link'), wfMsgExt('abusefilter-edit-export', 'parseinline')); $tools .= Xml::element('textarea', array('readonly' => 'readonly', 'id' => 'mw-abusefilter-export'), $exportText); $fields['abusefilter-edit-tools'] = $tools; $form = Xml::buildForm($fields); $form = Xml::fieldset(wfMsg('abusefilter-edit-main'), $form); $form .= Xml::fieldset(wfMsg('abusefilter-edit-consequences'), $this->buildConsequenceEditor($row, $actions)); if ($this->canEdit()) { $form .= Xml::submitButton(wfMsg('abusefilter-edit-save'), array('accesskey' => 's')); $form .= Html::hidden('wpEditToken', $user->getEditToken(array('abusefilter', $filter))); } $form = Xml::tags('form', array('action' => $this->getTitle($filter)->getFullURL(), 'method' => 'post'), $form); $output .= $form; return $output; }