legacy.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Legacy command line upgrade script
  4. *
  5. * This script can be used to upgrade old versions of DokuWiki that won't easily run on
  6. * modern PHP releases. It works by not actually loading any of the existing (and outdated)
  7. * DokuWiki code, but instead fakes an absolute minimal environment to run the upgrade.
  8. *
  9. * This means this script will make more assumptions and take shortcuts:
  10. *
  11. * - no proxy support
  12. * - no tmp dir changes
  13. * - english only
  14. * - only "normal" releases (no snapshots or git checkouts)
  15. *
  16. * Only use this if you can't run the normal upgrade script.
  17. */
  18. require_once __DIR__ . '/vendor/autoload.php';
  19. // fake a minimal dokuwiki environment
  20. define('DOKU_INC', __DIR__ . '/../../../');
  21. global $conf;
  22. $conf['savedir'] = __DIR__ . '/../../../data/';
  23. $conf['cachedir'] = $conf['savedir'] . 'cache/';
  24. $conf['tmpdir'] = $conf['savedir'] . 'tmp/';
  25. $conf['proxy'] = ['host' => '', 'port' => '', 'user' => '', 'pass' => '', 'ssl' => '', 'except' => ''];
  26. $conf['allowdebug'] = false;
  27. function linesToHash($lines) {
  28. $lines = array_map('trim', $lines);
  29. $lines = array_filter($lines);
  30. $lines = array_map(function ($item) {
  31. return array_map('trim', explode(' ', $item, 2));
  32. }, $lines);
  33. return array_combine(array_column($lines, 0), array_column($lines, 1));
  34. }
  35. function conf_decodeString($string)
  36. {
  37. return $string;
  38. }
  39. function filesize_h($size)
  40. {
  41. return $size.'b';
  42. }
  43. function hsc($string)
  44. {
  45. return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
  46. }
  47. function io_mkdir_p($dir)
  48. {
  49. if(file_exists($dir)) return true;
  50. return mkdir($dir, 0777, true);
  51. }
  52. function getVersionData()
  53. {
  54. $version = array();
  55. if (file_exists(DOKU_INC . 'VERSION')) {
  56. //official release
  57. $version['date'] = trim(file_get_contents(DOKU_INC . 'VERSION'));
  58. $version['type'] = 'Release';
  59. }
  60. return $version;
  61. }
  62. function getVersion()
  63. {
  64. $version = getVersionData();
  65. return $version['type'].' '.$version['date'];
  66. }
  67. class Doku_Event
  68. {
  69. public function __construct($name, &$data)
  70. {
  71. }
  72. public function advise_before()
  73. {
  74. return true;
  75. }
  76. public function advise_after()
  77. {
  78. }
  79. }
  80. trait UpgradePluginTrait
  81. {
  82. protected $lang = null;
  83. /**
  84. * @return string
  85. */
  86. public function getInfo()
  87. {
  88. $data = file(__DIR__ . '/plugin.info.txt', FILE_IGNORE_NEW_LINES);
  89. return linesToHash($data);
  90. }
  91. /**
  92. * @param string $key
  93. * @return string
  94. */
  95. public function getLang($key)
  96. {
  97. if ($this->lang === null) {
  98. $lang = [];
  99. include __DIR__ . '/lang/en/lang.php';
  100. $this->lang = $lang;
  101. }
  102. return $this->lang[$key] ?? $key;
  103. }
  104. }
  105. abstract class DokuWiki_CLI_Plugin extends splitbrain\phpcli\CLI
  106. {
  107. use UpgradePluginTrait;
  108. }
  109. class DokuWiki_Plugin
  110. {
  111. use UpgradePluginTrait;
  112. }
  113. // now the CLI plugin should load and run
  114. include(__DIR__ . '/cli.php');
  115. (new cli_plugin_upgrade())->run();