Ejemplo n.º 1
0
/**
 * 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)
 */
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)) {
            $type = get_doku_pref('difftype', $type);
            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)) {
        $rev1 = (int) $rev2[0];
        $rev2 = (int) $rev2[1];
        if (!$rev1) {
            $rev1 = $rev2;
            unset($rev2);
        }
    } 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> ' . $lang['current'];
        $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) {
                $l_rev = $rev1;
                $r_rev = $rev2;
            } else {
                $l_rev = $rev2;
                $r_rev = $rev1;
            }
        } elseif ($rev1) {
            // single revision given, compare to current
            $r_rev = '';
            $l_rev = $rev1;
        } else {
            // no revision was given, compare previous to current
            $r_rev = '';
            $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) {
            $l_text = '';
        } else {
            $l_text = rawWiki($ID, $l_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');
    }
    /*
     * 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') {
        $diffformatter = new InlineDiffFormatter();
    } else {
        $diffformatter = new TableDiffFormatter();
    }
    /*
     * Display intro
     */
    if ($intro) {
        print p_locale_xhtml('diff');
    }
    /*
     * 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();
        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 
    //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 
}
Ejemplo n.º 2
0
    private function html_diff($frame, $device, $l_text = '', $r_text = '', $show = 1)
    {
        global $ID, $REV, $lang, $INPUT, $INFO;
        /*
         * Determine diff type
         */
        if ($INFO['ismobile']) {
            $type = 'inline';
        } else {
            $type = 'sidebyside';
        }
        /*
         * Create diff object and the formatter
         */
        require_once DOKU_INC . 'inc/DifferenceEngine.php';
        $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
        if ($type == 'inline') {
            $diffformatter = new InlineDiffFormatter();
        } else {
            $diffformatter = new TableDiffFormatter();
        }
        if ($show == 1) {
            $class = ' show';
        }
        /*
         * Display diff view table
         */
        ?>
        <div class="table frame-<?php 
        echo $frame;
        ?>
-diff<?php 
        echo $class;
        ?>
" data-frame="<?php 
        echo $frame;
        ?>
"
             data-device="<?php 
        echo $device;
        ?>
">
            <table class="diff diff_<?php 
        echo $type;
        ?>
">

                <?php 
        //navigation and header
        if ($type == 'inline') {
            ?>
                    <tr>
                        <td class="diff-lineheader">-</td>
                        <td>Current Version</td>
                    </tr>
                    <tr>
                        <th class="diff-lineheader">+</th>
                        <th><?php 
            echo $this->devices[$device]['name'];
            ?>
's Version</th>
                    </tr>
                <?php 
        } else {
            ?>
                    <tr>
                        <th colspan="2">Current Version</th>
                        <th colspan="2"><?php 
            echo $this->devices[$device]['name'];
            ?>
's Version</th>
                    </tr>
                <?php 
        }
        //diff view
        echo html_insert_softbreaks($diffformatter->format($diff));
        ?>

            </table>
            <form class="mode-action">
                <input type="hidden" name="frame" value="<?php 
        echo $frame;
        ?>
">
                <input type="hidden" name="device" value="<?php 
        echo $device;
        ?>
">
                <textarea name="content" class="door43gitmerge-content" rows="5"
                          cols="50"><?php 
        echo htmlspecialchars($r_text);
        ?>
</textarea>

                <div class="door43gitmerge-actions">
                <span class="door43gitmerge-action-interface">
                    <input name="do[door43gitmerge-dismiss]" type="submit" class="door43gitmerge-dismiss"
                           value="<?php 
        echo $this->getLang('dismiss');
        ?>
" data-page="<?php 
        echo $ID;
        ?>
"
                           data-frame="<?php 
        echo $frame;
        ?>
" data-device="<?php 
        echo $device;
        ?>
"
                           data-action="dismiss">
                    <input type="button" class="door43gitmerge-edit"
                           value="<?php 
        echo $this->getLang('edit_and_apply');
        ?>
" data-frame="<?php 
        echo $frame;
        ?>
"
                           data-device="<?php 
        echo $device;
        ?>
">
                    <input name="do[door43gitmerge-apply]" type="submit" class="door43gitmerge-apply"
                           value="<?php 
        echo $this->getLang('apply');
        ?>
" data-page="<?php 
        echo $ID;
        ?>
"
                           data-frame="<?php 
        echo $frame;
        ?>
" data-device="<?php 
        echo $device;
        ?>
" data-action="apply">
                </span>
                <span class="door43gitmerge-edit-interface">
                    <input type="button" class="door43gitmerge-cancel" value="<?php 
        echo $this->getLang('cancel');
        ?>
"
                           data-frame="<?php 
        echo $frame;
        ?>
" data-device="<?php 
        echo $device;
        ?>
">
                    <input type="reset" value="<?php 
        echo $this->getLang('reset');
        ?>
">
                    <input name="do[door43gitmerge-apply-edited]" type="submit" class="door43gitmerge-apply-edited"
                           value="<?php 
        echo $this->getLang('apply');
        ?>
" data-page="<?php 
        echo $ID;
        ?>
"
                           data-frame="<?php 
        echo $frame;
        ?>
" data-device="<?php 
        echo $device;
        ?>
"
                           data-action="apply-edited">
                </span>
                </div>
            </form>
        </div>
        <?php 
    }
Ejemplo n.º 3
0
/**
 * show diff
 *
 * @author Andreas Gohr <*****@*****.**>
 * @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)
 */
function html_diff($text = '', $intro = true, $type = null)
{
    global $ID;
    global $REV;
    global $lang;
    global $INPUT;
    global $INFO;
    if (!$type) {
        $type = $INPUT->str('difftype');
        if (empty($type)) {
            $type = get_doku_pref('difftype', $type);
            if (empty($type) && $INFO['ismobile']) {
                $type = 'inline';
            }
        }
    }
    if ($type != 'inline') {
        $type = 'sidebyside';
    }
    // 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)) {
        $rev1 = (int) $rev2[0];
        $rev2 = (int) $rev2[1];
        if (!$rev1) {
            $rev1 = $rev2;
            unset($rev2);
        }
    } else {
        $rev2 = $INPUT->int('rev2');
    }
    $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> ' . $lang['current'];
        $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) {
                $l_rev = $rev1;
                $r_rev = $rev2;
            } else {
                $l_rev = $rev2;
                $r_rev = $rev1;
            }
        } elseif ($rev1) {
            // single revision given, compare to current
            $r_rev = '';
            $l_rev = $rev1;
        } else {
            // no revision was given, compare previous to current
            $r_rev = '';
            $revs = getRevisions($ID, 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) {
            $l_text = '';
        } else {
            $l_text = rawWiki($ID, $l_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));
    if ($type == 'inline') {
        $tdf = new InlineDiffFormatter();
    } else {
        $tdf = new TableDiffFormatter();
    }
    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'));
        $form->printForm();
        $diffurl = wl($ID, array('do' => 'diff', 'rev2[0]' => $l_rev, 'rev2[1]' => $r_rev, 'difftype' => $type));
        ptln('<p><a class="wikilink1" href="' . $diffurl . '">' . $lang['difflink'] . '</a></p>');
        ptln('</div>');
    }
    ?>
    <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>
    </div>
    <?php 
}