Beispiel #1
0
 public function undoPatch(LogootPatch $patch)
 {
     $this->clock = utils::getNextClock();
     wfDebugLog('p2p', $this->clock . ' - function logootPlusEngine::undoPatch ');
     $opList = array();
     foreach ($patch as $op) {
         $opList[] = LogootPlusOperation::inv($op);
     }
     $undoPatch = new LogootPatch($this->sessionid . $this->clock, $opList);
     $undoPatch->setRefPatch($patch->getId());
     return $undoPatch;
 }
Beispiel #2
0
 /**
  *
  * @param <bool> $remote
  * @param <bool> $attachment
  * @param <array> $operations
  * @param <string> $siteUrl
  * @param <array> $causalLink
  * @param <string> $patchid
  * @param <string> $previousPatch
  * @param <string> $siteID
  * @param <string> $Mime
  * @param <string> $Size
  * @param <string> $Url
  * @param <string> $Date
  */
 public function __construct($remote, $attachment, $operations, $siteUrl = '', $causalLink = '', $patchid = '', $previousPatch = '', $siteID = '', $Mime = '', $Size = '', $Url = '', $Date = '')
 {
     global $wgServer;
     $this->mRemote = $remote;
     $this->mID = utils::generateID();
     if ($remote) {
         $this->mPatchId = $patchid;
         $this->mSiteId = $siteID;
         $this->mID = $patchid;
         wfDebugLog('p2p', '- ' . __METHOD__ . ' - ' . __CLASS__ . "- remote Patch (Site:{$siteID} ; PatchID:{$patchid} ) ");
     } else {
         $this->mPatchId = "Patch:" . $this->mID;
         $this->mSiteId = DSMWSiteId::getInstance()->getSiteId();
         wfDebugLog('p2p', '- ' . __METHOD__ . ' - ' . __CLASS__ . "- new Patch (Site:{$this->mSiteId} ; PatchID:{$this->mPatchId} ) ");
     }
     if (!isset($operations)) {
         $operations = new LogootPatch($this->mPatchId);
     } else {
         $operations->setId($this->mPatchId);
     }
     $this->mOperations = $operations;
     $this->mPrevPatch = $previousPatch;
     $this->mSiteUrl = $siteUrl;
     $this->mCausal = $causalLink;
     $this->mAttachment = $attachment;
     if ($attachment) {
         $this->mMime = $Mime;
         $this->mSize = $Size;
         if ($remote) {
             $this->mDate = $Date;
             $this->mUrl = $Url;
         } else {
             $this->mDate = date(DATE_RFC822);
             $this->mPatchId = "Patch:ATT" . $this->mID;
             $this->mUrl = $wgServer . $Url;
             $this->mID = "Patch:ATT" . $this->mID;
         }
     }
 }
Beispiel #3
0
 public function generate($oldText, $newText)
 {
     $this->clock = utils::getNextClock();
     wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate ');
     /* explode into lines */
     $ota = explode("\n", $oldText);
     $nta = explode("\n", $newText);
     $counter = 0;
     if (count($ota) == 1 && $ota[0] == "") {
         // c'est un nouveau document
         unset($ota[0]);
         wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - création ');
         $listOp = $this->generate_ins_text(1, $nta);
         return $listOp;
     } else {
         list($trouve, $deb, $fin) = $this->locate($ota, $nta);
         if ($trouve) {
             //il y a eu un ajout de texte au début et/ou à la fin uniquement
             $listOp = new LogootPatch($this->sessionid . $this->clock);
             if ($deb > 0) {
                 wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - ajout au début ');
                 $listOp1 = $this->generate_ins_text(1, array_slice($nta, 0, $deb));
                 $listOp->addPatch($listOp1);
                 $delta = $listOp1->size();
             } else {
                 $delta = 0;
             }
             if ($fin + 1 < count($nta)) {
                 wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - ajout à la fin ');
                 $listOp2 = $this->generate_ins_text(count($ota) + 1 + $delta, array_slice($nta, $fin + 1, count($nta) - ($fin + 1)));
                 $listOp->addPatch($listOp2);
             }
             return $listOp;
         } else {
             $listOp = new LogootPatch($this->sessionid . $this->clock);
             $diffs = new Diff1($ota, $nta);
             /* convert 4 operations into 2 operations */
             foreach ($diffs->edits as $operation) {
                 switch ($operation->type) {
                     case "add":
                         $adds = $operation->closing;
                         ksort($adds, SORT_NUMERIC);
                         foreach ($adds as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Ajout ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_ins_line($lineNb, $linetxt));
                             $counter += 1;
                         }
                         break;
                     case "delete":
                         foreach ($operation->orig as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Suppression ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_del_line($lineNb + $counter, $linetxt));
                             $counter -= 1;
                         }
                         break;
                     case "change":
                         foreach ($operation->orig as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Change/Suppression ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_del_line($lineNb + $counter, $linetxt));
                             $counter -= 1;
                         }
                         $adds1 = $operation->closing;
                         ksort($adds1, SORT_NUMERIC);
                         foreach ($adds1 as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Change/Ajout ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_ins_line($lineNb, $linetxt));
                             $counter += 1;
                         }
                         break;
                     case "copy":
                         break;
                     default:
                 }
             }
             $listOp->applied();
             return $listOp;
         }
     }
 }