Exemplo n.º 1
0
 function prefillForm()
 {
     global $wgRequest;
     $data = array();
     $id = $wgRequest->getInt('id');
     if ($id) {
         $data = Phalanx::getFromId($id);
         $data['type'] = Phalanx::getTypeNames($data['type']);
         $data['checkBlocker'] = '';
         $data['typeFilter'] = array();
     } else {
         $data['type'] = array_fill_keys($wgRequest->getArray('type', array()), true);
         $data['checkBlocker'] = $wgRequest->getText('wpPhalanxCheckBlocker', '');
         $data['typeFilter'] = array_fill_keys($wgRequest->getArray('wpPhalanxTypeFilter', array()), true);
     }
     $data['checkId'] = $id;
     $data['text'] = $wgRequest->getText('ip');
     $data['text'] = $wgRequest->getText('target', $data['text']);
     $data['text'] = $wgRequest->getText('text', $data['text']);
     $data['text'] = self::decodeValue($data['text']);
     $data['case'] = $wgRequest->getCheck('case');
     $data['regex'] = $wgRequest->getCheck('regex');
     $data['exact'] = $wgRequest->getCheck('exact');
     $data['expire'] = $wgRequest->getText('expire', $this->mDefaultExpire);
     $data['lang'] = $wgRequest->getText('lang', 'all');
     $data['reason'] = self::decodeValue($wgRequest->getText('reason'));
     // test form input
     $data['test'] = self::decodeValue($wgRequest->getText('test'));
     return $data;
 }
 private function block_stats($par)
 {
     global $wgOut, $wgLang, $wgUser, $wgRequest;
     #we have a valid id, change title to use it
     $wgOut->setPageTitle(wfMsg('phalanx-stats-title') . ' #' . $par);
     $block = array();
     $block = Phalanx::getFromId(intval($par));
     if (empty($block)) {
         $wgOut->addWikiMsg('phalanx-stats-block-notfound', $par);
         return true;
     }
     // process block data for display
     $data = array();
     $data['id'] = $block['id'];
     $data['author_id'] = User::newFromId($block['author_id'])->getName();
     $data['type'] = implode(', ', Phalanx::getTypeNames($block['type']));
     $data['timestamp'] = $wgLang->timeanddate($block['timestamp']);
     if ($block['expire'] == null) {
         $data['expire'] = 'infinite';
     } else {
         $data['expire'] = $wgLang->timeanddate($block['expire']);
     }
     $data['regex'] = $block['regex'] ? 'Yes' : 'No';
     $data['case'] = $block['case'] ? 'Yes' : 'No';
     $data['exact'] = $block['exact'] ? 'Yes' : 'No';
     $data['lang'] = empty($block['lang']) ? '*' : $block['lang'];
     #pull these out of the array, so they dont get used in the top rows
     if ($block['type'] & Phalanx::TYPE_EMAIL && !$wgUser->isAllowed('phalanxemailblock')) {
         // hide email from non-privildged users
         $data2['text'] = wfMsg('phalanx-email-filter-hidden');
     } else {
         $data2['text'] = $block['text'];
     }
     $data2['reason'] = $block['reason'];
     $headers = array(wfMsg('phalanx-stats-table-id'), wfMsg('phalanx-stats-table-user'), wfMsg('phalanx-stats-table-type'), wfMsg('phalanx-stats-table-create'), wfMsg('phalanx-stats-table-expire'), wfMsg('phalanx-stats-table-regex'), wfMsg('phalanx-stats-table-case'), wfMsg('phalanx-stats-table-exact'), wfMsg('phalanx-stats-table-language'));
     $html = '';
     $tableAttribs = array('border' => 1, 'class' => 'wikitable', 'style' => "font-family:monospace;");
     #use magic to build it
     $table = Xml::buildTable(array($data), $tableAttribs, $headers);
     #rip off bottom
     $table = str_replace("</table>", "", $table);
     #add some stuff
     $table .= "<tr><th>" . wfMsg('phalanx-stats-table-text') . "</th><td colspan='8'>" . htmlspecialchars($data2['text']) . "</td></tr>";
     $table .= "<tr><th>" . wfMsg('phalanx-stats-table-reason') . "</th><td colspan='8'>{$data2['reason']}</td></tr>";
     #seal it back up
     $table .= "</table>";
     $html .= $table . "\n";
     $phalanxUrl = Title::newFromText('Phalanx', NS_SPECIAL)->getFullUrl(array('id' => $block['id']));
     $html .= " &bull; <a class='modify' href='{$phalanxUrl}'>" . wfMsg('phalanx-link-modify') . "</a><br/>\n";
     $html .= "<br/>\n";
     $wgOut->addHTML($html);
     $pager = new PhalanxStatsPager($par);
     $html = '';
     $html .= $pager->getNavigationBar();
     $html .= $pager->getBody();
     $html .= $pager->getNavigationBar();
     $wgOut->addHTML($html);
 }
