DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:releases:refactor2023

developer changelog

Refactoring 2023

FIXME 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: Remove old workflow and add the new one

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.

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;

FIXME 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:

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 methodsAdded 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 form plugin.<pluginname>.<methodname>. Overwrite getMethods() 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> and dokuwiki.<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:

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);
devel/releases/refactor2023.txt · Last modified: by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki