实现历史功能 à 维基百科
我正在编写一个具有用于编辑文档的用户界面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用版本控制系统作为基础(将每个版本保存到 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.
如果不知道您正在使用什么框架和什么,这是一个很难回答的问题。
您是否使用数据库进行存储? 假设您的数据库中有一个
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 apages_versions
table for holding old revisions?When saving anything to the
pages
table first insert a copy, intopages_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.
您指的是后端设置,还是突出显示各个更改的前端?
我无法帮助您解决前端问题,但是...
如果是后端,您需要的是:
(我想我可能没有很好地解释这一点,对此感到抱歉!)
顺便说一句,如果您使用 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:
(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.
那么您将必须存储当前文档并存档更改以进行比较。 通常,主文档是数据库中的文档,然后保存时的旧版本将保存到另一个存档数据库或服务中。
然后你可以拉取最新的和最新的存档版本,并将其与 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.