2025-03-16 08:34:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DokuWiki Information about a page in JSON format
|
|
|
|
*
|
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
2025-04-13 13:09:37 +02:00
|
|
|
* @author Sascha Leib <sascha (dot) leib (at) kolmio (dot) com>
|
2025-03-16 08:34:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
|
2025-04-13 13:09:37 +02:00
|
|
|
// Turn off all error reporting
|
|
|
|
//error_reporting(0);
|
2025-03-16 08:34:47 +01:00
|
|
|
|
|
|
|
/* connect to DokuWiki: */
|
|
|
|
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
|
|
|
|
if (!defined('DOKU_INC')) { define('DOKU_INC', __DIR__ . '/../../../../'); }
|
|
|
|
require_once(DOKU_INC . 'inc/init.php');
|
|
|
|
|
|
|
|
/* get the output style (can be 'preview' or 'all') */
|
2025-04-13 13:09:37 +02:00
|
|
|
$style = ( array_key_exists('v', $_GET) ? strtolower($_GET['v']) : 'all' );
|
2025-03-16 08:34:47 +01:00
|
|
|
if ($style !== 'preview') { $style = 'all'; }
|
|
|
|
|
|
|
|
/* initialize the storage: */
|
|
|
|
$result = [
|
|
|
|
'type' => 'error'
|
|
|
|
];
|
|
|
|
|
|
|
|
/* find the page ID */
|
|
|
|
$id = $_GET['id'];
|
|
|
|
|
|
|
|
if ($id !== null) {
|
|
|
|
|
|
|
|
/* get all metadata; */
|
|
|
|
$meta = p_get_metadata($id);
|
|
|
|
|
2025-04-13 13:09:37 +02:00
|
|
|
if (array_key_exists('title', $meta) && $meta['title'] !== null) {
|
2025-03-16 08:34:47 +01:00
|
|
|
|
|
|
|
if ($style == 'preview') {
|
|
|
|
$result['type'] = 'preview';
|
|
|
|
} else {
|
|
|
|
$result['type'] = 'standard';
|
|
|
|
$result['pageid'] = $id;
|
|
|
|
$result['lang'] = $conf['lang'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result['title'] = $meta['title'];
|
|
|
|
|
|
|
|
/* The page URL(s) */
|
|
|
|
$url = wl($id);
|
|
|
|
|
|
|
|
if ($style == 'preview') {
|
|
|
|
$result['content_urls'] = [
|
|
|
|
'desktop' => [
|
|
|
|
'page' => wl($id)
|
|
|
|
]
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$url = $conf['baseurl'] . wl($id);
|
|
|
|
$set = [
|
|
|
|
'page' => $url,
|
|
|
|
'revisions' => $url . '?do=revisions',
|
|
|
|
'edit' => $url . '?do=edit'
|
|
|
|
];
|
|
|
|
$result['content_urls'] = [
|
|
|
|
'desktop' => $set,
|
|
|
|
'mobile' => $set
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract the first paragraph:*/
|
|
|
|
$parts = explode("\n", $meta['description']['abstract']);
|
2025-04-13 13:09:37 +02:00
|
|
|
$result['extract'] = ( count($parts) > 2 ? $parts[2] : '' );
|
|
|
|
$result['extract_html'] = '<p>'. ( count($parts) > 2 ? $parts[2] : '' ) .'</p>';
|
2025-03-16 08:34:47 +01:00
|
|
|
|
|
|
|
} else {
|
2025-04-13 13:09:37 +02:00
|
|
|
/* page does not exist */
|
2025-03-16 08:34:47 +01:00
|
|
|
$result['extract'] = 'Error: page does not exist.';
|
|
|
|
$result['extract_html'] = '<p><strong>' . $result['extract'] . '</strong></p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output the result: */
|
|
|
|
echo json_encode($result);
|