Esempio n. 1
0
 /**
  * Get the section title for a talk page post
  * @param $event EchoEvent
  * @param $user User
  * @return string
  */
 protected function getSectionTitle($event, $user)
 {
     $extra = $event->getExtra();
     if (!empty($extra['section-title'])) {
         if ($event->userCan(Revision::DELETED_TEXT, $user)) {
             return EchoDiscussionParser::getTextSnippet($extra['section-title'], 30);
         } else {
             return $this->getMessage('echo-rev-deleted-text-view')->text();
         }
     }
     return '';
 }
 public function execute()
 {
     $apiURL = 'http://en.wikipedia.org/w/api.php';
     $revisions = explode(',', $this->getArg(0));
     // Retrieve original revisions and their predecessors
     $requestData = array('format' => 'php', 'action' => 'query', 'prop' => 'revisions', 'revids' => implode('|', $revisions));
     $originalData = Http::post($apiURL, array('postData' => $requestData));
     $data = unserialize($originalData);
     $pages = $data['query']['pages'];
     foreach ($pages as $page) {
         if (count($page['revisions']) != 1) {
             continue;
         }
         $revid = $page['revisions'][0]['revid'];
         $newRequest = array('format' => 'php', 'action' => 'query', 'prop' => 'revisions', 'titles' => $page['title'], 'rvstartid' => $revid, 'rvlimit' => 2, 'rvprop' => 'ids|content|user');
         $newData = Http::post($apiURL, array('postData' => $newRequest));
         $newData = unserialize($newData);
         $oldText = '';
         $newText = '';
         $allData = $newData['query']['pages'];
         $pageData = array_shift($allData);
         if (count($pageData['revisions']) == 2) {
             $revision1 = $pageData['revisions'][0];
             $revision2 = $pageData['revisions'][1];
             $oldText = trim($revision2['*']) . "\n";
             $newText = trim($revision1['*']) . "\n";
         } elseif (count($pageData['revisions']) == 1) {
             $revision1 = $pageData['revisions'][0];
             $newText = trim($revision1['*']) . "\n";
             $oldText = '';
         }
         $user = $pageData['revisions'][0]['user'];
         print "http://en.wikipedia.org/w/index.php?diff=prev&oldid={$revid}\n";
         EchoDiscussionParser::getInterestedUsers($oldText, $newText, $user);
         // FIXME: getInterestedUsers() is undefined
     }
 }
Esempio n. 3
0
 /**
  * @dataProvider provider_getChangeSet
  */
 public function testGetChangeSet($message, array $expect, $leftText, $rightText)
 {
     $changeSet = EchoDiscussionParser::getMachineReadableDiff($leftText, $rightText);
     unset($changeSet['_info']);
     $this->assertEquals($expect, $changeSet, $message);
 }
 /**
  * Gets the username (or IP) from the provided signature.
  *
  * @return string|null Returns username, IP, or null if none could be detected
  */
 public static function extractUserFromSignature($signatureText)
 {
     $users = \EchoDiscussionParser::extractUsersFromLine($signatureText);
     if (count($users) > 0) {
         return $users[0];
     } else {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * Handler for ArticleSaveComplete hook
  * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete
  * @param $article Article edited
  * @param $user User who edited
  * @param $text string New article text
  * @param $summary string Edit summary
  * @param $minoredit bool Minor edit or not
  * @param $watchthis bool Watch this article?
  * @param $sectionanchor string Section that was edited
  * @param $flags int Edit flags
  * @param $revision Revision that was created
  * @param $status Status
  * @return bool true in all cases
  */
 public static function onArticleSaved(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status)
 {
     global $wgEchoNotifications, $wgRequest;
     if ($revision) {
         EchoDiscussionParser::generateEventsForRevision($revision);
         // Handle the case of someone undoing an edit, either through the
         // 'undo' link in the article history or via the API.
         if (isset($wgEchoNotifications['reverted'])) {
             $title = $article->getTitle();
             $undidRevId = $wgRequest->getVal('wpUndidRevision');
             if ($undidRevId) {
                 $undidRevision = Revision::newFromId($undidRevId);
                 if ($undidRevision && $undidRevision->getTitle()->equals($title)) {
                     $victimId = $undidRevision->getUser();
                     if ($victimId) {
                         // No notifications for anonymous users
                         EchoEvent::create(array('type' => 'reverted', 'title' => $title, 'extra' => array('revid' => $revision->getId(), 'reverted-user-id' => $victimId, 'reverted-revision-id' => $undidRevId, 'method' => 'undo'), 'agent' => $user));
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Gets a regular expression that will match this wiki's
  * timestamps as given by ~~~~.
  *
  * @throws MWException
  * @return String regular expression fragment.
  */
 static function getTimestampRegex()
 {
     if (self::$timestampRegex !== null) {
         return self::$timestampRegex;
     }
     // Step 1: Get an exemplar timestamp
     $title = Title::newMainPage();
     $user = User::newFromName('Test');
     $options = new ParserOptions();
     global $wgParser;
     $exemplarTimestamp = $wgParser->preSaveTransform('~~~~~', $title, $user, $options);
     // Step 2: Generalise it
     // Trim off the timezone to replace at the end
     $output = $exemplarTimestamp;
     $tzRegex = '/\\s*\\(\\w+\\)\\s*$/';
     $tzMatches = array();
     preg_match($tzRegex, $output, $tzMatches);
     $output = preg_replace($tzRegex, '', $output);
     $output = preg_quote($output, '/');
     $output = preg_replace('/[^\\d\\W]+/u', '[^\\d\\W]+', $output);
     $output = preg_replace('/\\d+/u', '\\d+', $output);
     $output .= preg_quote($tzMatches[0]);
     if (!preg_match("/{$output}/u", $exemplarTimestamp)) {
         throw new MWException("Timestamp regex does not match exemplar");
     }
     self::$timestampRegex = $output;
     return $output;
 }
Esempio n. 7
0
 /**
  * Extract the comment left by a user on a talk page from the event.
  * @param $event EchoEvent The event to format the comment of
  * @param $user User The user to format content for
  * @return string Up to the first 200 characters of the comment
  */
 protected function formatCommentText(EchoEvent $event, $user)
 {
     if (!$event->userCan(Revision::DELETED_TEXT, $user)) {
         return $this->getMessage('echo-rev-deleted-text-view')->text();
     }
     $extra = $event->getExtra();
     if (!isset($extra['content'])) {
         return '';
     }
     $content = EchoDiscussionParser::stripHeader($extra['content']);
     $content = EchoDiscussionParser::stripSignature($content);
     $content = EchoDiscussionParser::stripIndents($content);
     return EchoDiscussionParser::getTextSnippet($content, 200);
 }
 public function testGetSectionCount()
 {
     $one = "==Zomg==\nfoobar\n";
     $two = "===SubZomg===\nHi there\n";
     $three = "==Header==\nOh Hai!\n";
     $this->assertEquals(1, EchoDiscussionParser::getSectionCount($one));
     $this->assertEquals(2, EchoDiscussionParser::getSectionCount($one . $two));
     $this->assertEquals(2, EchoDiscussionParser::getSectionCount($one . $three));
     $this->assertEquals(3, EchoDiscussionParser::getSectionCount($one . $two . $three));
 }