Table of Contents
Refactoring 2023
Update of this page is in Progress
This page lists changes since April 2023. For older changes see refactor2022, refactor2021 and refactor2020.
Welcome to add more notes/examples/etc on this page, to make updating of plugins and templates easy! Please share all remarks and possible improvements. See forum topic. Thank you very much! Klap-in |
---|
How to find deprecated code
A lot of code has been marked as deprecated. Which means it will be removed in future releases of DokuWiki. While this does (normally) not cause plugins to malfunction now, it may lead to nasty surprises after future updates.
Plugin/template authors can easily check if they use any deprecated functions, classes or methods:
Since the Igor 2022 release:
- logging of deprecated messages is default enabled, otherwise you need to uncheck
deprecated
in the dontlog configuration setting - use the plugin
- check LogViewer (or
data/log/deprecated/<date>.log
).
Since [upcoming] release:
- Setup GitHub Action (or setup Rector locally), to get code improvement suggestions. Plugin authors who want to use the new workflow can easily add it using the dev plugin:
ptln()
ptln()
is deprecated in 4045.
- ptln('your message', 4); + echo 'your message';
str_start_with/str_ends_with/str_contains()
Polyfills are added in 4045, so these PHP8 functions can already be used.
- if (substr($url, 0, 3) == 'ftp'); + if (str_starts_with($url, 'ftp')); - if (substr($target, -1, 1) === ':') { + if (str_ends_with($target, ':')) { - ...; + str_contains();
Refactor fulltext search functions and class Doku_Indexer
Indexer: idx_get_version, idx_addPage, idx_getIndex, idx_listIndexLengths, idx_indexLengths, idx_get_indexer
MetadataIndex: ft_pageLookup, ft_mediainuse, ft_backlinks,
FulltextIndex: ft_pageSearch, ft_snippet, ft_snippet_re_preprocess, ft_queryParser, ft_queryUnparser_simple
General improvement suggestions
Check for plugin interface/class instead of not null
- if ($auth) { - $info = $auth->getUserData($username); - } + if ($auth instanceof AuthPlugin) { + $info = $auth->getUserData($username); + } - if (!$auth) return false; + if (!$auth instanceof AuthPlugin) return false;
- $plugin = plugin_load('remote', 'example'); - if (!$plugin) { - return; - } + $plugin = plugin_load('remote', 'example'); + if (!$plugin instanceof PluginInterface) { + return; + } - if (!$plugin = plugin_load('syntax', 'example)) return false; + if (!($plugin = plugin_load('syntax', 'example)) instanceof PluginInterface) return false;
As you use typically specific functionality, you can also update PluginInterface to the specific class of the component.