实现历史功能 à 维基百科

发布于 2024-07-24 08:35:35 字数 73 浏览 1 评论 0原文

我正在编写一个具有用于编辑文档的用户界面的 Web 应用程序。 实现像维基百科这样可以查看文档编辑的历史记录功能的最佳方法是什么?

I am writing a Web application that has a user interface for editing documents. What is the best way to implement a history feature like Wikipedia's where edits to a document can be viewed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

友谊不毕业 2024-07-31 08:35:36

使用版本控制系统作为基础(将每个版本保存到 vcs 中),它们将更改存储在增量中。 然后,您可以使用它们的 diff 功能来获取差异,但随后您必须解析输出。 例如,在 git 中,您可以通过简单地将哈希值作为参数提供给 git-diff

也就是说,如果您不愿意使用现有系统。

Use a version control system as your basis (save every version into a vcs), they store changes in deltas. You could then use their diff features to get the differences, but then you would have to parse the output. In git, for instance, you can get output from two different revisions by simply giving their hash as a parameter to git-diff.

That is, if you are not willing to use an existing system.

凝望流年 2024-07-31 08:35:36

如果不知道您正在使用什么框架和什么,这是一个很难回答的问题。

您是否使用数据库进行存储? 假设您的数据库中有一个 pages 表,为什么不创建一个 pages_versions 表来保存旧版本呢?

将任何内容保存到 pages 表时,首先将副本插入到 pages_versions 中。 检索旧版本将不会比通过任何其他一对多关系加载数据更困难。 此时,您可以使用彩色差异或其他方式美化数据。

我相信一些框架现在支持使用版本控制系统作为存储后端,因此这也值得研究。

Without knowing what framework and whatnot you are using this is a difficult question to answer well.

Are you using a database for your storage? Let's say you have a pages table in your database, why not create a pages_versions table for holding old revisions?

When saving anything to the pages table first insert a copy, into pages_versions. Retrieving the old versions will then be no more difficult than loading data through any other one to many relationship. You can beautify the data with a colourised diff or whatnot at this point.

I believe some frameworks now have support for using a version control system as a storage backend so that may also be worth investigating.

倾其所爱 2024-07-31 08:35:36

您指的是后端设置,还是突出显示各个更改的前端?

我无法帮助您解决前端问题,但是...

如果是后端,您需要的是:

  1. 一个包含 say、id 和 title 列的“文档”表。
  2. 包含 document_id (FK)、body_text、edit_date、author、version 列的“versions”表
  3. 在您的应用程序中,首先在文档表中创建新文档引用,然后将数据作为新版本存储在版本表中。 当用户更新旧文档时,将使用 document_id 中的相同文档引用创建新版本。

(我想我可能没有很好地解释这一点,对此感到抱歉!)

顺便说一句,如果您使用 Rails,有几个插件可以为您完成大部分工作。 我首先想到的是 Acts_As_Versioned。

Are you referring to the back-end set up, or the front-end with the individual changes highlighted?

I can't help you with the front-end bit, but...

If it's the back-end, what you need is:

  1. a 'documents' table with say, id and title columns.
  2. a 'versions' table with columns for document_id (FK), body_text, edit_date, author, version
  3. In your application, a new document reference is first created in the documents table, then the data is stored as a new version in the versions table. When a user updates an old document, a new version is created with the same document reference in document_id.

(I think I've probably not explained this very well, so sorry about that!)

BTW, if you're using Rails there are several plug-ins which will do most of this for you. Acts_As_Versioned is the first which comes to mind.

拥抱我好吗 2024-07-31 08:35:35

那么您将必须存储当前文档并存档更改以进行比较。 通常,主文档是数据库中的文档,然后保存时的旧版本将保存到另一个存档数据库或服务中。

然后你可以拉取最新的和最新的存档版本,并将其与 diff 算法进行比较。

Python有一个diff算法工具difflib:http://docs.python.org/library/difflib。 html
也是一个目录和文件比较工具: http://docs.python.org/ Library/filecmp.html#module-filecmp

许多其他语言也有 diff 算法实现。

您可以仅存储更改时的增量并像 Subversion 等 Berkley DB 一样重新创建,但为了简单起见,我建议仅保存内容的副本,然后比较每个最新内容或用户选择的内容。

Well you will have to store the current document and archive changes to compare. Typically the main document is the one in the database then older versions on save are saved to another archive database or service.

Then you can pull the latest and the latest archived version and compare it with a diff algorithm.

Python has a diff algorithm tool difflib: http://docs.python.org/library/difflib.html
Also a directory and file compare tool: http://docs.python.org/library/filecmp.html#module-filecmp

Many other languages also have diff algorithm implementations.

You can just store the deltas on change and recreate like a Berkley DB like Subversion but I recommend for simplicity just save a copy of the content then compare each of the latest, or the ones the user selects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文