DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:releases:refactor2020

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
devel:releases:refactor2020 [2020-09-22 22:54] – [Extension and Event] Klap-indevel:releases:refactor2020 [2023-11-05 14:47] (current) – add old javascript functions and DOKU_TPL* constants Klap-in
Line 3: Line 3:
 ====== Refactoring 2020====== ====== Refactoring 2020======
  
-For the release of 2020 big parts of DokuWiki are refactored.+For the "Hogfather" release of 2020 big parts of DokuWiki are refactored. This page lists changes upto August 2020. For more recent changes see [[devel:releases:refactor2021]].
 ^Please share all remarks and possible improvements. See [[https://forum.dokuwiki.org/d/18268-guidance-for-finding-deprecated-code-and-how-to-update|forum topic]]. Thank you very much! [[user>klap-in]]^ ^Please share all remarks and possible improvements. See [[https://forum.dokuwiki.org/d/18268-guidance-for-finding-deprecated-code-and-how-to-update|forum topic]]. Thank you very much! [[user>klap-in]]^
  
Line 10: Line 10:
  
 Plugin/template authors can easily check if they use any deprecated functions, classes or methods: 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 controlled by the [[config:dontlog]] configuration setting; it is enabled by default, if not uncheck ''deprecated''
 +  * use the plugin
 +  * check [[plugin:LogViewer]] (or ''data/log/deprecated/<date>.log'').
 +
 +Up to the Hogfather 2020 release:
  
   * enable the [[config:allowdebug]] setting in the Configuration Manager   * enable the [[config:allowdebug]] setting in the Configuration Manager
   * use the plugin   * use the plugin
-  * check ''data/cache/debug.log'' for any information about deprecated calls caused by the plugin.+  * Check logs for any information about deprecated calls caused by the plugin in ''data/cache/debug.log'' 
 +===== Removed code ===== 
 +==== mail_send() ==== 
 + 
 +Pull request [[pr>3067]]: 
 + 
 +[[codesearch>mail_send]]() and [[codesearch>mail_encode_address]]() are **removed**. Functions were replaced by the [[devel:mail|Mailer]] class some years ago. 
 + 
 +Example 
 +<code diff> 
 +  $text = rawLocale('password'); 
 +- $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); 
 +- $text = str_replace('@FULLNAME@',$userinfo['name'],$text); 
 +- $text = str_replace('@LOGIN@',$user,$text); 
 +- $text = str_replace('@PASSWORD@',$password,$text); 
 +- $text = str_replace('@TITLE@',$conf['title'],$text); 
 +-  
 +- return mail_send($userinfo['name'].' <'.$userinfo['mail'].'>', 
 +-         $lang['regpwmail'], 
 +-         $text, 
 +-         $conf['mailfrom']); 
 ++ $trep = array( 
 ++             'FULLNAME' => $userinfo['name'], 
 ++             'LOGIN'    => $user, 
 ++             'PASSWORD' => $password 
 ++         ); 
 ++  
 ++ $mail = new Mailer(); 
 ++ $mail->to($userinfo['name'].' <'.$userinfo['mail'].'>'); 
 ++ $mail->subject($lang['regpwmail']); 
 ++ $mail->setBody($text,$trep); 
 ++ return $mail->send(); 
 +</code>
  
 ===== Deprecated and changed code ===== ===== Deprecated and changed code =====
Line 19: Line 58:
  
 Most of the changes documented here are merged with pull request [[pr>2358]]. Sometimes some smaller pull requests are referred as well. Most of the changes documented here are merged with pull request [[pr>2358]]. Sometimes some smaller pull requests are referred as well.
 +
 +
 ==== JSON class is deprecated ==== ==== JSON class is deprecated ====
  
Line 219: Line 260:
  
 |global $[[codesearch>plugin_types]]|PluginController::PLUGIN_TYPES| |global $[[codesearch>plugin_types]]|PluginController::PLUGIN_TYPES|
 +
 +==== ACL admin class admin_plugin_acl====
 +[[https://github.com/dokuwiki/dokuwiki/pull/2358/files#diff-7067f3fb07729507ec0ce23198cc289f1a45c8a9d13e2f7345bc3c02528f0fd8|PR 2358]] and [[github>55cc5b999d5e659fe30cd52ddad4a3f0dea44474|55cc5b9]]
 +
 +Renamed public functions:
 +|[[codesearch>_init_acl_config]]()|initAclConfig()|
 +|[[codesearch>_acl_add]]()|addACL()|
 +|[[codesearch>_acl_del]]()|deleteACL()|
 +|[[codesearch>_get_tree]]()|makeTree() |
 +|[[codesearch>_html_list_acl]]()|makeTreeItem()|
 +|[[codesearch>_html_li_acl]]()|makeListItem()|
 +|[[codesearch>_tree_sort]]()|treeSort()|
 +|[[codesearch>_html_info]]()|printInfo() |
 +
 +
 +Renamed and changed to protected functions:
 +|[[codesearch>_get_opts]]()|getLinkOptions()|
 +|[[codesearch>_html_explorer]]()|makeExplorer()|
 +|[[codesearch>_html_detail]]()|printDetail()|
 +|[[codesearch>_html_acleditor]]()|printAclEditor()|
 +|[[codesearch>_html_table]]()|printAclTable()|
 +|[[codesearch>_get_exact_perm]]()|getExactPermisson()|
 +|[[codesearch>_html_checkboxes]]()|makeCheckboxes()|
 +|[[codesearch>_html_select]]()|makeSelect()|
 +|[[codesearch>_html_explain]]()|printExplanation()|
 +
  
  
Line 334: Line 401:
 ===== Deprecated 2016 ===== ===== Deprecated 2016 =====
  
 +==== Changed signatures hooks, handle() and render() ====
 There are some old signatures that need still some attention in some plugins. There are some old signatures that need still some attention in some plugins.
  
Line 352: Line 420:
 + public function render($mode, Doku_Renderer $renderer, $data) { + public function render($mode, Doku_Renderer $renderer, $data) {
 </code> </code>
 +
 +==== Replace DOKU_TPL* constants by tpl_* functions ====
 +In 2012, [[github>c4766956646b53ab644ec6ddbd17d9cba07cf872|c476695]] replaced the path in constants by functions which are more dynamic.
 +
 +<code diff>
 +- if (file_exists(DOKU_TPLINC . 'user/logo.png')){
 +-     //user defined PNG
 +-     echo '<img src="' . DOKU_TPL . 'user/logo.png" id="tmpl_header_logo_img" alt=""/>';
 ++ if (file_exists(tpl_incdir() . 'user/logo.png')) {
 ++     //user defined PNG
 ++     echo '<img src="' . tpl_basedir() . 'user/logo.png" id="tmpl_header_logo_img" alt=""/>';
 +</code>
 +
 +==== Old Javascript functions ====
 +The introduction of jQuery in 2011, replaced a set of helpful functions. See also [[devel:jqueryfaq|jQuery FAQ]].
 +
 +==== $('...') ====
 +''$('…')'' as shortcut for ''document.getElementById('…')'' is replaced by ''jQuery('#…')''
 +<code diff>
 +- var obj = $('some__id');
 +- // obj now is a DOM object
 +
 ++ let $obj = jQuery('#some__id');
 ++ // $obj is a jQuery object - if you really need the DOM object use [0] e.g.:
 ++ let obj = $obj[0];
 +</code>
 +
 +==== getElementsByClass() ====
 +
 +use jQuery's [[http://api.jquery.com/jQuery/#jQuery1|selectors]] instead
 +
 +<code diff>
 +- var htmlelements = getElementsByClass( 'class', document, 'tag');
 +- // htmlelements now is an array of DOM elements
 +- for(var n in htmlelements ) {
 +-     dosomething( htmlelements[n] );
 +- }
 +
 +  /* New code */
 ++ jQuery('tag.class').each(function(){
 ++     dosomething(this);
 ++ });
 +
 +  /* Or, this new code */
 ++ let $jqueryelements = jQuery('tag.class');
 ++ // $jqueryelements is a jquery thing: an array plus some other stuff.
 ++ $jqueryelements.each(function(){
 ++     dosomething(this);
 ++ });
 +
 +  /* or, if you prefer (it shows some part of the internals) */
 ++ for (let n = 0; n < $jqueryelements.length; ++n ) {
 ++     dosomething($jqueryelements[n]);
 ++ }
 +</code>
 +
 +  * It is common to start the variable which contain a jQuery object with a ''$''-character, but it is not required.
 +
 +==== addInitEvent() ====
 +
 +registering callbacks to be run when the DOM is ready to be used - use jQuery's [[http://api.jquery.com/jQuery/#jQuery3|callback mechanism]] instead.
 +
 +<code diff>
 +- addInitEvent(function(){
 +-     alert("DOM is ready");
 +- });
 +
 ++ jQuery(function(){
 ++     alert("DOM is ready");
 ++ });
 +</code>
 +
 +==== addEvent() ====
 +
 +Registering event handlers - use jQuery's [[https://api.jquery.com/category/events/|event methods]] instead.
 +
 +<code diff>
 +  /* Old code */
 +- addEvent(obj, "click", function(){ 
 +-     alert("Click happened!")
 +- });
 +
 +  /* Recenter old code */
 +- jQuery(obj).click(function(){ 
 +-     alert("Click happened!"
 +- });
 +
 +  /* New code */
 ++ jQuery(obj).on("click", function(){ 
 ++     alert("Click happened!"
 ++ });
 +</code>
 +
 +  * replace "click" by the event you need e.g. "change", "blur", "focus" and the like (see jQuery link above)
 +
 +==== tw_sack ====
 +
 +executing AJAX requests - use jQuery's [[http://api.jquery.com/category/ajax/|AJAX methods]] instead.
 +
 +<code diff>
 +  /* Old code */
 +- sack = new sack(DOKU_BASE + 'lib/exe/ajax.php');                                                        
 +- sack.AjaxFailedAlert = '';                                                                              
 +- sack.encodeURIString = false;
 +- sack.runAJAX('call=linkwiz&q='+encodeURI(value));
 +
 +  /* New code */
 ++ jQuery.post(
 ++     DOKU_BASE + 'lib/exe/ajax.php',
 ++     { call: 'linkwiz', q: value }
 ++ );
 +</code>
 +
 +
 +
 +
  
 ===== General cleanup suggestions ===== ===== General cleanup suggestions =====
Line 383: Line 567:
  
 <code diff> <code diff>
-- require_once(DOKU_PLUGIN.'syntax.php'); +- require_once(DOKU_PLUGIN . 'syntax.php'); 
-- require_once(DOKU_PLUGIN.'action.php'); +- require_once(DOKU_PLUGIN . 'action.php'); 
-- require_once(DOKU_PLUGIN.'admin.php'); +- require_once(DOKU_PLUGIN . 'admin.php'); 
-etc+etc
  
 - require_once DOKU_INC . 'inc/parser/lexer.php'; - require_once DOKU_INC . 'inc/parser/lexer.php';
 - require_once DOKU_INC . 'inc/parser/handler.php'; - require_once DOKU_INC . 'inc/parser/handler.php';
 +etc
 +</code>
 +
 +The historical ''getInfo()'' is superseeded by ''plugin.info.txt'' ([[devel:plugin_info|more details]]). The old ''getInfo()'' can be removed in 99.9% of the cases.
 +
 +
 +<code diff>
 +- public function getInfo() {
 +- ...
 +- }
 </code> </code>
  
devel/releases/refactor2020.1600808086.txt.gz · Last modified: 2020-09-22 22:54 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