public static function getEdits($articleId) { $dbr = wfGetDB(DB_SLAVE); $gr = 0; $gr = $dbr->selectField('good_revision', array('gr_rev'), array('gr_page' => $articleId)); $edits = self::getSigEdits($gr); if ($edits) { return $edits; } $res = $dbr->select(array('revision', 'text'), array('rev_id', 'old_text', 'old_flags', 'rev_timestamp', 'rev_user', 'rev_user_text'), array('rev_page' => $articleId, 'rev_text_id = old_id'), __METHOD__, array('order by' => 'rev_timestamp asc')); $txts = array(); $grTxt = false; foreach ($res as $row) { $flags = explode(',', $row->old_flags); $rowText = Revision::decompressRevisionText($row->old_text, $flags); $stepsSection = Wikitext::getStepsSection($rowText); //print("Got txt for rev" . $row->rev_id . "\n"); $txts[] = array('text' => $stepsSection[0], 'rev_page' => $row->rev_page, 'rev_id' => $row->rev_id, 'rev_user' => $row->rev_user, 'rev_user_text' => $row->rev_user_text); if ($row->rev_id == $gr) { $grTxt = $stepsSection[0]; break; } } if (!$grText) { $grText = $txts[sizeof($txts) - 1]['text']; $gr = $txts[sizeof($txts) - 1]['rev_id']; } global $wgContLang; $segmentedGr = $wgContLang->segmentForDiff($grText); $grArr = explode("\n", $segmentedGr); $grSize = strlen($segmentedGr) - sizeof($grArr) + 1; // Amount added $added = 0; $edits = array(); $first = true; $lastAdds = 0; foreach ($txts as $txt) { $txtArr = explode("\n", $wgContLang->segmentForDiff($txt['text'])); //print("diff for rev " . $txt['rev_id'] . " " . wfTimestampNow() . "\n"); $diffs = new Diff($txtArr, $grArr); $adds = 0; foreach ($diffs as $diff) { foreach ($diff as $d) { if ($d->type == 'copy') { foreach ($d->closing as $cl) { $adds += strlen($cl); } } elseif ($d->type == 'change') { $wld = new WordLevelDiff($d->orig, $d->closing); foreach ($wld->edits as $edit) { if ($edit->type == 'copy') { foreach ($edit->orig as $o) { $adds += strlen($o); } } } } } } if ($adds > $added) { $newAdded = $adds - $added; $added = $adds; } else { $newAdded = 0; } if ($newAdded > 0) { // First edit or didn't add steps // This prevents counting the steps section formatting fix as a contributor if ($first || $lastAdds != 0) { $edits[] = array('added' => $newAdded, 'gr' => $gr, 'rev' => $txt['rev_id'], 'page' => $txt['page_id'], 'user' => $txt['rev_user'], 'username' => $txt['rev_user_text']); } } $first = false; $lastAdds = $adds; } if ($edits) { self::saveSigEdits($edits); } return $edits; }
/** * @return string */ public function getContentRaw() { if ($this->decompressedContent === null) { $this->decompressedContent = \Revision::decompressRevisionText($this->content, $this->flags); } return $this->decompressedContent; }