diff options
Diffstat (limited to 'inc/html.php')
-rw-r--r-- | inc/html.php | 480 |
1 files changed, 368 insertions, 112 deletions
diff --git a/inc/html.php b/inc/html.php index fcec29670..57a22b880 100644 --- a/inc/html.php +++ b/inc/html.php @@ -19,6 +19,7 @@ if(!defined('NL')) define('NL',"\n"); * @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'); @@ -64,6 +65,20 @@ function html_login(){ print '</div>'.NL; } + +/** + * Denied page content + * + * @return string html + */ +function html_denied() { + print p_locale_xhtml('denied'); + + if(!$_SERVER['REMOTE_USER']){ + html_login(); + } +} + /** * inserts section edit buttons if wanted or removes the markers * @@ -414,20 +429,23 @@ function html_revisions($first=0, $media_id = false){ global $conf; global $lang; $id = $ID; + if ($media_id) { + $id = $media_id; + $changelog = new MediaChangeLog($id); + } else { + $changelog = new PageChangeLog($id); + } + /* we need to get one additional log entry to be able to * decide if this is the last page or is there another one. * see html_recent() */ - if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); - else { - $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); - $id = $media_id; - } + + $revisions = $changelog->getRevisions($first, $conf['recent']+1); if(count($revisions)==0 && $first!=0){ $first=0; - if (!$media_id) $revisions = getRevisions($ID, $first, $conf['recent']+1); - else $revisions = getRevisions($media_id, $first, $conf['recent']+1, 8192, true); + $revisions = $changelog->getRevisions($first, $conf['recent']+1); } $hasNext = false; if (count($revisions)>$conf['recent']) { @@ -486,15 +504,18 @@ function html_revisions($first=0, $media_id = false){ $form->addElement(form_makeCloseTag('span')); } + $changelog->setChunkSize(1024); + $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); - if (!$media_id) $editor = $INFO['editor']; - else { - $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); - if($revinfo['user']){ + if($media_id) { + $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id)))); + if($revinfo['user']) { $editor = $revinfo['user']; - }else{ + } else { $editor = $revinfo['ip']; } + } else { + $editor = $INFO['editor']; } $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor)); $form->addElement(form_makeCloseTag('span')); @@ -509,12 +530,11 @@ function html_revisions($first=0, $media_id = false){ foreach($revisions as $rev){ $date = dformat($rev); - if (!$media_id) { - $info = getRevisionInfo($id,$rev,true); - $exists = page_exists($id,$rev); - } else { - $info = getRevisionInfo($id,$rev,true,true); - $exists = @file_exists(mediaFN($id,$rev)); + $info = $changelog->getRevisionInfo($rev); + if($media_id) { + $exists = @file_exists(mediaFN($id, $rev)); + } else { + $exists = page_exists($id, $rev); } if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) @@ -691,7 +711,7 @@ function html_recent($first=0, $show_changes='both'){ $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); - if ($recent['media']) { + if (!empty($recent['media'])) { $form->addElement(media_printicon($recent['id'])); } else { $icon = DOKU_BASE.'lib/images/fileicons/file.png'; @@ -705,7 +725,7 @@ function html_recent($first=0, $show_changes='both'){ $diff = false; $href = ''; - if ($recent['media']) { + if (!empty($recent['media'])) { $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id']))); if ($diff) { $href = media_managerURL(array('tab_details' => 'history', @@ -715,7 +735,7 @@ function html_recent($first=0, $show_changes='both'){ $href = wl($recent['id'],"do=diff", false, '&'); } - if ($recent['media'] && !$diff) { + if (!empty($recent['media']) && !$diff) { $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); } else { $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); @@ -729,7 +749,7 @@ function html_recent($first=0, $show_changes='both'){ $form->addElement(form_makeCloseTag('a')); } - if ($recent['media']) { + if (!empty($recent['media'])) { $href = media_managerURL(array('tab_details' => 'history', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); } else { @@ -745,7 +765,7 @@ function html_recent($first=0, $show_changes='both'){ ))); $form->addElement(form_makeCloseTag('a')); - if ($recent['media']) { + if (!empty($recent['media'])) { $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2'; $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href))); @@ -1008,10 +1028,15 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa $ml_or_wl = $media ? 'ml' : 'wl'; $l_minor = $r_minor = ''; + if($media) { + $changelog = new MediaChangeLog($id); + } else { + $changelog = new PageChangeLog($id); + } if(!$l_rev){ $l_head = '—'; }else{ - $l_info = getRevisionInfo($id,$l_rev,true, $media); + $l_info = $changelog->getRevisionInfo($l_rev); if($l_info['user']){ $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>'; if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>'; @@ -1029,7 +1054,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa } if($r_rev){ - $r_info = getRevisionInfo($id,$r_rev,true, $media); + $r_info = $changelog->getRevisionInfo($r_rev); if($r_info['user']){ $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>'; if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>'; @@ -1045,7 +1070,7 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa $r_head_title.'</a></bdi>'. $head_separator.$r_user.' '.$r_sum; }elseif($_rev = @filemtime($media_or_wikiFN($id))){ - $_info = getRevisionInfo($id,$_rev,true, $media); + $_info = $changelog->getRevisionInfo($_rev); if($_info['user']){ $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>'; if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>'; @@ -1069,162 +1094,386 @@ function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = fa } /** - * show diff + * Show diff + * between current page version and provided $text + * or between the revisions provided via GET or POST * * @author Andreas Gohr <andi@splitbrain.org> - * @param string $text - 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) + * @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) */ -function html_diff($text='',$intro=true,$type=null){ +function html_diff($text = '', $intro = true, $type = null) { global $ID; global $REV; global $lang; global $INPUT; global $INFO; + $pagelog = new PageChangeLog($ID); + /* + * Determine diff type + */ if(!$type) { $type = $INPUT->str('difftype'); - if (empty($type)) { + if(empty($type)) { $type = get_doku_pref('difftype', $type); - if (empty($type) && $INFO['ismobile']) { + if(empty($type) && $INFO['ismobile']) { $type = 'inline'; } } } if($type != 'inline') $type = 'sidebyside'; + /* + * Determine requested revision(s) + */ // we're trying to be clever here, revisions to compare can be either // given as rev and rev2 parameters, with rev2 being optional. Or in an // array in rev2. $rev1 = $REV; $rev2 = $INPUT->ref('rev2'); - if(is_array($rev2)){ + if(is_array($rev2)) { $rev1 = (int) $rev2[0]; $rev2 = (int) $rev2[1]; - if(!$rev1){ + if(!$rev1) { $rev1 = $rev2; unset($rev2); } - }else{ + } else { $rev2 = $INPUT->int('rev2'); } + /* + * Determine left and right revision, its texts and the header + */ $r_minor = ''; $l_minor = ''; - if($text){ // compare text to the most current revision - $l_rev = ''; - $l_text = rawWiki($ID,''); - $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. - $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. + if($text) { // compare text to the most current revision + $l_rev = ''; + $l_text = rawWiki($ID, ''); + $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . + $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . $lang['current']; - $r_rev = ''; - $r_text = cleanText($text); - $r_head = $lang['yours']; - }else{ - if($rev1 && isset($rev2) && $rev2){ // two specific revisions wanted + $r_rev = ''; + $r_text = cleanText($text); + $r_head = $lang['yours']; + } else { + if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted // make sure order is correct (older on the left) - if($rev1 < $rev2){ + if($rev1 < $rev2) { $l_rev = $rev1; $r_rev = $rev2; - }else{ + } else { $l_rev = $rev2; $r_rev = $rev1; } - }elseif($rev1){ // single revision given, compare to current + } elseif($rev1) { // single revision given, compare to current $r_rev = ''; $l_rev = $rev1; - }else{ // no revision was given, compare previous to current + } else { // no revision was given, compare previous to current $r_rev = ''; - $revs = getRevisions($ID, 0, 1); + $revs = $pagelog->getRevisions(0, 1); $l_rev = $revs[0]; $REV = $l_rev; // store revision back in $REV } // when both revisions are empty then the page was created just now - if(!$l_rev && !$r_rev){ + if(!$l_rev && !$r_rev) { $l_text = ''; - }else{ - $l_text = rawWiki($ID,$l_rev); + } else { + $l_text = rawWiki($ID, $l_rev); } - $r_text = rawWiki($ID,$r_rev); + $r_text = rawWiki($ID, $r_rev); list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); } - $df = new Diff(explode("\n",$l_text),explode("\n",$r_text)); + /* + * Build navigation + */ + $l_nav = ''; + $r_nav = ''; + if(!$text) { + list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev); + } + /* + * Create diff object and the formatter + */ + $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); - if($type == 'inline'){ - $tdf = new InlineDiffFormatter(); + if($type == 'inline') { + $diffformatter = new InlineDiffFormatter(); } else { - $tdf = new TableDiffFormatter(); + $diffformatter = new TableDiffFormatter(); } - + /* + * Display intro + */ if($intro) print p_locale_xhtml('diff'); - if (!$text) { - ptln('<div class="diffoptions">'); - - $form = new Doku_Form(array('action'=>wl())); - $form->addHidden('id',$ID); - $form->addHidden('rev2[0]',$l_rev); - $form->addHidden('rev2[1]',$r_rev); - $form->addHidden('do','diff'); - $form->addElement(form_makeListboxField( - 'difftype', - array( - 'sidebyside' => $lang['diff_side'], - 'inline' => $lang['diff_inline']), - $type, - $lang['diff_type'], - '','', - array('class'=>'quickselect'))); - $form->addElement(form_makeButton('submit', 'diff','Go')); + /* + * Display type and exact reference + */ + if(!$text) { + ptln('<div class="diffoptions group">'); + + + $form = new Doku_Form(array('action' => wl())); + $form->addHidden('id', $ID); + $form->addHidden('rev2[0]', $l_rev); + $form->addHidden('rev2[1]', $r_rev); + $form->addHidden('do', 'diff'); + $form->addElement( + form_makeListboxField( + 'difftype', + array( + 'sidebyside' => $lang['diff_side'], + 'inline' => $lang['diff_inline'] + ), + $type, + $lang['diff_type'], + '', '', + array('class' => 'quickselect') + ) + ); + $form->addElement(form_makeButton('submit', 'diff', 'Go')); $form->printForm(); - $diffurl = wl($ID, array( - 'do' => 'diff', - 'rev2[0]' => $l_rev, - 'rev2[1]' => $r_rev ? $r_rev : $INFO['currentrev'], // link to exactly this view FS#2835 - 'difftype' => $type, - )); - ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>'); - ptln('</div>'); + ptln('<p>'); + // link to exactly this view FS#2835 + echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); + ptln('</p>'); + + ptln('</div>'); // .diffoptions } + + /* + * Display diff view table + */ ?> <div class="table"> - <table class="diff diff_<?php echo $type?>"> - <?php if ($type == 'inline') { ?> - <tr> - <th class="diff-lineheader">-</th><th <?php echo $l_minor?>> - <?php echo $l_head?> - </th> - </tr> - <tr> - <th class="diff-lineheader">+</th><th <?php echo $r_minor?>> - <?php echo $r_head?> - </th> - </tr> - <?php } else { ?> - <tr> - <th colspan="2" <?php echo $l_minor?>> - <?php echo $l_head?> - </th> - <th colspan="2" <?php echo $r_minor?>> - <?php echo $r_head?> - </th> - </tr> - <?php } - echo html_insert_softbreaks($tdf->format($df)); ?> + <table class="diff diff_<?php echo $type ?>"> + + <?php + //navigation and header + if($type == 'inline') { + if(!$text) { ?> + <tr> + <td class="diff-lineheader">-</td> + <td class="diffnav"><?php echo $l_nav ?></td> + </tr> + <tr> + <th class="diff-lineheader">-</th> + <th <?php echo $l_minor ?>> + <?php echo $l_head ?> + </th> + </tr> + <?php } ?> + <tr> + <td class="diff-lineheader">+</td> + <td class="diffnav"><?php echo $r_nav ?></td> + </tr> + <tr> + <th class="diff-lineheader">+</th> + <th <?php echo $r_minor ?>> + <?php echo $r_head ?> + </th> + </tr> + <?php } else { + if(!$text) { ?> + <tr> + <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> + <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> + </tr> + <?php } ?> + <tr> + <th colspan="2" <?php echo $l_minor ?>> + <?php echo $l_head ?> + </th> + <th colspan="2" <?php echo $r_minor ?>> + <?php echo $r_head ?> + </th> + </tr> + <?php } + + //diff view + echo html_insert_softbreaks($diffformatter->format($diff)); ?> + </table> </div> - <?php +<?php } +/** + * 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 + */ +function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { + global $INFO, $ID; + + // last timestamp is not in changelog, retrieve timestamp from metadata + // note: when page is removed, the metadata timestamp is zero + $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; + + //retrieve revisions with additional info + list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev); + $l_revisions = array(); + if(!$l_rev) { + $l_revisions[0] = array(0, "", false); //no left revision given, add dummy + } + foreach($l_revs as $rev) { + $info = $pagelog->getRevisionInfo($rev); + $l_revisions[$rev] = array( + $rev, + dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'], + $r_rev ? $rev >= $r_rev : false //disable? + ); + } + $r_revisions = array(); + if(!$r_rev) { + $r_revisions[0] = array(0, "", false); //no right revision given, add dummy + } + foreach($r_revs as $rev) { + $info = $pagelog->getRevisionInfo($rev); + $r_revisions[$rev] = array( + $rev, + dformat($info['date']) . ' ' . editorinfo($info['user']) . ' ' . $info['sum'], + $rev <= $l_rev //disable? + ); + } + + //determine previous/next revisions + $l_index = array_search($l_rev, $l_revs); + $l_prev = $l_revs[$l_index + 1]; + $l_next = $l_revs[$l_index - 1]; + if($r_rev) { + $r_index = array_search($r_rev, $r_revs); + $r_prev = $r_revs[$r_index + 1]; + $r_next = $r_revs[$r_index - 1]; + } else { + //removed page + if($l_next) { + $r_prev = $r_revs[0]; + } else { + $r_prev = null; + } + $r_next = null; + } + + /* + * Left side: + */ + $l_nav = ''; + //move back + if($l_prev) { + $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev); + $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev); + } + //dropdown + $form = new Doku_Form(array('action' => wl())); + $form->addHidden('id', $ID); + $form->addHidden('difftype', $type); + $form->addHidden('rev2[1]', $r_rev); + $form->addHidden('do', 'diff'); + $form->addElement( + form_makeListboxField( + 'rev2[0]', + $l_revisions, + $l_rev, + '', '', '', + array('class' => 'quickselect') + ) + ); + $form->addElement(form_makeButton('submit', 'diff', 'Go')); + $l_nav .= $form->getForm(); + //move forward + if($l_next && ($l_next < $r_rev || !$r_rev)) { + $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev); + } + + /* + * Right side: + */ + $r_nav = ''; + //move back + if($l_rev < $r_prev) { + $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev); + } + //dropdown + $form = new Doku_Form(array('action' => wl())); + $form->addHidden('id', $ID); + $form->addHidden('rev2[0]', $l_rev); + $form->addHidden('difftype', $type); + $form->addHidden('do', 'diff'); + $form->addElement( + form_makeListboxField( + 'rev2[1]', + $r_revisions, + $r_rev, + '', '', '', + array('class' => 'quickselect') + ) + ); + $form->addElement(form_makeButton('submit', 'diff', 'Go')); + $r_nav .= $form->getForm(); + //move forward + if($r_next) { + if($pagelog->isCurrentRevision($r_next)) { + $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page + } else { + $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next); + } + $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next); + } + return array($l_nav, $r_nav); +} + +/** + * 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 + */ +function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { + global $ID, $lang; + if(!$rrev) { + $urlparam = array( + 'do' => 'diff', + 'rev' => $lrev, + 'difftype' => $difftype, + ); + } else { + $urlparam = array( + 'do' => 'diff', + 'rev2[0]' => $lrev, + 'rev2[1]' => $rrev, + 'difftype' => $difftype, + ); + } + return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' . + '<span>' . $lang[$linktype] . '</span>' . + '</a>' . "\n"; +} + +/** + * Insert soft breaks in diff html + * + * @param $diffhtml + * @return string + */ function html_insert_softbreaks($diffhtml) { // search the diff html string for both: // - html tags, so these can be ignored @@ -1232,6 +1481,12 @@ function html_insert_softbreaks($diffhtml) { return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml); } +/** + * callback which adds softbreaks + * + * @param array $match array with first the complete match + * @return string the replacement + */ function html_softbreak_callback($match){ // if match is an html tag, return it intact if ($match[0]{0} == '<') return $match[0]; @@ -1343,7 +1598,7 @@ function html_updateprofile(){ global $conf; global $INPUT; global $INFO; - /** @var auth_basic $auth */ + /** @var DokuWiki_Auth_Plugin $auth */ global $auth; print p_locale_xhtml('updateprofile'); @@ -1517,6 +1772,7 @@ function html_edit(){ * Display the default edit form * * Is the default action for HTML_EDIT_FORMSELECTION. + * @param mixed[] $param */ function html_edit_form($param) { global $TEXT; @@ -1559,7 +1815,7 @@ function html_minoredit(){ function html_debug(){ global $conf; global $lang; - /** @var auth_basic $auth */ + /** @var DokuWiki_Auth_Plugin $auth */ global $auth; global $INFO; |