示例#1
0
    function testGetLastPatchIdwithConc()
    {
        // $patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertFalse($lastPatchId);
        //false because there's no previous patch
        //unset ($patch);
        /*1st patch*/
        $pageName = "Patch:localhost/wiki19010";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki19010]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::none]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertEquals('Patch:Localhost/wiki19010', $lastPatchId);
        //unset ($patch);
        /*2nd patch*/
        $pageName = "Patch:localhost/wiki19020";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki19020]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::Patch:Localhost/wiki19010]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertEquals('Patch:Localhost/wiki19020', $lastPatchId);
        //unset ($patch);
        /*3rd patch*/
        $pageName = "Patch:localhost/wiki18020";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki18020]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::Patch:Localhost/wiki19020]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertEquals('Patch:Localhost/wiki18020', $lastPatchId);
        //unset ($patch);
        /*4th patch*/
        $pageName = "Patch:localhost/wiki18030";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki18030]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::Patch:Localhost/wiki19020]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $patchid = array_shift($lastPatchId);
        $this->assertEquals('Patch:Localhost/wiki18020', $patchid);
        $patchid = array_shift($lastPatchId);
        $this->assertEquals('Patch:Localhost/wiki18030', $patchid);
        // unset ($patch);
        /*5th patch*/
        $pageName = "Patch:localhost/wiki17000";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki17000]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::Patch:Localhost/wiki18030;Patch:Localhost/wiki18020]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertEquals('Patch:Localhost/wiki17000', $lastPatchId);
        //unset ($patch);
        /*6th patch*/
        $pageName = "Patch:localhost/wiki19050";
        $Patchcontent = 'Patch: patchID: [[patchID::Patch:Localhost/wiki19050]]
 onPage: [[onPage::cooper1]]  hasOperation: [[hasOperation::localhost/wiki1902;
Insert;( 5053487913627490220,42601d9c1af38da968d697efde65a473 ) 901;content]]
previous: [[previous::Patch:Localhost/wiki17000]]';
        $res = $this->p2pBot1->createPage($pageName, $Patchcontent);
        //$patch = new Patch('', '', '', '');
        $lastPatchId = utils::getLastPatchId('cooper1', $this->p2pBot1->bot->wikiServer);
        //assert
        $this->assertEquals('Patch:Localhost/wiki19050', $lastPatchId);
        //unset ($patch);
    }
