Пример #1
0
 /**
  * singleton
  *
  * @return WUMThreeWayBasedMerger
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Пример #2
0
 /**
  * This method appends a pretty printed version of a patch fault to the corresponding section
  * 
  * @param unknown_type $text
  * @param unknown_type $patches
  * @return unknown_type
  */
 private function appendPatchesToSections($text, $patches)
 {
     global $wgParser;
     foreach ($patches as $patch) {
         if ($patch->section == -1) {
             $patchText = WUMThreeWayBasedMerger::getInstance()->getPatchText($patch);
             $patchText = str_replace("=", "//--\\", $patchText);
             $text .= "\n\n" . $patchText;
         } else {
             $sectionText = $wgParser->getSection($text, $patch->section);
             $patchText = WUMThreeWayBasedMerger::getInstance()->getPatchText($patch);
             $patchText = str_replace("=", "//--\\", $patchText);
             $sectionText .= "\n\n" . $patchText;
             $text = $wgParser->replaceSection($text, $patch->section, $sectionText);
         }
     }
     return $text;
 }
Пример #3
0
 /**
  * This method is indirectly called by WP if one edits
  * an article in the WP clone. It starts and controls the
  * merge process and returns its result.
  *
  * @param $title
  * @param $newWPText
  * @param $currentUPText
  * @return unknown_type
  */
 public function merge($title, $newWPText, $currentUPText)
 {
     wfProfileIn('WUMMergeController->merge');
     if ($this->checkIgnoreNewWPVersion($currentUPText)) {
         return $currentUPText;
     }
     $overwrite = $this->checkOverwriteUPVersion($newWPText);
     if ($overwrite !== false) {
         return $overwrite;
     }
     //get the last WP version
     $originalWPText = $this->getOriginalWPText($title);
     $newWPText = $this->prepareText($newWPText);
     $originalWPText = $this->prepareText($originalWPText);
     $currentUPText = $this->prepareText($currentUPText);
     if (strlen($originalWPText) == 0) {
         return $newWPText . "\n" . $currentUPText;
     }
     //check whether to use the table based merger
     global $wumUseTableBasedMerger;
     if ($wumUseTableBasedMerger) {
         $tbm = WUMTableBasedMerger::getInstance();
         list($newWPText, $currentUPText, $originalWPText) = $tbm->merge($title, $newWPText, $currentUPText, $originalWPText);
         //wfProfileOut('WUMMergeController->merge');
         //return $currentUPText;
     }
     //do three way merge
     $twmResult = WUMThreeWayBasedMerger::getInstance()->merge($originalWPText, $newWPText, $currentUPText);
     //do section based merge if merge faults occured during three way merge
     if (count($twmResult['mergeFaults']) == 0) {
         $text = $twmResult['mergedText'];
     } else {
         $text = WUMSectionBasedMerger::getInstance()->merge($originalWPText, $newWPText, $currentUPText, $twmResult['mergedText'], $twmResult['mergeFaults']);
     }
     //finalize merge result, i.e. replace temporary characters
     $text = WUMThreeWayBasedMerger::getInstance()->finalizeMergeResult($text);
     wfProfileOut('WUMMergeController->merge');
     return $text;
 }
 /**
  * helper method for the patch_apply method
  *
  * @param unknown_type $text
  * @param unknown_type $patch
  * @param unknown_type $offset
  * @return unknown_type
  */
 function patch_DoApply($text, $patch, $offset)
 {
     $match_distance = $this->Match_Distance;
     $start = $patch->start1 - $match_distance + $offset;
     if ($start < 0) {
         $start = 0;
     }
     $end = $patch->start1 + $patch->length1 + $match_distance + $offset;
     if ($end > strlen($text)) {
         $end = strlen($text);
     }
     $subText = substr($text, $start, $end - $start);
     $pattern = "";
     for ($i = 0; $i < count($patch->diffs); $i++) {
         if ($patch->diffs[$i][0] == DIFF_EQUAL || $patch->diffs[$i][0] == DIFF_DELETE) {
             $pattern .= $patch->diffs[$i][1];
         }
     }
     $startSubString = strpos($subText, $pattern);
     if ($startSubString != strrpos($subText, $pattern) || $startSubString === false) {
         //no exact match
         return array(0 => $text, 1 => false);
     }
     $replacement = "";
     for ($i = 0; $i < count($patch->diffs); $i++) {
         if ($patch->diffs[$i][0] == DIFF_EQUAL || $patch->diffs[$i][0] == DIFF_INSERT) {
             $replacement .= $patch->diffs[$i][1];
         }
     }
     $patchText = WUMThreeWayBasedMerger::getInstance()->getPatchText($patch);
     $replacement = str_replace($patchText, str_replace("=", "//--\\", $patchText), $replacement);
     $text = substr($text, 0, $start + $startSubString) . $replacement . substr($text, $start + $startSubString + $patch->length1);
     return array(0 => $text, 1 => true);
 }