示例#1
0
 public function deletePage(PCPUserCredentials $uc = NULL, $title = NULL, $reason = NULL)
 {
     // check if new user credentials are set
     if ($userCredentials != NULL && $this->usedUC->un != $userCredentials->un) {
         $this->usedUC = $userCredentials;
         $this->login();
     }
     if (!isset($title)) {
         return false;
     }
     // get the edit token for the page
     $this->getEditToken(NULL, urldecode($title));
     // extract only the first title
     $title = PCPUtil::trimFirstTitle($title);
     foreach (PCPUtil::replaceInHash($this->queryDeletePage, array(urlencode($title), urlencode($this->usedUC->editToken), urlencode($reason))) as $__parameter => $__parameterValue) {
         $__parameters .= $__parameter . '=' . $__parameterValue . '&';
     }
     $__request = $this->targetWiki->url . '/' . $this->targetWiki->api . '?' . $__parameters . $this->_returnFormat;
     // sets the return format
     $__curlHandler = curl_init();
     curl_setopt($__curlHandler, CURLOPT_URL, $__request);
     if ($this->targetWiki->proxyAddr != "") {
         curl_setopt($__curlHandler, CURLOPT_PROXY, $this->targetWiki->proxyAddr);
     }
     curl_setopt($__curlHandler, CURLOPT_HEADER, false);
     // don't return the header in teh result
     curl_setopt($__curlHandler, CURLOPT_COOKIEJAR, $this->cookieFile);
     curl_setopt($__curlHandler, CURLOPT_COOKIEFILE, $this->cookieFile);
     // set the file where cookies from which cookies are being read
     curl_setopt($__curlHandler, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($__curlHandler, CURLOPT_POST, 1);
     // use the POST method
     #curl_setopt($__curlHandler, CURLOPT_POSTFIELDS, "wpName=".$this->usedUC->un."&wpLoginToken=".$this->usedUC->lgToken);
     $__serializedResult = curl_exec($__curlHandler);
     curl_close($__curlHandler);
     $__result = unserialize($__serializedResult);
     return $__result;
 }
示例#2
0
 public function &readPage(PCPUserCredentials $userCredentials = NULL, $title = NULL, $revisionID = NULL)
 {
     $this->page = new PCPPage($title);
     $this->setCookies($userCredentials);
     // extract only the first title
     $title = PCPUtil::trimFirstTitle($title);
     $__request = new FauxRequest(PCPUtil::replaceInHash($this->queryReadPage, array($title)));
     $__api = new ApiMain($__request, true);
     $__api->execute();
     $__result =& $__api->GetResultData();
     if (!isset($__result['query']['pages'])) {
         // error handling
         print "ERROR: Reading a single page failed" . __FILE__;
     } else {
         // there could be more than one page in the result
         // each entry in the hashmap has the page ID as key
         foreach ($__result['query']['pages'] as $__pageid => $__pageObject) {
             if ($__result['query']['pages'][$__pageid]['title'] == str_replace('_', ' ', $title)) {
                 // get the page that has the matching title
                 if ($__pageid !== -1) {
                     // the page exists
                     $this->page->pageid = $__pageid;
                     $this->page->title = $__result['query']['pages'][$__pageid]['title'];
                     $this->page->lastrevid = $__result['query']['pages'][$__pageid]['lastrevid'];
                     $this->page->basetimestamp = $__result['query']['pages'][$__pageid]['touched'];
                     $this->page->namespace = $__result['query']['pages'][$__pageid]['ns'];
                     if ($revisionID !== NULL) {
                         foreach ($__result['query']['pages'][$__pageid]['revisions'] as $__idx => $__revision) {
                             if ($__revision['revid'] == $revisionID) {
                                 $this->page->usedrevid = $revisionID;
                                 $this->page->text = $__revision['*'];
                             }
                         }
                     } else {
                         $this->page->usedrevid = $__result['query']['pages'][$__pageid]['lastrevid'];
                         foreach ($__result['query']['pages'][$__pageid]['revisions'] as $__idx => $__revision) {
                             if ($__revision['revid'] == $this->page->lastrevid) {
                                 $this->page->text = $__result['query']['pages'][$__pageid]['revisions'][$__idx]['*'];
                             }
                         }
                     }
                 }
             }
         }
         return $this->page;
     }
 }