diff options
Diffstat (limited to 'inc/Remote/ApiCore.php')
-rw-r--r-- | inc/Remote/ApiCore.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/inc/Remote/ApiCore.php b/inc/Remote/ApiCore.php index 5a173cf89..1a859ddfe 100644 --- a/inc/Remote/ApiCore.php +++ b/inc/Remote/ApiCore.php @@ -4,6 +4,7 @@ namespace dokuwiki\Remote; use Doku_Renderer_xhtml; use dokuwiki\ChangeLog\PageChangeLog; +use dokuwiki\ChangeLog\MediaChangeLog; use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\Event; use dokuwiki\Remote\Response\Link; @@ -66,6 +67,7 @@ class ApiCore 'core.getMediaInfo' => new ApiCall([$this, 'getMediaInfo'], 'media'), 'core.getMediaUsage' => new ApiCall([$this, 'getMediaUsage'], 'media'), // todo: implement getMediaHistory + 'core.getMediaHistory' => new ApiCall([$this, 'getMediaHistory'], 'media'), 'core.saveMedia' => new ApiCall([$this, 'saveMedia'], 'media'), 'core.deleteMedia' => new ApiCall([$this, 'deleteMedia'], 'media'), @@ -904,6 +906,56 @@ class ApiCore } /** + * Returns a list of available revisions of a given wiki media + * + * + * + * @link https://www.dokuwiki.org/config:recent + * @param string $media file id + * @param int $first skip the first n changelog lines, 0 starts at the current revision + * @return MediaChange[] + * @throws AccessDeniedException + * @throws RemoteException + * @author + */ + public function getMediaHistory($media, $first = 0) + { + global $conf; + + $media = cleanID($media); + // check that this media exists + if (auth_quickaclcheck($media) < AUTH_READ) { + throw new AccessDeniedException('You are not allowed to read this media file', 211); + } + if (!media_exists($media, 0)) { + throw new RemoteException('The requested media file does not exist', 221); + } + + $medialog = new MediaChangeLog($media); + $medialog->setChunkSize(1024); + // old revisions are counted from 0, so we need to subtract 1 for the current one + $revisions = $medialog->getRevisions($first - 1, $conf['recent']); + + $result = []; + foreach ($revisions as $rev) { + if (!media_exists($media, $rev)) continue; // skip non-existing revisions + $info = $medialog->getRevisionInfo($rev); + + $result[] = new MediaChange( + $media, + $rev, + $info['user'], + $info['ip'], + $info['sum'], + $info['type'], + $info['sizechange'] + ); + } + + return $result; + } + + /** * Uploads a file to the wiki * * The file data has to be passed as a base64 encoded string. |