用户生成和修改内容的版本比较
我正在开发一个构建在线协作工具的项目。 查看维基百科,我注意到用户生成的页面的迭代可以轻松地相互比较; 比较突出了差异。
从概念上讲,我需要实现什么才能做到几乎完全相同?
I'm working on a project constructing an online collaboration tool. Looking at Wikipedia, I noticed that user-generated itterations of a page can easily be compared to each other; the comparison highlights the differences.
Conceptually, what would I need to implement to do pretty much exactly the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由好建议组成:
最简单的方法是仅使用任何现有的 wiki 引擎。 有很多优秀的维基引擎。 不要重新发明轮子。
例如,StackOverflow 本身就是一个定制的 wiki。 查看 Stack Overflow 上的编辑查看器,看看其功能与问题中描述的功能是否相符。
Composited from the good advice:
The easiest way is to just use any of the already existing wiki engines. There are plenty of good wiki engines. Don't reinvent the wheel.
For example, StackOverflow itself is a custom built wiki. Look at the edit viewer on Stack Overflow to see how well its functionality meets the one described in the question.
您需要一个版本化数据存储和一个差异算法。
通过为每个资源提供修订号来存储资源的版本。 当用户编辑资源时,不要替换资源,而是将编辑内容保存为数据存储中的新条目,并使用新的更高版本号。 当您想要检索资源时,请返回具有最高修订版本的资源。
您可以使用时间戳来代替修订号。 时间戳不仅总是增加,而且修订号本身可以用来识别资源何时被修改。
根据您存储资源的方式选择差异算法。 Wikitext 通常是逐行的,因此如果用户正在编辑它,那么使用像标准 Unix
diff
实用程序那样的逐行比较是有意义的。 如果资源是 XML,您可能希望找到 XML 特定的 diff 算法,以便用户清楚差异在哪里。You'll need a versioned datastore and a diffing algorithm.
Store versions of your resources by giving each resource a revision number. When a user edits a resource, instead of replacing the resource, save the edit as a new entry in your datastore with a new, higher revision number. When you want to retrieve the resource, return the one with the highest revision.
Instead of a revision number you could use timestamps. Not only do timestamps always increase, but the revision number itself could be used to identify when the resource was modified.
Choose a diff algorithm based on how you're storing the resources. Wikitext is usually linewise, so if users are editing that, it would make sense to use a linewise diff like the standard Unix
diff
utility. If the resources are XML, you may wish to find an XML-specific diff algorithm so that it would be clear to users where the differences are.