Private GIT

Skip to content
Snippets Groups Projects
Commit 67345895 authored by Kevin Duret's avatar Kevin Duret
Browse files

fix wiki page deletion on new mediawiki version

parent 511de7c3
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,7 @@ class WikiApi ...@@ -49,6 +49,7 @@ class WikiApi
private $curl; private $curl;
private $loggedIn; private $loggedIn;
private $tokens; private $tokens;
private $cookies;
/** /**
* WikiApi constructor. * WikiApi constructor.
...@@ -63,6 +64,7 @@ class WikiApi ...@@ -63,6 +64,7 @@ class WikiApi
$this->password = $config['kb_wiki_password']; $this->password = $config['kb_wiki_password'];
$this->curl = $this->getCurl(); $this->curl = $this->getCurl();
$this->version = $this->getWikiVersion(); $this->version = $this->getWikiVersion();
$this->cookies = array();
} }
private function getCurl() private function getCurl()
...@@ -103,26 +105,42 @@ class WikiApi ...@@ -103,26 +105,42 @@ class WikiApi
return $this->loggedIn; return $this->loggedIn;
} }
curl_setopt($this->curl, CURLOPT_HEADER, true);
// Get Connection Cookie/Token // Get Connection Cookie/Token
$postfields = array( $postfields = array(
'action' => 'login', 'action' => 'login',
'format' => 'json', 'format' => 'json',
'lgname' => $this->username, 'lgname' => $this->username
'lgpassword' => $this->password
); );
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($this->curl); $result = curl_exec($this->curl);
$result = json_decode($result, true); $header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
// Get cookies
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header, $matches);
$this->cookies = array_merge($this->cookies, $matches[1]);
$cookies = implode('; ', $this->cookies);
curl_setopt($this->curl, CURLOPT_COOKIE, $cookies);
$result = json_decode($body, true);
$token = '';
if (isset($result['login']['lgtoken'])) {
$token = $result['login']['lgtoken']; $token = $result['login']['lgtoken'];
} elseif (isset($result['login']['token'])) {
$token = $result['login']['token'];
}
// Launch Connection // Launch Connection
$postfields['lgpassword'] = $this->password;
$postfields['lgtoken'] = $token; $postfields['lgtoken'] = $token;
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($this->curl, CURLOPT_HEADER, true);
$result = curl_exec($this->curl); $result = curl_exec($this->curl);
curl_setopt($this->curl, CURLOPT_HEADER, false);
$header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE); $header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size); $header = substr($result, 0, $header_size);
...@@ -130,7 +148,8 @@ class WikiApi ...@@ -130,7 +148,8 @@ class WikiApi
// Get cookies // Get cookies
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header, $matches); preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header, $matches);
$cookies = implode('; ', $matches[1]); $this->cookies = array_merge($this->cookies, $matches[1]);
$cookies = implode('; ', $this->cookies);
curl_setopt($this->curl, CURLOPT_COOKIE, $cookies); curl_setopt($this->curl, CURLOPT_COOKIE, $cookies);
$result = json_decode($body, true); $result = json_decode($body, true);
...@@ -141,6 +160,8 @@ class WikiApi ...@@ -141,6 +160,8 @@ class WikiApi
$this->loggedIn = true; $this->loggedIn = true;
} }
curl_setopt($this->curl, CURLOPT_HEADER, false);
return $this->loggedIn; return $this->loggedIn;
} }
...@@ -182,7 +203,6 @@ class WikiApi ...@@ -182,7 +203,6 @@ class WikiApi
'titles' => $title 'titles' => $title
); );
} }
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($this->curl); $result = curl_exec($this->curl);
$result = json_decode($result, true); $result = json_decode($result, true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment