滚动您自己的Plaintext Wiki(Wiki中的一个DB) [英] Rolling Your Own Plaintext Wiki (Wiki inside a DB)

查看:232
本文介绍了滚动您自己的Plaintext Wiki(Wiki中的一个DB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道一个API(php最好,但我对任何语言感兴趣)创建wiki类数据存储?



滚动时的任何资源你自己的明文wiki?其他纯文本维基是如何处理文本文件的格式?



我明白我可以使用Markdown或Textile进行格式化。但我最感兴趣的是如何处理多用户编辑的纯文本存储。



我正在编写一个主要是数据库驱动的Web应用程序。我要这个数据库的至少一个文本字段是类似wiki的格式。具体来说,此文本可以由多个用户编辑,能够回滚到任何版本。请考虑 Last.FM 的wiki / bio部分(几乎整个网站都是严格的结构化



到目前为止,我将MediaWiki拆分并将其嵌入到数据库中的方法似乎太过分了。我认为滚动我自己的明文维基,并将这个文件存储在数据库的相应文本字段将会容易得多。

解决方案

p>因此,基本上这是一个我如何在我的数据库版本文本信息。



好吧,最简单的方法是简单地复制数据。

只需创建一个包含数据旧版本的版本表,并将其链接回您的主表。

  create table docs {
id整数主键不为null,
版本整数不为null,
create_date日期,
change_date日期,
create_user_id integer not null引用用户(id),
change_user_id整数引用用户(id),
text_data文本
}

创建表版本{
id整数主键不为null,
doc_id整数不为空引用docs(id),
版本整数,
change_date日期,
change_user整数not null引用用户),
text_data text
}

无论何时更新原始文档,

 选择版本,change_date,更新日期和更改日期, change_user,text_data 
into l_version,l_change_data,l_change_user,l_text_data
from docs where id = l_doc_id;

插入到版本值(newid,l_doc_id,l_version,
l_change_date,l_change_user,l_text_data);

update docs set version = version + 1,change_date = now,
change_user = cur_user,text_data = l_new_text其中id = l_doc_id;

如果您的数据库支持这些,您甚至可以在触发器中执行此操作。



这种方法的缺点是它的数据的完整副本(所以如果你有一个大文档,版本保持大)。你可以通过使用像diff(1)和patch(1)缓解。



例如:

  diff version2.txt version1.txt> ; difffile 

然后,您可以将该difffile存储为版本1。



为了从版本2恢复版本1,你抓住版本2数据,运行修补程序使用差异文件数据,并给你v1。



如果你想从v3到v1,你需要做两次(一次获得v2,然后再获得v1)。



这会降低你的存储负担,但增加你的处理(显然),所以你必须判断你想怎么做。


Anyone know of an API (php preferable but I'd be interested in any language) for creating wiki-like data storage?

How about any resources on rolling your own plaintext wiki? How do other plaintext wikis handle the format of the text file?

I understand I can use Markdown or Textile for the formatting. But what I'm most interested in is how to approach the plaintext storage of multi-user edits.

I'm writing a web application that is primarily database driven. I want at least one text field of this database to be in a wiki-like format. Specifically, this text can be edited by multiple users with the ability to roll back to any version. Think the wiki/bio section of Last.FM (almost the entire site is strictly structured by a database except for this one section per artist).

So far, my approach of taking apart MediaWiki and wedging it into a database seems like overkill. I'm thinking it would be much easier to roll my own plaintext wiki, and store this file in the database's appropriate text field.

解决方案

So, basically this is a "how do I version text information in my DB".

Well, the simplest way is simply copying the data.

Simply, create a "version" table that holds "old versions" of the data, and link it back to your main table.

create table docs {
    id integer primary key not null,
    version integer not null,
    create_date date,
    change_date date,
    create_user_id integer not null references users(id),
    change_user_id integer references users(id),
    text_data text
}

create table versions {
    id integer primary key not null,
    doc_id integer not null references docs(id),
    version integer,
    change_date date,
    change_user integer not null references users(id),
    text_data text
}

Whenever you update your original document, you copy the old text value in to this table, copy the user and change date and bump the version.

select version, change_date, change_user, text_data 
    into l_version, l_change_data, l_change_user, l_text_data 
from docs where id = l_doc_id;

insert into versions values (newid, l_doc_id, l_version, 
    l_change_date, l_change_user, l_text_data);

update docs set version = version + 1, change_date = now, 
    change_user = cur_user, text_data = l_new_text where id = l_doc_id;

You could even do this in a trigger if your DB supports those.

Faults with this method are that its a full copy of the data (so if you have a large document, the version stay large). You can mitigate that by using something like diff(1) and patch(1).

For example:

diff version2.txt version1.txt > difffile

Then you can store that difffile as "version 1".

In order to recover version 1 from version 2, you grab the version 2 data, run patch on it using the diff file data, and that gives you v1.

If you want to go from v3 to v1, you need to do this twice (once to get v2, and then again to get v1).

This lowers your storage burden, but increases your processing (obviously), so you'll have to judge how you want to do this.

这篇关于滚动您自己的Plaintext Wiki(Wiki中的一个DB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