/**
     * Executed the user opens the DSMW administration special page
     * Calculates the PushFeed list and the pullfeed list (and everything that
     * is displayed on the psecial page
     *
     * @global <Object> $wgOut Output page instance
     * @global <String> $wgServerName
     * @global <String> $wgScriptPath
     * @return <bool>
     */
    public function execute()
    {
        global $wgOut, $wgServerName, $wgScriptPath, $wgScriptExtension, $wgUser;
        if (!$this->userCanExecute($wgUser)) {
            // If the user is not authorized, show an error.
            $this->displayRestrictionError();
            return;
        }
        $url = 'http://' . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}";
        $urlServer = 'http://' . $wgServerName . $wgScriptPath;
        // $wgOut->addHeadItem('script', ArticleAdminPage::javascript());
        $script1 = '<SCRIPT type="text/javascript"> function pushFeedDel(){
  for (var i=0; i < document.getElementsByName("push[]").length; i++)
     {
     if (document.getElementsByName("push[]")[i].checked)
        {
            //alert(document.getElementsByName("push[]")[i].value);
            var feed = document.getElementsByName("push[]")[i].value;
            window.location.href = "' . $url . '/Special:ArticleAdminPage?FeedDel=true&feed="+feed;
        }
     }
}

function pullFeedDel(){
  for (var i=0; i < document.getElementsByName("pull[]").length; i++)
     {
     if (document.getElementsByName("pull[]")[i].checked)
        {
           // alert(document.getElementsByName("pull[]")[i].value);
            var feed = document.getElementsByName("pull[]")[i].value;
            window.location.href = "' . $url . '/Special:ArticleAdminPage?FeedDel=true&feed="+feed;
        }
     }
}
function displayRemotePatch(test){
//alert(test);
if(test==true){
  window.location.href = "' . $url . '/Special:ArticleAdminPage?display=true";
}else{
  window.location.href = "' . $url . '/Special:ArticleAdminPage";
}
}
</SCRIPT>';
        $wgOut->addScript($script1);
        /// Special:ArticleAdminPage?FeedDel=true&feed=document.getElementsByName("push[]")[i].value
        if (isset($_GET['FeedDel'])) {
            $this->deleteFeed($_GET['feed']);
        }
        $wgOut->setPagetitle("DSMW Administration");
        // Set the limit of rows returned
        $page_limit = 30;
        $i = 0;
        $db =& wfGetDB(DB_SLAVE);
        $style = ' style="border-bottom: 2px solid #000;"';
        $tableStyle = ' style=" clear:both; float: left; margin-left: 40px; margin-top: 20px"';
        $output = "";
        ///////////// PULLFEEDS TABLE//////////////////////////
        $i = 0;
        $req = "[[PullFeed:+]][[deleted::false]]";
        $pullFeeds = $this->getRequestedPages($req);
        $output .= '
<FORM name="formPull">

<table' . $tableStyle . ' >
  <a href="javascript:displayRemotePatch(true);">[Display]</a><a href="javascript:displayRemotePatch(false);">[Hide]</a> remote patches
  <tr bgcolor=#c0e8f0>';
        if (isset($_GET['display'])) {
            $output .= '    <th colspan="5"' . $style . '>PULL:
  <a href=' . $url . '?title=administration_pull_site_addition&action=addpullpage>[Add]</a>';
        } else {
            $output .= '    <th colspan="4"' . $style . '>PULL:
  <a href=' . $url . '?title=administration_pull_site_addition&action=addpullpage>[Add]</a>';
        }
        if ($pullFeeds != false) {
            $output .= '<a href="javascript:pullFeedDel();">[Remove]</a>
  <input type="button" value="PULL" onClick="allpull(\'' . $url . '\');"></input></th>
  </tr>
  <tr>
    <th colspan="2" >Site</th>
    <th >Pages</th>';
            if (isset($_GET['display'])) {
                $output .= '    <th>Remote <br>Patches</th>';
            }
            $output .= '    <th >Local <br>Patches</th>


  </tr>
  ';
            foreach ($pullFeeds as $pullFeed) {
                $i = $i + 1;
                $pullFeed = str_replace(' ', '_', $pullFeed);
                // count the number of local page concerned by the current pullFeed
                $tabPage = utils::getPageConcernedByPull($pullFeed);
                // if connection failed
                if ($tabPage === false) {
                    $pageConcerned = "-";
                } else {
                    $pageConcerned = count($tabPage);
                }
                if (isset($_GET['display'])) {
                    // count the number of remote patch concerned by the current pullFeed
                    $pushServer = getPushURL($pullFeed);
                    $pushName = getPushName($pullFeed);
                    $published = utils::getPublishedPatchs($pushServer, $pushName);
                    // if connection failed
                    if ($published === false) {
                        $countRemotePatch = "-";
                    } else {
                        $countRemotePatch = count($published);
                    }
                }
                // count the number of local patch concerned by the current pullFeed
                $results = array();
                $pulledCS = utils::getSemanticQuery('[[ChangeSet:+]][[inPullFeed::' . $pullFeed . ']]', '?hasPatch');
                if ($pulledCS === false) {
                    $countPulledPatch = "-";
                } else {
                    $count = $pulledCS->getCount();
                    for ($i = 0; $i < $count; $i++) {
                        $row = $pulledCS->getNext();
                        if ($row === false) {
                            break;
                        }
                        $row = $row[1];
                        $col = $row->getContent();
                        // SMWResultArray object
                        foreach ($col as $object) {
                            // SMWDataValue object
                            $wikiValue = $object->getWikiValue();
                            $results[] = $wikiValue;
                        }
                    }
                    $countPulledPatch = count($results);
                }
                $pullFeedLink = str_replace(' ', '_', $pullFeed);
                $output .= '
  <tr>
    <td align="center"><input type="checkbox" id="' . $i . '" name="pull[]" value="' . $pullFeed . '"  /></td>
    <td ><a href=' . $url . '?title=' . $pullFeedLink . '>' . $pullFeed . '</a></td>
    <td align="center" title="Number of locally concerned pages">[' . $pageConcerned . ']</td>';
                if (isset($_GET['display'])) {
                    $output .= '
    <td align="center" title="Published patches">[' . $countRemotePatch . ']</td>';
                }
                $output .= '    <td align="center" title="Local patches">[' . $countPulledPatch . ']</td>
  </tr>';
            }
        }
        $output .= '

</table>
</FORM>';
        ///////////// PUSHFEEDS TABLE//////////////////////////
        $i = 0;
        $req = "[[PushFeed:+]][[deleted::false]]";
        $pushFeeds = $this->getRequestedPages($req);
        $output .= '
<FORM name="formPush">
<table' . $tableStyle . '  >
  <tr bgcolor=#c0e8f0>
    <th colspan="6"' . $style . '>PUSH:
  <a href=' . $url . '?title=administration_push_site_addition&action=addpushpage>[Add]</a>';
        if ($pushFeeds != false) {
            $output .= ' <a href="javascript:pushFeedDel();">[Remove]</a>
  <input type="button" value="PUSH" onClick="allpush(\'' . $url . '\');"></input></th>
  </tr>
  <tr>
    <th colspan="2" >Site</th>
    <th >Pages</th>
    <th>All patches</th>
    <th>Published <br>Patches</th>
    <th >Unpublished <br>Patches</th>


  </tr>
  ';
            foreach ($pushFeeds as $pushFeed) {
                $i = $i + 1;
                $pushName = str_replace(' ', '_', $pushFeed);
                // count the number of page concerned by the current pushFeed
                $request = getPushFeedRequest($pushName);
                $results1 = array();
                $tabPage = utils::getSemanticQuery($request);
                // if connection failed
                if ($tabPage === false) {
                    $countConcernedPage = "-";
                    $countPatchs = "-";
                } else {
                    $count = $tabPage->getCount();
                    for ($i = 0; $i < $count; $i++) {
                        $row = $tabPage->getNext();
                        if ($row === false) {
                            break;
                        }
                        $row = $row[0];
                        $col = $row->getContent();
                        // SMWResultArray object
                        foreach ($col as $object) {
                            // SMWDataValue object
                            $wikiValue = $object->getWikiValue();
                            $results1[] = $wikiValue;
                        }
                    }
                    $countConcernedPage = count($results1);
                    // count the number of patchs from the page concerned
                    $countPatchs = 0;
                    foreach ($results1 as $page) {
                        $results = array();
                        $patchs = utils::getSemanticQuery('[[Patch:+]][[onPage::' . $page . ']]', '?patchID');
                        $count = $patchs->getCount();
                        for ($i = 0; $i < $count; $i++) {
                            $row = $patchs->getNext();
                            if ($row === false) {
                                break;
                            }
                            $row = $row[0];
                            $col = $row->getContent();
                            // SMWResultArray object
                            foreach ($col as $object) {
                                // SMWDataValue object
                                $wikiValue = $object->getWikiValue();
                                $results[] = $wikiValue;
                            }
                        }
                        $countPatchs += count($results);
                    }
                }
                // count the number of patchs published by the current pushFeed
                $published = utils::getPublishedPatchs($urlServer, $pushName);
                if ($published === false) {
                    $countPublished = "-";
                } else {
                    $countPublished = count($published);
                }
                // count the number of patchs unpublished
                if ($results1 === false || $published === false) {
                    $countUnpublished = "-";
                } else {
                    $countUnpublished = $countPatchs - $countPublished;
                }
                $pushFeedLink = str_replace(' ', '_', $pushFeed);
                $output .= '
  <tr>
    <td align="center"><input type="checkbox" id="' . $i . '" name="push[]" value="' . $pushFeed . '" /></td>
    <td ><a href=' . $url . '?title=' . $pushFeedLink . '>' . $pushFeed . '</a></td>
    <td align="center" title="Number of concerned pages">[' . $countConcernedPage . ']</td>
    <td align="center" title="Sum of all the patches">[' . $countPatchs . ']</td>
    <td align="center" title="Published patches">[' . $countPublished . ']</td>
    <td align="center" title="Unpublished patches">[' . $countUnpublished . ']</td>
  </tr>';
            }
        }
        $output .= '

