Пример #1
0
 protected function showDiff($str1, $str2)
 {
     $diff = new Diff(explode("\n", $str1), explode("\n", $str2));
     if ($diff->isEmpty()) {
         $this->fail("No difference ???");
     } else {
         $fmt = new UnifiedDiffFormatter();
         $this->fail($fmt->format($diff));
     }
 }
 function paintDiff($stringA, $stringB)
 {
     $diff = new Diff(explode("\n", $stringA), explode("\n", $stringB));
     if ($diff->isEmpty()) {
         $this->_response->addContent('<p>Erreur diff : bizarre, aucune différence d\'aprés la difflib...</p>');
     } else {
         $fmt = new UnifiedDiffFormatter();
         $this->_response->addContent($fmt->format($diff));
     }
 }
Пример #3
0
 function paintDiff($stringA, $stringB)
 {
     $diff = new Diff(explode("\n", $stringA), explode("\n", $stringB));
     if ($diff->isEmpty()) {
         echo '<p>Erreur diff : bizarre, aucune différence d\'aprés la difflib...</p>';
     } else {
         $fmt = new HtmlUnifiedDiffFormatter();
         echo $fmt->format($diff);
     }
 }
Пример #4
0
/**
 * function plugin : show a diff between two string
 *
 * @param jTpl $tpl template engine
 * @param string $str1 the first string
 * @param string $str2 the second string
 * @param array $options contains : 'nodiffmsg' message when no diff found ; 'version1' ; 'version2' to be compared ; 'type' of display
 */
function jtpl_function_html_diff($tpl, $str1, $str2, $options = array())
{
    $nodiffmsg = 'Pas de différence';
    $version1 = '';
    $version2 = '';
    $type = 'unifieddiff';
    $supported_output_format = array('unifieddiff', 'inlinetable', 'sidebyside');
    if (!is_array($options)) {
        $nodiffmsg = $options;
    } else {
        if (array_key_exists('nodiffmsg', $options)) {
            $nodiffmsg = $options['nodiffmsg'];
        }
        if (array_key_exists('version1', $options)) {
            $version1 = $options['version1'];
        }
        if (array_key_exists('version2', $options)) {
            $version2 = $options['version2'];
        }
        //the type of ouput format of the diff
        //1) type option exists ?
        if (array_key_exists('type', $options)) {
            $type = $options['type'];
        }
        //2) is it a supported type ouput format ?
        if (!in_array($type, $supported_output_format)) {
            $type = 'unifieddiff';
        }
    }
    $diff = new Diff(explode("\n", $str1), explode("\n", $str2));
    if ($diff->isEmpty()) {
        echo $nodiffmsg;
    } else {
        switch ($type) {
            case 'unifieddiff':
                $fmt = new HtmlUnifiedDiffFormatter();
                break;
            case 'inlinetable':
                require_once LIB_PATH . 'diff/difftableformatter.php';
                $fmt = new HtmlInlineTableDiffFormatter($version1, $version2);
                break;
            case 'sidebyside':
                require_once LIB_PATH . 'diff/difftableformatter.php';
                $fmt = new HtmlTableDiffFormatter($version1, $version2);
                break;
        }
        echo $fmt->format($diff);
    }
}
Пример #5
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (is_array($versions)) {
         // Version selection from pageinfo.php display:
         rsort($versions);
         list($version, $previous) = $versions;
     }
     // abort if page doesn't exist
     $page = $request->getPage($pagename);
     $current = $page->getCurrentRevision();
     if ($current->getVersion() < 1) {
         $html = HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown'))));
         return $html;
         //early return
     }
     if ($version) {
         if (!($new = $page->getRevision($version))) {
             NoSuchRevision($request, $page, $version);
         }
         $new_version = fmt("version %d", $version);
     } else {
         $new = $current;
         $new_version = _("current version");
     }
     if (preg_match('/^\\d+$/', $previous)) {
         if (!($old = $page->getRevision($previous))) {
             NoSuchRevision($request, $page, $previous);
         }
         $old_version = fmt("version %d", $previous);
         $others = array('major', 'minor', 'author');
     } else {
         switch ($previous) {
             case 'author':
                 $old = $new;
                 while ($old = $page->getRevisionBefore($old)) {
                     if ($old->get('author') != $new->get('author')) {
                         break;
                     }
                 }
                 $old_version = _("revision by previous author");
                 $others = array('major', 'minor');
                 break;
             case 'minor':
                 $previous = 'minor';
                 $old = $page->getRevisionBefore($new);
                 $old_version = _("previous revision");
                 $others = array('major', 'author');
                 break;
             case 'major':
             default:
                 $old = $new;
                 while ($old && $old->get('is_minor_edit')) {
                     $old = $page->getRevisionBefore($old);
                 }
                 if ($old) {
                     $old = $page->getRevisionBefore($old);
                 }
                 $old_version = _("predecessor to the previous major change");
                 $others = array('minor', 'author');
                 break;
         }
     }
     $new_link = WikiLink($new, '', $new_version);
     $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
     $page_link = WikiLink($page);
     $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link)));
     $otherdiffs = HTML::p(_("Other diffs:"));
     $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author"));
     foreach ($others as $other) {
         $args = array('pagename' => $pagename, 'previous' => $other);
         if ($version) {
             $args['version'] = $version;
         }
         if (count($otherdiffs->getContent()) > 1) {
             $otherdiffs->pushContent(", ");
         } else {
             $otherdiffs->pushContent(" ");
         }
         $otherdiffs->pushContent(Button($args, $label[$other]));
     }
     $html->pushContent($otherdiffs);
     if ($old and $old->getVersion() == 0) {
         $old = false;
     }
     $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new, $request), $this->PageInfoRow(_("Older page:"), $old, $request)));
     if ($new && $old) {
         $diff = new Diff($old->getContent(), $new->getContent());
         if ($diff->isEmpty()) {
             $html->pushContent(HTML::hr(), HTML::p('[', _("Versions are identical"), ']'));
         } else {
             // New CSS formatted unified diffs (ugly in NS4).
             $fmt = new HtmlUnifiedDiffFormatter();
             // Use this for old table-formatted diffs.
             //$fmt = new TableUnifiedDiffFormatter;
             $html->pushContent($fmt->format($diff));
         }
     }
     //$html = HTML::tt(fmt('%s: %s', $salutation, WikiLink($name, 'auto')),
     //                 THE_END);
     return $html;
 }
Пример #6
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (is_array($versions)) {
         // Version selection from pageinfo.php display:
         rsort($versions);
         list($version, $previous) = $versions;
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $pagename)) {
         return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename));
     }
     // abort if page doesn't exist
     $page = $request->getPage($pagename);
     $current = $page->getCurrentRevision();
     if ($current->getVersion() < 1) {
         $html = HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown'))));
         return $html;
         //early return
     }
     if ($version) {
         if (!($new = $page->getRevision($version))) {
             NoSuchRevision($request, $page, $version);
         }
         $new_version = fmt("version %d", $version);
     } else {
         $new = $current;
         $new_version = _("current version");
     }
     if (preg_match('/^\\d+$/', $previous)) {
         if (!($old = $page->getRevision($previous))) {
             NoSuchRevision($request, $page, $previous);
         }
         $old_version = fmt("version %d", $previous);
         $others = array('major', 'minor', 'author');
     } else {
         switch ($previous) {
             case 'author':
                 $old = $new;
                 while ($old = $page->getRevisionBefore($old)) {
                     if ($old->get('author') != $new->get('author')) {
                         break;
                     }
                 }
                 $old_version = _("revision by previous author");
                 $others = array('major', 'minor');
                 break;
             case 'minor':
                 $previous = 'minor';
                 $old = $page->getRevisionBefore($new);
                 $old_version = _("previous revision");
                 $others = array('major', 'author');
                 break;
             case 'major':
             default:
                 $old = $new;
                 while ($old && $old->get('is_minor_edit')) {
                     $old = $page->getRevisionBefore($old);
                 }
                 if ($old) {
                     $old = $page->getRevisionBefore($old);
                 }
                 $old_version = _("predecessor to the previous major change");
                 $others = array('minor', 'author');
                 break;
         }
     }
     $new_link = WikiLink($new, '', $new_version);
     $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
     $page_link = WikiLink($page);
     $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link)));
     $otherdiffs = HTML::p(_("Other diffs:"));
     $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author"));
     foreach ($others as $other) {
         $args = array('pagename' => $pagename, 'previous' => $other);
         if ($version) {
             $args['version'] = $version;
         }
         if (count($otherdiffs->getContent()) > 1) {
             $otherdiffs->pushContent(", ");
         } else {
             $otherdiffs->pushContent(" ");
         }
         $otherdiffs->pushContent(Button($args, $label[$other]));
     }
     $html->pushContent($otherdiffs);
     if ($old and $old->getVersion() == 0) {
         $old = false;
     }
     $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new, $request), $this->PageInfoRow(_("Older page:"), $old, $request)));
     if ($new && $old) {
         $diff = new Diff($old->getContent(), $new->getContent());
         if ($diff->isEmpty()) {
             $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical.")));
             // If two consecutive versions have the same content, it is because the page was
             // renamed, or metadata changed: ACL, owner, markup.
             // We give the reason by printing the summary.
             if ($new->getVersion() - $old->getVersion() == 1) {
                 $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary')));
             }
         } else {
             $fmt = new HtmlUnifiedDiffFormatter();
             $html->pushContent($fmt->format($diff));
         }
     }
     return $html;
 }
 function paintDiff($stringA, $stringB)
 {
     $diff = new Diff(explode("\n", $stringA), explode("\n", $stringB));
     if ($diff->isEmpty()) {
         $this->_response->content .= '<p>Diff Error  : weird, no difference said difflib...</p>';
     } else {
         $fmt = new UnifiedDiffFormatter();
         $this->_response->content .= $fmt->format($diff);
     }
 }
 function paintDiff($stringA, $stringB)
 {
     $this->_response->body->append('MAIN', '<!--A:' . $stringA . '-->');
     $this->_response->body->append('MAIN', '<!--B:' . $stringB . '-->');
     $diff = new Diff(explode("\n", $stringA), explode("\n", $stringB));
     if ($diff->isEmpty()) {
         $this->_response->body->append('MAIN', '<p>Erreur diff : bizarre, aucune différence d\'aprés la difflib...</p>');
     } else {
         $fmt = new HtmlUnifiedDiffFormatter();
         $this->_response->body->append('MAIN', $fmt->format($diff));
     }
 }
Пример #9
0
function showDiff(&$request)
{
    $pagename = $request->getArg('pagename');
    if (is_array($versions = $request->getArg('versions'))) {
        // Version selection from pageinfo.php display:
        rsort($versions);
        list($version, $previous) = $versions;
    } else {
        $version = $request->getArg('version');
        $previous = $request->getArg('previous');
    }
    // abort if page doesn't exist
    $dbi = $request->getDbh();
    $page = $request->getPage();
    $current = $page->getCurrentRevision(false);
    if ($current->getVersion() < 1) {
        $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown'))));
        require_once 'lib/Template.php';
        GeneratePage($html, sprintf(_("Diff: %s"), $pagename), false);
        return;
        //early return
    }
    if ($version) {
        if (!($new = $page->getRevision($version))) {
            NoSuchRevision($request, $page, $version);
        }
        $new_version = fmt("version %d", $version);
    } else {
        $new = $current;
        $new_version = _("current version");
    }
    if (preg_match('/^\\d+$/', $previous)) {
        if (!($old = $page->getRevision($previous))) {
            NoSuchRevision($request, $page, $previous);
        }
        $old_version = fmt("version %d", $previous);
        $others = array('major', 'minor', 'author');
    } else {
        switch ($previous) {
            case 'author':
                $old = $new;
                while ($old = $page->getRevisionBefore($old)) {
                    if ($old->get('author') != $new->get('author')) {
                        break;
                    }
                }
                $old_version = _("revision by previous author");
                $others = array('major', 'minor');
                break;
            case 'minor':
                $previous = 'minor';
                $old = $page->getRevisionBefore($new);
                $old_version = _("previous revision");
                $others = array('major', 'author');
                break;
            case 'major':
            default:
                $old = $new;
                while ($old && $old->get('is_minor_edit')) {
                    $old = $page->getRevisionBefore($old);
                }
                if ($old) {
                    $old = $page->getRevisionBefore($old);
                }
                $old_version = _("predecessor to the previous major change");
                $others = array('minor', 'author');
                break;
        }
    }
    $new_link = WikiLink($new, '', $new_version);
    $old_link = $old ? WikiLink($old, '', $old_version) : $old_version;
    $page_link = WikiLink($page);
    $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link)));
    $otherdiffs = HTML::p(_("Other diffs:"));
    $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author"));
    foreach ($others as $other) {
        $args = array('action' => 'diff', 'previous' => $other);
        if ($version) {
            $args['version'] = $version;
        }
        if (count($otherdiffs->getContent()) > 1) {
            $otherdiffs->pushContent(", ");
        } else {
            $otherdiffs->pushContent(" ");
        }
        $otherdiffs->pushContent(Button($args, $label[$other]));
    }
    $html->pushContent($otherdiffs);
    if ($old and $old->getVersion() == 0) {
        $old = false;
    }
    $html->pushContent(HTML::Table(PageInfoRow(_("Newer page:"), $new, $request, empty($version)), PageInfoRow(_("Older page:"), $old, $request, false)));
    if ($new && $old) {
        $diff = new Diff($old->getContent(), $new->getContent());
        if ($diff->isEmpty()) {
            $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical.")));
            // If two consecutive versions have the same content, it is because the page was
            // renamed, or metadata changed: ACL, owner, markup.
            // We give the reason by printing the summary.
            if ($new->getVersion() - $old->getVersion() == 1) {
                $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary')));
            }
        } else {
            $fmt = new HtmlUnifiedDiffFormatter();
            $html->pushContent($fmt->format($diff));
        }
        $html->pushContent(HTML::hr(), HTML::h2($new_version));
        require_once "lib/BlockParser.php";
        $html->pushContent(TransformText($new, $new->get('markup'), $pagename));
    }
    require_once 'lib/Template.php';
    GeneratePage($html, sprintf(_("Diff: %s"), $pagename), $new);
}
Пример #10
0
 function getDiff()
 {
     require_once 'lib/diff.php';
     $html = HTML();
     $diff = new Diff($this->current->getContent(), explode("\n", $this->getContent()));
     if ($diff->isEmpty()) {
         $html->pushContent(HTML::hr(), HTML::p('[', _("Versions are identical"), ']'));
     } else {
         // New CSS formatted unified diffs
         $fmt = new HtmlUnifiedDiffFormatter();
         $html->pushContent($fmt->format($diff));
     }
     return $html;
 }