示例#2
0
文件: Patch.php 项目: hala54/DSMW
 public function storePage($pageName, $rev)
 {
     wfDebugLog('p2p', '- ' . __METHOD__ . ' - ' . __CLASS__ . "- {$pageName} ({$rev} ; {$this->mPatchId} ; ) ");
     global $wgUser;
     $text = "\n[[Special:ArticleAdminPage|DSMW Admin functions]]\n\n" . "==Features==\n[[patchID::" . $this->mPatchId . "| ]]\n\n" . "'''SiteID:''' [[siteID::" . $this->mSiteId . "]]\n\n" . "'''SiteUrl:''' [[siteUrl::" . $this->mSiteUrl . "]]\n\n" . "'''Rev:''' [[Rev::" . $rev . "]]\n\n";
     if ($this->mRemote) {
         $text .= "'''Remote Patch'''\n\n";
     } 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) . "\n\n";
     if ($this->mAttachment) {
         $text .= "'''Date of upload of the Attachment:''' [[DateAtt::" . $this->mDate . "]]\n\n" . "'''Mime:''' [[Mime::" . $this->mMime . "]]\n\n" . "'''Size:''' [[Size::" . $this->mSize . "]]\n\n" . "'''Url:''' [[Url::" . $this->mUrl . "]]\n\n";
     }
     $text .= "'''User:''' " . $wgUser->getName() . "\n\nThis is a patch of the article: [[onPage::" . $pageName . "]] <br>\n\n";
     if (!$this->mAttachment) {
         $text .= "==Operations of the patch==\n\n{| " . "class='wikitable' border='1' style='text-align:left; width:80%;'" . "\n|-\n" . "!bgcolor=#c0e8f0 scope=col | Type\n" . "!bgcolor=#c0e8f0 scope=col | Content\n" . "|-\n";
         $liste_op = "";
         $i = 1;
         //op counter
         foreach ($this->mOperations as $operation) {
             $lineContent = $operation->getLineContent();
             $lineContent1 = utils::contentEncoding($lineContent);
             //base64 encoding
             $type = "";
             if ($operation->type() == LogootOperation::INSERT) {
                 // instanceof LogootIns)
                 $type = "Insert";
             } else {
                 $type = "Delete";
             }
             $operationID = utils::generateID();
             $liste_op .= '|[[hasOperation::' . $operationID . ';' . $type . ';' . $operation->getLogootPosition()->toString() . ';' . $lineContent1 . '| ]]' . $type;
             //displayed text
             $lineContent2 = $lineContent;
             $liste_op .= "\n|<nowiki>" . $lineContent2 . " : " . $operation->getLogootPosition()->toString() . "</nowiki>\n|-\n";
         }
         $text .= $liste_op . '|}';
     }
     if (is_array($this->mPrevPatch)) {
         $text .= "\n\n==Previous patch(es)==\n[[previous::";
         foreach ($this->mPrevPatch as $prev) {
             $text .= $prev . ';';
         }
         $text .= ']]';
     } else {
         $text .= "\n\n==Previous patch(es)==\n[[previous::" . $this->mPrevPatch . ']]';
     }
     $text .= "\n\n==Causal Link==\n[[causal::" . $this->mCausal . ']]';
     $title = Title::newFromText($this->mID, PATCH);
     $article = new Article($title);
     $article->doEdit($text, $summary = "");
     wfDebugLog('p2p', '- ' . __METHOD__ . ' - ' . __CLASS__ . "- ############# Début ###################");
     wfDebugLog('p2p', $text);
     wfDebugLog('p2p', '- ' . __METHOD__ . ' - ' . __CLASS__ . "- #############  Fin  ###################");
 }
示例#3
0
/**
 * A ChangeSet has patches which has operations
 * this function is used to integrate these operations
 * It's a local changeSet (downloaded from a remote site)
 * @param <String> $changeSetId with NS
 */
