Example #1
0
 /**
  * Really do the upload
  * Checks are made in SpecialUpload::execute()
  * @access private
  */
 function processUpload()
 {
     global $wgUser, $wgOut;
     /* Check for PHP error if any, requires php 4.2 or newer */
     if ($this->mUploadError == 1) {
         $this->mainUploadForm(wfMsgHtml('largefileserver'));
         return;
     }
     /**
      * If there was no filename or a zero size given, give up quick.
      */
     if (trim($this->mOname) == '' || empty($this->mUploadSize)) {
         $this->mainUploadForm(wfMsgHtml('emptyfile'));
         return;
     }
     # Chop off any directories in the given filename
     if ($this->mDestFile) {
         $basename = wfBaseName($this->mDestFile);
     } else {
         $basename = wfBaseName($this->mOname);
     }
     /**
      * We'll want to blacklist against *any* 'extension', and use
      * only the final one for the whitelist.
      */
     list($partname, $ext) = $this->splitExtensions($basename);
     if (count($ext)) {
         $finalExt = $ext[count($ext) - 1];
     } else {
         $finalExt = '';
     }
     $fullExt = implode('.', $ext);
     # If there was more than one "extension", reassemble the base
     # filename to prevent bogus complaints about length
     if (count($ext) > 1) {
         for ($i = 0; $i < count($ext) - 1; $i++) {
             $partname .= '.' . $ext[$i];
         }
     }
     if (strlen($partname) < 3) {
         $this->mainUploadForm(wfMsgHtml('minlength'));
         return;
     }
     // WERELATE - added validation tests
     if (!$this->mLicense && !$this->mReUploading) {
         $this->uploadError("You must select a license (press the \"back button\" on your browser to correct this)");
         return;
     }
     /**
      * Filter out illegal characters, and try to make a legible name
      * out of it. We'll strip some silently that Title would die on.
      */
     $filtered = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $basename);
     $nt = Title::newFromText($filtered);
     if (is_null($nt)) {
         $this->uploadError(wfMsgWikiHtml('illegalfilename', htmlspecialchars($filtered)));
         return;
     }
     $nt =& Title::makeTitle(NS_IMAGE, $nt->getDBkey());
     $this->mUploadSaveName = $nt->getDBkey();
     /**
      * If the image is protected, non-sysop users won't be able
      * to modify it by uploading a new revision.
      */
     if (!$nt->userCanEdit()) {
         return $this->uploadError(wfMsgWikiHtml('protectedpage'));
     }
     /**
      * In some cases we may forbid overwriting of existing files.
      */
     $overwrite = $this->checkOverwrite($this->mUploadSaveName);
     if (WikiError::isError($overwrite)) {
         return $this->uploadError($overwrite->toString());
     }
     /* Don't allow users to override the blacklist (check file extension) */
     global $wgStrictFileExtensions;
     global $wgFileExtensions, $wgFileBlacklist;
     if ($this->checkFileExtensionList($ext, $wgFileBlacklist) || $wgStrictFileExtensions && !$this->checkFileExtension($finalExt, $wgFileExtensions)) {
         return $this->uploadError(wfMsgHtml('badfiletype', htmlspecialchars($fullExt)));
     }
     /**
      * Look at the contents of the file; if we can recognize the
      * type but it's corrupt or data of the wrong type, we should
      * probably not accept it.
      */
     if (!$this->mStashed) {
         $this->checkMacBinary();
         $veri = $this->verify($this->mUploadTempName, $finalExt);
         if ($veri !== true) {
             //it's a wiki error...
             return $this->uploadError($veri->toString());
         }
     }
     /**
      * Provide an opportunity for extensions to add futher checks
      */
     $error = '';
     if (!wfRunHooks('UploadVerification', array($this->mUploadSaveName, $this->mUploadTempName, &$error))) {
         return $this->uploadError($error);
     }
     /**
      * Check for non-fatal conditions
      */
     if (!$this->mIgnoreWarning) {
         $warning = '';
         global $wgCapitalLinks;
         if ($wgCapitalLinks) {
             $filtered = ucfirst($filtered);
         }
         if ($this->mUploadSaveName != $filtered) {
             $warning .= '<li>' . wfMsgHtml('badfilename', htmlspecialchars($this->mUploadSaveName)) . '</li>';
         }
         global $wgCheckFileExtensions;
         if ($wgCheckFileExtensions) {
             if (!$this->checkFileExtension($finalExt, $wgFileExtensions)) {
                 $warning .= '<li>' . wfMsgHtml('badfiletype', htmlspecialchars($fullExt)) . '</li>';
             }
         }
         global $wgUploadSizeWarning;
         if ($wgUploadSizeWarning && $this->mUploadSize > $wgUploadSizeWarning) {
             # TODO: Format $wgUploadSizeWarning to something that looks better than the raw byte
             # value, perhaps add GB,MB and KB suffixes?
             $warning .= '<li>' . wfMsgHtml('largefile', $wgUploadSizeWarning, $this->mUploadSize) . '</li>';
         }
         if ($this->mUploadSize == 0) {
             $warning .= '<li>' . wfMsgHtml('emptyfile') . '</li>';
         }
         if ($nt->getArticleID()) {
             global $wgUser;
             $sk = $wgUser->getSkin();
             $dlink = $sk->makeKnownLinkObj($nt);
             $warning .= '<li>' . wfMsgHtml('fileexists', $dlink) . '</li>';
             // WERELATE: added fileexistsnoreupload warning; assume that if user entered license, then this isn't a case of purposeful re-uploading
             if ($this->mLicense) {
                 $warning .= '<li>' . wfMsgHtml('fileexistsnoreupload') . '</li>';
             }
         } else {
             # If the file existed before and was deleted, warn the user of this
             # Don't bother doing so if the image exists now, however
             // WERELATE: remove
             //				$image = new Image( $nt );
             //				if( $image->wasDeleted() ) {
             //					$skin = $wgUser->getSkin();
             //					$ltitle = Title::makeTitle( NS_SPECIAL, 'Log' );
             //					$llink = $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'deletionlog' ), 'type=delete&page=' . $nt->getPrefixedUrl() );
             //					$warning .= wfOpenElement( 'li' ) . wfMsgWikiHtml( 'filewasdeleted', $llink ) . wfCloseElement( 'li' );
             //				}
         }
         if ($warning != '') {
             /**
              * Stash the file in a temporary location; the user can choose
              * to let it through and we'll complete the upload then.
              */
             return $this->uploadWarning($warning);
         }
     }
     /**
      * Try actually saving the thing...
      * It will show an error form on failure.
      */
     $hasBeenMunged = !empty($this->mSessionKey) || $this->mRemoveTempFile;
     if ($this->saveUploadedFile($this->mUploadSaveName, $this->mUploadTempName, $hasBeenMunged)) {
         /**
          * Update the upload log and create the description page
          * if it's a new file.
          */
         $img = Image::newFromName($this->mUploadSaveName);
         // WERELATE - changed - added getMetadata, null out license (because we capture it in metadata), redirect only if target is empty
         $success = $img->recordUpload($this->mUploadOldVersion, $this->mUploadDescription, '', $this->mUploadCopyStatus, $this->mUploadSource, $this->mWatchthis, $this->getMetadata(), !$this->mTarget);
         if ($success) {
             // WERELATE - if we're uploading for a P/F target, showSuccess, else just redirect
             if ($this->mTarget) {
                 $this->showSuccess();
             } else {
                 $article = new Article($img->getTitle());
                 $article->doRedirect();
             }
             wfRunHooks('UploadComplete', array(&$img));
         } else {
             // Image::recordUpload() fails if the image went missing, which is
             // unlikely, hence the lack of a specialised message
             $wgOut->showFileNotFoundError($this->mUploadSaveName);
         }
     }
 }
