public static function getInstance() { if (is_null(self::$_instance)) { self::$_instance = new DSMWSiteId(); } return self::$_instance; }
/** * * @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 == true) { $this->mPatchId = $patchid; $this->mSiteId = $siteID; $this->mID = $patchid; } else { $this->mPatchId = "Patch:" . $this->mID; $this->mSiteId = DSMWSiteId::getInstance()->getSiteId(); } $this->mOperations = $operations; $this->mPrevPatch = $previousPatch; $this->mSiteUrl = $siteUrl; $this->mCausal = $causalLink; $this->mAttachment = $attachment; if ($attachment == true) { $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; } } }
/** * * @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; } } }
/** * tests if the patch is remote * @param <String> $patchId * @return <int or bool> false if no occurence */ static function isRemote($patchId) { $serverId = DSMWSiteId::getInstance(); return strpos(strtolower($patchId), strtolower($serverId->getSiteId())); }
/** *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 attemptSave($editpage) { global $wgServerName, $wgScriptPath; $urlServer = 'http://' . $wgServerName . $wgScriptPath; wfDebugLog('p2p', "@@@@@@@@@@@@@@@@@@@@@ attemptSave : {$wgServerName}, {$wgScriptPath} - "); $ns = $editpage->mTitle->getNamespace(); if ($ns == PATCH || $ns == PUSHFEED || $ns == PULLFEED || $ns == CHANGESET) { return true; } $actualtext = $editpage->textbox1; //V2 $dbr = wfGetDB(DB_SLAVE); $lastRevision = Revision::loadFromTitle($dbr, $editpage->mTitle); if (is_null($lastRevision)) { $conctext = ""; $rev_id = 0; } elseif (($ns == NS_FILE || $ns == NS_IMAGE || $ns == NS_MEDIA) && $lastRevision->getRawText() == "") { $rev_id = 0; $conctext = $lastRevision->getText(); } else { $conctext = $lastRevision->getText(); //V1 conc $rev_id = $lastRevision->getId(); } //if there is no modification on the text if ($actualtext == $conctext) { return true; } $model = manager::loadModel($rev_id); $logoot = manager::getNewEngine($model, DSMWSiteId::getInstance()->getSiteId()); // new logootEngine($model); //get the revision with the edittime==>V0 $rev = Revision::loadFromTimestamp($dbr, $editpage->mTitle, $editpage->edittime); if (is_null($rev)) { $text = ""; $rev_id1 = 0; } else { $text = $rev->getText(); //VO $rev_id1 = $rev->getId(); } if ($conctext != $text) { //if last revision is not V0, there is editing conflict wfDebugLog('p2p', ' -> CONCURRENCE: '); wfDebugLog('p2p', ' -> + conctext :' . $conctext . '+(' . $rev_id . ') ts ' . $lastRevision->getTimestamp()); wfDebugLog('p2p', ' -> + text ' . $text . '+(' . $rev_id1 . ') ts ' . $editpage->edittime . ' ' . $rev->getTimestamp()); $model1 = manager::loadModel($rev_id1); $logoot1 = manager::getNewEngine($model1, DSMWSiteId::getInstance()->getSiteId()); // new logootEngine($model1); wfDebugLog('p2p', "========== Conc - {$urlServer} : \n" . $conctext . "\n--\n" . $text . "\n--\n" . $actualtext . "\n--\n"); $listOp1 = $logoot1->generate($text, $actualtext); wfDebugLog('p2p', $listOp1 . "===\n\n"); //creation Patch P2 $tmp = serialize($listOp1); $patch = new Patch(false, false, $listOp1, $urlServer, $rev_id1); if ($editpage->mTitle->getNamespace() == 0) { $title = $editpage->mTitle->getText(); } else { $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); } //integration: diffs between VO and V2 into V1 $logoot->integrate($listOp1); $modelAfterIntegrate = $logoot->getModel(); } else { //no edition conflict wfDebugLog('p2p', "=========== Std - {$urlServer} : \n" . $conctext . "\n--\n" . $actualtext . "\n--\n"); $listOp = $logoot->generate($conctext, $actualtext); wfDebugLog('p2p', $listOp . "===\n\n"); $modelAfterIntegrate = $logoot->getModel(); $tmp = serialize($listOp); $patch = new Patch(false, false, $listOp, $urlServer, $rev_id1); if ($editpage->mTitle->getNamespace() == 0) { $title = $editpage->mTitle->getText(); } else { $title = $editpage->mTitle->getNsText() . ':' . $editpage->mTitle->getText(); } } $revId = utils::getNewArticleRevId() + 1; wfDebugLog('p2p', ' -> store model rev : ' . $revId . ' session ' . session_id() . ' model ' . $modelAfterIntegrate->getText()); manager::storeModel($revId, $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0); $patch->storePage($title, $revId); //stores the patch in a wikipage $editpage->textbox1 = $modelAfterIntegrate->getText(); return true; }
function run() { global $wgServerName, $wgScriptPath, $wgServer, $wgScriptExtension; $urlServer = 'http://' . $wgServerName; wfProfileIn('DSMWUpdateJob::run()'); $revids = array(); $revids1 = array(); $page_ids = array(); //Getting all the revision ids of pages having been logootized $db = wfGetDB(DB_SLAVE); $model_table = $db->tableName('model'); $sql = "SELECT `rev_id` FROM {$model_table}"; $res = $db->query($sql); while ($row = $db->fetchObject($res)) { $revids[] = $row->rev_id; } $db->freeResult($res); //if (count($revids)==0) $revids=array(); //Getting all the revision ids without the pages in the DSMW namespaces and //Administration_pull_site_addition and Administration_pull_site_addition pages $rev_table = $db->tableName('revision'); $page_table = $db->tableName('page'); $sql = "SELECT {$rev_table}.`rev_id` FROM {$rev_table}, {$page_table} WHERE\n `rev_page`=`page_id` and `page_namespace`!= 110 and `page_namespace`!= 200\n and `page_namespace`!= 210 and `page_namespace`!= 220 \nand `page_title`!= \"Administration_pull_site_addition\"\nand `page_title` != \"Administration_push_site_addition\""; $res1 = $db->query($sql); while ($row = $db->fetchObject($res1)) { $revids1[] = $row->rev_id; } $db->freeResult($res1); //if (count($revids1)==0) $revids1=array(); //Array_diff returns an array containing all the entries from $revids1 that are //not present in $revids. $diff = array_diff($revids1, $revids); //get page ids of these revisions (each id must be unique in the array) foreach ($diff as $id) { $page_id = $db->selectField('revision', 'rev_page', array('rev_id' => $id)); $page_ids[] = $page_id; } $page_ids = array_unique($page_ids); sort($page_ids); //Now we can logootize: if (count($page_ids) != 0) { foreach ($page_ids as $pageid) { $title = Title::newFromID($pageid); $ns = $title->getNamespace(); $lastRev = Revision::loadFromPageId($db, $pageid); $pageText = $lastRev->getText(); //load an empty model $model = manager::loadModel(0); $logoot = manager::getNewEngine($model, DSMWSiteId::getInstance()->getSiteId()); // new logootEngine($model); $listOp = $logoot->generate("", $pageText); $modelAfterIntegrate = $logoot->getModel(); $tmp = serialize($listOp); $patchid = sha1($tmp); if ($ns == NS_FILE || $ns == NS_IMAGE || $ns == NS_MEDIA) { $apiUrl = $wgServer . $wgScriptPath . "/api" . $wgScriptExtension; $onPage = str_replace(array(' '), array('%20'), $lastRev->getTitle()->getText()); $download = $apiUrl . "?action=query&titles=File:" . $onPage . "&prop=imageinfo&format=php&iiprop=mime|url|size"; $resp = Http::get($download); $resp = unserialize($resp); $a = $resp['query']['pages']; $a = current($a); $a = $a['imageinfo']; $a = current($a); $mime = $a['mime']; $size = $a['size']; $url = $a['url']; $patch = new Patch(false, true, null, $urlServer . $wgScriptPath, 0, null, null, null, $mime, $size, $url, null); $patch->storePage('File:' . $lastRev->getTitle()->getText(), $lastRev->getId()); } else { $patch = new Patch(false, false, $listOp, $urlServer, 0); $patch->storePage($lastRev->getTitle()->getText(), $lastRev->getId()); } manager::storeModel($lastRev->getId(), $sessionId = session_id(), $modelAfterIntegrate, $blobCB = 0); } } wfProfileOut('DSMWUpdateJob::run()'); return true; }