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