1<?php 2 3namespace dokuwiki\ChangeLog; 4 5/** 6 * methods for handling of changelog of pages or media files 7 */ 8abstract class ChangeLog 9{ 10 /** @var string */ 11 protected $id; 12 /** @var int */ 13 protected $chunk_size; 14 /** @var array */ 15 protected $flags; 16 /** @var array */ 17 protected $cache; 18 19 /** 20 * Constructor 21 * 22 * @param string $id page id 23 * @param int $chunk_size maximum block size read from file 24 */ 25 public function __construct($id, $chunk_size = 8192) 26 { 27 global $cache_revinfo; 28 29 $this->cache =& $cache_revinfo; 30 if (!isset($this->cache[$id])) { 31 $this->cache[$id] = array(); 32 } 33 34 $this->id = $id; 35 $this->setChunkSize($chunk_size); 36 37 $this->flags['ignore_external_edit'] = false; 38 // FIXME: see unittest class changelog_getrevisionsaround_test 39 // test page "mailinglist.txt" is newer than last entry of meta/mailinglist.changes 40 // temporary disable external edit check to prevent failures during unittest 41 if (defined('DOKU_UNITTEST')) { 42 $this->setFlags('ignore_external_edit', true); 43 } 44 } 45 46 /** 47 * Set chunk size for file reading 48 * Chunk size zero let read whole file at once 49 * 50 * @param int $chunk_size maximum block size read from file 51 */ 52 public function setChunkSize($chunk_size) 53 { 54 if (!is_numeric($chunk_size)) $chunk_size = 0; 55 56 $this->chunk_size = (int)max($chunk_size, 0); 57 } 58 59 /** 60 * Set flags for ChangeLog 61 * 62 * @param string $name 63 * @param mixed $value 64 * @return bool 65 */ 66 public function setFlags($name, $value) 67 { 68 if (array_key_exists($name, $this->flags)) { 69 $this->flags[$name] = $value; 70 return true; 71 } 72 return false; 73 } 74 75 /** 76 * Returns path to changelog 77 * 78 * @return string path to file 79 */ 80 abstract protected function getChangelogFilename(); 81 82 /** 83 * Returns path to current page/media 84 * 85 * @return string path to file 86 */ 87 abstract protected function getFilename(); 88 89 /** 90 * Get the changelog information for a specific page id and revision (timestamp) 91 * 92 * Adjacent changelog lines are optimistically parsed and cached to speed up 93 * consecutive calls to getRevisionInfo. For large changelog files, only the chunk 94 * containing the requested changelog line is read. 95 * 96 * @param int $rev revision timestamp 97 * @return bool|array false or array with entries: 98 * - date: unix timestamp 99 * - ip: IPv4 address (127.0.0.1) 100 * - type: log line type 101 * - id: page id 102 * - user: user name 103 * - sum: edit summary (or action reason) 104 * - extra: extra data (varies by line type) 105 * - sizechange: change of filesize 106 * 107 * @author Ben Coburn <btcoburn@silicodon.net> 108 * @author Kate Arzamastseva <pshns@ukr.net> 109 */ 110 public function getRevisionInfo($rev) 111 { 112 $rev = max(0, $rev); 113 if (!$rev) return false; 114 115 // check if it's already in the memory cache 116 if (isset($this->cache[$this->id]) && isset($this->cache[$this->id][$rev])) { 117 return $this->cache[$this->id][$rev]; 118 } 119 120 //read lines from changelog 121 list($fp, $lines) = $this->readloglines($rev); 122 if ($fp) { 123 fclose($fp); 124 } 125 if (empty($lines)) return false; 126 127 // parse and cache changelog lines 128 foreach ($lines as $value) { 129 $tmp = parseChangelogLine($value); 130 if ($tmp !== false) { 131 $this->cache[$this->id][$tmp['date']] = $tmp; 132 } 133 } 134 if (!isset($this->cache[$this->id][$rev])) { 135 return false; 136 } 137 return $this->cache[$this->id][$rev]; 138 } 139 140 /** 141 * Return a list of page revisions numbers 142 * 143 * Does not guarantee that the revision exists in the attic, 144 * only that a line with the date exists in the changelog. 145 * By default the current revision is skipped. 146 * 147 * The current revision is automatically skipped when the page exists. 148 * See $INFO['meta']['last_change'] for the current revision. 149 * A negative $first let read the current revision too. 150 * 151 * For efficiency, the log lines are parsed and cached for later 152 * calls to getRevisionInfo. Large changelog files are read 153 * backwards in chunks until the requested number of changelog 154 * lines are recieved. 155 * 156 * @param int $first skip the first n changelog lines 157 * @param int $num number of revisions to return 158 * @return array with the revision timestamps 159 * 160 * @author Ben Coburn <btcoburn@silicodon.net> 161 * @author Kate Arzamastseva <pshns@ukr.net> 162 */ 163 public function getRevisions($first, $num) 164 { 165 $revs = array(); 166 $lines = array(); 167 $count = 0; 168 169 $num = max($num, 0); 170 if ($num == 0) { 171 return $revs; 172 } 173 174 if ($first < 0) { 175 $first = 0; 176 } else { 177 if (file_exists($this->getFilename())) { 178 // skip current revision if the page exists 179 $first = max($first + 1, 0); 180 } 181 } 182 183 $file = $this->getChangelogFilename(); 184 185 if (!file_exists($file)) { 186 return $revs; 187 } 188 if (filesize($file) < $this->chunk_size || $this->chunk_size == 0) { 189 // read whole file 190 $lines = file($file); 191 if ($lines === false) { 192 return $revs; 193 } 194 } else { 195 // read chunks backwards 196 $fp = fopen($file, 'rb'); // "file pointer" 197 if ($fp === false) { 198 return $revs; 199 } 200 fseek($fp, 0, SEEK_END); 201 $tail = ftell($fp); 202 203 // chunk backwards 204 $finger = max($tail - $this->chunk_size, 0); 205 while ($count < $num + $first) { 206 $nl = $this->getNewlinepointer($fp, $finger); 207 208 // was the chunk big enough? if not, take another bite 209 if ($nl > 0 && $tail <= $nl) { 210 $finger = max($finger - $this->chunk_size, 0); 211 continue; 212 } else { 213 $finger = $nl; 214 } 215 216 // read chunk 217 $chunk = ''; 218 $read_size = max($tail - $finger, 0); // found chunk size 219 $got = 0; 220 while ($got < $read_size && !feof($fp)) { 221 $tmp = @fread($fp, max(min($this->chunk_size, $read_size - $got), 0)); 222 if ($tmp === false) { 223 break; 224 } //error state 225 $got += strlen($tmp); 226 $chunk .= $tmp; 227 } 228 $tmp = explode("\n", $chunk); 229 array_pop($tmp); // remove trailing newline 230 231 // combine with previous chunk 232 $count += count($tmp); 233 $lines = array_merge($tmp, $lines); 234 235 // next chunk 236 if ($finger == 0) { 237 break; 238 } else { // already read all the lines 239 $tail = $finger; 240 $finger = max($tail - $this->chunk_size, 0); 241 } 242 } 243 fclose($fp); 244 } 245 246 // skip parsing extra lines 247 $num = max(min(count($lines) - $first, $num), 0); 248 if ($first > 0 && $num > 0) { 249 $lines = array_slice($lines, max(count($lines) - $first - $num, 0), $num); 250 } else { 251 if ($first > 0 && $num == 0) { 252 $lines = array_slice($lines, 0, max(count($lines) - $first, 0)); 253 } elseif ($first == 0 && $num > 0) { 254 $lines = array_slice($lines, max(count($lines) - $num, 0)); 255 } 256 } 257 258 // handle lines in reverse order 259 for ($i = count($lines) - 1; $i >= 0; $i--) { 260 $tmp = parseChangelogLine($lines[$i]); 261 if ($tmp !== false) { 262 $this->cache[$this->id][$tmp['date']] = $tmp; 263 $revs[] = $tmp['date']; 264 } 265 } 266 267 return $revs; 268 } 269 270 /** 271 * Get the nth revision left or right handside for a specific page id and revision (timestamp) 272 * 273 * For large changelog files, only the chunk containing the 274 * reference revision $rev is read and sometimes a next chunck. 275 * 276 * Adjacent changelog lines are optimistically parsed and cached to speed up 277 * consecutive calls to getRevisionInfo. 278 * 279 * @param int $rev revision timestamp used as startdate (doesn't need to be revisionnumber) 280 * @param int $direction give position of returned revision with respect to $rev; positive=next, negative=prev 281 * @return bool|int 282 * timestamp of the requested revision 283 * otherwise false 284 */ 285 public function getRelativeRevision($rev, $direction) 286 { 287 $rev = max($rev, 0); 288 $direction = (int)$direction; 289 290 //no direction given or last rev, so no follow-up 291 if (!$direction || ($direction > 0 && $this->isCurrentRevision($rev))) { 292 return false; 293 } 294 295 //get lines from changelog 296 list($fp, $lines, $head, $tail, $eof) = $this->readloglines($rev); 297 if (empty($lines)) return false; 298 299 // look for revisions later/earlier then $rev, when founded count till the wanted revision is reached 300 // also parse and cache changelog lines for getRevisionInfo(). 301 $revcounter = 0; 302 $relativerev = false; 303 $checkotherchunck = true; //always runs once 304 while (!$relativerev && $checkotherchunck) { 305 $tmp = array(); 306 //parse in normal or reverse order 307 $count = count($lines); 308 if ($direction > 0) { 309 $start = 0; 310 $step = 1; 311 } else { 312 $start = $count - 1; 313 $step = -1; 314 } 315 for ($i = $start; $i >= 0 && $i < $count; $i = $i + $step) { 316 $tmp = parseChangelogLine($lines[$i]); 317 if ($tmp !== false) { 318 $this->cache[$this->id][$tmp['date']] = $tmp; 319 //look for revs older/earlier then reference $rev and select $direction-th one 320 if (($direction > 0 && $tmp['date'] > $rev) || ($direction < 0 && $tmp['date'] < $rev)) { 321 $revcounter++; 322 if ($revcounter == abs($direction)) { 323 $relativerev = $tmp['date']; 324 } 325 } 326 } 327 } 328 329 //true when $rev is found, but not the wanted follow-up. 330 $checkotherchunck = $fp 331 && ($tmp['date'] == $rev || ($revcounter > 0 && !$relativerev)) 332 && !(($tail == $eof && $direction > 0) || ($head == 0 && $direction < 0)); 333 334 if ($checkotherchunck) { 335 list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, $direction); 336 337 if (empty($lines)) break; 338 } 339 } 340 if ($fp) { 341 fclose($fp); 342 } 343 344 return $relativerev; 345 } 346 347 /** 348 * Returns revisions around rev1 and rev2 349 * When available it returns $max entries for each revision 350 * 351 * @param int $rev1 oldest revision timestamp 352 * @param int $rev2 newest revision timestamp (0 looks up last revision) 353 * @param int $max maximum number of revisions returned 354 * @return array with two arrays with revisions surrounding rev1 respectively rev2 355 */ 356 public function getRevisionsAround($rev1, $rev2, $max = 50) 357 { 358 $max = floor(abs($max) / 2) * 2 + 1; 359 $rev1 = max($rev1, 0); 360 $rev2 = max($rev2, 0); 361 362 if ($rev2) { 363 if ($rev2 < $rev1) { 364 $rev = $rev2; 365 $rev2 = $rev1; 366 $rev1 = $rev; 367 } 368 } else { 369 //empty right side means a removed page. Look up last revision. 370 $revs = $this->getRevisions(-1, 1); 371 $rev2 = $revs[0]; 372 } 373 //collect revisions around rev2 374 list($revs2, $allrevs, $fp, $lines, $head, $tail) = $this->retrieveRevisionsAround($rev2, $max); 375 376 if (empty($revs2)) return array(array(), array()); 377 378 //collect revisions around rev1 379 $index = array_search($rev1, $allrevs); 380 if ($index === false) { 381 //no overlapping revisions 382 list($revs1, , , , ,) = $this->retrieveRevisionsAround($rev1, $max); 383 if (empty($revs1)) $revs1 = array(); 384 } else { 385 //revisions overlaps, reuse revisions around rev2 386 $revs1 = $allrevs; 387 while ($head > 0) { 388 for ($i = count($lines) - 1; $i >= 0; $i--) { 389 $tmp = parseChangelogLine($lines[$i]); 390 if ($tmp !== false) { 391 $this->cache[$this->id][$tmp['date']] = $tmp; 392 $revs1[] = $tmp['date']; 393 $index++; 394 395 if ($index > floor($max / 2)) break 2; 396 } 397 } 398 399 list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, -1); 400 } 401 sort($revs1); 402 //return wanted selection 403 $revs1 = array_slice($revs1, max($index - floor($max / 2), 0), $max); 404 } 405 406 return array(array_reverse($revs1), array_reverse($revs2)); 407 } 408 409 410 /** 411 * Checks if the ID has old revisons 412 * @return boolean 413 */ 414 public function hasRevisions() { 415 $file = $this->getChangelogFilename(); 416 return file_exists($file); 417 } 418 419 /** 420 * Returns lines from changelog. 421 * If file larger than $chuncksize, only chunck is read that could contain $rev. 422 * 423 * @param int $rev revision timestamp 424 * @return array|false 425 * if success returns array(fp, array(changeloglines), $head, $tail, $eof) 426 * where fp only defined for chuck reading, needs closing. 427 * otherwise false 428 */ 429 protected function readloglines($rev) 430 { 431 $file = $this->getChangelogFilename(); 432 433 if (!file_exists($file)) { 434 return false; 435 } 436 437 $fp = null; 438 $head = 0; 439 $tail = 0; 440 $eof = 0; 441 442 if (filesize($file) < $this->chunk_size || $this->chunk_size == 0) { 443 // read whole file 444 $lines = file($file); 445 if ($lines === false) { 446 return false; 447 } 448 } else { 449 // read by chunk 450 $fp = fopen($file, 'rb'); // "file pointer" 451 if ($fp === false) { 452 return false; 453 } 454 $head = 0; 455 fseek($fp, 0, SEEK_END); 456 $eof = ftell($fp); 457 $tail = $eof; 458 459 // find chunk 460 while ($tail - $head > $this->chunk_size) { 461 $finger = $head + floor(($tail - $head) / 2.0); 462 $finger = $this->getNewlinepointer($fp, $finger); 463 $tmp = fgets($fp); 464 if ($finger == $head || $finger == $tail) { 465 break; 466 } 467 $tmp = parseChangelogLine($tmp); 468 $finger_rev = $tmp['date']; 469 470 if ($finger_rev > $rev) { 471 $tail = $finger; 472 } else { 473 $head = $finger; 474 } 475 } 476 477 if ($tail - $head < 1) { 478 // cound not find chunk, assume requested rev is missing 479 fclose($fp); 480 return false; 481 } 482 483 $lines = $this->readChunk($fp, $head, $tail); 484 } 485 return array( 486 $fp, 487 $lines, 488 $head, 489 $tail, 490 $eof, 491 ); 492 } 493 494 /** 495 * Read chunk and return array with lines of given chunck. 496 * Has no check if $head and $tail are really at a new line 497 * 498 * @param resource $fp resource filepointer 499 * @param int $head start point chunck 500 * @param int $tail end point chunck 501 * @return array lines read from chunck 502 */ 503 protected function readChunk($fp, $head, $tail) 504 { 505 $chunk = ''; 506 $chunk_size = max($tail - $head, 0); // found chunk size 507 $got = 0; 508 fseek($fp, $head); 509 while ($got < $chunk_size && !feof($fp)) { 510 $tmp = @fread($fp, max(min($this->chunk_size, $chunk_size - $got), 0)); 511 if ($tmp === false) { //error state 512 break; 513 } 514 $got += strlen($tmp); 515 $chunk .= $tmp; 516 } 517 $lines = explode("\n", $chunk); 518 array_pop($lines); // remove trailing newline 519 return $lines; 520 } 521 522 /** 523 * Set pointer to first new line after $finger and return its position 524 * 525 * @param resource $fp filepointer 526 * @param int $finger a pointer 527 * @return int pointer 528 */ 529 protected function getNewlinepointer($fp, $finger) 530 { 531 fseek($fp, $finger); 532 $nl = $finger; 533 if ($finger > 0) { 534 fgets($fp); // slip the finger forward to a new line 535 $nl = ftell($fp); 536 } 537 return $nl; 538 } 539 540 /** 541 * Check whether given revision is the current page 542 * 543 * @param int $rev timestamp of current page 544 * @return bool true if $rev is current revision, otherwise false 545 */ 546 public function isCurrentRevision($rev) 547 { 548 return $rev == @filemtime($this->getFilename()); 549 } 550 551 /** 552 * Return an existing revision for a specific date which is 553 * the current one or younger or equal then the date 554 * 555 * @param number $date_at timestamp 556 * @return string revision ('' for current) 557 */ 558 public function getLastRevisionAt($date_at) 559 { 560 //requested date_at(timestamp) younger or equal then modified_time($this->id) => load current 561 if (file_exists($this->getFilename()) && $date_at >= @filemtime($this->getFilename())) { 562 return ''; 563 } else { 564 if ($rev = $this->getRelativeRevision($date_at + 1, -1)) { //+1 to get also the requested date revision 565 return $rev; 566 } else { 567 return false; 568 } 569 } 570 } 571 572 /** 573 * Returns the next lines of the changelog of the chunck before head or after tail 574 * 575 * @param resource $fp filepointer 576 * @param int $head position head of last chunk 577 * @param int $tail position tail of last chunk 578 * @param int $direction positive forward, negative backward 579 * @return array with entries: 580 * - $lines: changelog lines of readed chunk 581 * - $head: head of chunk 582 * - $tail: tail of chunk 583 */ 584 protected function readAdjacentChunk($fp, $head, $tail, $direction) 585 { 586 if (!$fp) return array(array(), $head, $tail); 587 588 if ($direction > 0) { 589 //read forward 590 $head = $tail; 591 $tail = $head + floor($this->chunk_size * (2 / 3)); 592 $tail = $this->getNewlinepointer($fp, $tail); 593 } else { 594 //read backward 595 $tail = $head; 596 $head = max($tail - $this->chunk_size, 0); 597 while (true) { 598 $nl = $this->getNewlinepointer($fp, $head); 599 // was the chunk big enough? if not, take another bite 600 if ($nl > 0 && $tail <= $nl) { 601 $head = max($head - $this->chunk_size, 0); 602 } else { 603 $head = $nl; 604 break; 605 } 606 } 607 } 608 609 //load next chunck 610 $lines = $this->readChunk($fp, $head, $tail); 611 return array($lines, $head, $tail); 612 } 613 614 /** 615 * Collect the $max revisions near to the timestamp $rev 616 * 617 * @param int $rev revision timestamp 618 * @param int $max maximum number of revisions to be returned 619 * @return bool|array 620 * return array with entries: 621 * - $requestedrevs: array of with $max revision timestamps 622 * - $revs: all parsed revision timestamps 623 * - $fp: filepointer only defined for chuck reading, needs closing. 624 * - $lines: non-parsed changelog lines before the parsed revisions 625 * - $head: position of first readed changelogline 626 * - $lasttail: position of end of last readed changelogline 627 * otherwise false 628 */ 629 protected function retrieveRevisionsAround($rev, $max) 630 { 631 $lastChangelogRev = 0; 632 $externaleditRevinfo = $this->getExternalEditRevInfo(); 633 634 if ($externaleditRevinfo) { 635 $revisions = $this->getRevisions(-1, 1); 636 $lastChangelogRev = $revisions[0]; 637 if ($externaleditRevinfo['date'] == $rev) { 638 $rev = $lastChangelogRev; //replace by an existing changelog line 639 } 640 } 641 642 $revs = array(); 643 $aftercount = $beforecount = 0; 644 645 //get lines from changelog 646 list($fp, $lines, $starthead, $starttail, /* $eof */) = $this->readloglines($rev); 647 if (empty($lines)) { 648 if ($externaleditRevinfo) { 649 $revs[] = $externaleditRevinfo['date']; 650 return array($revs, $revs, false, [], 0, 0); 651 } else { 652 return false; 653 } 654 } 655 656 //parse chunk containing $rev, and read forward more chunks until $max/2 is reached 657 $head = $starthead; 658 $tail = $starttail; 659 while (count($lines) > 0) { 660 foreach ($lines as $line) { 661 $tmp = parseChangelogLine($line); 662 if ($tmp !== false) { 663 $this->cache[$this->id][$tmp['date']] = $tmp; 664 $revs[] = $tmp['date']; 665 //add external edit next to the first existing line from the changelog 666 if ($externaleditRevinfo && $tmp['date'] == $lastChangelogRev) { 667 $revs[] = $externaleditRevinfo['date']; 668 } 669 if ($tmp['date'] >= $rev) { 670 //count revs after reference $rev 671 $aftercount++; 672 if ($aftercount == 1) $beforecount = count($revs); 673 } 674 //enough revs after reference $rev? 675 if ($aftercount > floor($max / 2)) break 2; 676 } 677 } 678 //retrieve next chunk 679 list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, 1); 680 } 681 if ($aftercount == 0) return false; 682 683 $lasttail = $tail; 684 685 //read additional chuncks backward until $max/2 is reached and total number of revs is equal to $max 686 $lines = array(); 687 $i = 0; 688 if ($aftercount > 0) { 689 $head = $starthead; 690 $tail = $starttail; 691 while ($head > 0) { 692 list($lines, $head, $tail) = $this->readAdjacentChunk($fp, $head, $tail, -1); 693 694 for ($i = count($lines) - 1; $i >= 0; $i--) { 695 $tmp = parseChangelogLine($lines[$i]); 696 if ($tmp !== false) { 697 $this->cache[$this->id][$tmp['date']] = $tmp; 698 $revs[] = $tmp['date']; 699 $beforecount++; 700 //enough revs before reference $rev? 701 if ($beforecount > max(floor($max / 2), $max - $aftercount)) break 2; 702 } 703 } 704 } 705 } 706 sort($revs); 707 708 //keep only non-parsed lines 709 $lines = array_slice($lines, 0, $i); 710 //trunk desired selection 711 $requestedrevs = array_slice($revs, -$max, $max); 712 713 return array($requestedrevs, $revs, $fp, $lines, $head, $lasttail); 714 } 715 716 /** 717 * Returns revision logline in same format as @see ChangeLog::getRevisionInfo() 718 * 719 * @return bool|array false if not external edit/deletion, otherwise array with entries: 720 * - date: unix timestamp for external edit or 'unknown' for external deletion 721 * - ip: IPv4 address (127.0.0.1) 722 * - type: log line type 723 * - id: page id 724 * - user: user name 725 * - sum: edit summary (or action reason) 726 * - extra: extra data (varies by line type) 727 * - sizechange: change of filesize 728 * 729 * @author Gerrit Uitslag <klapinklapin@gmail.com> 730 */ 731 public function getExternalEditRevInfo() 732 { 733 global $lang; 734 global $cache_externaledit; //caches external edits per page 735 736 if ($this->flags['ignore_external_edit']) return false; 737 738 // check if it's already in the memory cache 739 if (isset($cache_externaledit[$this->id])) { 740 if ($cache_externaledit[$this->id] === false) { 741 return false; 742 } else { 743 return $this->cache[$this->id][$cache_externaledit[$this->id]]; 744 } 745 } 746 $externaleditRevinfo = false; 747 $cache_externaledit[$this->id] = false; 748 749 //in attic no revision of current existing wiki page, so external edit occurred 750 $fileLastMod = $this->getFilename(); 751 $lastMod = @filemtime($fileLastMod); // from wiki page, suppresses warning in case the file not exists 752 $lastRev = $this->getRevisions(-1, 1); // from changelog 753 $lastRev = (int) (empty($lastRev) ? 0 : $lastRev[0]); 754 if (!file_exists($this->getFilename($lastMod)) && file_exists($fileLastMod) && $lastRev < $lastMod) { 755 $cache_externaledit[$this->id] = $lastMod; 756 $fileLastRev = $this->getFilename($lastRev); //returns current wikipage path if $lastRev==false 757 $revinfo = $this->getRevisionInfo($lastRev); 758 if (empty($lastRev) || !file_exists($fileLastRev) || $revinfo['type'] == DOKU_CHANGE_TYPE_DELETE) { 759 $filesize_old = 0; 760 } else { 761 $filesize_old = io_getSizeFile($fileLastRev); 762 } 763 $filesize_new = filesize($fileLastMod); 764 $sizechange = $filesize_new - $filesize_old; 765 $isJustCreated = empty($lastRev) || !file_exists($fileLastRev); 766 767 $externaleditRevinfo = [ 768 'date' => $lastMod, 769 'ip' => '127.0.0.1', 770 'type' => $isJustCreated ? DOKU_CHANGE_TYPE_CREATE : DOKU_CHANGE_TYPE_EDIT, 771 'id' => $this->id, 772 'user' => '', 773 'sum' => ($isJustCreated ? $lang['created'] .' - ' : '') . $lang['external_edit'], 774 'extra' => '', 775 'sizechange' => $sizechange 776 ]; 777 $cache_externaledit[$this->id] = $externaleditRevinfo['date']; 778 $this->cache[$this->id][$externaleditRevinfo['date']] = $externaleditRevinfo; 779 } 780 781 $revinfo = $this->getRevisionInfo($lastRev); 782 //deleted wiki page, but not registered in changelog 783 if (!file_exists($fileLastMod) // there is no current page=>true 784 && !empty($lastRev) && $revinfo['type'] !== DOKU_CHANGE_TYPE_DELETE) { 785 $fileLastRev = $this->getFilename($lastRev); 786 $externaleditRevinfo = [ 787 'date' => 9999999999, //unknown deletion date, always higher as latest rev 788 'ip' => '127.0.0.1', 789 'type' => DOKU_CHANGE_TYPE_DELETE, 790 'id' => $this->id, 791 'user' => '', 792 'sum' => $lang['deleted']. ' - ' . $lang['external_edit'], 793 'extra' => '', 794 'sizechange' => -io_getSizeFile($fileLastRev) 795 ]; 796 $cache_externaledit[$this->id] = $externaleditRevinfo['date']; 797 $this->cache[$this->id][$externaleditRevinfo['date']] = $externaleditRevinfo; 798 } 799 800 return $externaleditRevinfo; 801 } 802} 803