/** *Integrates the operation(LogootOp) into the article via the logoot algorithm * * @param <Object> $operation * @param <String or Object> $article */ function logootIntegrate($operations, $article) { global $wgCanonicalNamespaceNames; $indexNS = 0; wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@@@@@@@ - function logootIntegrate : ' . $article); $dbr = wfGetDB(DB_SLAVE); $dbr->immediateBegin(); if (is_string($article)) { //if there is a space in the title, repalce by '_' $article = str_replace(" ", "_", $article); if (strpos($article, ":") === false) { $pageid = $dbr->selectField('page', 'page_id', array('page_title' => $article)); } else { //if there is a namespace preg_match("/^(.+?)_*:_*(.*)\$/S", $article, $tmp); $articleWithoutNS = $tmp[2]; $NS = $tmp[1]; if (in_array($NS, $wgCanonicalNamespaceNames)) { foreach ($wgCanonicalNamespaceNames as $key => $value) { if ($NS == $value) { $indexNS = $key; } } } $pageid = $dbr->selectField('page', 'page_id', array('page_title' => $articleWithoutNS, 'page_namespace' => $indexNS)); } // get the page namespace $pageNameSpace = $dbr->selectField('page', 'page_namespace', array('page_id' => $pageid)); /*the ns must not be a pullfeed, pushfeed, changeset or patch namespace. If the page name is the same in different ns we can get the wrong * page id */ if ($pageNameSpace == PULLFEED || $pageNameSpace == PUSHFEED || $pageNameSpace == PATCH || $pageNameSpace == CHANGESET) { $pageid = 0; } $lastRev = Revision::loadFromPageId($dbr, $pageid); if (is_null($lastRev)) { $rev_id = 0; } else { $rev_id = $lastRev->getId(); } wfDebugLog('p2p', ' -> pageId : ' . $pageid); wfDebugLog('p2p', ' -> rev_id : ' . $rev_id); $title = Title::newFromText($article); $article = new Article($title); } else { $rev_id = $article->getRevIdFetched(); } $listOp = array(); //$blobInfo = BlobInfo::loadBlobInfo($rev_id); $model = manager::loadModel($rev_id); $logoot = manager::getNewEngine($model, DSMWSiteId::getInstance()->getSiteId()); // new logootEngine($model); foreach ($operations as $operation) { wfDebugLog('p2p', ' - operation : ' . $operation); wfDebugLog('testlog', ' - operation : ' . $operation); if (!$operation instanceof LogootOperation) { $operation = operationToLogootOp($operation); } if ($operation != false && is_object($operation)) { $listOp[] = $operation; wfDebugLog('testlog', ' -> Operation: ' . $operation->getLogootPosition()->toString()); //$blobInfo->integrateBlob($operation); } } //end foreach operations $p = new LogootPatch($rev_id, $listOp); $logoot->integrate($p); $modelAfterIntegrate = $logoot->getModel(); //$revId = utils::getNewArticleRevId(); $status = $article->doEdit($modelAfterIntegrate->getText(), $summary = ""); $revId = $status->value['revision']->getId(); manager::storeModel($revId, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0); return array($revId, $p); }
function testOperationToLogootOp() { $pageName = 'Toto'; $content = 'toto tata titi'; $this->assertTrue($this->p2pBot1->createPage($pageName, $content), 'failed to create page ' . $pageName . ' (' . $this->p2pBot1->bot->results . ')'); $patchId = getSemanticRequest($this->p2pBot1->bot->wikiServer, '[[Patch:+]][[onPage::Toto]]', ''); $patchId = $patchId[0]; $dom = getPatchXML($this->p2pBot1->bot->wikiServer, $patchId); $op = $dom->getElementsByTagName('operation'); foreach ($op as $o) { $operations[] = $o->firstChild->nodeValue; } $this->assertTrue(count($operations) == 1); $op = operationToLogootOp($operations[0]); $this->assertTrue($op instanceof LogootIns, 'failed to create logootIns operation'); $this->assertEquals($content, $op->getLineContent()); // logoutIntegrate }