DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

Our Privacy Policy

devel:releases:refactor2

Refactoring

Suggestions for development version (August 2020 and later) of Dokuwiki.

develonly

Refactored UI elements using Form\Form class

Implemented by PR 3198

Only new events with dokuwiki\Form\Form from DokuWiki

DokuWiki used before this release Doku_Form at a lot of places. The old Doku_Form triggered a HTML_*FORM_OUTPUT event, when it was outputted by html_form(). DokuWiki core code is updated to use the new forms, therefore the old events are not triggered anymore. The new style Form triggers FORM_*_OUTPUT event when its HTML-representation is generated by toHTML() method.

The old Doku_Form had been passed to handler of old HTML_EDIT_FORMSELECTION event, that is not triggered anymore. Instead, DokuWiki core code has changed to triggers new EDIT_FORM_ADDTEXTAREA event that provides a dokuwiki/Form/Form in the $data['form'] and the event handler will complete the editor form.

:!: To enable your actions again, the new event handlers have to be implemented as well. The new events should pass the new dokuwiki\Form\Form object as the event data. The old event handlers can be kept temporary for backward compatibility.

See for the description of the events:

Changes to the dokuwiki\Form\Form class. An optional argument is added to toHTML() to make code simple without a separate event trigger.

- Event::createAndTrigger('FORM_SEARCH_OUTPUT', $searchForm);
- return $searchForm->toHTML();
+ return $searchForm->toHTML('Search');

UI elements implemented as class methods

Action Router calls Action::tplContent(), which calls Ui::show() that returns the actual HTML to output.

Deprecated functions: html_login, html_edit, html_edit_form, html_show, html_locked, html_index, html_backlinks, html_diff, html_conflict, html_register, tpl_subscribe

Deprecated and only used in DokuWiki: html_denied, html_showrev, html_draft, html_revisions, html_recent, html_updateprofile, html_resendpwd, html_diff_head, html_diff_navigation, html_diff_navigationlink

Removed functions: html_minoredit.

// inc/html.php
- html_login($svg)
+ (new dokuwiki\Ui\Login($svg))->show()
 
- html_denied() 
+ (new dokuwiki\Action\Denied())->showBanner()
 
- html_edit()
+ (new dokuwiki\Ui\Editor)->show()
 
-    html_edit_form($data)
+    (new dokuwiki\Ui\Editor)->addTextarea($data)
 
-    html_minoredit()
+    // obsoleted: integrated into dokuwiki\Ui\Editor::show()  
 
- html_showrev()
+ (new dokuwiki\Ui\PageView)->showrev()
 
- html_show($txt)
+ (new dokuwiki\Ui\PageView($txt))->show()
 
- html_draft()
+ (new Ui\PageDraft)->show()
 
- html_locked()
+ (new dokuwiki\Action\Locked())->showBanner()
 
- html_revisions($first, $media_id)
+ (new dokuwiki\Ui\Revisions($first, $media_id))->show()
 
- html_recent($first, $show_changes)
+ (new dokuwiki\Ui\Recent($first, $show_changes))->show()
 
- html_index($ns)
+ (new dokuwiki\Ui\Index($ns))->show()
 
-    html_list_index($item)
+    (new dokuwiki\Ui\Index)->formatListItem($item)
 
-    html_li_index($item)
+    (new dokuwiki\Ui\Index)->tagListItem($item)
 
- html_backlinks() {
+ (new dokuwiki\Ui\Backlinks)->show();
 
- html_diff($text, $intro, $type)
+ (new dokuwiki\Ui\Diff($text, $intro, $type))->show()
 
-    html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false)
+    // changed to protected method; dokuwiki\Ui\Diff()::diffHead()
 
-    html_diff_navigation($pagelog, $type, $l_rev, $r_rev)
+    // changed to protected method; dokuwiki\Ui\Diff()::diffNavigation()
 
-    html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null)
+    // changed to protected method; dokuwiki\Ui\Diff()::diffViewlink()
 
-    html_insert_softbreaks($diffhtml)
+    (new dokuwiki\Ui\Diff())->insertSoftbreaks($diffhtml)
 
- html_conflict($text, $summary)
+ (new dokuwiki\Ui\Conflict($text, $summary))->show()
 
- html_register()
+ (new dokuwiki\Ui\UserRegister)->show()
 
- html_updateprofile()
+ (new dokuwiki\Ui\UserProfile)->show()
 
- html_resendpwd()
+ (new dokuwiki\Ui\UserResendPwd)->show()
// inc/template.php
- tpl_subscribe()
+ (new \dokuwiki\Ui\Subscribe)->show()

Small callbacks changed to annonymous functions

Removed functions: html_hilight_callback, which was used by html_hilight().

// html_hilight_callback() is integrated into html_hilight() 
- $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
+ $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui", function ($match) {
+     $hlight = unslash($match[0]);
+     if (!isset($match[2])) {
+         $hlight = '<span class="search_hit">'.$hlight.'</span>';
+     }
+     return $hlight;
+ }, $html);

Removed function: html_softbreak_callback, which was used by html_insert_softbreaks().

// html_softbreak_callback() is integrated into Ui\Diff::insertSoftbreaks()
- return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
+ return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/', function ($match) {
+   ...
+ }, $diffhtml);

Changed usage of html_buildlist(), of which 4th argument callable html_li_default has deprecated.

- function html_buildlist($data, $class, $func, $lifunc = 'html_li_default', $forcewrapper = false){
+ function html_buildlist($data, $class, $func, $lifunc = null, $forcewrapper = false) {
+   ...
+   // set callback function to build the <li> tag, formerly defined as html_li_default()
+   if (!is_callable($lifunc)) {
+      $lifunc = function ($item) {
+          return '<li class="level'.$item['level'].'">';
+      };
+   }
+   ....
+ }
  // Example if you want to use own 'html_li_default' function/method in your plugin ...
+     protected function myLiFunc($item) { ... }
+     $html = html_buildlist($data, $class, $func, [$this, 'myLiFunc']);
 
  // if you want to use callbacks in Ui\Index class:
+     $idx = new dokuwiki\Ui\Index;
+     $html = html_buildlist($data, $class, [$idx,'formatListItem'], [$idx,'tagListItem'])

Other changed functions

Changed function: html_sizechange

- html_sizechange($sizechange, $form) // where $form is the old Doku_Form
+ $html = html_sizechange($sizechange)

Sort with collator

3115

Improved sort in different languages. Not backward compatible. Maybe include library with exist check?

Refactor fulltext search functions and class Doku_Indexer

devel/releases/refactor2.txt · Last modified: 2020-09-28 11:40 by s-sahara