function integrate($changeSetId, $patchIdList, $relatedPushServer, $csName)
{
    //global $wgScriptExtension;
    // $patchIdList = getPatchIdList($changeSetId);
    //  $lastPatch = utils::getLastPatchId($pageName);
    global $wgServerName, $wgScriptPath, $wgScriptExtension, $wgOut;
    $urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$csName}";
    wfDebugLog('p2p', '@@@@@@@@@@@@@@@@@@@ - function integrate : ' . $changeSetId);
    $i = 1;
    $j = count($patchIdList);
    $pages = array();
    foreach ($patchIdList as $patchId) {
        $name = 'patch';
        $sub = substr($patchId, 6, 3);
        wfDebugLog('p2p', '  -> patchId : ' . $patchId);
        if (!utils::pageExist($patchId)) {
            //if this patch exists already, don't apply it
            wfDebugLog('p2p', '      -> patch unexist');
            $url = utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=patch&papatchId=" . $patchId . '&format=xml';
            wfDebugLog('p2p', '      -> getPatch request url ' . $url);
            $patch = utils::file_get_contents_curl($url);
            /*test if it is a xml file. If not, the server is not reachable via the url
             * Then we try to reach it with the .php5 extension
             */
            if (strpos($patch, "<?xml version=\"1.0\"?>") === false) {
                $url = utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=patch&papatchId=" . $patchId . '&format=xml';
                wfDebugLog('p2p', '      -> getPatch request url ' . $url);
                $patch = utils::file_get_contents_curl($url);
            }
            if (strpos($patch, "<?xml version=\"1.0\"?>") === false) {
                $patch = false;
            }
            //echo $patch;
            if ($patch === false) {
                throw new MWException(__METHOD__ . ': Cannot connect to Push Server (Patch API)');
            }
            $patch = trim($patch);
            wfDebugLog('p2p', '      -> patch content :' . $patch);
            $dom = new DOMDocument();
            $dom->loadXML($patch);
            $patchs = $dom->getElementsByTagName($name);
            //when the patch is not found, mostly when the id passed
            //through the url is wrong
            if (empty($patchs) || is_null($patchs)) {
                throw new MWException(__METHOD__ . ': Error: Patch not found!');
            }
            //        $patchID = null;
            foreach ($patchs as $p) {
                if ($p->hasAttribute("onPage")) {
                    $onPage = $p->getAttribute('onPage');
                }
                if ($p->hasAttribute("previous")) {
                    $previousPatch = $p->getAttribute('previous');
                }
                if ($p->hasAttribute("siteID")) {
                    $siteID = $p->getAttribute('siteID');
                }
                if ($p->hasAttribute("mime")) {
                    $Mime = $p->getAttribute('mime');
                }
                if ($p->hasAttribute("size")) {
                    $Size = $p->getAttribute('size');
                }
                if ($p->hasAttribute("url")) {
                    $Url = $p->getAttribute('url');
                }
                if ($p->hasAttribute("DateAtt")) {
                    $Date = $p->getAttribute('DateAtt');
                }
                if ($p->hasAttribute("siteUrl")) {
                    $SiteUrl = $p->getAttribute('siteUrl');
                }
                if ($p->hasAttribute("causal")) {
                    $causal = $p->getAttribute('causal');
                }
            }
            $operations = null;
            $op = $dom->getElementsByTagName('operation');
            foreach ($op as $o) {
                $operations[] = $o->firstChild->nodeValue;
            }
            $lastPatch = utils::getLastPatchId($onPage);
            if ($lastPatch == false) {
                $lastPatch = 'none';
            }
            //            foreach ($operations as $operation) {
            //                $operation = operationToLogootOp($operation);
            //                if ($operation!=false && is_object($operation)) {
            //                    logootIntegrate($operation, $onPage);
            //                }
            //            }
            if (!in_array($onPage, $pages)) {
                $onPage1 = str_replace(array(' '), array('_'), $onPage);
                utils::writeAndFlush("<span style=\"margin-left:60px;\">Page: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$onPage1}>" . $onPage . "</A></span><br/>");
                $pages[] = $onPage;
            }
            if ($sub === 'ATT') {
                touch(utils::prepareString($Mime, $Size, $Url));
                $DateLastPatch = utils::getLastAttPatchTimestamp($onPage);
                //$DateOtherPatch = utils::getOtherAttPatchTimestamp($patchIdList);
                if ($DateLastPatch == null) {
                    downloadFile($Url);
                    $edit = true;
                    utils::writeAndFlush("<span style=\"margin-left:98px;\">download attachment (" . round($Size / 1000000, 2) . "Mo)</span><br/>");
                } elseif ($DateLastPatch < $Date) {
                    downloadFile($Url);
                    $edit = true;
                    utils::writeAndFlush("<span style=\"margin-left:98px;\">download attachment (" . round($Size / 1000000, 2) . "Mo)</span><br/>");
                } else {
                    newRev($onPage);
                    $edit = false;
                }
                unlink(utils::prepareString($Mime, $Size, $Url));
            }
            utils::writeAndFlush("<span style=\"margin-left:80px;\">" . $i . "/" . $j . ": Integration of Patch: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php/{$patchId}>" . $patchId . "</A></span><br/>");
            if ($sub === 'ATT') {
                $rev = logootIntegrateAtt($onPage, $edit);
                if ($rev > 0) {
                    $lop = array();
                    foreach ($operations as $o) {
                        if ($o instanceof LogootOperation) {
                            $lop[] = $o;
                        } else {
                            $lop[] = operationToLogootOp($o);
                        }
                    }
                    $patch = new Patch(true, true, new LogootPatch($patchId, $lop), $SiteUrl, $causal, $patchId, $lastPatch, $siteID, $Mime, $Size, $Url, $Date);
                    $patch->storePage($onPage, $rev);
                } else {
                    throw new MWException(__METHOD__ . ': article not saved!');
                }
            } else {
                list($rev, $operations) = logootIntegrate($operations, $onPage, $sub);
                if ($rev > 0) {
                    $patch = new Patch(true, false, $operations, $SiteUrl, $causal, $patchId, $lastPatch, $siteID, null, null, null, null);
                    $patch->storePage($onPage, $rev);
                } else {
                    throw new MWException(__METHOD__ . ': article not saved!');
                }
            }
        }
        //end if pageExists
        $i++;
    }
    utils::writeAndFlush("<span style=\"margin-left:30px;\">Go to <A HREF=" . $urlServer . ">ChangeSet</A></span> <br/>");
}
    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 = "");
    }
示例#5
0
 public function testPushWithChangeSet1()
 {
     $this->testCreatePush();
     $this->assertTrue($this->p2pBot1->createPage('Arches', "content arches [[Category:titi]]", 'failed to create page Arches (' . $this->p2pBot1->bot->results . ')'));
     $this->assertTrue($this->p2pBot1->createPage('Paris11', 'content Paris11 [[Category:titi]]', 'failed to create page Paris11 (' . $this->p2pBot1->bot->results . ')'));
     $this->assertTrue($this->p2pBot1->push('PushFeed:PushCity11'), 'failed to push ' . $pushName . ' (' . $this->p2pBot1->bot->results . ')');
     // assert that pushHead attribute is not null and the changeSet page exist
     $pushFound = getSemanticRequest($this->p2pBot1->bot->wikiServer, '[[name::PushFeed:PushCity11]]', '-3FhasPushHead');
     $this->assertNotEquals('', $pushFound[0]);
     $CSIDFound = $pushFound[0];
     assertPageExist($this->p2pBot1->bot->wikiServer, $CSIDFound);
     // assert the changeSet created is ok
     $CSFound = getSemanticRequest($this->p2pBot1->bot->wikiServer, '[[changeSetID::' . $CSIDFound . ']]', '-3FchangeSetID/-3FinPushFeed/-3FpreviousChangeSet/-3FhasPatch');
     // assert inPushFeed
     $this->assertEquals(strtolower('PushFeed:PushCity11'), strtolower($CSFound[1]), 'failed to push PushCity11, ChangeSet push name must be PushFeed:' . $pushName . ' but ' . $CSFound[1] . ' was found');
     // assert previousChangeSet
     $this->assertEquals('none', strtolower($CSFound[2]), 'failed to push PushCity11, ChangeSet previous must be None but ' . $CSFound[2] . ' was found');
     $patchCS = explode(',', $CSFound[3]);
     $this->assertTrue(count($patchCS) == 2, 'failed to push PushCity11, ChangeSet must contains 2 patchs but ' . count($patchCS) . ' patchs were found');
     // assert patchs contains in the changeSet is ok
     $lastPatchNancy = utils::getLastPatchId('Arches', $this->p2pBot1->bot->wikiServer);
     $lastPatchParis = utils::getLastPatchId('Paris11', $this->p2pBot1->bot->wikiServer);
     $assert1 = strtolower($lastPatchNancy) == strtolower($patchCS[0]) || strtolower($lastPatchNancy) == strtolower($patchCS[1]);
     $assert2 = strtolower($lastPatchParis) == strtolower($patchCS[0]) || strtolower($lastPatchParis) == strtolower($patchCS[1]);
     $this->assertTrue($assert1 && $assert2, 'failed to push ' . $pushName . ', wrong patch in changeSet');
 }