id = cleanID($data['id'] ?? ''); if ($this->id === '') { throw new \InvalidArgumentException('Missing id'); } if (!media_exists($this->id)) { throw new \InvalidArgumentException('Media does not exist'); } // FIXME this isn't really managing the difference between old and current revs correctly $this->revision = (int)($data['rev'] ?? $data['mtime'] ?? @filemtime(mediaFN($this->id))); $this->size = (int)($data['size'] ?? @filesize(mediaFN($this->id))); $this->perms = $data['perm'] ?? auth_quickaclcheck($this->id); $this->isimage = (bool)($data['isimg'] ?? false); $this->hash = $data['hash'] ?? ''; } /** * Calculate the hash for this page * * This is a heavy operation and should only be called when needed. */ public function calculateHash() { if (!media_exists($this->id)) return; $this->hash = md5(io_readFile(mediaFN($this->id))); } }