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