function assertContentPatch($server, $patchId, $clock, $pageName, $op, $previousPatch) { $patchName = substr($patchId, 0, -strlen($clock - 1)); $patch = getSemanticRequest($server, '[[patchID::' . $patchId, '-3FonPage/-3FhasOperation/-3Fprevious'); PHPUnit_Framework_Assert::assertEquals($pageName, $patch[0]); if (strtolower(substr($patch[2], 0, strlen('Patch:'))) == 'patch:') { $patch[2] = substr($patch[2], strlen('patch:')); } PHPUnit_Framework_Assert::assertEquals(strtolower($previousPatch), strtolower(substr($patch[2], 0, -1)), 'Previous patch on patch ' . $patchId . ' must be but is ' . $patch[2]); $opFound = explode(',', $patch[1]); PHPUnit_Framework_Assert::assertTrue(count($op[$pageName]) == count($opFound), 'Patch ' . $patchId . ' must contains ' . count($op[$pageName]) . ' operations but ' . count($opFound) . ' operations were found'); for ($j = 0; $j < count($opFound); $j++) { $o = str_replace(' ', '', $opFound[$j]); $opi = explode(';', $o); PHPUnit_Framework_Assert::assertEquals(strtolower(substr($patchName . $clock, strlen('patch:'))), strtolower($opi[0]), 'Operation id on patch ' . $patchId . ' must be ' . $patchName . $clock . ' but ' . strtolower($opi[0]) . ' was found'); $a = strtolower($op[$pageName][$j][strtolower($opi[1])]); $b = strtolower(utils::contentDecoding($opi[3])); PHPUnit_Framework_Assert::assertEquals(strtolower($op[$pageName][$j][strtolower($opi[1])]), strtolower(utils::contentDecoding($opi[3]))); $clock = $clock + 1; } }
public function storePage($pageName, $rev) { global $wgUser; $text = ' [[Special:ArticleAdminPage|DSMW Admin functions]] ==Features== [[patchID::' . $this->mPatchId . '| ]] \'\'\'SiteID:\'\'\' [[siteID::' . $this->mSiteId . ']] \'\'\'SiteUrl:\'\'\' [[siteUrl::' . $this->mSiteUrl . ']] \'\'\'Rev:\'\'\' [[Rev::' . $rev . ']] '; if ($this->mRemote) { $text .= '\'\'\'Remote Patch\'\'\' '; } else { $this->mPrevPatch = utils::getLastPatchId($pageName); if ($this->mPrevPatch == false) { $this->mPrevPatch = "none"; } $this->mCausal = utils::searchCausalLink($pageName, $this->mCausal); } $text .= '\'\'\'Date:\'\'\' ' . date(DATE_RFC822) . ' '; if ($this->mAttachment) { $text .= '\'\'\'Date of upload of the Attachment:\'\'\' [[DateAtt::' . $this->mDate . ']] \'\'\'Mime:\'\'\' [[Mime::' . $this->mMime . ']] \'\'\'Size:\'\'\' [[Size::' . $this->mSize . ']] \'\'\'Url:\'\'\' [[Url::' . $this->mUrl . ']] '; } $text .= '\'\'\'User:\'\'\' ' . $wgUser->getName() . ' This is a patch of the article: [[onPage::' . $pageName . ']] <br> '; if ($this->mAttachment == false) { $text .= '==Operations of the patch== {| class="wikitable" border="1" style="text-align:left; width:80%;" |- !bgcolor=#c0e8f0 scope=col | Type !bgcolor=#c0e8f0 scope=col | Content |- '; if ($this->mRemote == true) { foreach ($this->mOperations as $op) { $opArr = explode(";", $op); $text .= '|[[hasOperation::' . $op . '| ]]' . $opArr[1] . ' |<nowiki>' . utils::contentDecoding($opArr[3]) . '</nowiki> |- '; } } else { $i = 1; // op counter foreach ($this->mOperations as $operation) { $lineContent = $operation->getLineContent(); $lineContent1 = utils::contentEncoding($lineContent); // base64 encoding $type = $operation instanceof LogootIns ? 'Insert' : 'Delete'; $operationID = utils::generateID(); $text .= '|[[hasOperation::' . $operationID . ';' . $type . ';' . $operation->getLogootPosition()->toString() . ';' . $lineContent1 . '| ]]' . $type; // displayed text $lineContent2 = $lineContent; $text .= ' |<nowiki>' . $lineContent2 . '</nowiki> |- '; } } $text .= '|}'; } if (is_array($this->mPrevPatch)) { $text .= ' ==Previous patch(es)== [[previous::'; foreach ($this->mPrevPatch as $prev) { $text .= $prev . ';'; } $text .= ']]'; } else { $text .= ' ==Previous patch(es)== [[previous::' . $this->mPrevPatch . ']]'; } $text .= ' ==Causal Link== [[causal::' . $this->mCausal . ']]'; $title = Title::newFromText($this->mID, PATCH); $article = new Article($title); $article->doEdit($text, $summary = ""); }
/** * create a new patch (page) * * @param <String> $patchId * @param <String> $onPage * @param <String> $previousPatch * @param <array> $operations */ static function createPatch($patchId, $onPage, $previousPatch, $operations, $siteID) { $text = ' [[Special:ArticleAdminPage|DSMW Admin functions]] ==Features== [[patchID::' . $patchId . '| ]] \'\'\'SiteID:\'\'\' [[siteID::' . $siteID . ']] \'\'\'Remote Patch\'\'\' \'\'\'Integration Date:\'\'\' ' . date(DATE_RFC822) . ' This is a patch of the article: [[onPage::' . $onPage . ']] ==Operations of the patch== {| class="wikitable" border="1" style="text-align:left; width:80%;" |- !bgcolor=#c0e8f0 scope=col | Type !bgcolor=#c0e8f0 scope=col | Content |- '; foreach ($operations as $op) { $opArr = explode(";", $op); $text .= '|[[hasOperation::' . $op . '| ]]' . $opArr[1] . ' |<nowiki>' . utils::contentDecoding($opArr[3]) . '</nowiki> |- '; } if (is_array($previousPatch)) { $text .= '|}'; $text .= ' ==Previous patch(es)== [[previous::'; foreach ($previousPatch as $prev) { $text .= $prev . ';'; } $text .= ']]'; } else { $text .= '|}'; $text .= ' ==Previous patch(es)== [[previous::' . $previousPatch . ']]'; } $title = Title::newFromText($patchId, PATCH); $article = new Article($title); $article->doEdit($text, $summary = ""); }
/** *transforms a string operation from a patch page into a logoot operation * insertion or deletion * returns false if there is a problem with the type of the operation * * @param <String> $operation * @return <Object> logootOp */ function operationToLogootOp($operation) { wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@@@@@@@@@@@ - function operationToLogootOp : ' . $operation); $arr = array(); $res = explode(';', $operation); foreach ($res as $key => $attr) { $res[$key] = trim($attr, " "); } //echo $operation." <--\n"; //var_dump($res); $position = $res[2]; $position = str_ireplace('(', '', $position); $position = str_ireplace(')', '', $position); $res1 = explode(' ', $position); foreach ($res1 as $id) { $id1 = explode(':', $id); $idArrray = new LogootId($id1[0], $id1[1], $id1[2]); $arr[] = $idArrray; } $logootPos = new LogootPosition($arr); /*$id1 = str_ireplace('(', '', $res[2]); $id2 = $res[3]; $id3 = str_ireplace(')', '', $res[4]); $idArrray = new LogootId($id1, $id2, $id3); echo $logootPos->toString();*/ // if(strpos($res[3], '-5B-5B')!==false || strpos($res[3], '-5D-5D')!==false) { // $res[3] = utils::decodeRequest($res[3]); // } $res[3] = utils::contentDecoding($res[3]); // if($res[3]=="") $res[3]="\r\n"; if ($res[1] == "Insert") { $logootOp = manager::getNewLogootIns($logootPos, $res[3]); //new LogootIns($logootPos, $res[3]); } elseif ($res[1] == "Delete") { $logootOp = manager::getNewLogootDel($logootPos, $res[3]); //new LogootDel($logootPos, $res[3]); } else { $logootOp = false; } //echo $logootOp; return $logootOp; }
/** *transforms a string operation from a patch page into a logoot operation * insertion or deletion * returns false if there is a problem with the type of the operation * * @param <String> $operation * @return <Object> logootOp */ function operationToLogootOp($operation) { wfDebugLog('p2p', ' - function operationToLogootOp : ' . $operation); $arr = array(); $res = explode(';', $operation); foreach ($res as $key => $attr) { $res[$key] = trim($attr, " "); } $position = $res[2]; $position = str_ireplace('(', '', $position); $position = str_ireplace(')', '', $position); $res1 = explode(' ', $position); foreach ($res1 as $id) { $id1 = explode(':', $id); $idArrray = new LogootId($id1[0], $id1[1]); $arr[] = $idArrray; } $logootPos = new LogootPosition($arr); // if(strpos($res[3], '-5B-5B')!==false || strpos($res[3], '-5D-5D')!==false) { // $res[3] = utils::decodeRequest($res[3]); // } $res[3] = utils::contentDecoding($res[3]); // if($res[3]=="") $res[3]="\r\n"; if ($res[1] == "Insert") { $logootOp = new LogootIns($logootPos, $res[3]); } elseif ($res[1] == "Delete") { $logootOp = new LogootDel($logootPos, $res[3]); } else { $logootOp = false; } return $logootOp; }