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