Skip to content

Commit 9f4e5e6

Browse files
Create patrol.php
1 parent ffece8c commit 9f4e5e6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

php/patrol.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
require_once 'includes/headerOAuth.php';
3+
4+
if (!isset($_SESSION['tokenKey']) || !isset($_SESSION['tokenSecret']) || !isset($_SESSION['userName']) || !isset($_POST["project"]) || !isset($_POST["rev"]) || !is_numeric($_POST["rev"])) {
5+
echo json_encode(["result" => "Invalid request data.", "info" => "Invalid request"]);
6+
session_write_close();
7+
exit();
8+
}
9+
session_write_close();
10+
11+
$apiUrl = "https://" . $_POST["project"] . "/w/api.php";
12+
$rev = $_POST["rev"];
13+
14+
$params = ['action' => 'query', 'meta' => 'tokens', 'type' => 'csrf', 'format' => 'json'];
15+
$token = json_decode($client->makeOAuthCall($accessToken, $apiUrl, true, $params));
16+
$token = $token->query->tokens->csrftoken;
17+
18+
$params = ["action" => "review", "format" => "json", "revid" => $rev, "comment" => "via [[m:SWViewer|SWViewer]]", "token" => $token];
19+
$res = json_decode($client->makeOAuthCall($accessToken, $apiUrl, true, $params));
20+
if (isset($res->review->result)) {
21+
if ($res->review->result === "Success")
22+
$response = ["result" => "success"];
23+
else
24+
$response = ["result" => "error", "info" => $res];
25+
}
26+
else
27+
$response = ["result" => "error", "info" => $res->error->info];
28+
echo json_encode($response);
29+
?>

0 commit comments

Comments
 (0)