</table>
</FORM>
<div id="pullstatus" style="display: none; width: 100%; clear: both;" >
<a name="PULL_Progress_:" id="PULL_Progress_:"></a><h2> <span class="mw-headline"> PULL Progress&#160;: </span></h2>
<div id="statepull" ></div><br />
</div>
<div id="pushstatus" style="display: none; width: 100%; clear: both;" >
<a name="PUSH_Progress_:" id="PUSH_Progress_:"></a><h2> <span class="mw-headline"> PUSH Progress&#160;: </span></h2>
<div id="statepush" ></div><br />
</div>
';
        $wgOut->addHTML($output);
        return false;
    }
 /**
  * MW Hook used to redirect to page creation (pushfeed, pullfeed, changeset),
  * to forms or to push/pull action testing the action param
  *
  * @since 1.1
  *
  * @param string $action
  * @param Article $article
  *
  * @return true
  */
 public function onUnknownAction($action, Article $article)
 {
     global $wgOut, $wgServerName, $wgScriptPath, $wgUser, $wgScriptExtension, $wgDSMWIP;
     $urlServer = 'http://' . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}";
     $urlAjax = 'http://' . $wgServerName . $wgScriptPath;
     ///////// / pull form page////////
     if (isset($_GET['action']) && $_GET['action'] == 'addpullpage') {
         wfDebugLog('p2p', 'addPullPage ');
         $newtext = "Add a new site:\n\t<div id='dsmw' style=\"color:green;\"></div>\n\n\t{{#form:action=" . $urlServer . "?action=pullpage|method=POST|\n\t\tPushFeed Url: {{#input:type=button|value=Url test|onClick=\n\t\tvar url = document.getElementsByName('url')[0].value;\n\t\tif(url.indexOf('PushFeed')==-1){\n\t\t\talert('No valid PushFeed syntax, see example.');\n\t\t}else{\n\t\t\tvar urlTmp = url.substring( 0, url.indexOf( 'PushFeed' ) );\n\t\t\t//alert(urlTmp);\n\n\t\t\tvar pos1 = urlTmp.indexOf( 'index.php' );\n\t\t\t//alert( pos1 );\n\t\t\tvar pushUrl='';\n\t\t\tif( pos1 != -1 ){\n\t\t\t\tpushUrl = urlTmp.substring(0,pos1);\n\t\t\t\t//alert('if');\n\t\t\t} else {\n\t\t\t\tpushUrl = urlTmp;\n\t\t\t\t//alert('else');\n\t\t\t}\n\t\t\t//alert(pushUrl);\n\n\t\t\t//alert(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml');\n\t\t\tvar xhr_object = null;\n\n\t\t\tif( window.XMLHttpRequest ) { // Firefox\n\t\t\t\txhr_object = new XMLHttpRequest();\n\t\t\t}else if( window.ActiveXObject ) { // Internet Explorer\n\t\t\t\txhr_object = new ActiveXObject('Microsoft.XMLHTTP');\n\t\t\t} else {\n\t\t\t\talert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\txhr_object.open('GET', '" . $urlAjax . "/extensions/DSMW/files/ajax.php?url='+escape(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'), true);\n\t\t\t} catch( e ) {\n\t\t\t\t//alert('There is no DSMW Server responding at this URL');\n\t\t\t\tdocument.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n\t\t\t\tdocument.getElementById('dsmw').style.color = 'red';\n\t\t\t}\n\t\t\txhr_object.onreadystatechange = function() {\n\n\t\t\tif( xhr_object.readyState == 4 ) {\n\t\t\t\tif( xhr_object.statusText=='OK' ){\n\t\t\t\t\tif( xhr_object.responseText == 'true' ){\n\t\t\t\t\t\t//alert('URL valid, there is a DSMW Server responding');\n\t\t\t\t\t\tdocument.getElementById('dsmw').innerHTML = 'URL valid, there is a DSMW Server responding!';\n\t\t\t\t\t\tdocument.getElementById('dsmw').style.color = 'green';\n\t\t\t\t\t} else{ //alert('There is no DSMW Server responding at this URL');\n\t\t\t\t\t\tdocument.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n\t\t\t\t\t\tdocument.getElementById('dsmw').style.color = 'red';\n\t\t\t\t\t}\n\t\t\t\t} else{\n\t\t\t\t\t//alert('There is no DSMW Server responding at this URL');\n\t\t\t\t\tdocument.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n\t\t\t\t\tdocument.getElementById('dsmw').style.color = 'red';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\txhr_object.send(null);\n\t}\n\t}}<br>        {{#input:type=text|name=url|size=50}} <b>e.g. http://server/path/index.php?title=PushFeed:PushName</b><br>\n\tPullFeed Name:   <br>    {{#input:type=text|name=pullname}}<br>\n\t{{#input:type=submit|value=ADD}}\n\t}}";
         $article->doEdit($newtext, $summary = "");
         $wgOut->redirect($article->getTitle()->getFullURL());
         return false;
     } elseif (isset($_GET['action']) && $_GET['action'] == 'addpushpage') {
         wfDebugLog('p2p', 'addPushPage');
         $specialAsk = $urlServer . '?title=Special:Ask';
         $newtext = "Add a new pushfeed:\n\n\t{{#form:action=" . $urlServer . "?action=pushpage|method=POST|\n\tPushFeed Name:   <br>    {{#input:class=test|name=name|type=text|onKeyUp=test('{$urlServer}');}}<div style=\"display:inline; \" id=\"state\" ></div><br />\n\tRequest: {{#input:type=button|value=Test your query|title=click here to test your query results|onClick=\n\tvar query = document.getElementsByName('keyword')[0].value;\n\tvar query1 = encodeURI(query);\n\twindow.open('" . $specialAsk . "&q='+query1+'&eq=yes&p%5Bformat%5D=broadtable','querywindow','menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=900');}}\n\t  <br>{{#input:type=textarea|cols=30 | style=width:auto |rows=2|name=keyword}} <b>e.g. [[Category:city]][[locatedIn::France]]</b><br>\n\t{{#input:type=submit|value=ADD}}\n\t}}";
         $article->doEdit($newtext, $summary = "");
         $wgOut->redirect($article->getTitle()->getFullURL());
         return false;
     } elseif (isset($_GET['action']) && $_GET['action'] == 'pushpage') {
         // $url = $_POST['url'];//pas url mais changesetId
         wfDebugLog('p2p', 'Create new push ' . $_POST['name'] . ' with ' . $_POST['keyword']);
         $name = $_POST['name'];
         $request = $_POST['keyword'];
         $stringReq = utils::encodeRequest($request);
         // avoid "semantic injection" :))
         // addPushSite($url, $name, $request);
         $newtext = "\n[[Special:ArticleAdminPage|DSMW Admin functions]]\n\n==Features==\n[[name::PushFeed:" . $name . "| ]]\n'''Semantic query:''' [[hasSemanticQuery::" . $stringReq . "| ]]<nowiki>" . $request . "</nowiki>\n\n'''Pages concerned:'''\n{{#ask: " . $request . "}}\n[[deleted::false| ]]\n\n==Actions==\n\n{{#input:type=ajax|value=PUSH|onClick=pushpull('" . $urlServer . "','PushFeed:" . $name . "', 'onpush');}}\nThe \"PUSH\" action publishes the (unpublished) modifications of the articles listed above.\n\n== PUSH Progress : ==\n<div id=\"state\" ></div><br />\n";
         wfDebugLog('p2p', '  -> push page contains : ' . $newtext);
         $title = Title::newFromText($_POST['name'], PUSHFEED);
         $article = new Article($title);
         $edit = $article->doEdit($newtext, $summary = "");
         $wgOut->redirect($title->getFullURL());
         return false;
     } elseif (isset($_POST['action']) && $_POST['action'] == 'onpush') {
         /* In case we push directly from an article page */
         if (isset($_POST['page']) && isset($_POST['request'])) {
             $articlename = Title::newFromText($_POST['name']);
             if (!$articlename->exists()) {
                 $result = utils::createPushFeed($_POST['name'], $_POST['request']);
                 utils::writeAndFlush("Create push <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title=" . $_POST['name'] . ">" . $_POST['name'] . "</a>");
                 if ($result == false) {
                     throw new MWException(__METHOD__ . ': no Pushfeed created in utils:: createPushFeed: ' . 'name: ' . $_POST['name'] . ' request' . $_POST['request']);
                 }
             }
         }
         wfDebugLog('p2p', 'push on ');
         $patches = array();
         $tmpPatches = array();
         if (isset($_POST['name'])) {
             $name1 = $_POST['name'];
             if (!is_array($name1)) {
                 $name1 = array($name1);
             }
             foreach ($name1 as $push) {
                 wfDebugLog('p2p', ' - ' . $push);
             }
         } else {
             $name1 = '';
         }
         if ($name1 == '') {
             utils::writeAndFlush('<p><b>No pushfeed selected!</b></p>');
             $title = Title::newFromText('Special:ArticleAdminPage');
             $wgOut->redirect($title->getFullURL());
             return false;
         }
         // $name = $name1[0];
         utils::writeAndFlush('<p><b>Start push </b></p>');
         foreach ($name1 as $name) {
             utils::writeAndFlush("<span style=\"margin-left:30px;\">begin push: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title={$name}>" . $name . "</a></span> <br/>");
             $patches = array();
             // / / for each pushfeed name==> push
             wfDebugLog('p2p', '  -> pushname ' . $name);
             // $name = $_GET['name'];//PushFeed name
             $request = getPushFeedRequest($name);
             // $previousCSID = getPreviousCSID($name);
             $previousCSID = getHasPushHead($name);
             if ($previousCSID == false) {
                 $previousCSID = "none";
                 // $CSID = $name."_0";
             }
             // else{
             //	$count = explode(" ", $previousCSID);
             //	$cnt = $count[1] + 1;
             //	$CSID = $name."_".$cnt;
             // }
             wfDebugLog('p2p', '  ->pushrequest ' . $request);
             wfDebugLog('p2p', '  ->pushHead : ' . $previousCSID);
             $CSID = utils::generateID();
             // changesetID
             if ($request == false) {
                 $outtext = '<p><b>No semantic request found!</b></p> <a href="' . $_SERVER['HTTP_REFERER'] . '">back</a>';
                 $wgOut->addHTML($outtext);
                 return false;
             }
             $pages = getRequestedPages($request);
             // ce sont des pages et non des patches
             foreach ($pages as $page) {
                 wfDebugLog('p2p', '  ->requested page ' . $page);
                 $page = str_replace('"', '', $page);
                 $request1 = '[[Patch:+]][[onPage::' . $page . ']]';
                 $tmpPatches = utils::orderPatchByPrevious($page);
                 if (!is_array($tmpPatches)) {
                     throw new MWException(__METHOD__ . ': $tmpPatches is not an array');
                 }
                 $patches = array_merge($patches, $tmpPatches);
                 wfDebugLog('p2p', '  -> ' . count($tmpPatches) . 'patchs were found for the page ' . $page);
             }
             wfDebugLog('p2p', '  -> ' . count($patches) . ' patchs were found for the pushfeed ' . $name);
             $published = getPublishedPatches($name);
             $unpublished = array_diff($patches, $published);
             /* unpublished = patches-published */
             wfDebugLog('p2p', '  -> ' . count($published) . ' patchs were published for the pushfeed ' . $name . ' and ' . count($unpublished) . ' unpublished patchs');
             if (empty($unpublished)) {
                 wfDebugLog('p2p', '  -> no unpublished patch');
                 utils::writeAndFlush("<span style=\"margin-left:60px;\">no unpublished patch</span><br/>");
                 // return false; //If there is no unpublished patch
             } else {
                 utils::writeAndFlush("<span style=\"margin-left:60px;\">" . count($unpublished) . " unpublished patch</span><br/>");
                 $pos = strrpos($CSID, ":");
                 // NS removing
                 if ($pos === false) {
                     // not found...
                     $articleName = $CSID;
                     $CSID = "ChangeSet:" . $articleName;
                 } else {
                     $articleName = substr($CSID, 0, $pos + 1);
                     $CSID = "ChangeSet:" . $articleName;
                 }
                 $newtext = "\n[[Special:ArticleAdminPage|DSMW Admin functions]]\n\n==Features==\n[[changeSetID::" . $CSID . "| ]]\n\n'''Date:''' " . date(DATE_RFC822) . "\n\n'''User:''' " . $wgUser->getName() . "\n\nThis ChangeSet is in : [[inPushFeed::" . $name . "]]<br>\n==Published patches==\n\n{| class=\"wikitable\" border=\"1\" style=\"text-align:left; width:30%;\"\n|-\n!bgcolor=#c0e8f0 scope=col | Patch\n|-\n";
                 // wfDebugLog('p2p','  -> count unpublished patch '.count($unpublished));
                 foreach ($unpublished as $patch) {
                     wfDebugLog('p2p', '  -> unpublished patch ' . $patch);
                     $newtext .= "|[[hasPatch::" . $patch . "]]\n\t|-\n\t";
                 }
                 $newtext .= "\n\t|}";
                 $newtext .= "\n==Previous ChangeSet==\n[[previousChangeSet::" . $previousCSID . "]]\n";
                 $update = updatePushFeed($name, $CSID);
                 if ($update == true) {
                     // update the "hasPushHead" value successful
                     $title = Title::newFromText($articleName, CHANGESET);
                     $article = new Article($title);
                     $article->doEdit($newtext, $summary = "");
                 } else {
                     $outtext = '<p><b>PushFeed has not been updated!</b></p>';
                     $wgOut->addHTML($outtext);
                 }
             }
         }
         // end foreach pushfeed list
         utils::writeAndFlush('<p><b>End push</b></p>');
         $title = Title::newFromText('Special:ArticleAdminPage');
         $wgOut->redirect($title->getFullURL());
         return false;
     } elseif (isset($_GET['action']) && $_GET['action'] == 'pullpage') {
         // wfDebugLog('p2p','Create pull '.$_POST['pullname'].' with pushName '.$_POST['pushname'].' on '.$_POST['url']);
         // $url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one
         $urlTmp = $_POST['url'];
         if (utils::isValidURL($urlTmp) == false) {
             // throws an exception if $url is invalid
             throw new MWException(__METHOD__ . ': ' . $urlTmp . ' seems not to be an url');
         }
         $res = utils::parsePushURL($urlTmp);
         if ($res === false || empty($res)) {
             throw new MWException(__METHOD__ . ': URL format problem');
         }
         $pushname = $res[0];
         $url = $res[1];
         // $pushname = $_POST['pushname'];
         $pullname = $_POST['pullname'];
         $newtext = "\n[[Special:ArticleAdminPage|DSMW Admin functions]]\n\n==Features==\n\n[[name::PullFeed:" . $pullname . "| ]]\n'''URL of the DSMW PushServer:''' [[pushFeedServer::" . $url . "]]<br>\n'''PushFeed name:''' [[pushFeedName::PushFeed:" . $pushname . "]]\n[[deleted::false| ]]\n\n==Actions==\n\n{{#input:type=ajax|value=PULL|onClick=pushpull('" . $urlServer . "','PullFeed:" . $pullname . "','onpull');}}\n\nThe \"PULL\" action gets the modifications published in the PushFeed of the PushFeedServer above.\n\n== PULL Progress : ==\n<div id=\"state\" ></div><br />\n";
         $title = Title::newFromText($pullname, PULLFEED);
         $article = new Article($title);
         $article->doEdit($newtext, $summary = "");
         $wgOut->redirect($title->getFullURL());
         return false;
     } elseif (isset($_POST['action']) && $_POST['action'] == 'onpull') {
         if (isset($_POST['name'])) {
             $name1 = $_POST['name'];
             wfDebugLog('p2p', 'pull on ');
             if (!is_array($name1)) {
                 $name1 = array($name1);
             }
         } else {
             $name1 = '';
         }
         if ($name1 == '') {
             utils::writeAndFlush('<p><b>No pullfeed selected!</b></p> ');
             $title = Title::newFromText('Special:ArticleAdminPage');
             $article = new Article($title);
             $article->doEdit('', $summary = "");
             $wgOut->redirect($title->getFullURL());
             return false;
         }
         // $name = $name1[0];//with NS
         utils::writeAndFlush('<p><b>Start pull</b></p>');
         foreach ($name1 as $name) {
             // for each pullfeed name==> pull
             utils::writeAndFlush("<span style=\"margin-left:30px;\">begin pull: <A HREF=" . 'http://' . $wgServerName . $wgScriptPath . "/index.php?title={$name}>" . $name . "</a></span> <br/>");
             wfDebugLog('p2p', '      -> pull : ' . $name);
             // $previousCSID = getPreviousPulledCSID($name);
             // if($previousCSID==false) {
             //	$previousCSID = "none";
             // }
             $previousCSID = getHasPullHead($name);
             if ($previousCSID == false) {
                 $previousCSID = "none";
             }
             wfDebugLog('p2p', '      -> pullHead : ' . $previousCSID);
             $relatedPushServer = getPushURL($name);
             if (is_null($relatedPushServer)) {
                 throw new MWException(__METHOD__ . ': no relatedPushServer url');
             }
             $namePush = getPushName($name);
             $namePush = str_replace(' ', '_', $namePush);
             wfDebugLog('p2p', '      -> pushServer : ' . $relatedPushServer);
             wfDebugLog('p2p', '      -> pushName : ' . $namePush);
             if (is_null($namePush)) {
                 throw new MWException(__METHOD__ . ': no PushName');
             }
             // split NS and name
             preg_match("/^(.+?)_*:_*(.*)\$/S", $namePush, $m);
             $nameWithoutNS = $m[2];
             // $url = $relatedPushServer.'/api.php?action=query&meta=changeSet&cspushName='.$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml';
             // $url = $relatedPushServer."/api{$wgScriptExtension}?action=query&meta=changeSet&cspushName=".$nameWithoutNS.'&cschangeSet='.$previousCSID.'&format=xml';
             wfDebugLog('testlog', '      -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
             $cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
             /* 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($cs, "<?xml version=\"1.0\"?>") === false) {
                 $cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
             }
             if (strpos($cs, "<?xml version=\"1.0\"?>") === false) {
                 $cs = false;
             }
             if ($cs === false) {
                 throw new MWException(__METHOD__ . ': Cannot connect to Push Server (ChangeSet API)');
             }
             $cs = trim($cs);
             $dom = new DOMDocument();
             $dom->loadXML($cs);
             $changeSet = $dom->getElementsByTagName('changeSet');
             $CSID = null;
             foreach ($changeSet as $cs) {
                 if ($cs->hasAttribute("id")) {
                     $CSID = $cs->getAttribute('id');
                     $csName = $CSID;
                 }
             }
             wfDebugLog('p2p', '     -> changeSet found ' . $CSID);
             while ($CSID != null) {
                 // if(!utils::pageExist($CSID)) {
                 $listPatch = null;
                 $patchs = $dom->getElementsByTagName('patch');
                 foreach ($patchs as $p) {
                     wfDebugLog('p2p', '          -> patch ' . $p->firstChild->nodeValue);
                     $listPatch[] = $p->firstChild->nodeValue;
                 }
                 // $CSID = substr($CSID,strlen('changeSet:'));
                 utils::createChangeSetPull($CSID, $name, $previousCSID, $listPatch);
                 integrate($CSID, $listPatch, $relatedPushServer, $csName);
                 updatePullFeed($name, $CSID);
                 // }
                 $previousCSID = $CSID;
                 wfDebugLog('p2p', '     -> request ChangeSet : ' . $relatedPushServer . '/api.php?action=query&meta=changeSet&cspushName=' . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
                 $cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
                 /* 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($cs, "<?xml version=\"1.0\"?>") === false) {
                     $cs = utils::file_get_contents_curl(utils::lcfirst($relatedPushServer) . "/api.php5?action=query&meta=changeSet&cspushName=" . $nameWithoutNS . '&cschangeSet=' . $previousCSID . '&format=xml');
                 }
                 if (strpos($cs, "<?xml version=\"1.0\"?>") === false) {
                     $cs = false;
                 }
                 if ($cs === false) {
                     throw new MWException(__METHOD__ . ': Cannot connect to Push Server (ChangeSet API)');
                 }
                 $cs = trim($cs);
                 $dom = new DOMDocument();
                 $dom->loadXML($cs);
                 $changeSet = $dom->getElementsByTagName('changeSet');
                 $CSID = null;
                 foreach ($changeSet as $cs) {
                     if ($cs->hasAttribute("id")) {
                         $CSID = $cs->getAttribute('id');
                     }
                 }
                 wfDebugLog('p2p', '     -> changeSet found ' . $CSID);
             }
             if (is_null($csName)) {
                 wfDebugLog('p2p', '  - redirect to Special:ArticleAdminPage');
                 utils::writeAndFlush("<span style=\"margin-left:60px;\">no new patch</span><br/>");
             } else {
                 wfDebugLog('p2p', '  - redirect to ChangeSet:' . $csName);
             }
         }
         // end foreach list pullfeed
         utils::writeAndFlush('<p><b>End pull</b></p>');
         $title = Title::newFromText('Special:ArticleAdminPage');
         $wgOut->redirect($title->getFullURL());
         return false;
     } else {
         return true;
     }
 }
示例#3
0
    /**
     * $action=admin is generated when the administration tab is clicked
     * Calculates every that is displayed on this page (cf user manual)
     *
     * @global <Object> $wgOut output page instance
     * @global <Object> $wgCachePages
     * @global <String> $wgServerName
     * @global <String> $wgScriptPath
     * @param <String> $action
     * @param <Object> $article
     * @return <bool>
     */
    function onUnknownAction($action, $article)
    {
        global $wgOut, $wgCachePages, $wgServerName, $wgScriptPath, $wgScriptExtension;
        $urlServer = 'http://' . $wgServerName . $wgScriptPath;
        $wgCachePages = false;
        //Verify that the action coming in is "admin"
        if ($action == "admin") {
            wfDebugLog('p2p', 'Admin page');
            if ($article->mTitle->getNamespace() == 0) {
                $title = $article->mTitle->getText();
            } else {
                $title = $article->mTitle->getNsText() . ':' . $article->mTitle->getText();
            }
            wfDebugLog('p2p', ' -> title : ' . $title);
            $wgOut->setPagetitle('DSMW on ' . $title);
            //part list of patch
            $patchs = utils::orderPatchByPrevious($title);
            $wgOut->addWikiText('[[Special:ArticleAdminPage|DSMW Admin functions]]

==Features==');
            $output = '<div style="width:60%;height:40%;overflow:auto;">
<table style="border-bottom: 2px solid #000;">
<caption><b>List of patchs</b></caption>';
            //color the remote patch of the current page
            foreach ($patchs as $patch) {
                wfDebugLog('p2p', '  -> patchId : ' . $patch);
                if (!utils::isRemote($patch)) {
                    wfDebugLog('p2p', '      -> remote patch');
                    $output .= '<tr BGCOLOR="#CCCCCC"><td>' . wfTimestamp(TS_RFC2822, $article->getTimestamp()) . ' : </td>';
                    // $output .= '<tr><td BGCOLOR="#33CC00"><a href="'.$_SERVER['PHP_SELF'].'?title='.$patch.'">'.$patch.'</a></td>';
                } else {
                    wfDebugLog('p2p', '      -> local patch');
                    $output .= '<tr><td>' . wfTimestamp(TS_RFC2822, $article->getTimestamp()) . ' : </td>';
                    //$output .= '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?title='.$patch.'">'.$patch.'</a></td>';
                }
                //count the number of delete and insert operations into the patch
                $results = array();
                $op = utils::getSemanticQuery('[[Patch:+]][[patchID::' . $patch . ']]', '?hasOperation');
                $count = $op->getCount();
                for ($i = 0; $i < $count; $i++) {
                    $row = $op->getNext();
                    if ($row === false) {
                        break;
                    }
                    $row = $row[1];
                    $col = $row->getContent();
                    //SMWResultArray object
                    foreach ($col as $object) {
                        //SMWDataValue object
                        $wikiValue = $object->getWikiValue();
                        $results[] = $wikiValue;
                    }
                }
                $countOp = utils::countOperation($results);
                //old code passed $op parameter
                $output .= '<td>' . $countOp['insert'] . '  insert, ' . $countOp['delete'] . ' delete</td>';
                $output .= '<td>(<a href="' . $_SERVER['PHP_SELF'] . '?title=' . $patch . '">' . $patch . '</a>)</td></tr>';
                /*$titlePatch = Title::newFromText( $patch,PATCH );
                  $article = new Article( $title );*/
            }
            $output .= '</table></div>';
            //list of push
            $pushs = array();
            $res = utils::getSemanticQuery('[[ChangeSet:+]][[hasPatch::' . $patchs[0] . ']][[inPushFeed::+]]', '?inPushFeed');
            $count = $res->getCount();
            for ($i = 0; $i < $count; $i++) {
                $row = $res->getNext();
                if ($row === false) {
                    break;
                }
                $row = $row[1];
                $col = $row->getContent();
                //SMWResultArray object
                foreach ($col as $object) {
                    //SMWDataValue object
                    $wikiValue = $object->getWikiValue();
                    $pushs[] = $wikiValue;
                }
            }
            if (!empty($pushs)) {
                $output .= '<br><div style="width:60%;height:40%;overflow:auto;"><table style="border-bottom: 2px solid #000;"><caption><b>List of pushs</b></caption>';
                foreach ($pushs as $push) {
                    $pushName = $push;
                    $output .= '<tr><td align="right" width="50%"><a href="' . $_SERVER['PHP_SELF'] . '?title=' . $pushName . '">' . $pushName . '</a> : </td>';
                    //count the number of published patchs by the current pushFeed for the current page
                    $published = utils::getPublishedPatchs($urlServer, $pushName, $title);
                    //$publishedInPush = utils::getSemanticRequest('http://'.$wgServerName.$wgScriptPath, '', $param);
                    //count the number of unpublished patchs
                    $unpublished = array_diff($patchs, $published);
                    if (!is_null($unpublished) && count($unpublished) > 0) {
                        $output .= '<td align="left" width="50%">' . count($unpublished) . ' unpublished patchs on ' . count($patchs) . ' </td></tr>';
                    } else {
                        $output .= '<td align="left" width="50%"> all ' . $title . "'" . 'patchs are pushed </td></tr>';
                    }
                }
                $output .= '</table></div>';
            }
            //end if empty $pushs
            //part list of pull
            $pulls = array();
            $res = utils::getSemanticQuery('[[ChangeSet:+]][[hasPatch::' . $patchs[0] . ']][[inPullFeed::+]]', '?inPullFeed');
            $count = $res->getCount();
            for ($i = 0; $i < $count; $i++) {
                $row = $res->getNext();
                if ($row === false) {
                    break;
                }
                $row = $row[1];
                $col = $row->getContent();
                //SMWResultArray object
                foreach ($col as $object) {
                    //SMWDataValue object
                    $wikiValue = $object->getWikiValue();
                    $pulls[] = $wikiValue;
                }
            }
            if (!empty($pulls)) {
                $output .= '<br><div style="width:60%;height:40%;overflow:auto;"><table style="border-bottom: 2px solid #000;"><caption><b>List of pull</b></caption>';
                foreach ($pulls as $pull) {
                    $pullName = $pull;
                    $pushServer = getPushURL($pullName);
                    $pushName = getPushName($pullName);
                    $output .= '<tr><td align="right" width="50%"><a href="' . $_SERVER['PHP_SELF'] . '?title=' . $pullName . '">' . $pullName . '</a> : </td>';
                    $pulledPatch = utils::getPulledPatches($pullName);
                    $patchs = array();
                    foreach ($pulledPatch as $patch) {
                        $onPage = array();
                        $res = utils::getSemanticQuery('[[Patch:+]][[patchID::' . $patch . ']]', '?onPage');
                        $count = $res->getCount();
                        for ($i = 0; $i < $count; $i++) {
                            $row = $res->getNext();
                            if ($row === false) {
                                break;
                            }
                            $row = $row[1];
                            $col = $row->getContent();
                            //SMWResultArray object
                            foreach ($col as $object) {
                                //SMWDataValue object
                                $wikiValue = $object->getWikiValue();
                                $onPage[] = $wikiValue;
                            }
                        }
                        if ($onPage[0] == $title) {
                            $patchs[] = $patch;
                        }
                    }
                    $published = utils::getPublishedPatchs($pushServer, $pushName, $title);
                    if (!is_null($published)) {
                        $unpublished = array_diff($patchs, $published);
                        $t = count($published);
                        $t = count($patchs);
                        $count = count($published) - count($patchs);
                        $output .= '<td align="left" width="50%"> ' . $count . ' unpulled patchs </td></tr>';
                    } else {
                        $output .= '<td align="left" width="50%"> up to date </td></tr>';
                    }
                }
                $output .= '</table></div>';
            }
            //end if empty $pulls
            //part push page
            $url = "http://" . $wgServerName . $wgScriptPath . "/index{$wgScriptExtension}";
            $output .= '
<h2>Actions</h2>
<div><FORM  name="formPush">
<table >
<tr><td> <input type="button" value="PUSH" onClick="pushpage(\'' . $url . '\',\'' . $title . '\');"></input></td></tr></table></form></div>
This [Push page : "' . $title . '"] action will create a PushFeed and
publish the modifications of the "' . $title . '" article

<div id="pushstatus" style="display: none; width: 100%; clear: both;" >
<a name="PUSH_Progress_:" id="PUSH_Progress_:"></a><h2> <span class="mw-headline"> PUSH Progress&nbsp;: </span></h2>
<div id="statepush" ></div><br />
</div>
';
            $wgOut->addHTML($output);
            return false;
        } else {
            return true;
        }
    }