1<?php 2 3namespace dokuwiki\Remote\Response; 4 5/** 6 * Represents a single page revision in the wiki. 7 */ 8class Page extends ApiResponse 9{ 10 /** @var string The page ID */ 11 public $id; 12 /** @var int The page revision aka last modified timestamp */ 13 public $revision; 14 /** @var int The page size in bytes */ 15 public $size; 16 /** @var string The page title */ 17 public $title; 18 /** @var int The current user's permissions for this page */ 19 public $perms; 20 /** @var string MD5 sum over the page's content (only if requested) */ 21 public $hash; 22 23 /** @inheritdoc */ 24 public function __construct($data) 25 { 26 $this->id = cleanID($data['id'] ?? ''); 27 if ($this->id === '') { 28 throw new \InvalidArgumentException('Missing id'); 29 } 30 31 $this->revision = (int)($data['rev'] ?? $data['lastModified'] ?? @filemtime(wikiFN($this->id))); 32 $this->size = (int)($data['size'] ?? @filesize(wikiFN($this->id))); 33 $this->title = $data['title'] ?? $this->retrieveTitle(); 34 $this->perms = $data['perm'] ?? auth_quickaclcheck($this->id); 35 $this->hash = $data['hash'] ?? ''; 36 } 37 38 /** 39 * Get the title for the page 40 * 41 * Honors $conf['useheading'] 42 * 43 * @return string 44 */ 45 protected function retrieveTitle() 46 { 47 global $conf; 48 49 if ($conf['useheading']) { 50 $title = p_get_first_heading($this->id); 51 if ($title) { 52 return $title; 53 } 54 } 55 return $this->id; 56 } 57 58} 59