diff options
author | Andreas Gohr <andi@splitbrain.org> | 2025-03-15 15:02:10 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2025-03-15 15:10:33 +0100 |
commit | 72b0e523364ae0c255437ef22a1bba67dd9b28a4 (patch) | |
tree | 9aa71ca9e7fee98c96e20800444c965f82c6c31e | |
parent | 61d21e86ed667b6b4110b90d683dddf13903de67 (diff) | |
download | dokuwiki-72b0e523364ae0c255437ef22a1bba67dd9b28a4.tar.gz dokuwiki-72b0e523364ae0c255437ef22a1bba67dd9b28a4.zip |
API: proper access to the current media revision
Even when the revision is explictly given instead of set to 0. See #4419
for ponderings about why this is necessary and a different approach.
-rw-r--r-- | inc/Remote/ApiCore.php | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/inc/Remote/ApiCore.php b/inc/Remote/ApiCore.php index 1a859ddfe..1c8de2ddf 100644 --- a/inc/Remote/ApiCore.php +++ b/inc/Remote/ApiCore.php @@ -66,7 +66,6 @@ class ApiCore 'core.getMedia' => new ApiCall([$this, 'getMedia'], 'media'), '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'), @@ -836,6 +835,11 @@ class ApiCore throw new AccessDeniedException('You are not allowed to read this media file', 211); } + // was the current revision requested? + if ($this->isCurrentMediaRev($media, $rev)) { + $rev = 0; + } + $file = mediaFN($media, $rev); if (!@ file_exists($file)) { throw new RemoteException('The requested media file (revision) does not exist', 221); @@ -867,6 +871,12 @@ class ApiCore if (auth_quickaclcheck($media) < AUTH_READ) { throw new AccessDeniedException('You are not allowed to read this media file', 211); } + + // was the current revision requested? + if ($this->isCurrentMediaRev($media, $rev)) { + $rev = 0; + } + if (!media_exists($media, $rev)) { throw new RemoteException('The requested media file does not exist', 221); } @@ -938,7 +948,10 @@ class ApiCore $result = []; foreach ($revisions as $rev) { - if (!media_exists($media, $rev)) continue; // skip non-existing revisions + // the current revision needs to be checked against the current file path + $check = $this->isCurrentMediaRev($media, $rev) ? '' : $rev; + if (!media_exists($media, $check)) continue; // skip non-existing revisions + $info = $medialog->getRevisionInfo($rev); $result[] = new MediaChange( @@ -1039,6 +1052,20 @@ class ApiCore } } + /** + * Check if the given revision is the current revision of this file + * + * @param string $id + * @param int $rev + * @return bool + */ + protected function isCurrentMediaRev(string $id, int $rev) + { + $current = @filemtime(mediaFN($id)); + if ($current === $rev) return true; + return false; + } + // endregion |