Exemplo n.º 3
0
 /**
  * test if provided text is blocked
  * @param string $text string to be tested against filter
  * @param array $blocksData blocks data (text, params, id), either in full or short format
  * @param boolean $writeStats should stats be recorded?
  * @param array $matchingBlockData (out) block data that matched
  *
  * @return Array with 'blocked' key containing boolean status
  *
  * @author Maciej Błaszkowski <marooned at wikia-inc.com>
  * @author Władysław Bodzek
  */
 static function findBlocked($text, $blocksData, $writeStats = true, &$matchingBlockData = null)
 {
     wfProfileIn(__METHOD__);
     $result = array('blocked' => false, 'msg' => '');
     foreach ($blocksData as $blockData) {
         if (isset($blockData['id'])) {
             // full format
             $blockId = $blockData['id'];
             $blockText = $blockData['text'];
             $isRegex = $blockData['regex'];
             $isExact = $blockData['exact'];
             $isCase = $blockData['case'];
         } else {
             // short format
             list($blockId, $blockText, $blockFlags) = $blockData;
             $isRegex = ($blockFlags & self::FLAG_REGEX) > 0;
             $isExact = ($blockFlags & self::FLAG_EXACT) > 0;
             $isCase = ($blockFlags & self::FLAG_CASE) > 0;
         }
         $origText = $blockText;
         if ($isRegex) {
             //escape slashes uses as regex delimiter
             $blockText = str_replace('/', '\\/', preg_replace('|\\\\*/|', '/', $blockText));
             if ($isExact) {
                 //add begining and end anchor only once (user might added it already)
                 if (strpos($blockText, '^') !== 0) {
                     $blockText = '^' . $blockText;
                 }
                 if (substr($blockText, -1) != '$') {
                     $blockText .= '$';
                 }
             }
             $blockText = "/{$blockText}/";
             if (!$isCase) {
                 $blockText .= 'i';
             }
             //QuickFix™ for bad regexes
             //TODO: validate regexes on save/edit
             wfSuppressWarnings();
             $matched = preg_match($blockText, $text, $matches);
             if ($matched === false) {
                 Wikia::log(__METHOD__, __LINE__, "Bad regex found: {$blockText}");
             }
             wfRestoreWarnings();
             if ($matched) {
                 $blockData = Phalanx::getFromId($blockId);
                 if ($blockData) {
                     if ($writeStats) {
                         self::addStats($blockData['id'], $blockData['type']);
                     }
                     $result['blocked'] = true;
                     $result['msg'] = $matches[0];
                 }
             }
         } else {
             //plain text
             if (!$isCase) {
                 $text = strtolower($text);
                 $blockText = strtolower($blockText);
             }
             if ($isExact) {
                 if ($text == $blockText) {
                     $blockData = Phalanx::getFromId($blockId);
                     if ($blockData) {
                         if ($writeStats) {
                             self::addStats($blockData['id'], $blockData['type']);
                         }
                         $result['blocked'] = true;
                         $result['msg'] = $origText;
                         //original case
                     }
                 }
             } else {
                 if (!empty($blockText) && strpos($text, $blockText) !== false) {
                     $blockData = Phalanx::getFromId($blockId);
                     if ($blockData) {
                         if ($writeStats) {
                             self::addStats($blockData['id'], $blockData['type']);
                         }
                         $result['blocked'] = true;
                         $result['msg'] = $origText;
                         //original case
                     }
                 }
             }
         }
         if ($result['blocked']) {
             $matchingBlockData = $blockData;
             break;
         }
     }
     $expected_id = isset($matchingBlockData) && $matchingBlockData['id'] ? $matchingBlockData['id'] : 0;
     PhalanxShadowing::check($text, $expected_id);
     wfProfileOut(__METHOD__);
     return $result;
 }
Exemplo n.º 4
0
 public static function removeFilter($blockId, $updateCache = true)
 {
     global $wgExternalSharedDB, $wgUser, $wgMemc;
     wfProfileIn(__METHOD__);
     // todo this will need to be changed
     //get data before deletion - we need it for cache update
     $data = Phalanx::getFromId($blockId);
     $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
     $dbw->delete('phalanx', array('p_id' => intval($blockId)), __METHOD__);
     if (!$dbw->affectedRows()) {
         wfProfileOut(__METHOD__);
         return array('error' => true);
     }
     $dbw->commit();
     if ($updateCache) {
         self::updateCache($data, null);
     }
     self::logDelete($data);
     $result = array('error' => false, 'text' => wfMsg('phalanx-unblock-message', $data['id']));
     wfProfileOut(__METHOD__);
     return $result;
 }