Kawai Wiki

Compare Revisions

Ignore whitespace Rev 77 → Rev 78

/trunk/src/main/java/org/kawai/action/PageAction.java
8,6 → 8,7
import org.kawai.model.Language;
import org.kawai.model.Page;
import org.kawai.model.Preview;
import org.kawai.model.Revision;
import org.mentawai.filter.AuthenticationFree;
import org.mentawai.rule.MethodRule;
import org.mentawai.rule.RegexRule;
223,10 → 224,17
if (preview != null) {
Page page = pageDAO.loadByName(name, lang);
if (page != null) {
String oldTitle = page.getTitle();
String oldBody = page.getBody();
page.setTitle(preview.getTitle());
page.setBody(preview.getBody());
page.setModifiedById(preview.getUserId());
pageDAO.update(page);
insertRevision(page, oldTitle, oldBody);
pageDAO.deletePreview(userId, name, lang);
} else {
page = preview.getPage();
238,6 → 246,18
return SUCCESS;
}
private void insertRevision(Page page, String oldTitle, String oldBody) {
Revision r = new Revision();
r.setName(page.getName());
r.setLanguageId(page.getLanguageId());
r.setUserId(sessionUser.getId());
r.setNewTitle(page.getTitle());
r.setNewBody(page.getBody());
r.setOldTitle(oldTitle);
r.setOldBody(oldBody);
pageDAO.insertRevision(r);
}
public String edit() {
if (!isPost()) return INDEX;
String name = input.getString("name");
248,12 → 268,21
}
Page page = pageDAO.loadByName(name, Language.fromString(lang));
if (page != null) {
String oldTitle = page.getTitle();
String oldBody = page.getBody();
input.inject(page);
page.setModifiedById(sessionUser.getId());
if (input.getBoolean("isPreview")) {
pageDAO.insertPreview(sessionUser.getId(), page);
} else {
pageDAO.update(page);
insertRevision(page, oldTitle, oldBody);
// and now you have to delete the preview!
pageDAO.deletePreview(sessionUser.getId(), page.getName(), page.getLanguage());
}