Table of Contents
Refactoring 2023
Update of this page is in Progress
This page lists changes from April 2023 to February 2024. For older changes see refactor2022, refactor2021 and refactor2020, for newer refactor2024.
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 Kaos 2024 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();
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.
Fixed size logo
3938 4189 support a svg logo, but also introduced a fixed height for the logo. Use user_styles to override the height.
- conf/userstyle.css
#dokuwiki__header .logo img { height: 128px; }
resolving id
4074 strips any trailing dots when resolving IDs.
This might effect some alternative uses for resolving the namespace id.
Eventual inspiration:
$ns = "$ns:arandompagehere"; $resolver = new PageResolver($id); $ns = getNs($resolver->resolveId($ns)); $ns = $ns === false ? '' : $ns;
Or is it worth to have namespace resolving?
API refactoring
For developers of Remote plugins
Base class dokuwiki\Extension\RemotePlugin for remote plugins is modified:
- Modified: getApi() returns
dokuwiki\Remote\Api
which is changed.
dokuwiki\Remote\Api | |
---|---|
Methods with (internal) changes | |
getMethods (returns now ApiCall[]) getCoreMethods (returns now ApiCall[]) getPluginMethods (returns now ApiCall[]) call (calls ApiCall for the given name) |
|
Removed methods | Added methods |
hasAccess forceAccess toFile toDate dummyTransformation setDateTransformation setFileTransformation argumentWarningHandler | ensureApiIsEnabled ensureAccessIsAllowed |
Since version 12 of the core API, dokuwiki\Remote\ApiCore has new methods ordered in core.<method>
namespace.
Functionality of former dokuwiki\Remote\ApiCore
is mainly moved to dokuwiki\Remote\LegacyApiCore which has now the methods ordered in wiki.<method>
and dokuwiki.<method>
and is deprecated.
Changes for remote plugins:
- auto registration with
getMethods()
, no_getMethods()
needed. All public methods of the plugin class (with an underscore are skipped) will be automatically registered as remote API call in the formplugin.<pluginname>.<methodname>
. OverwritegetMethods()
for changing the default behaviour. - no transformation supported via
getApi()
, now assumes always:- dates as unix timestamp integers
- media files as base64 encoded string
- Docblocks document your methods. This info is used for auto generating the API documentation available at
lib/exe/openapi.php
of your wiki. - There is now dokuwiki\Remote\ApiResponse to return complex data
- Reminder, return unique (for your plugin) error codes that should be listed in your plugin's documentation.
For users of the API
- In version 12 of the core API new methods are introduced ordered in a single
core.<method>
namespace. - Deprecated The former methods ordered in
wiki.<method>
anddokuwiki.<method>
are now part of the legacy core api. The intent was to be equal. - Autogenerated API documentation is available at
lib/exe/openapi.php
of your wiki. - JSONRPC is added and recommended
- XMLRPC is available as before, however, deprecating is probably considered in the future
More info see: Remote API, Patreon Blog Post: A Better Remote API
FeedCreator
4156 This breaks up the humongous functions from feed.php into multiple classes. To keep compatibility with existing Plugin events, the basic principle of how the feed is assembled has not been changed.
Removed: rss_parseOptions(), rss_buildItems(), rssRecentChanges(), rssListNamespace(), rssSearch()
Replace by:
- abstract dokuwiki\Feed\FeedItemProcessor
LesserPHP
e6380ba This replaces the abandoned fork with an own fork at splitbrain/lesserphp. That fork has been cleaned up somewhat.
- $less = new lessc(); - $less->importDir = [DOKU_INC]; + $less = new LesserPHP\Lessc(); + $less->setImportDir([DOKU_INC]); $less->setPreserveComments(!$conf['compress']); - $less->importDir[] = TMP_DIR; + $less->addImportDir(TMP_DIR);