16cce3332SAndreas Gohr<?php 26cce3332SAndreas Gohr 36cce3332SAndreas Gohrnamespace dokuwiki\Remote\Response; 46cce3332SAndreas Gohr 56cce3332SAndreas Gohr/** 66cce3332SAndreas Gohr * Represents a single media revision in the wiki. 76cce3332SAndreas Gohr */ 86cce3332SAndreas Gohrclass Media extends ApiResponse 96cce3332SAndreas Gohr{ 106cce3332SAndreas Gohr /** @var string The media ID */ 116cce3332SAndreas Gohr public $id; 126cce3332SAndreas Gohr /** @var int The media revision aka last modified timestamp */ 136cce3332SAndreas Gohr public $revision; 146cce3332SAndreas Gohr /** @var int The page size in bytes */ 156cce3332SAndreas Gohr public $size; 166cce3332SAndreas Gohr /** @var int The current user's permissions for this file */ 17*58ae4747SAndreas Gohr public $permission; 186cce3332SAndreas Gohr /** @var bool Wether this is an image file */ 196cce3332SAndreas Gohr public $isimage; 206cce3332SAndreas Gohr /** @var string MD5 sum over the file's content (if available and requested) */ 216cce3332SAndreas Gohr public $hash; 226cce3332SAndreas Gohr 23*58ae4747SAndreas Gohr /** @var string The file path to this media revision */ 24*58ae4747SAndreas Gohr protected $file; 25*58ae4747SAndreas Gohr 26*58ae4747SAndreas Gohr /** 27*58ae4747SAndreas Gohr * Media constructor. 28*58ae4747SAndreas Gohr * 29*58ae4747SAndreas Gohr * @param string $id The media ID 30*58ae4747SAndreas Gohr * @param int $revision The media revision aka last modified timestamp 31*58ae4747SAndreas Gohr * @param int $mtime The media revision aka last modified timestamp 32*58ae4747SAndreas Gohr * @param int|null $size The page size in bytes 33*58ae4747SAndreas Gohr * @param int|null $perms The current user's permissions for this file 34*58ae4747SAndreas Gohr * @param bool|null $isimage Wether this is an image file 35*58ae4747SAndreas Gohr * @param string $hash MD5 sum over the file's content 36*58ae4747SAndreas Gohr */ 37*58ae4747SAndreas Gohr public function __construct( 38*58ae4747SAndreas Gohr $id, 39*58ae4747SAndreas Gohr $revision = 0, 40*58ae4747SAndreas Gohr $mtime = 0, 41*58ae4747SAndreas Gohr $size = null, 42*58ae4747SAndreas Gohr $perms = null, 43*58ae4747SAndreas Gohr $isimage = null, 44*58ae4747SAndreas Gohr $hash = '' 45*58ae4747SAndreas Gohr ) 466cce3332SAndreas Gohr { 47*58ae4747SAndreas Gohr $this->id = $id; 48*58ae4747SAndreas Gohr $this->file = mediaFN($this->id, $revision); 49*58ae4747SAndreas Gohr $this->revision = $revision ?: $mtime ?: filemtime($this->file); 50*58ae4747SAndreas Gohr $this->size = $size ?? filesize($this->file); 51*58ae4747SAndreas Gohr $this->permission = $perms ?? auth_quickaclcheck($this->id);; 52*58ae4747SAndreas Gohr $this->isimage = (bool)($isimage ?? false); 53*58ae4747SAndreas Gohr $this->hash = $hash; 546cce3332SAndreas Gohr } 556cce3332SAndreas Gohr 566cce3332SAndreas Gohr /** 576cce3332SAndreas Gohr * Calculate the hash for this page 586cce3332SAndreas Gohr * 596cce3332SAndreas Gohr * This is a heavy operation and should only be called when needed. 606cce3332SAndreas Gohr */ 616cce3332SAndreas Gohr public function calculateHash() 626cce3332SAndreas Gohr { 63*58ae4747SAndreas Gohr $this->hash = md5(io_readFile($this->file, false)); 646cce3332SAndreas Gohr } 656cce3332SAndreas Gohr} 66