13aad9612SMichael Grosse<?php 23aad9612SMichael Grosse 33aad9612SMichael Grossenamespace dokuwiki\plugin\struct\meta; 43aad9612SMichael Grosse 53aad9612SMichael Grosseclass PageMeta { 63aad9612SMichael Grosse 73aad9612SMichael Grosse /** @var \helper_plugin_sqlite */ 83aad9612SMichael Grosse protected $sqlite; 93aad9612SMichael Grosse 103aad9612SMichael Grosse protected $pid; 113aad9612SMichael Grosse protected $title = null; 123aad9612SMichael Grosse protected $lasteditor = null; 133aad9612SMichael Grosse protected $lastrev = null; 14*88b58a21SSzymon Olewniczak protected $lastsummary = null; 153aad9612SMichael Grosse 163aad9612SMichael Grosse protected $saveNeeded = false; 173aad9612SMichael Grosse 183aad9612SMichael Grosse public function __construct($pid) { 193aad9612SMichael Grosse /** @var \helper_plugin_struct_db $helper */ 203aad9612SMichael Grosse $helper = plugin_load('helper', 'struct_db'); 213aad9612SMichael Grosse $this->sqlite = $helper->getDB(); 223aad9612SMichael Grosse $this->pid = $pid; 233aad9612SMichael Grosse } 243aad9612SMichael Grosse 253aad9612SMichael Grosse /** 263aad9612SMichael Grosse * If data was explicitly set, then save it to the database if that hasn't happened yet. 273aad9612SMichael Grosse */ 283aad9612SMichael Grosse public function __destruct() { 293aad9612SMichael Grosse if ($this->saveNeeded) { 303aad9612SMichael Grosse $this->savePageData(); 313aad9612SMichael Grosse } 323aad9612SMichael Grosse } 333aad9612SMichael Grosse 343aad9612SMichael Grosse /** 353aad9612SMichael Grosse * Save title, last editor and revision timestamp to database 363aad9612SMichael Grosse */ 373aad9612SMichael Grosse public function savePageData() { 38*88b58a21SSzymon Olewniczak $sql = "REPLACE INTO titles (pid, title, lasteditor, lastrev, lastsummary) VALUES (?,?,?,?,?)"; 39*88b58a21SSzymon Olewniczak $this->sqlite->query($sql, array($this->pid, $this->title, $this->lasteditor, $this->lastrev, $this->lastsummary)); 403aad9612SMichael Grosse $this->saveNeeded = false; 413aad9612SMichael Grosse } 423aad9612SMichael Grosse 433aad9612SMichael Grosse /** 443aad9612SMichael Grosse * Sets a new title 453aad9612SMichael Grosse * 463aad9612SMichael Grosse * @param string|null $title set null to derive from PID 473aad9612SMichael Grosse */ 483aad9612SMichael Grosse public function setTitle($title) { 493aad9612SMichael Grosse if($title === null) { 503aad9612SMichael Grosse $title = noNS($this->pid); 513aad9612SMichael Grosse } 523aad9612SMichael Grosse 533aad9612SMichael Grosse $this->title = $title; 543aad9612SMichael Grosse $this->saveNeeded = true; 553aad9612SMichael Grosse } 563aad9612SMichael Grosse 573aad9612SMichael Grosse /** 583aad9612SMichael Grosse * Sets the last editor 593aad9612SMichael Grosse * 603aad9612SMichael Grosse * @param string|null $lastEditor 613aad9612SMichael Grosse */ 623aad9612SMichael Grosse public function setLastEditor($lastEditor) { 633aad9612SMichael Grosse if($lastEditor === null) { 643aad9612SMichael Grosse $lastEditor = ''; 653aad9612SMichael Grosse } 663aad9612SMichael Grosse 673aad9612SMichael Grosse $this->lasteditor = $lastEditor; 683aad9612SMichael Grosse $this->saveNeeded = true; 693aad9612SMichael Grosse } 703aad9612SMichael Grosse 713aad9612SMichael Grosse /** 723aad9612SMichael Grosse * Sets the revision timestamp 733aad9612SMichael Grosse * 743aad9612SMichael Grosse * @param int|null $lastrev 753aad9612SMichael Grosse */ 763aad9612SMichael Grosse public function setLastRevision($lastrev) { 773aad9612SMichael Grosse if($lastrev === null) { 783aad9612SMichael Grosse $lastrev = 0; 793aad9612SMichael Grosse } 803aad9612SMichael Grosse 813aad9612SMichael Grosse $this->lastrev = $lastrev; 823aad9612SMichael Grosse $this->saveNeeded = true; 833aad9612SMichael Grosse } 843aad9612SMichael Grosse 853aad9612SMichael Grosse /** 86*88b58a21SSzymon Olewniczak * Sets the last summary 87*88b58a21SSzymon Olewniczak * 88*88b58a21SSzymon Olewniczak * @param int|null $lastsummary 89*88b58a21SSzymon Olewniczak */ 90*88b58a21SSzymon Olewniczak public function setLastSummary($lastsummary) { 91*88b58a21SSzymon Olewniczak if($lastsummary === null) { 92*88b58a21SSzymon Olewniczak $lastsummary = ''; 93*88b58a21SSzymon Olewniczak } 94*88b58a21SSzymon Olewniczak 95*88b58a21SSzymon Olewniczak $this->lastsummary = $lastsummary; 96*88b58a21SSzymon Olewniczak $this->saveNeeded = true; 97*88b58a21SSzymon Olewniczak } 98*88b58a21SSzymon Olewniczak 99*88b58a21SSzymon Olewniczak /** 1003aad9612SMichael Grosse * @return string the page's ID 1013aad9612SMichael Grosse */ 1023aad9612SMichael Grosse public function getPid() { 1033aad9612SMichael Grosse return $this->pid; 1043aad9612SMichael Grosse } 1053aad9612SMichael Grosse} 106