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
19
20require_once __DIR__ . '/vendor/autoload.php';
21
22// fake a minimal dokuwiki environment
23define('DOKU_INC', __DIR__ . '/../../../');
24global $conf;
25$conf['savedir'] = __DIR__ . '/../../../data/';
26$conf['cachedir'] = $conf['savedir'] . 'cache/';
27$conf['tmpdir'] = $conf['savedir'] . 'tmp/';
28$conf['proxy'] = ['host' => '', 'port' => '', 'user' => '', 'pass' => '', 'ssl' => '', 'except' => ''];
29$conf['allowdebug'] = false;
30
31function linesToHash($lines) {
32    $lines = array_map('trim', $lines);
33    $lines = array_filter($lines);
34    $lines = array_map(function ($item) {
35        return array_map('trim', explode(' ', $item, 2));
36    }, $lines);
37    return array_combine(array_column($lines, 0), array_column($lines, 1));
38}
39
40function conf_decodeString($string)
41{
42    return $string;
43}
44
45function filesize_h($size)
46{
47    return $size.'b';
48}
49
50function hsc($string)
51{
52    return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
53}
54
55function io_mkdir_p($dir)
56{
57    if(file_exists($dir)) return true;
58    return mkdir($dir, 0777, true);
59}
60
61function getVersionData()
62{
63    $version = array();
64    if (file_exists(DOKU_INC . 'VERSION')) {
65        //official release
66        $version['date'] = trim(file_get_contents(DOKU_INC . 'VERSION'));
67        $version['type'] = 'Release';
68    }
69    return $version;
70}
71
72function getVersion()
73{
74    $version = getVersionData();
75    return $version['type'].' '.$version['date'];
76}
77
78class Doku_Event
79{
80    public function __construct($name, &$data)
81    {
82    }
83
84    public function advise_before()
85    {
86        return true;
87    }
88
89    public function advise_after()
90    {
91    }
92}
93
94trait UpgradePluginTrait
95{
96    protected $lang = null;
97
98    /**
99     * @return string
100     */
101    public function getInfo()
102    {
103        $data = file(__DIR__ . '/plugin.info.txt', FILE_IGNORE_NEW_LINES);
104        return linesToHash($data);
105    }
106
107    /**
108     * @param string $key
109     * @return string
110     */
111    public function getLang($key)
112    {
113        if ($this->lang === null) {
114            $lang = [];
115            include __DIR__ . '/lang/en/lang.php';
116            $this->lang = $lang;
117        }
118        return $this->lang[$key] ?? $key;
119    }
120}
121
122abstract class DokuWiki_CLI_Plugin extends splitbrain\phpcli\CLI
123{
124    use UpgradePluginTrait;
125}
126
127class  DokuWiki_Plugin
128{
129    use UpgradePluginTrait;
130}
131
132// now the CLI plugin should load and run
133include(__DIR__ . '/cli.php');
134(new cli_plugin_upgrade())->run();
135