Example #2
0
File: DSMW.php Project: hala54/DSMW
/**
 * MW Hook used to redirect to page creation (pushfeed, pullfeed, changeset),
 * to forms or to push/pull action testing the action param
 *
 *
 * @global <Object> $wgOut
 * @param <Object> $action
 * @param <Object> $article
 * @return <boolean>
 */
function onUnknownAction($action, $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<div id='dsmw' style=\"color:green;\"></div>\n\n{{#form:action=" . $urlServer . "?action=pullpage|method=POST|\nPushFeed Url: {{#input:type=button|value=Url test|onClick=\nvar url = document.getElementsByName('url')[0].value;\nif(url.indexOf('PushFeed')==-1){\nalert('No valid PushFeed syntax, see example.');\n}else{\nvar urlTmp = url.substring(0,url.indexOf('PushFeed'));\n//alert(urlTmp);\n\nvar pos1 = urlTmp.indexOf('index.php');\n//alert(pos1);\nvar pushUrl='';\nif(pos1!=-1){\npushUrl = urlTmp.substring(0,pos1);\n//alert('if');\n}else{\npushUrl = urlTmp;\n//alert('else');\n}\n//alert(pushUrl);\n\n//alert(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml');\nvar xhr_object = null;\n\n\t   if(window.XMLHttpRequest) // Firefox\n\t      xhr_object = new XMLHttpRequest();\n\t   else if(window.ActiveXObject) // Internet Explorer\n\t      xhr_object = new ActiveXObject('Microsoft.XMLHTTP');\n\t   else {\n\t      alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...');\n\t      return;\n\t   }\n          try{ xhr_object.open('GET', '" . $urlAjax . "/extensions/DSMW/files/ajax.php?url='+escape(pushUrl+'api.php?action=query&meta=patch&papatchId=1&format=xml'), true);}\n          catch(e){\n                    //alert('There is no DSMW Server responding at this URL');\n                    document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n                    document.getElementById('dsmw').style.color = 'red';\n                  }\n           xhr_object.onreadystatechange = function() {\n\nif(xhr_object.readyState == 4) {\n            if(xhr_object.statusText=='OK'){\n                if(xhr_object.responseText == 'true'){ //alert('URL valid, there is a DSMW Server responding');\n                        document.getElementById('dsmw').innerHTML = 'URL valid, there is a DSMW Server responding!';\n                        document.getElementById('dsmw').style.color = 'green';\n                  }\n                else{ //alert('There is no DSMW Server responding at this URL');\n                        document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n                        document.getElementById('dsmw').style.color = 'red';\n                  }\n                }\n                else{\n                //alert('There is no DSMW Server responding at this URL');\n                document.getElementById('dsmw').innerHTML = 'There is no DSMW Server responding at this URL!';\n                document.getElementById('dsmw').style.color = 'red';\n}\n\t\t  }\n\t   }\n\n\t   xhr_object.send(null);\n}\n}}<br>        {{#input:type=text|name=url|size=50}} <b>e.g. http://server/path/index.php?title=PushFeed:PushName</b><br>\nPullFeed Name:   <br>    {{#input:type=text|name=pullname}}<br>\n{{#input:type=submit|value=ADD}}\n}}";
        //if article doesn't exist insertNewArticle
        if ($article->mTitle->exists()) {
            $article->updateArticle($newtext, $summary = "", false, false);
        } else {
            $article->insertNewArticle($newtext, $summary = "", false, false);
        }
        $article->doRedirect();
        return false;
    } elseif (isset($_GET['action']) && $_GET['action'] == 'addpushpage') {
        wfDebugLog('p2p', '@@@@@@@@@@@@@@@@ addPushPage');
        $specialAsk = $urlServer . '?title=Special:Ask';
        $newtext = "Add a new pushfeed:\n\n{{#form:action=" . $urlServer . "?action=pushpage|method=POST|\nPushFeed Name:   <br>    {{#input:class=test|name=name|type=text|onKeyUp=test('{$urlServer}');}}<div style=\"display:inline; \" id=\"state\" ></div><br />\nRequest: {{#input:type=button|value=Test your query|title=click here to test your query results|onClick=\nvar query = document.getElementsByName('keyword')[0].value;\nvar query1 = encodeURI(query);\nwindow.open('" . $specialAsk . "&q='+query1+'&eq=yes&p%5Bformat%5D=broadtable','querywindow','menubar=no, status=no, scrollbars=yes, menubar=no, width=1000, height=900');}}\n  <br>{{#input:type=textarea|cols=30 | style=width:auto |rows=2|name=keyword}} <b>e.g. [[Category:city]][[locatedIn::France]]</b><br>\n{{#input:type=submit|value=ADD}}\n}}";
        $article->doEdit($newtext, $summary = "");
        $article->doRedirect();
        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 = "");
        $article->doRedirect();
        return false;
    } elseif (isset($_POST['action']) && $_POST['action'] == 'onpush') {
        wfDebugLog('p2p', '@@@@@@@@@@@@  ChangeSet page');
        /* 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');
            $article = new Article($title);
            $article->doRedirect();
            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|-\n";
                }
                $newtext .= "\n|}";
                $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');
        $article = new Article($title);
        $article->doRedirect();
        return false;
    } elseif (isset($_GET['action']) && $_GET['action'] == 'pullpage') {
        //$url = rtrim($_POST['url'], "/"); //removes the final "/" if there is one
        $urlTmp = $_POST['url'];
        if (utils::isValidURL($urlTmp) == false) {
            throw new MWException(__METHOD__ . ': ' . $urlTmp . ' seems not to be an url');
        }
        //throws an exception if $url is invalid
        $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'];
        wfDebugLog('p2p', '@@@@@@@@@@@@@ Create pull ' . $pullname . ' with pushName ' . $pushname . ' on ' . $url);
        $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 = "");
        $article->doRedirect();
        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 = "");
            $article->doRedirect();
            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;
            $csName = 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');
        $article = new Article($title);
        $article->doRedirect();
        return false;
    } else {
        return true;
    }
}