Exemplo n.º 1
0
 /**
  * Called from Phalanx::findBlocked
  *
  * @param $content string text to check
  */
 public static function check($content, $expected_id)
 {
     global $wgPhalanxShadowingPercentage;
     if (empty($wgPhalanxShadowingPercentage) || !is_numeric($wgPhalanxShadowingPercentage)) {
         return;
     }
     if (mt_rand(1, 100) <= $wgPhalanxShadowingPercentage) {
         wfProfileIn(__METHOD__);
         if (self::$typeName !== null) {
             wfDebug(__METHOD__ . '::' . self::$typeName . "\n");
             $service = new PhalanxService();
             $service->matchShadow(self::$typeName, $content, $expected_id);
         }
         wfProfileOut(__METHOD__);
     }
     self::$typeName = null;
 }
 /**
  * Get HTML with the list of block that apply for given text
  *
  * @param $blockText string text to be test against all blocks
  * @return string HTML
  */
 private function handleBlockTest($blockText)
 {
     wfProfileIn(__METHOD__);
     $service = new PhalanxService();
     $service->setLimit(20);
     $listing = '';
     $noMatches = true;
     foreach (Phalanx::getAllTypeNames() as $blockType) {
         $res = $service->match($blockType, $blockText);
         if (empty($res)) {
             continue;
         }
         $noMatches = false;
         $pager = new PhalanxBlockTestPager($blockType);
         $pager->setRows($res);
         $listing .= $pager->getHeader();
         $listing .= $pager->getBody();
     }
     if ($noMatches) {
         $pager = new PhalanxBlockTestPager(0);
         $listing .= $pager->getEmptyBody();
     }
     wfProfileOut(__METHOD__);
     return $listing;
 }
Exemplo n.º 3
0
 /**
  * Reload Phalanx II service to keep service in sync with blocks added from old Phalanx
  *
  * @param int|null $id block ID to be reloaded (or null to reload all blocks)
  * @return bool true if the request was successful
  */
 private static function reload($id = null)
 {
     wfProfileIn(__METHOD__);
     $service = new PhalanxService();
     $res = $service->reload(!is_null($id) ? [$id] : []) === 1;
     if ($res === false) {
         Wikia::log(__METHOD__, false, 'reload failed', true);
     }
     wfProfileOut(__METHOD__);
     return $res;
 }
Exemplo n.º 4
0
 /**
  * testBlock
  *
  * performs a test of all available phalanx filters and returns warning message if there are any
  * @author Kamil Koterba <*****@*****.**>
  *
  * @param $text String to match
  * @return String with HTML to display via AJAX
  */
 public static function testBlock($text)
 {
     wfProfileIn(__METHOD__);
     if (!class_exists('PhalanxService')) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $service = new PhalanxService();
     $blockFound = false;
     foreach (Phalanx::getAllTypeNames() as $blockType) {
         $res = $service->match($blockType, $text);
         if (!empty($res)) {
             $blockFound = true;
             break;
         }
     }
     $warning = '';
     if ($blockFound) {
         $phalanxTestTitle = SpecialPage::getTitleFor('Phalanx', 'test');
         $linkToTest = Linker::link($phalanxTestTitle, wfMessage('userrenametool-see-list-of-blocks')->escaped(), [], ['wpBlockText' => $text]);
         $warning = wfMessage('userrenametool-warning-phalanx-block', $text)->rawParams($linkToTest)->escaped();
     }
     wfProfileOut(__METHOD__);
     return $warning;
 }
Exemplo n.º 5
0
 /**
  * Delete Phalanx block
  *
  * @param $id Int - block ID
  * @return boolean true or false if error
  *
  * @author moli
  */
 public static function onDeletePhalanxBlock($id)
 {
     wfProfileIn(__METHOD__);
     $phalanx = Phalanx::newFromId($id);
     $id = $phalanx->delete();
     if ($id) {
         $service = new PhalanxService();
         $ids = array($id);
         $ret = $service->reload($ids);
     } else {
         $ret = false;
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }