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
Branches
Tags v4.0.13
No related merge requests found
......@@ -49,6 +49,7 @@ class WikiApi
private $curl;
private $loggedIn;
private $tokens;
private $cookies;
/**
* WikiApi constructor.
......@@ -63,6 +64,7 @@ class WikiApi
$this->password = $config['kb_wiki_password'];
$this->curl = $this->getCurl();
$this->version = $this->getWikiVersion();
$this->cookies = array();
}
private function getCurl()
......@@ -103,26 +105,42 @@ class WikiApi
return $this->loggedIn;
}
curl_setopt($this->curl, CURLOPT_HEADER, true);
// Get Connection Cookie/Token
$postfields = array(
'action' => 'login',
'format' => 'json',
'lgname' => $this->username,
'lgpassword' => $this->password
'lgname' => $this->username
);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
$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'];
} elseif (isset($result['login']['token'])) {
$token = $result['login']['token'];
}
// Launch Connection
$postfields['lgpassword'] = $this->password;
$postfields['lgtoken'] = $token;
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($this->curl, CURLOPT_HEADER, true);
$result = curl_exec($this->curl);
curl_setopt($this->curl, CURLOPT_HEADER, false);
$header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
......@@ -130,7 +148,8 @@ class WikiApi
// Get cookies
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);
$result = json_decode($body, true);
......@@ -141,6 +160,8 @@ class WikiApi
$this->loggedIn = true;
}
curl_setopt($this->curl, CURLOPT_HEADER, false);
return $this->loggedIn;
}
......@@ -182,7 +203,6 @@ class WikiApi
'titles' => $title
);
}
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($this->curl);
$result = json_decode($result, true);
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment