*/ use dokuwiki\Action\Denied; use dokuwiki\Action\Locked; use dokuwiki\ChangeLog\PageChangeLog; use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\Event; use dokuwiki\Ui\Backlinks; use dokuwiki\Ui\Editor; use dokuwiki\Ui\Index; use dokuwiki\Ui\Login; use dokuwiki\Ui\PageConflict; use dokuwiki\Ui\PageDiff; use dokuwiki\Ui\PageDraft; use dokuwiki\Ui\PageRevisions; use dokuwiki\Ui\PageView; use dokuwiki\Ui\Recent; use dokuwiki\Ui\UserProfile; use dokuwiki\Ui\UserRegister; use dokuwiki\Ui\UserResendPwd; use dokuwiki\Utf8\Clean; if (!defined('SEC_EDIT_PATTERN')) { define('SEC_EDIT_PATTERN', '##'); } /** * Convenience function to quickly build a wikilink * * @author Andreas Gohr * @param string $id id of the target page * @param string $name the name of the link, i.e. the text that is displayed * @param string|array $search search string(s) that shall be highlighted in the target page * @return string the HTML code of the link */ function html_wikilink($id, $name = null, $search = '') { /** @var Doku_Renderer_xhtml $xhtml_renderer */ static $xhtml_renderer = null; if (is_null($xhtml_renderer)) { $xhtml_renderer = p_get_renderer('xhtml'); } return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); } /** * The loginform * * @author Andreas Gohr * * @param bool $svg Whether to show svg icons in the register and resendpwd links or not * @deprecated 2020-07-18 */ function html_login($svg = false) { dbg_deprecated(Login::class .'::show()'); (new dokuwiki\Ui\Login($svg))->show(); } /** * Denied page content * * @deprecated 2020-07-18 not called anymore, see inc/Action/Denied::tplContent() */ function html_denied() { dbg_deprecated(Denied::class .'::showBanner()'); (new dokuwiki\Action\Denied())->showBanner(); } /** * inserts section edit buttons if wanted or removes the markers * * @author Andreas Gohr * * @param string $text * @param bool $show show section edit buttons? * @return string */ function html_secedit($text, $show = true) { global $INFO; if ((isset($INFO) && !$INFO['writable']) || !$show || (isset($INFO) && $INFO['rev'])) { return preg_replace(SEC_EDIT_PATTERN,'',$text); } return preg_replace_callback(SEC_EDIT_PATTERN, 'html_secedit_button', $text); } /** * prepares section edit button data for event triggering * used as a callback in html_secedit * * @author Andreas Gohr * * @param array $matches matches with regexp * @return string * @triggers HTML_SECEDIT_BUTTON */ function html_secedit_button($matches){ $json = htmlspecialchars_decode($matches[1], ENT_QUOTES); $data = json_decode($json, true); if ($data === null) { return ''; } $data['target'] = strtolower($data['target']); $data['hid'] = strtolower($data['hid'] ?? ''); return Event::createAndTrigger( 'HTML_SECEDIT_BUTTON', $data, 'html_secedit_get_button' ); } /** * prints a section editing button * used as default action form HTML_SECEDIT_BUTTON * * @author Adrian Lang * * @param array $data name, section id and target * @return string html */ function html_secedit_get_button($data) { global $ID; global $INFO; if (!isset($data['name']) || $data['name'] === '') return ''; $name = $data['name']; unset($data['name']); $secid = $data['secid']; unset($data['secid']); $params = array_merge( array('do' => 'edit', 'rev' => $INFO['lastmod'], 'summary' => '['.$name.'] '), $data ); $html = '
'; $html.= html_btn('secedit', $ID, '', $params, 'post', $name); $html.= '
'; return $html; } /** * Just the back to top button (in its own form) * * @author Andreas Gohr * * @return string html */ function html_topbtn() { global $lang; return '' .''; } /** * Displays a button (using its own form) * If tooltip exists, the access key tooltip is replaced. * * @author Andreas Gohr * * @param string $name * @param string $id * @param string $akey access key * @param string[] $params key-value pairs added as hidden inputs * @param string $method * @param string $tooltip * @param bool|string $label label text, false: lookup btn_$name in localization * @param string $svg (optional) svg code, inserted into the button * @return string */ function html_btn($name, $id, $akey, $params, $method = 'get', $tooltip = '', $label = false, $svg = null) { global $conf; global $lang; if (!$label) $label = $lang['btn_'.$name]; //filter id (without urlencoding) $id = idfilter($id,false); //make nice URLs even for buttons if ($conf['userewrite'] == 2) { $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; } elseif ($conf['userewrite']) { $script = DOKU_BASE.$id; } else { $script = DOKU_BASE.DOKU_SCRIPT; $params['id'] = $id; } $html = '
'; if (is_array($params)) { foreach ($params as $key => $val) { $html .= ''; } } $tip = empty($tooltip) ? hsc($label) : hsc($tooltip); $html .= ''; $html .= '
'; return $html; } /** * show a revision warning * * @author Szymon Olewniczak * @deprecated 2020-07-18 */ function html_showrev() { dbg_deprecated(PageView::class .'::showrev()'); } /** * Show a wiki page * * @author Andreas Gohr * * @param null|string $txt wiki text or null for showing $ID * @deprecated 2020-07-18 */ function html_show($txt=null) { dbg_deprecated(PageView::class .'::show()'); (new dokuwiki\Ui\PageView($txt))->show(); } /** * ask the user about how to handle an exisiting draft * * @author Andreas Gohr * @deprecated 2020-07-18 */ function html_draft() { dbg_deprecated(PageDraft::class .'::show()'); (new dokuwiki\Ui\PageDraft)->show(); } /** * Highlights searchqueries in HTML code * * @author Andreas Gohr * @author Harry Fuecks * * @param string $html * @param array|string $phrases * @return string html */ function html_hilight($html, $phrases) { $phrases = (array) $phrases; $phrases = array_map('preg_quote_cb', $phrases); $phrases = array_map('ft_snippet_re_preprocess', $phrases); $phrases = array_filter($phrases); $regex = join('|',$phrases); if ($regex === '') return $html; if (!Clean::isUtf8($regex)) return $html; return @preg_replace_callback("/((<[^>]*)|$regex)/ui", function ($match) { $hlight = unslash($match[0]); if (!isset($match[2])) { $hlight = ''.$hlight.''; } return $hlight; }, $html); } /** * Display error on locked pages * * @author Andreas Gohr * @deprecated 2020-07-18 not called anymore, see inc/Action/Locked::tplContent() */ function html_locked() { dbg_deprecated(Locked::class .'::showBanner()'); (new dokuwiki\Action\Locked())->showBanner(); } /** * list old revisions * * @author Andreas Gohr * @author Ben Coburn * @author Kate Arzamastseva * * @param int $first skip the first n changelog lines * @param string $media_id id of media, or empty for current page * @deprecated 2020-07-18 */ function html_revisions($first = -1, $media_id = '') { dbg_deprecated(PageRevisions::class .'::show()'); if ($media_id) { (new dokuwiki\Ui\MediaRevisions($media_id))->show($first); } else { global $INFO; (new dokuwiki\Ui\PageRevisions($INFO['id']))->show($first); } } /** * display recent changes * * @author Andreas Gohr * @author Matthias Grimm * @author Ben Coburn * @author Kate Arzamastseva * * @param int $first * @param string $show_changes * @deprecated 2020-07-18 */ function html_recent($first = 0, $show_changes = 'both') { dbg_deprecated(Recent::class .'::show()'); (new dokuwiki\Ui\Recent($first, $show_changes))->show(); } /** * Display page index * * @author Andreas Gohr * * @param string $ns * @deprecated 2020-07-18 */ function html_index($ns) { dbg_deprecated(Index::class .'::show()'); (new dokuwiki\Ui\Index($ns))->show(); } /** * Index tree item formatter for html_buildlist() * * User function for html_buildlist() * * @author Andreas Gohr * * @param array $item * @return string * @deprecated 2020-07-18 */ function html_list_index($item) { dbg_deprecated(Index::class .'::formatListItem()'); return (new dokuwiki\Ui\Index)->formatListItem($item); } /** * Index list item formatter for html_buildlist() * * This user function is used in html_buildlist to build the *
  • tags for namespaces when displaying the page index * it gives different classes to opened or closed "folders" * * @author Andreas Gohr * * @param array $item * @return string html * @deprecated 2020-07-18 */ function html_li_index($item) { dbg_deprecated(Index::class .'::tagListItem()'); return (new dokuwiki\Ui\Index)->tagListItem($item); } /** * Default list item formatter for html_buildlist() * * @author Andreas Gohr * * @param array $item * @return string html * @deprecated 2020-07-18 */ function html_li_default($item){ return '
  • '; } /** * Build an unordered list * * Build an unordered list from the given $data array * Each item in the array has to have a 'level' property * the item itself gets printed by the given $func user * function. The second and optional function is used to * print the
  • tag. Both user function need to accept * a single item. * * Both user functions can be given as array to point to * a member of an object. * * @author Andreas Gohr * * @param array $data array with item arrays * @param string $class class of ul wrapper * @param callable $func callback to print an list item * @param callable $lifunc (optional) callback to the opening li tag * @param bool $forcewrapper (optional) Trigger building a wrapper ul if the first level is * 0 (we have a root object) or 1 (just the root content) * @return string html of an unordered list */ function html_buildlist($data, $class, $func, $lifunc = null, $forcewrapper = false) { if (count($data) === 0) { return ''; } $firstElement = reset($data); $start_level = $firstElement['level']; $level = $start_level; $html = ''; $open = 0; // set callback function to build the
  • tag, formerly defined as html_li_default() if (!is_callable($lifunc)) { $lifunc = function ($item) { return '
  • '; }; } foreach ($data as $item) { if ($item['level'] > $level) { //open new list for ($i = 0; $i < ($item['level'] - $level); $i++) { if ($i) $html .= '
  • '; $html .= "\n".'
      '."\n"; $open++; } $level = $item['level']; } elseif ($item['level'] < $level) { //close last item $html .= ''."\n"; while ($level > $item['level'] && $open > 0 ) { //close higher lists $html .= '
    '."\n".'
  • '."\n"; $level--; $open--; } } elseif ($html !== '') { //close previous item $html .= ''."\n"; } //print item $html .= call_user_func($lifunc, $item); $html .= '
    '; $html .= call_user_func($func, $item); $html .= '
    '; } //close remaining items and lists $html .= ''."\n"; while ($open-- > 0) { $html .= ''."\n"; } if ($forcewrapper || $start_level < 2) { // Trigger building a wrapper ul if the first level is // 0 (we have a root object) or 1 (just the root content) $html = "\n".'
      '."\n".$html.'
    '."\n"; } return $html; } /** * display backlinks * * @author Andreas Gohr * @author Michael Klier * @deprecated 2020-07-18 */ function html_backlinks() { dbg_deprecated(Backlinks::class .'::show()'); (new dokuwiki\Ui\Backlinks)->show(); } /** * Get header of diff HTML * * @param string $l_rev Left revisions * @param string $r_rev Right revision * @param string $id Page id, if null $ID is used * @param bool $media If it is for media files * @param bool $inline Return the header on a single line * @return string[] HTML snippets for diff header * @deprecated 2020-07-18 */ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { dbg_deprecated('see '. PageDiff::class .'::buildDiffHead()'); return ['', '', '', '']; } /** * Show diff * between current page version and provided $text * or between the revisions provided via GET or POST * * @author Andreas Gohr * @param string $text when non-empty: compare with this text with most current version * @param bool $intro display the intro text * @param string $type type of the diff (inline or sidebyside) * @deprecated 2020-07-18 */ function html_diff($text = '', $intro = true, $type = null) { dbg_deprecated(PageDiff::class .'::show()'); global $INFO; (new dokuwiki\Ui\PageDiff($INFO['id']))->compareWith($text)->preference([ 'showIntro' => $intro, 'difftype' => $type, ])->show(); } /** * Create html for revision navigation * * @param PageChangeLog $pagelog changelog object of current page * @param string $type inline vs sidebyside * @param int $l_rev left revision timestamp * @param int $r_rev right revision timestamp * @return string[] html of left and right navigation elements * @deprecated 2020-07-18 */ function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { dbg_deprecated('see '. PageDiff::class .'::buildRevisionsNavigation()'); return ['', '']; } /** * Create html link to a diff defined by two revisions * * @param string $difftype display type * @param string $linktype * @param int $lrev oldest revision * @param int $rrev newest revision or null for diff with current revision * @return string html of link to a diff * @deprecated 2020-07-18 */ function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { dbg_deprecated('see '. PageDiff::class .'::diffViewlink()'); return ''; } /** * Insert soft breaks in diff html * * @param string $diffhtml * @return string * @deprecated 2020-07-18 */ function html_insert_softbreaks($diffhtml) { dbg_deprecated(PageDiff::class .'::insertSoftbreaks()'); return (new dokuwiki\Ui\PageDiff)->insertSoftbreaks($diffhtml); } /** * show warning on conflict detection * * @author Andreas Gohr * * @param string $text * @param string $summary * @deprecated 2020-07-18 */ function html_conflict($text, $summary) { dbg_deprecated(PageConflict::class .'::show()'); (new dokuwiki\Ui\PageConflict($text, $summary))->show(); } /** * Prints the global message array * * @author Andreas Gohr */ function html_msgarea() { global $MSG, $MSG_shown; /** @var array $MSG */ // store if the global $MSG has already been shown and thus HTML output has been started $MSG_shown = true; if (!isset($MSG)) return; $shown = array(); foreach ($MSG as $msg) { $hash = md5($msg['msg']); if (isset($shown[$hash])) continue; // skip double messages if (info_msg_allowed($msg)) { print '
    '; print $msg['msg']; print '
    '; } $shown[$hash] = 1; } unset($GLOBALS['MSG']); } /** * Prints the registration form * * @author Andreas Gohr * @deprecated 2020-07-18 */ function html_register() { dbg_deprecated(UserRegister::class .'::show()'); (new dokuwiki\Ui\UserRegister)->show(); } /** * Print the update profile form * * @author Christopher Smith * @author Andreas Gohr * @deprecated 2020-07-18 */ function html_updateprofile() { dbg_deprecated(UserProfile::class .'::show()'); (new dokuwiki\Ui\UserProfile)->show(); } /** * Preprocess edit form data * * @author Andreas Gohr * * @deprecated 2020-07-18 */ function html_edit() { dbg_deprecated(Editor::class .'::show()'); (new dokuwiki\Ui\Editor)->show(); } /** * Display the default edit form * * Is the default action for HTML_EDIT_FORMSELECTION. * * @param array $param * @deprecated 2020-07-18 */ function html_edit_form($param) { dbg_deprecated(Editor::class .'::addTextarea()'); (new dokuwiki\Ui\Editor)->addTextarea($param); } /** * prints some debug info * * @author Andreas Gohr */ function html_debug() { global $conf; global $lang; /** @var AuthPlugin $auth */ global $auth; global $INFO; //remove sensitive data $cnf = $conf; debug_guard($cnf); $nfo = $INFO; debug_guard($nfo); $ses = $_SESSION; debug_guard($ses); print ''; print '

    When reporting bugs please send all the following '; print 'output as a mail to andi@splitbrain.org '; print 'The best way to do this is to save this page in your browser

    '; print '$INFO:
    ';
        print_r($nfo);
        print '
    '; print '$_SERVER:
    ';
        print_r($_SERVER);
        print '
    '; print '$conf:
    ';
        print_r($cnf);
        print '
    '; print 'DOKU_BASE:
    ';
        print DOKU_BASE;
        print '
    '; print 'abs DOKU_BASE:
    ';
        print DOKU_URL;
        print '
    '; print 'rel DOKU_BASE:
    ';
        print dirname($_SERVER['PHP_SELF']).'/';
        print '
    '; print 'PHP Version:
    ';
        print phpversion();
        print '
    '; print 'locale:
    ';
        print setlocale(LC_ALL,0);
        print '
    '; print 'encoding:
    ';
        print $lang['encoding'];
        print '
    '; if ($auth) { print 'Auth backend capabilities:
    ';
            foreach ($auth->getCapabilities() as $cando) {
                print '   '.str_pad($cando,16) .' => '. (int)$auth->canDo($cando) . DOKU_LF;
            }
            print '
    '; } print '$_SESSION:
    ';
        print_r($ses);
        print '
    '; print 'Environment:
    ';
        print_r($_ENV);
        print '
    '; print 'PHP settings:
    ';
        $inis = ini_get_all();
        print_r($inis);
        print '
    '; if (function_exists('apache_get_version')) { $apache = array(); $apache['version'] = apache_get_version(); if (function_exists('apache_get_modules')) { $apache['modules'] = apache_get_modules(); } print 'Apache
    ';
            print_r($apache);
            print '
    '; } print ''; } /** * Form to request a new password for an existing account * * @author Benoit Chesneau * @author Andreas Gohr * @deprecated 2020-07-18 */ function html_resendpwd() { dbg_deprecated(UserResendPwd::class .'::show()'); (new dokuwiki\Ui\UserResendPwd)->show(); } /** * Return the TOC rendered to XHTML * * @author Andreas Gohr * * @param array $toc * @return string html */ function html_TOC($toc) { if (!count($toc)) return ''; global $lang; $out = ''.DOKU_LF; $out .= '
    '.DOKU_LF; $out .= '

    '; $out .= $lang['toc']; $out .= '

    '.DOKU_LF; $out .= '
    '.DOKU_LF; $out .= html_buildlist($toc, 'toc', 'html_list_toc', null, true); $out .= '
    '.DOKU_LF.'
    '.DOKU_LF; $out .= ''.DOKU_LF; return $out; } /** * Callback for html_buildlist * * @param array $item * @return string html */ function html_list_toc($item) { if (isset($item['hid'])){ $link = '#'.$item['hid']; } else { $link = $item['link']; } return ''.hsc($item['title']).''; } /** * Helper function to build TOC items * * Returns an array ready to be added to a TOC array * * @param string $link - where to link (if $hash set to '#' it's a local anchor) * @param string $text - what to display in the TOC * @param int $level - nesting level * @param string $hash - is prepended to the given $link, set blank if you want full links * @return array the toc item */ function html_mktocitem($link, $text, $level, $hash='#') { return array( 'link' => $hash.$link, 'title' => $text, 'type' => 'ul', 'level' => $level ); } /** * Output a Doku_Form object. * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT * * @author Tom N Harris * * @param string $name The name of the form * @param Doku_Form $form The form * @return void * @deprecated 2020-07-18 */ function html_form($name, $form) { dbg_deprecated('use dokuwiki\Form\Form instead of Doku_Form'); // Safety check in case the caller forgets. $form->endFieldset(); Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); } /** * Form print function. * Just calls printForm() on the form object. * * @param Doku_Form $form The form * @return void * @deprecated 2020-07-18 */ function html_form_output($form) { dbg_deprecated('use dokuwiki\Form\Form::toHTML()'); $form->printForm(); } /** * Embed a flash object in HTML * * This will create the needed HTML to embed a flash movie in a cross browser * compatble way using valid XHTML * * The parameters $params, $flashvars and $atts need to be associative arrays. * No escaping needs to be done for them. The alternative content *has* to be * escaped because it is used as is. If no alternative content is given * $lang['noflash'] is used. * * @author Andreas Gohr * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml * * @param string $swf - the SWF movie to embed * @param int $width - width of the flash movie in pixels * @param int $height - height of the flash movie in pixels * @param array $params - additional parameters () * @param array $flashvars - parameters to be passed in the flashvar parameter * @param array $atts - additional attributes for the tag * @param string $alt - alternative content (is NOT automatically escaped!) * @return string - the XHTML markup */ function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ global $lang; $out = ''; // prepare the object attributes if(is_null($atts)) $atts = array(); $atts['width'] = (int) $width; $atts['height'] = (int) $height; if(!$atts['width']) $atts['width'] = 425; if(!$atts['height']) $atts['height'] = 350; // add object attributes for standard compliant browsers $std = $atts; $std['type'] = 'application/x-shockwave-flash'; $std['data'] = $swf; // add object attributes for IE $ie = $atts; $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; // open object (with conditional comments) $out .= ''.NL; $out .= ''.NL; $out .= ''.NL; $out .= ''.NL; // print params if(is_array($params)) foreach($params as $key => $val){ $out .= ' '.NL; } // add flashvars if(is_array($flashvars)){ $out .= ' '.NL; } // alternative content if($alt){ $out .= $alt.NL; }else{ $out .= $lang['noflash'].NL; } // finish $out .= ''.NL; $out .= ''.NL; return $out; } /** * Prints HTML code for the given tab structure * * @param array $tabs tab structure * @param string $current_tab the current tab id * @return void */ function html_tabs($tabs, $current_tab = null) { echo '
      '.NL; foreach ($tabs as $id => $tab) { html_tab($tab['href'], $tab['caption'], $id === $current_tab); } echo '
    '.NL; } /** * Prints a single tab * * @author Kate Arzamastseva * @author Adrian Lang * * @param string $href - tab href * @param string $caption - tab caption * @param boolean $selected - is tab selected * @return void */ function html_tab($href, $caption, $selected = false) { $tab = '
  • '; if ($selected) { $tab .= ''; } else { $tab .= ''; } $tab .= hsc($caption) . '' . '
  • '.NL; echo $tab; } /** * Display size change * * @param int $sizechange - size of change in Bytes * @param Doku_Form $form - (optional) form to add elements to * @return void|string */ function html_sizechange($sizechange, $form = null) { if (isset($sizechange)) { $class = 'sizechange'; $value = filesize_h(abs($sizechange)); if ($sizechange > 0) { $class .= ' positive'; $value = '+' . $value; } elseif ($sizechange < 0) { $class .= ' negative'; $value = '-' . $value; } else { $value = '±' . $value; } if (!isset($form)) { return ''.$value.''; } else { // Doku_Form $form->addElement(form_makeOpenTag('span', array('class' => $class))); $form->addElement($value); $form->addElement(form_makeCloseTag('span')); } } }