/**
  * @param AbstractRevision $revision
  * @param Title $title
  * @return array
  */
 public function getLinks(AbstractRevision $revision, Title $title)
 {
     global $wgParser;
     $options = new \ParserOptions();
     $output = $wgParser->parse($revision->getContent('wikitext'), $title, $options);
     return array_keys($output->getExternalLinks());
 }
 /**
  * @param IContextSource $context
  * @param AbstractRevision $newRevision
  * @param AbstractRevision|null $oldRevision
  * @param Title $title
  * @return Status
  */
 public function validate(IContextSource $context, AbstractRevision $newRevision, AbstractRevision $oldRevision = null, Title $title)
 {
     global $wgSpamRegex;
     /*
      * This should not roundtrip to Parsoid; SpamRegex checks will be
      * performed upon submitting new content, and content is always
      * submitted in wikitext. It will only be transformed once it's being
      * saved to DB.
      */
     $text = $newRevision->getContent('wikitext');
     // back compat, $wgSpamRegex may be a single string or an array of regexes
     $regexes = (array) $wgSpamRegex;
     foreach ($regexes as $regex) {
         if (preg_match($regex, $text, $matches)) {
             return Status::newFatal('spamprotectionmatch', $matches[0]);
         }
     }
     return Status::newGood();
 }
 /**
  * @param IContextSource $context
  * @param AbstractRevision $newRevision
  * @param AbstractRevision|null $oldRevision
  * @param Title $title
  * @return Status
  */
 public function validate(IContextSource $context, AbstractRevision $newRevision, AbstractRevision $oldRevision = null, Title $title)
 {
     global $wgOut;
     $newContent = $newRevision->getContent('wikitext');
     $oldContent = $oldRevision !== null ? $oldRevision->getContent('wikitext') : '';
     /** @var SimpleCaptcha $captcha */
     $captcha = ConfirmEditHooks::getInstance();
     $wikiPage = new WikiPage($title);
     // first check if the submitted content is offensive (as flagged by
     // ConfirmEdit), next check for a (valid) captcha to have been entered
     if ($captcha->shouldCheck($wikiPage, $newContent, false, false, $oldContent) && !$captcha->passCaptchaLimited()) {
         // getting here means we submitted bad content without good captcha
         // result (or any captcha result at all) - let's get the captcha
         // HTML to display as error message!
         $html = $captcha->getForm();
         // some captcha implementations need CSS and/or JS, which is added
         // via their getForm() methods (which we just called) -
         // let's extract those and respond them along with the form HTML
         $html = $wgOut->buildCssLinks() . $wgOut->getScriptsForBottomQueue(true) . $html;
         $msg = wfMessage('flow-spam-confirmedit-form')->rawParams($html);
         return Status::newFatal($msg);
     }
     return Status::newGood();
 }
 protected function calcContentLength(AbstractRevision $revision)
 {
     if ($revision->isModerated() && !$revision->isLocked()) {
         return 0;
     } else {
         return $revision->getContentLength() ?: mb_strlen($revision->getContent('wikitext'));
     }
 }
 /**
  * @param AbstractRevision $revision
  * @return string
  */
 public function getContent(AbstractRevision $revision)
 {
     return $this->apply($revision->getContent('html'), $revision->getCollection()->getTitle());
 }