<= [[devel:releases|developer changelog]] ====== Refactoring 2020====== 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]]^ ===== 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 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/.log''). Up to the Hogfather 2020 release: * enable the [[config:allowdebug]] setting in the Configuration Manager * use 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 $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(); ===== Deprecated and changed code ===== Below, you find lists with renamed, changed and moved parts of DokuWiki. Some examples are provided for easier update of plugins and templates. References to codesearch.dokuwiki.org can help locate its usage. 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 ==== Code changes: [[github>d443762bafe99b9292cee141f99fbe818e8d2f16|d443762baf]] and [[pr>2686]] Search usage: [[codesearch>"inc\/JSON.php"]], [[codesearch>"json->encode"]] and [[codesearch>"json->decode"]] // Remove always the require, since years already autoloaded // and file is now removed as well - require_once DOKU_INC . 'inc/JSON.php'; - $json = new JSON; - $str = $json->encode($data); - $data = $json->decode($str); + $str = json_encode($data); + $data = json_decode($str); - $json = new JSON(JSON_LOOSE_TYPE); - $str = $json->encode($data); - $data = $json->decode($str); + $str = json_encode($data, true); + $data = json_decode($str, true); ==== Handlers callwriters, modes and lexer are renamed ==== e.g. ''Doku_Handler_List'' is replaced by ''dokuwiki\Parsing\Handler\Lists''. Needed code update: //import at begin of the file: + use dokuwiki\Parsing\Handler\Lists; //at place of usage: - class Doku_Handler_Creole_List extends Doku_Handler_List { + class Doku_Handler_Creole_List extends Lists { **Tip**: when using a IDE, like [[deveL:Intellij idea]], it will suggest a lot of the imports if you use the class names. The following classes are renamed: ^Old ^New ^ | [[codesearch>Doku_Handler_CallWriter_Interface]] [[codesearch>Doku_Handler_CallWriter]] | dokuwiki\Parsing\Handler\CallWriterInterface dokuwiki\Parsing\Handler\CallWriter| |new \\ new \\ [[codesearch>Doku_Handler_Block]]\\ [[codesearch>Doku_Handler_List]]\\ [[codesearch>Doku_Handler_Nest]] [[codesearch>Doku_Handler_Preformatted]] [[codesearch>Doku_Handler_Quote]] [[codesearch>Doku_Handler_Table]]|dokuwiki\Parsing\Handler\ReWriterInterface dokuwiki\Parsing\Handler\AbstractRewriter dokuwiki\Parsing\Handler\Block dokuwiki\Parsing\Handler\Lists dokuwiki\Parsing\Handler\Nest dokuwiki\Parsing\Handler\Preformatted dokuwiki\Parsing\Handler\Quote dokuwiki\Parsing\Handler\Table| |[[codesearch>Doku_Parser]]|dokuwiki\Parsing\Parser| |[[codesearch>Doku_Lexer]]\\ [[codesearch>Doku_LexerParallelRegex]] [[codesearch>Doku_LexerStateStack]]|dokuwiki\Parsing\Lexer\Lexer dokuwiki\Parsing\Lexer\ParallelRegex dokuwiki\Parsing\Lexer\StateStack| |[[codesearch>Doku_Parser_Mode_Interface]] [[codesearch>Doku_Parser_Mode]] [[codesearch>Doku_Parser_Mode_acronym]] [[codesearch>Doku_Parser_Mode_base]] [[codesearch>Doku_Parser_Mode_camelcaselink]] [[codesearch>Doku_Parser_Mode_code]] [[codesearch>Doku_Parser_Mode_emaillink]] [[codesearch>Doku_Parser_Mode_entity]] [[codesearch>Doku_Parser_Mode_eol]] [[codesearch>Doku_Parser_Mode_externallink]] [[codesearch>Doku_Parser_Mode_file]] [[codesearch>Doku_Parser_Mode_filelink]] [[codesearch>Doku_Parser_Mode_footnote]] [[codesearch>Doku_Parser_Mode_formatting]] [[codesearch>Doku_Parser_Mode_header]] [[codesearch>Doku_Parser_Mode_hr]] [[codesearch>Doku_Parser_Mode_html]] [[codesearch>Doku_Parser_Mode_internallink]] [[codesearch>Doku_Parser_Mode_linebreak]] [[codesearch>Doku_Parser_Mode_listblock]] [[codesearch>Doku_Parser_Mode_media]] [[codesearch>Doku_Parser_Mode_multiplyentity]] [[codesearch>Doku_Parser_Mode_nocache]] [[codesearch>Doku_Parser_Mode_notoc]] [[codesearch>Doku_Parser_Mode_php]] [[codesearch>Doku_Parser_Mode_Plugin]] [[codesearch>Doku_Parser_Mode_preformatted]] [[codesearch>Doku_Parser_Mode_quote]] [[codesearch>Doku_Parser_Mode_quotes]] [[codesearch>Doku_Parser_Mode_rss]] [[codesearch>Doku_Parser_Mode_smiley]] [[codesearch>Doku_Parser_Mode_table]] [[codesearch>Doku_Parser_Mode_unformatted]] [[codesearch>Doku_Parser_Mode_windowssharelink]] [[codesearch>Doku_Parser_Mode_wordblock]]|dokuwiki\Parsing\ParserMode\ModeInterface dokuwiki\Parsing\ParserMode\AbstractMode dokuwiki\Parsing\ParserMode\Acronym dokuwiki\Parsing\ParserMode\Base dokuwiki\Parsing\ParserMode\Camelcaselink dokuwiki\Parsing\ParserMode\Code dokuwiki\Parsing\ParserMode\Emaillink dokuwiki\Parsing\ParserMode\Entity dokuwiki\Parsing\ParserMode\Eol dokuwiki\Parsing\ParserMode\Externallink dokuwiki\Parsing\ParserMode\File dokuwiki\Parsing\ParserMode\Filelink dokuwiki\Parsing\ParserMode\Footnote dokuwiki\Parsing\ParserMode\Formatting dokuwiki\Parsing\ParserMode\Header dokuwiki\Parsing\ParserMode\Hr dokuwiki\Parsing\ParserMode\Html dokuwiki\Parsing\ParserMode\Internallink dokuwiki\Parsing\ParserMode\Linebreak dokuwiki\Parsing\ParserMode\Listblock dokuwiki\Parsing\ParserMode\Media dokuwiki\Parsing\ParserMode\Multiplyentity dokuwiki\Parsing\ParserMode\Nocache dokuwiki\Parsing\ParserMode\Notoc dokuwiki\Parsing\ParserMode\Php dokuwiki\Parsing\ParserMode\Plugin dokuwiki\Parsing\ParserMode\Preformatted dokuwiki\Parsing\ParserMode\Quote dokuwiki\Parsing\ParserMode\Quotes dokuwiki\Parsing\ParserMode\Rss dokuwiki\Parsing\ParserMode\Smiley dokuwiki\Parsing\ParserMode\Table dokuwiki\Parsing\ParserMode\Unformatted dokuwiki\Parsing\ParserMode\Windowssharelink dokuwiki\Parsing\ParserMode\Wordblock| ==== Changes of the internals of the handler ==== Variables are not available anymore: * ''%%$handler->status[]%%'' * ''%%$handler->CallWriter%%'' Functions renamed: * ''%%$handler->_addCall()%%'' * ''%%$handler->_finalize()%%'' Search usage: [[codesearch>status]], [[codesearch>CallWriter]] and [[codesearch>_addCall]], [[codesearch>_finalize]] Replacements: - $status = $handler->status['section'] + $status = $handler->getStatus('section') - $handler->status['section'] = true + $handler->setStatus('section', true) case DOKU_LEXER_ENTER: - $ReWriter = new Doku_Handler_Creole_List($handler->CallWriter); - $handler->CallWriter = & $ReWriter; + $ReWriter = new Doku_Handler_Creole_List($handler->getCallWriter()); + $handler->setCallWriter($ReWriter); case DOKU_LEXER_EXIT: - $handler->CallWriter->process(); - $ReWriter = & $handler->CallWriter; - $handler->CallWriter = & $ReWriter->CallWriter; + $ReWriter = $handler->getCallWriter(); + $handler->setCallWriter($ReWriter->process()); - $handler->_addCall('list_close', array(), $pos); + $handler->addCall('list_close', array(), $pos); Note: some general ''addCall()'' can be replaced by the specific functions like ''header()'', ''eof()'', ''hr()'', ''strong()'', ''emphasis()'', ''underline()'', etc etc. Could be worth a check, however there should be typical a reason that these specific functions were not used. ==== Changes of the internals of the parser ==== Renamed variables: ''Handler'' and ''Lexer'' to ''handler'' and ''lexer''. (maybe no difference in practice due to case-insensitivity) Changed visibility, these variables are now protected: ''handler'', ''lexer'', ''modes'', ''connected''. The ''handler'' can be set via the constructor. There are no setters or getters for the others. - $parser = new Doku_Parser(); - $parser->Handler = $handler; + $parser = new Parser($handler); ==== Changes of the internals of the Lexer ==== Variables and functions are not available anymore: * ''%%$lexer->_mode%%'' * function ''%%Doku_Lexer_Escape($str)%%'' Search usage: [[codesearch>_mode]], [[codesearch>Doku_Lexer_Escape]] and [[codesearch>_dispatchTokens]] - $lexer->_mode->getCurrent(); + $lexer->getModeStack()->getCurrent(); - $str = Doku_Lexer_Escape($str); + $str = \dokuwiki\Parsing\Lexer\Lexer::escape($str); Other renamed protected functions of Lexer: ''_dispatchTokens()'', ''_isModeEnd()'', ''_isSpecialMode()'', ''_decodeSpecial()'', ''_invokeParser()'' and ''_reduce()''. Renamed protected functions of ParallelRegex: ''_getCompoundedRegex()'', ''_getPerlMatchingFlags()''. ==== UTF-8 functions ==== All UTF-8 functions are moved and renamed. Refactored mostly in [[pr>2780]]. ^Old ^New ^ |inline code|\dokuwiki\Utf8\Asian::isAsianWords()\\ \dokuwiki\Utf8\Asian::separateAsianWords()\\ \dokuwiki\Utf8\Asian::splitAsianWords()| |[[codesearch>IDX_ASIAN]]|\dokuwiki\Utf8\Asian::REGEXP| |[[codesearch>utf8_isASCII]]\\ [[codesearch>utf8_check]]\\ [[codesearch>utf8_strip]]\\ [[codesearch>utf8_stripspecials]]\\ [[codesearch>utf8_bad_replace]]\\ [[codesearch>utf8_deaccent]]\\ [[codesearch>utf8_romanize]]\\ [[codesearch>utf8_correctIdx]]|\dokuwiki\Utf8\Clean::isASCII()\\ \dokuwiki\Utf8\Clean::isUtf8()\\ \dokuwiki\Utf8\Clean::strip()\\ \dokuwiki\Utf8\Clean::stripspecials()\\ \dokuwiki\Utf8\Clean::replaceBadBytes()\\ \dokuwiki\Utf8\Clean::deaccent()\\ \dokuwiki\Utf8\Clean::romanize()\\ \dokuwiki\Utf8\Clean::correctIdx()| |[[codesearch>utf8_tohtml]]\\ [[codesearch>utf8_unhtml]]\\ [[codesearch>utf8_to_utf16be]]\\ [[codesearch>utf16be_to_utf8]]|\dokuwiki\Utf8\Conversion::toHtml()\\ \dokuwiki\Utf8\Conversion::fromHtml()\\ \dokuwiki\Utf8\Conversion::toUtf16be()\\ \dokuwiki\Utf8\Conversion::fromUtf16be()| |[[codesearch>utf8_basename]]\\ [[codesearch>utf8_strlen]]\\ [[codesearch>utf8_substr]]\\ [[codesearch>utf8_substr_replace]]\\ [[codesearch>utf8_ltrim]]\\ [[codesearch>utf8_rtrim]]\\ [[codesearch>utf8_trim]]\\ [[codesearch>utf8_strtolower]]\\ [[codesearch>utf8_strtoupper]]\\ [[codesearch>utf8_ucfirst]]\\ [[codesearch>utf8_ucwords]]\\ [[codesearch>utf8_strpos]]|\dokuwiki\Utf8\PhpString::basename()\\ \dokuwiki\Utf8\PhpString::strlen()\\ \dokuwiki\Utf8\PhpString::substr()\\ \dokuwiki\Utf8\PhpString::substr_replace()\\ \dokuwiki\Utf8\PhpString::ltrim()\\ \dokuwiki\Utf8\PhpString::rtrim()\\ \dokuwiki\Utf8\PhpString::trim()\\ \dokuwiki\Utf8\PhpString::strtolower()\\ \dokuwiki\Utf8\PhpString::strtoupper()\\ \dokuwiki\Utf8\PhpString::ucfirst()\\ \dokuwiki\Utf8\PhpString::ucwords()\\ \dokuwiki\Utf8\PhpString::strpos()| |[[codesearch>utf8_to_unicode]]\\ [[codesearch>unicode_to_utf8]]|\dokuwiki\Utf8\Unicode::fromUtf8()\\ \dokuwiki\Utf8\Unicode::toUtf8()| |globals\\ [[codesearch>UTF8_UPPER_TO_LOWER]]\\ [[codesearch>UTF8_LOWER_TO_UPPER]]\\ [[codesearch>UTF8_LOWER_ACCENTS]]\\ [[codesearch>UTF8_UPPER_ACCENTS]]\\ [[codesearch>UTF8_ROMANIZATION]]\\ [[codesearch>UTF8_SPECIAL_CHARS]]\\ [[codesearch>UTF8_SPECIAL_CHARS2]] |\\ \dokuwiki\Utf8\Table::upperCaseToLowerCase()\\ \dokuwiki\Utf8\Table::lowerCaseToUpperCase()\\ \dokuwiki\Utf8\Table::lowerAccents()\\ \dokuwiki\Utf8\Table::upperAccents()\\ \dokuwiki\Utf8\Table::romanization()\\ \dokuwiki\Utf8\Table::specialChars()\\ **TO CHECK**: combined? or deprecated/removed??| Class for handling UTF-8 in filenames. Renamed functions: |SafeFN::[[codesearch>validate_printable_utf8]]\\ SafeFN::[[codesearch>validate_safe]]| SafeFN::validatePrintableUtf8()\\ SafeFN::validateSafe()|| ==== Cache ==== |[[codesearch>cache]]\\ [[codesearch>cache_parser]]\\ [[codesearch>cache_renderer]]\\ [[codesearch> cache_instructions]]|dokuwiki\Cache\Cache\\ dokuwiki\Cache\CacheParser\\ dokuwiki\Cache\CacheRenderer\\ dokuwiki\Cache\CacheInstructions| Changed visibility, these variables are now protected and have new setters/getters: |[[codesearch>_event]]| setEvent($event)\\ getEvent() | |[[codesearch>_time]]|getTime()| |[[codesearch>_nocache]]|isNoCache()| FIXME? CHECK: NO SETTER FOR nocache, while used in plugins - $time = $cache->_time + $time = $cache->getTime()) - $cache = new cache_renderer($ID, $file, 'xhtml'); - $useCache = $cache->_nocache + $cache = new CacheRenderer($ID, $file, 'xhtml'); + $useCache = $cache->isNoCache() - $cache->_event = $event + $cache->setEvent($event) - $event = $cache->_event + $event = $cache->getEvent() ==== Changelog ==== Renamed and moved classes: | [[codesearch>Changelog]]\\ [[codesearch>MediaChangelog]]\\ [[codesearch>PageChangelog]]|dokuwiki\ChangeLog\Changelog\\ dokuwiki\ChangeLog\MediaChangeLog\\ dokuwiki\ChangeLog\PageChangeLog| ==== Sitemap ==== Renamed and moved classes: |[[codesearch>SitemapItem]]\\ [[codesearch>Sitemapper]]|dokuwiki\Sitemap\Item\\ dokuwiki\Sitemap\Mapper| ====Extension and Event==== Refactored mostly in [[pr>2757]] Renamed and moved classes: ^Old ^New ^ |[[codesearch>Doku_Plugin_Controller]]\\ [[codesearch>DokuWiki_PluginInterface]]\\ [[codesearch>DokuWiki_PluginTrait]]\\ [[codesearch>Doku_Plugin]]\\ [[codesearch>DokuWiki_Action_Plugin]]\\ [[codesearch>DokuWiki_Admin_Plugin]]\\ [[codesearch>DokuWiki_Auth_Plugin]]\\ [[codesearch>DokuWiki_CLI_Plugin]]\\ [[codesearch>DokuWiki_Remote_Plugin]]\\ [[codesearch>DokuWiki_Syntax_Plugin]]|dokuwiki\Extension\PluginController\\ dokuwiki\Extension\PluginInterface\\ dokuwiki\Extension\PluginTrait\\ dokuwiki\Extension\Plugin\\ dokuwiki\Extension\ActionPlugin\\ dokuwiki\Extension\AdminPlugin\\ dokuwiki\Extension\AuthPlugin\\ dokuwiki\Extension\CLIPlugin\\ dokuwiki\Extension\RemotePlugin\\ dokuwiki\Extension\SyntaxPlugin| |[[codesearch>Doku_Event]]\\ [[codesearch>Doku_Event_Handler]] |dokuwiki\Extension\Event\\ dokuwiki\Extension\EventHandler| |[[codesearch>DokuCLI]] | \splitbrain\phpcli\CLI| Renamed and moved functions: * [[codesearch>trigger_event]]() -> Event::createAndTrigger() * [[codesearch>isdisabled]]() -> %%!$plugin_controller->isEnabled()%% + use dokuwiki\Extension\Event; - trigger_event('FEED_OPTS_POSTPROCESS', $eventData); + Event::createAndTrigger('FEED_OPTS_POSTPROCESS', $eventData); global $pluginController; - $isDisabled = $pluginController->isdisabled($plugin); + $isDisabled = !$pluginController->isEnabled($plugin); Variables |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()| ==== Subscription ==== Renamed and refactored in separated classes: ^Old ^New ^ |**[[codesearch>Subscription]]** with functions:\\ - [[codesearch>isenabled]]()\\ - [[codesearch>add]]()\\ - [[codesearch>remove]]()\\ - [[codesearch>subcribers]]()\\ - [[codesearch>user_subscription]]()\\ - [[codesearch>notifyaddresses]]()\\ \\ \\ \\ - [[codesearch>send_bulk]]()\\ \\ - [[codesearch>send_media_diff]]()\\ \\ - [[codesearch>send_diff]]()\\ \\ - [[codesearch>send_register]]()| **dokuwiki\Subscriptions\SubscriberManager**\\ - isenabled()\\ - add()\\ - remove()\\ - subscribers()\\ - userSubscription()\\ - notifyAddresses()\\ \\ **dokuwiki\Subscriptions\SubscriptionSender**\\ **dokuwiki\Subscriptions\BulkSubscriptionSender**\\ - sendBulk()\\ **dokuwiki\Subscriptions\MediaSubscriptionSender**\\ - sendMediaDiff()\\ **dokuwiki\Subscriptions\PageSubscriptionSender**\\ - sendPageDiff()\\ **dokuwiki\Subscriptions\RegistrationSubscriptionSender**\\ - sendRegister()\\ \\ **dokuwiki\Subscriptions\SubscriberRegexBuilder**\\ - buildRegex() | Examples: - $subscription = new Subscription(); - $success = $subscription->send_register($login, $fullname, $email); + $subscription = new RegistrationSubscriptionSender(); + $success = $subscription->sendRegister($login, $fullname, $email); - $sub = new Subscription(); - $info['subscribed'] = $sub->user_subscription(); + $subManager = new SubscriberManager(); + $info['subscribed'] = $subManager->userSubscription(); - $subscription = new Subscription(); - $success = $subscription->send_diff($to, $tpl, $id, $rev, $summary); + $subscription = new PageSubscriptionSender(); + $success = $subscription->sendPageDiff($to, $tpl, $id, $rev, $summary); - $subscription = new Subscription(); - $success = $subscription->send_media_diff($subscriber_mail, $template, $id, $rev); + $subscriptionSender = new MediaSubscriptionSender(); + $success = $subscriptionSender->sendMediaDiff($subscriber_mail, $template, $id, $rev); - $subscription = new Subscription(); - $success = $subscription->isenabled(); - $success = $subscription->subscribers($page, $user, $style, $data); - $success = $subscription->add($id, $user, $style, $data) - $success = $subscription->remove($id, $user, $style, $data) - $success = $subscription->user_subscription($id, $user) - $subscription->notifyaddresses($data) + $manager = new SubscriberManager(); + $success = $manager->isenabled(); + $success = $manager->subscribers($page, $user, $style, $data); + $success = $manager->add($id, $user, $style, $data); + $success = $manager->remove($id, $user, $style, $data); + $success = $manager->userSubscription($id, $user); + $manager->notifyAddresses($data); - $subscription = new Subscription(); - $success = $subscription->send_bulk($page); + $subscriptionSender = new BulkSubscriptionSender(); + $success = $subscriptionSender->sendBulk($page); ==== Remote API and Server ==== Renamed and moved classes: ^Old ^New ^ |[[codesearch>RemoteAPI]]\\ [[codesearch>RemoteAPICore]]\\ [[codesearch>RemoteAccessDeniedException]]|dokuwiki\Remote\Api\\ dokuwiki\Remote\ApiCore\\ dokuwiki\Remote\AccessDeniedException| |variable:\\ [[codesearch>DOKU_API_VERSION]]|\\ %%ApiCore::API_VERSION%%| |[[codesearch>dokuwiki_xmlrpc_server]]\\ [[codesearch>RemoteException]]|dokuwiki\Remote\XmlRpcServer\\ dokuwiki\Remote\RemoteException| ==== HTTP Client ==== |[[codesearch>HTTPClient]]\\ [[codesearch>DokuHTTPClient]]\\ [[codesearch>HTTPClientException]]|dokuwiki\HTTP\HTTPClient\\ dokuwiki\HTTP\DokuHTTPClient\\ dokuwiki\HTTP\HTTPClientException| Visibility changed to protected variables: [[codesearch>connections]], [[codesearch>boundary]] Visibility changed to protected and renamed functions: [[codesearch>_ssltunnel]], [[codesearch>_sendData]], [[codesearch>_readData]], [[codesearch>_readLine]], [[codesearch>_debug _debug_html]], [[codesearch>_debug_text]], [[codesearch>_time]], [[codesearch>_parseHeaders]], [[codesearch>_buildHeaders]], [[codesearch>_getCookies]], [[codesearch>_postEncode]], [[codesearch>_postMultipartEncode]], [[codesearch>_uniqueConnectionId]]. All the underscored are removed from the function names, and two names changed more: ''debugHtml'', ''debugText''. ==== Input ==== Renamed and moved classes: ^Old ^New ^ |[[codesearch>Input]]\\ [[codesearch>GetInput]]\\ [[codesearch>PostInput]]\\ [[codesearch>ServerInput]] |dokuwiki\Input\Input\\ dokuwiki\Input\Get\\ dokuwiki\Input\Post\\ dokuwiki\Input\Server| ==== Settings ==== Refactored mostly in [[pr>2382]] Renamed and moved classes: ^ Old ^ New ^ | [[codesearch>configuration]] | dokuwiki\plugin\config\core\Configuration dokuwiki\plugin\config\core\ConfigParser dokuwiki\plugin\config\core\Loader\\ dokuwiki\plugin\config\core\Writer | | CM_KEYMARKER DOKU_PLUGIN_IMAGES PLUGIN_METADATA | Configuration::KEYMARKER\\ admin_plugin_config::IMGDIR\\ admin_plugin_config::METADATA | | [[codesearch>setting]]\\ [[codesearch>setting_array]] [[codesearch>setting_authtype]] [[codesearch>setting_compression]] [[codesearch>setting_dirchoice]] [[codesearch>setting_disableactions]] [[codesearch>setting_email]] [[codesearch>setting_fieldset]] [[codesearch>setting_hidden]] [[codesearch>setting_im_convert]] [[codesearch>setting_license]] [[codesearch>setting_multicheckbox]] [[codesearch>setting_multichoice]] [[codesearch>setting_no_class]] [[codesearch>setting_no_default]]\\ \\ [[codesearch>setting_numeric]] [[codesearch>setting_numericopt]] [[codesearch>setting_onoff]] [[codesearch>setting_password]] [[codesearch>setting_regex]] [[codesearch>setting_renderer]] [[codesearch>setting_savedir]] [[codesearch>setting_sepchar]] [[codesearch>setting_string]] [[codesearch>setting_undefined]] | dokuwiki\plugin\config\core\Setting\Setting dokuwiki\plugin\config\core\Setting\SettingArray dokuwiki\plugin\config\core\Setting\SettingAuthtype dokuwiki\plugin\config\core\Setting\SettingCompression dokuwiki\plugin\config\core\Setting\SettingDirchoice dokuwiki\plugin\config\core\Setting\SettingDisableactions dokuwiki\plugin\config\core\Setting\SettingEmail dokuwiki\plugin\config\core\Setting\SettingFieldset dokuwiki\plugin\config\core\Setting\SettingHidden dokuwiki\plugin\config\core\Setting\SettingImConvert dokuwiki\plugin\config\core\Setting\SettingLicense dokuwiki\plugin\config\core\Setting\SettingMulticheckbox dokuwiki\plugin\config\core\Setting\SettingMultichoice dokuwiki\plugin\config\core\Setting\SettingNoClass dokuwiki\plugin\config\core\Setting\SettingNoDefault dokuwiki\plugin\config\core\Setting\SettingNoKnownClass dokuwiki\plugin\config\core\Setting\SettingNumeric dokuwiki\plugin\config\core\Setting\SettingNumericopt dokuwiki\plugin\config\core\Setting\SettingOnoff dokuwiki\plugin\config\core\Setting\SettingPassword dokuwiki\plugin\config\core\Setting\SettingRegex dokuwiki\plugin\config\core\Setting\SettingRenderer dokuwiki\plugin\config\core\Setting\SettingSavedir dokuwiki\plugin\config\core\Setting\SettingSepchar dokuwiki\plugin\config\core\Setting\SettingString dokuwiki\plugin\config\core\Setting\SettingUndefined | The ''Configuration'' class is significant refactored. So check yourself for functions moved to the new classes and renamed functions. ==== Other ==== Renamed and moved classes: |[[codesearch>FeedParser_File]] |dokuwiki\FeedParserFile| |[[codesearch>PassHash]] |dokuwiki\Passhash| ===== Deprecated 2016 ===== ==== Changed signatures hooks, handle() and render() ==== There are some old signatures that need still some attention in some plugins. In action.php: - function alwaysHide(Doku_Event &$event, $params) { + function alwaysHide(Doku_Event $event, $params) { and syntax.php: - public function handle($match, $state, $pos, &$handler){ + public function handle($match, $state, $pos, Doku_Handler $handler){ - public function render($mode, &$renderer, $data) { + public function render($mode, Doku_Renderer $renderer, $data) { ==== Replace DOKU_TPL* constants by tpl_* functions ==== In 2012, [[github>c4766956646b53ab644ec6ddbd17d9cba07cf872|c476695]] replaced the path in constants by functions which are more dynamic. - if (file_exists(DOKU_TPLINC . 'user/logo.png')){ - //user defined PNG - echo ''; + if (file_exists(tpl_incdir() . 'user/logo.png')) { + //user defined PNG + echo ''; ==== 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('#…')'' - 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]; ==== getElementsByClass() ==== use jQuery's [[http://api.jquery.com/jQuery/#jQuery1|selectors]] instead - 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]); + } * 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. - addInitEvent(function(){ - alert("DOM is ready"); - }); + jQuery(function(){ + alert("DOM is ready"); + }); ==== addEvent() ==== Registering event handlers - use jQuery's [[https://api.jquery.com/category/events/|event methods]] instead. /* 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!") + }); * 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. /* 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 } + ); ===== General cleanup suggestions ===== Lot of plugins uses the following older code. Today these are already included via the core or not needed anymore. The following code is only needed if a file has main code that is executed. Otherwise it can be left out. - if(!defined('DOKU_INC')) die('meh.'); Code beautification. The defines are already in core, so can be deleted. Further these code beautifications are not needed anymore with current debugging tools. - // Some whitespace to help View > Source - if(!defined('DOKU_LF')) define ('DOKU_LF', "\n"); - // Some whitespace to help View > Source - if(!defined('DOKU_TAB')) define ('DOKU_TAB', "\t"); - if(!defined('NL')) define('NL',"\n"); This directory is set in the core, not needed per plugin. - if(!defined('DOKU_PLUGIN')) { - define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); - } Scripts includes such as ''require'' and ''require_one'' are not needed for all the DokuWiki files or the typical plugin files. DokuWiki has an autoloader. More and more parts of the core use namespaces. Please use them, see [[devel:autoloader]] how these are related to your files. - require_once(DOKU_PLUGIN . 'syntax.php'); - require_once(DOKU_PLUGIN . 'action.php'); - require_once(DOKU_PLUGIN . 'admin.php'); etc - require_once DOKU_INC . 'inc/parser/lexer.php'; - require_once DOKU_INC . 'inc/parser/handler.php'; etc 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. - public function getInfo() { - ... - } ===== Code improvements ===== Do not use public properties, but setter/getter functions if available. Example for the renderer: - $renderer->info['cache'] = false; + $renderer->nocache();