From 8df3db566a3a937b45ebf11adb90d265e6f5e2d4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:45:02 +0100 Subject: initial checking of customized version 1.0rc9 --- plugins/dokuwiki/inc/html.php | 1290 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1290 insertions(+) create mode 100644 plugins/dokuwiki/inc/html.php (limited to 'plugins/dokuwiki/inc/html.php') diff --git a/plugins/dokuwiki/inc/html.php b/plugins/dokuwiki/inc/html.php new file mode 100644 index 0000000..795e357 --- /dev/null +++ b/plugins/dokuwiki/inc/html.php @@ -0,0 +1,1290 @@ + + */ + + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + + require_once(DOKU_INC.'inc/parserutils.php'); + +/** + * Convenience function to quickly build a wikilink + * + * @author Andreas Gohr + */ +function html_wikilink($id,$name=NULL,$search=''){ + static $xhtml_renderer = NULL; + if(is_null($xhtml_renderer)){ + require_once(DOKU_INC.'inc/parser/xhtml.php'); + $xhtml_renderer = new Doku_Renderer_xhtml(); + } + + return $xhtml_renderer->internallink($id,$name,$search,true); +} + +/** + * Helps building long attribute lists + * + * @author Andreas Gohr + */ +function html_attbuild($attributes){ + $ret = ''; + foreach ( $attributes as $key => $value ) { + $ret .= $key.'="'.formtext($value).'" '; + } + return trim($ret); +} + +/** + * The loginform + * + * @author Andreas Gohr + */ +function html_login(){ + global $lang; + global $conf; + global $ID; + global $auth; + + print p_locale_xhtml('login'); + ?> +
+
+
+ + + +
+
+ + +
+
+ canDo('addUser') && actionOK('register')){ + print '

'; + print $lang['reghere']; + print ': '.$lang['register'].''; + print '

'; + } + + if ($auth->canDo('modPass') && actionOK('resendpwd')) { + print '

'; + print $lang['pwdforget']; + print ': '.$lang['btn_resendpwd'].''; + print '

'; + } + ?> +
+ + */ +function html_secedit_button($matches){ + global $ID; + global $INFO; + + $section = $matches[2]; + $name = $matches[1]; + + $secedit = ''; + $secedit .= '
'; + $secedit .= html_btn('secedit',$ID,'', + array('do' => 'edit', + 'lines' => "$section", + 'rev' => $INFO['lastmod']), + 'post', $name); + $secedit .= '
'; + return $secedit; +} + +/** + * inserts section edit buttons if wanted or removes the markers + * + * @author Andreas Gohr + */ +function html_secedit($text,$show=true){ + global $INFO; + + if($INFO['writable'] && $show && !$INFO['rev']){ + $text = preg_replace_callback('##', + 'html_secedit_button', $text); + }else{ + $text = preg_replace('##','',$text); + } + + return $text; +} + +/** + * Just the back to top button (in its own form) + * + * @author Andreas Gohr + */ +function html_topbtn(){ + global $lang; + + $ret = ''; + $ret = ''; + + return $ret; +} + +/** + * Just the back to media window button in its own form + * + * @author Matthias Grimm + */ +function html_backtomedia_button($params,$akey=''){ + global $conf; + global $lang; + + $ret = '
'; + + reset($params); + while (list($key, $val) = each($params)) { + $ret .= ''; + } + + $ret .= ' + */ +function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){ + global $conf; + global $lang; + + $label = $lang['btn_'.$name]; + + $ret = ''; + $tip = ''; + + //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; + } + + $ret .= '
'; + + if(is_array($params)){ + reset($params); + while (list($key, $val) = each($params)) { + $ret .= ''; + } + } + + if ($tooltip!='') { + $tip = htmlspecialchars($tooltip); + }else{ + $tip = htmlspecialchars($label); + } + + $ret .= ' + */ +function html_show($txt=''){ + global $ID; + global $REV; + global $HIGH; + //disable section editing for old revisions or in preview + if($txt || $REV){ + $secedit = false; + }else{ + $secedit = true; + } + + if ($txt){ + //PreviewHeader + print '
'; + print p_locale_xhtml('preview'); + print '
'; + print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); + print '
'; + print '
'; + + }else{ + if ($REV) print p_locale_xhtml('showrev'); + $html = p_wiki_xhtml($ID,$REV,true); + $html = html_secedit($html,$secedit); + print html_hilight($html,$HIGH); + } +} + +/** + * ask the user about how to handle an exisiting draft + * + * @author Andreas Gohr + */ +function html_draft(){ + global $INFO; + global $ID; + global $lang; + global $conf; + $draft = unserialize(io_readFile($INFO['draft'],false)); + $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); + + echo p_locale_xhtml('draft'); + ?> +
+ +
+ + +
+ + + + + + + */ +function html_search(){ + require_once(DOKU_INC.'inc/search.php'); + require_once(DOKU_INC.'inc/fulltext.php'); + global $conf; + global $QUERY; + global $ID; + global $lang; + + print p_locale_xhtml('searchpage'); + flush(); + + //check if search is restricted to namespace + if(preg_match('/([^@]*)@([^@]*)/',$QUERY,$match)) { + $id = cleanID($match[1]); + if(empty($id)) { + print '
'.$lang['nothingfound'].'
'; + flush(); + return; + } + } else { + $id = cleanID($QUERY); + } + + //show progressbar + print '
'; + print ''; + print "
\n"; + flush(); + + //do quick pagesearch + $data = array(); + + $data = ft_pageLookup($id); + if(count($data)){ + sort($data); + print '
'; + print '

'.$lang['quickhits'].':

'; + print '
    '; + foreach($data as $id){ + print '
  • '; + print html_wikilink(':'.$id,$conf['useheading']?NULL:$id); + print '
  • '; + } + print '
'; + //clear float (see http://www.complexspiral.com/publications/containing-floats/) + print '
 
'; + print '
'; + } + flush(); + + //do fulltext search + $data = ft_pageSearch($QUERY,$poswords); + if(count($data)){ + $num = 1; + foreach($data as $id => $cnt){ + print '
'; + print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords); + print ': '.$cnt.' '.$lang['hits'].'
'; + if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ? + print '
'.ft_snippet($id,$poswords).'
'; + } + print '
'; + flush(); + $num++; + } + }else{ + print '
'.$lang['nothingfound'].'
'; + } + + //hide progressbar + print ''; + flush(); +} + +/** + * Display error on locked pages + * + * @author Andreas Gohr + */ +function html_locked(){ + global $ID; + global $conf; + global $lang; + global $INFO; + + $locktime = filemtime(wikiLockFN($ID)); + $expire = @date($conf['dformat'], $locktime + $conf['locktime'] ); + $min = round(($conf['locktime'] - (time() - $locktime) )/60); + + print p_locale_xhtml('locked'); + print '
    '; + print '
  • '.$lang['lockedby'].': '.$INFO['locked'].'
  • '; + print '
  • '.$lang['lockexpire'].': '.$expire.' ('.$min.' min)
  • '; + print '
'; +} + +/** + * list old revisions + * + * @author Andreas Gohr + * @author Ben Coburn + */ +function html_revisions($first=0){ + global $ID; + global $INFO; + global $conf; + global $lang; + /* we need to get one additionally log entry to be able to + * decide if this is the last page or is there another one. + * see html_recent() + */ + $revisions = getRevisions($ID, $first, $conf['recent']+1); + if(count($revisions)==0 && $first!=0){ + $first=0; + $revisions = getRevisions($ID, $first, $conf['recent']+1);; + } + $hasNext = false; + if (count($revisions)>$conf['recent']) { + $hasNext = true; + array_pop($revisions); // remove extra log entry + } + + $date = @date($conf['dformat'],$INFO['lastmod']); + + print p_locale_xhtml('revisions'); + print ''; + + print ''; + +} + +/** + * display recent changes + * + * @author Andreas Gohr + * @author Matthias Grimm + * @author Ben Coburn + */ +function html_recent($first=0){ + global $conf; + global $lang; + global $ID; + /* we need to get one additionally log entry to be able to + * decide if this is the last page or is there another one. + * This is the cheapest solution to get this information. + */ + $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); + if(count($recents) == 0 && $first != 0){ + $first=0; + $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); + } + $hasNext = false; + if (count($recents)>$conf['recent']) { + $hasNext = true; + array_pop($recents); // remove extra log entry + } + + print p_locale_xhtml('recent'); + print ''; + + print ''; +} + +/** + * Display page index + * + * @author Andreas Gohr + */ +function html_index($ns){ + require_once(DOKU_INC.'inc/search.php'); + global $conf; + global $ID; + $dir = $conf['datadir']; + $ns = cleanID($ns); + #fixme use appropriate function + if(empty($ns)){ + $ns = dirname(str_replace(':','/',$ID)); + if($ns == '.') $ns =''; + } + $ns = utf8_encodeFN(str_replace(':','/',$ns)); + + print p_locale_xhtml('index'); + + $data = array(); + search($data,$conf['datadir'],'search_index',array('ns' => $ns)); + print html_buildlist($data,'idx','html_list_index','html_li_index'); +} + +/** + * Index item formatter + * + * User function for html_buildlist() + * + * @author Andreas Gohr + */ +function html_list_index($item){ + global $ID; + $ret = ''; + $base = ':'.$item['id']; + $base = substr($base,strrpos($base,':')+1); + if($item['type']=='d'){ + $ret .= ''; + $ret .= $base; + $ret .= ''; + }else{ + $ret .= html_wikilink(':'.$item['id']); + } + return $ret; +} + +/** + * Index List item + * + * This user function is used in html_build_lidt to build the + *
  • tags for namespaces when displaying the page index + * it gives different classes to opened or closed "folders" + * + * @author Andreas Gohr + */ +function html_li_index($item){ + if($item['type'] == "f"){ + return '
  • '; + }elseif($item['open']){ + return '
  • '; + }else{ + return '
  • '; + } +} + +/** + * Default List item + * + * @author Andreas Gohr + */ +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 + */ +function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ + $level = 0; + $opens = 0; + $ret = ''; + + foreach ($data as $item){ + + if( $item['level'] > $level ){ + //open new list + for($i=0; $i<($item['level'] - $level); $i++){ + if ($i) $ret .= "
  • \n"; + $ret .= "\n
      \n"; + } + }elseif( $item['level'] < $level ){ + //close last item + $ret .= "\n"; + for ($i=0; $i<($level - $item['level']); $i++){ + //close higher lists + $ret .= "
    \n
  • \n"; + } + }else{ + //close last item + $ret .= "\n"; + } + + //remember current level + $level = $item['level']; + + //print item + if(is_array($lifunc)){ + $ret .= $lifunc[0]->$lifunc[1]($item); //user object method + }else{ + $ret .= $lifunc($item); //user function + } + $ret .= '
    '; + if(is_array($func)){ + $ret .= $func[0]->$func[1]($item); //user object method + }else{ + $ret .= $func($item); //user function + } + $ret .= '
    '; + } + + //close remaining items and lists + for ($i=0; $i < $level; $i++){ + $ret .= "\n"; + } + + return $ret; +} + +/** + * display backlinks + * + * @author Andreas Gohr + */ +function html_backlinks(){ + require_once(DOKU_INC.'inc/fulltext.php'); + global $ID; + global $conf; + + print p_locale_xhtml('backlinks'); + + $data = ft_backlinks($ID); + + print '
      '; + foreach($data as $blink){ + print '
    • '; + print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink); + print '
    • '; + } + print '
    '; +} + +/** + * show diff + * + * @author Andreas Gohr + */ +function html_diff($text='',$intro=true){ + require_once(DOKU_INC.'inc/DifferenceEngine.php'); + global $ID; + global $REV; + global $lang; + global $conf; + + if($text){ + $df = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,''))), + explode("\n",htmlspecialchars(cleanText($text)))); + $left = ''. + $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).''. + $lang['current']; + $right = $lang['yours']; + }else{ + if($REV){ + $r = $REV; + }else{ + //use last revision if none given + $revs = getRevisions($ID, 0, 1); + $r = $revs[0]; + } + + if($r){ + $df = new Diff(explode("\n",htmlspecialchars(rawWiki($ID,$r))), + explode("\n",htmlspecialchars(rawWiki($ID,'')))); + $left = ''. + $ID.' '.date($conf['dformat'],$r).''; + }else{ + $df = new Diff(array(''), + explode("\n",htmlspecialchars(rawWiki($ID,'')))); + $left = ''. + $ID.''; + } + $right = ''. + $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).' '. + $lang['current']; + } + $tdf = new TableDiffFormatter(); + if($intro) print p_locale_xhtml('diff'); + ?> + + + + + + format($df)?> +
    + + + +
    + + */ +function html_conflict($text,$summary){ + global $ID; + global $lang; + + print p_locale_xhtml('conflict'); + ?> +
    +
    + + + + + + +
    +
    +



    + + */ +function html_msgarea(){ + global $MSG; + + if(!isset($MSG)) return; + + foreach($MSG as $msg){ + print '
    '; + print $msg['msg']; + print '
    '; + } +} + +/** + * Prints the registration form + * + * @author Andreas Gohr + */ +function html_register(){ + global $lang; + global $conf; + global $ID; + + print p_locale_xhtml('register'); +?> +
    +
    +
    + + + + +
    + + +
    +
    + + +
    +
    + +
    +
    +
    + + * @author Andreas Gohr + */ +function html_updateprofile(){ + global $lang; + global $conf; + global $ID; + global $INFO; + global $auth; + + print p_locale_xhtml('updateprofile'); + + if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; + if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; +?> +
    +
    +
    + + + + +
    +
    +

    + + canDo('modPass')) { ?> +
    +
    + + + +
    +
    + + + + +
    +
    +
    + + */ +function html_edit($text=null,$include='edit'){ //FIXME: include needed? + global $ID; + global $REV; + global $DATE; + global $RANGE; + global $PRE; + global $SUF; + global $INFO; + global $SUM; + global $lang; + global $conf; + + //set summary default + if(!$SUM){ + if($REV){ + $SUM = $lang['restored']; + }elseif(!$INFO['exists']){ + $SUM = $lang['created']; + } + } + + //no text? Load it! + if(!isset($text)){ + $pr = false; //no preview mode + if($INFO['exists']){ + if($RANGE){ + list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV); + }else{ + $text = rawWiki($ID,$REV); + } + }else{ + //try to load a pagetemplate + $data = array($ID); + $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true); + } + }else{ + $pr = true; //preview mode + } + + $wr = $INFO['writable']; + if($wr){ + if ($REV) print p_locale_xhtml('editrev'); + print p_locale_xhtml($include); + $ro=false; + }else{ + // check pseudo action 'source' + if(!actionOK('source')){ + msg('Command disabled: source',-1); + return; + } + print p_locale_xhtml('read'); + $ro='readonly="readonly"'; + } + if(!$DATE) $DATE = $INFO['lastmod']; + + +?> +
    + +
    +
    +
    + + + + +
    + +
    +
    + + +
    + + + + + +
    + + + +
    +
    + +
    + + + +
    + + +
    + + + +
    + +
    +
    +
    + + */ +function html_minoredit(){ + global $conf; + global $lang; + // minor edits are for logged in users only + if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ + return; + } + + $p = array(); + $p['name'] = 'minor'; + $p['type'] = 'checkbox'; + $p['id'] = 'minoredit'; + $p['tabindex'] = 3; + $p['value'] = '1'; + if(!empty($_REQUEST['minor'])) $p['checked']='checked'; + $att = buildAttributes($p); + + print ''; + print ""; + print ''; + print ''; +} + +/** + * prints some debug info + * + * @author Andreas Gohr + */ +function html_debug(){ + global $conf; + global $lang; + global $auth; + global $INFO; + + //remove sensitive data + $cnf = $conf; + $cnf['auth']='***'; + $cnf['notify']='***'; + $cnf['ftp']='***'; + $nfo = $INFO; + $nfo['userinfo'] = '***'; + $ses = $_SESSION; + $ses[$conf['title']]['auth'] = '***'; + + 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:
    ';
    +    print_r($auth->cando);
    +    print '
    '; + } + + print '$_SESSION:
    ';
    +  print_r($ses);
    +  print '
    '; + + print 'Environment:
    ';
    +  print_r($_ENV);
    +  print '
    '; + + print 'PHP settings:
    ';
    +  $inis = ini_get_all();
    +  print_r($inis);
    +  print '
    '; + + print ''; +} + +function html_admin(){ + global $ID; + global $lang; + global $conf; + + print p_locale_xhtml('admin'); + + // build menu of admin functions from the plugins that handle them + $pluginlist = plugin_list('admin'); + $menu = array(); + foreach ($pluginlist as $p) { + if($obj =& plugin_load('admin',$p) === NULL) continue; + $menu[] = array('plugin' => $p, + 'prompt' => $obj->getMenuText($conf['lang']), + 'sort' => $obj->getMenuSort() + ); + } + + usort($menu, 'p_sort_modes'); + + // output the menu + ptln('
      '); + + foreach ($menu as $item) { + if (!$item['prompt']) continue; + ptln('
    • '); + } + + ptln('
    '); +} + +/** + * Form to request a new password for an existing account + * + * @author Benoit Chesneau + */ +function html_resendpwd() { + global $lang; + global $conf; + global $ID; + + print p_locale_xhtml('resendpwd'); +?> +
    +
    +
    +
    + + + +
    + +
    +
    +
    +