1<?php
2
3use dokuwiki\Remote\OpenApiDoc\OpenAPIGenerator;
4
5if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
6require_once(DOKU_INC . 'inc/init.php');
7global $INPUT;
8
9if ($INPUT->has('spec')) {
10    header('Content-Type: application/json');
11    $apigen = new OpenAPIGenerator();
12    echo $apigen->generate();
13    exit();
14}
15?>
16<!doctype html>
17<html lang="en">
18<head>
19    <meta charset="utf-8">
20    <title>DokuWiki API Explorer</title>
21    <script src="https://unpkg.com/openapi-explorer/dist/browser/openapi-explorer.min.js" type="module"
22            defer=""></script>
23    <style>
24        body {
25            font-family: sans-serif;
26        }
27    </style>
28</head>
29<body>
30<openapi-explorer
31    spec-url="<?php echo DOKU_URL ?>lib/exe/openapi.php?spec=1"
32    hide-server-selection="true"
33    use-path-in-nav-bar="true"
34>
35    <div slot="overview-api-description">
36        <p>
37            This is an auto generated description and OpenAPI specification for the
38            <a href="https://www.dokuwiki.org/devel/jsonrpc">DokuWiki JSON-RPC API</a>.
39            It is generated from the source code and the inline documentation.
40        </p>
41
42        <p>
43            <a href="<?php echo DOKU_BASE ?>/lib/exe/openapi.php?spec=1" download="dokuwiki.json">Download
44                the API Spec</a>
45        </p>
46
47        <h3>Error Codes</h3>
48
49        <p>
50            The following error codes are currently used in the core methods. This list may be incomplete
51            or change in the future.
52        </p>
53
54        <table>
55            <tr><th>Code</th><th>Message</th></tr>
56            <tr><td>0</td><td>Success</td></tr>
57            <?php
58            $apigen = new OpenAPIGenerator();
59            $last = 0;
60            foreach ($apigen->getErrorCodes() as $code) {
61                // duplicate codes are only shown with debug
62                if ($code['code'] === $last && !$INPUT->has('debug')) continue;
63                $last = $code['code'];
64                echo '<tr><td>' . $code['code'] . '</td><td>' . hsc($code['message']) . '</td></tr>';
65            }
66            ?>
67        </table>
68    </div>
69
70    <div slot="authentication-footer">
71        <p>
72            <?php
73            if ($INPUT->server->has('REMOTE_USER')) {
74                echo 'You are currently logged in as <strong>' . hsc($INPUT->server->str('REMOTE_USER')) . '</strong>.';
75                echo '<br>API calls in this tool will be automatically executed with your permissions.';
76            } else {
77                echo 'You are currently not logged in.<br>';
78                echo 'You can provide credentials above.';
79            }
80            ?>
81        </p>
82    </div>
83</openapi-explorer>
84</body>
85</html>
86
87
88