Browse Source

Merge branch 'devel' of maxime-alves/wikipp-pad into master

nas 3 years ago
parent
commit
3ad9fd2e8f
6 changed files with 62 additions and 28 deletions
  1. 6
    1
      .gitignore
  2. 5
    3
      sql/mysql.sql
  3. 9
    0
      sql/patches/mysql/01-pad_url.sql
  4. 33
    21
      src/page.cpp
  5. 5
    3
      src/page_content.h
  6. 4
    0
      templates/page.tmpl

+ 6
- 1
.gitignore View File

1
-build
1
+wikipp.log
2
+config.local.js
3
+build/*
4
+*.swp
5
+*.o
6
+*.so

+ 5
- 3
sql/mysql.sql View File

22
 	lang varchar(16) not null,
22
 	lang varchar(16) not null,
23
 	slug varchar(128) not null,
23
 	slug varchar(128) not null,
24
 	title varchar(256) not null,
24
 	title varchar(256) not null,
25
-	content text not null,
25
+	content text null,
26
 	sidebar text not null,
26
 	sidebar text not null,
27
 	users_only integer not null,
27
 	users_only integer not null,
28
-	constraint unique (lang,slug)
28
+	constraint unique (lang,slug),
29
+	pad_url varchar(256) null
29
 ) Engine = InnoDB;
30
 ) Engine = InnoDB;
30
 
31
 
31
 create table history (
32
 create table history (
34
 	created datetime not null,
35
 	created datetime not null,
35
 	author varchar(32) not null,
36
 	author varchar(32) not null,
36
 	title varchar(256) not null,
37
 	title varchar(256) not null,
37
-	content text not null,
38
+	content text null,
38
 	sidebar text not null,
39
 	sidebar text not null,
39
 	constraint unique(id,version),
40
 	constraint unique(id,version),
41
+	pad_url varchar(256) null,
40
 	foreign key(id) references pages(id),
42
 	foreign key(id) references pages(id),
41
 	primary key(id,version)
43
 	primary key(id,version)
42
 ) Engine = InnoDB;
44
 ) Engine = InnoDB;

+ 9
- 0
sql/patches/mysql/01-pad_url.sql View File

1
+alter table pages
2
+add column pad_url varchar(256) null;
3
+alter table pages
4
+modify column content text null;
5
+
6
+alter table history
7
+add column pad_url varchar(256) null;
8
+alter table history
9
+modify column content text null;

+ 33
- 21
src/page.cpp View File

16
 {
16
 {
17
 	title.message(_("Title"));
17
 	title.message(_("Title"));
18
 	content.message(_("Content"));
18
 	content.message(_("Content"));
19
+	pad_url.message(_("Pad URL"));
19
 	sidebar.message(_("Sidebar"));
20
 	sidebar.message(_("Sidebar"));
20
 	save.value(_("Save"));
21
 	save.value(_("Save"));
21
 	save_cont.value(_("Save and Continue"));
22
 	save_cont.value(_("Save and Continue"));
22
 	preview.value(_("Preview"));
23
 	preview.value(_("Preview"));
23
 	fields.add(title);
24
 	fields.add(title);
24
 	fields.add(content);
25
 	fields.add(content);
26
+	fields.add(pad_url);
25
 	fields.add(sidebar);
27
 	fields.add(sidebar);
26
 	buttons.add(save);
28
 	buttons.add(save);
27
 	buttons.add(save_cont);
29
 	buttons.add(save_cont);
32
 	users_only.help(_("Disable editing by visitors"));
34
 	users_only.help(_("Disable editing by visitors"));
33
 	users_only.error_message(_("Please Login"));
35
 	users_only.error_message(_("Please Login"));
34
 	title.non_empty();
36
 	title.non_empty();
35
-	content.non_empty();
36
 	content.rows(25);
37
 	content.rows(25);
37
 	content.cols(60);
38
 	content.cols(60);
38
 	sidebar.rows(10);
39
 	sidebar.rows(10);
113
 	c.v2=v2;
114
 	c.v2=v2;
114
 	c.edit_v1=edit_version_url(v1);
115
 	c.edit_v1=edit_version_url(v1);
115
 	c.edit_v2=edit_version_url(v2);
116
 	c.edit_v2=edit_version_url(v2);
116
-	r=sql<<	"SELECT version,history.title,history.content,history.sidebar,pages.title FROM pages "
117
+	r=sql<<	"SELECT version,history.title,history.content,history.pad_url,history.sidebar,pages.title FROM pages "
117
 		"JOIN history ON pages.id=history.id "
118
 		"JOIN history ON pages.id=history.id "
118
 		"WHERE lang=? AND slug=? AND version IN (?,?) " << locale_name << slug << v1 << v2;
119
 		"WHERE lang=? AND slug=? AND version IN (?,?) " << locale_name << slug << v1 << v2;
119
 	
120
 	
120
-	std::string t1,c1,s1,t2,c2,s2;
121
+	std::string t1,c1,p1,s1,t2,c2,p2,s2;
121
 	int count=0;
122
 	int count=0;
122
 	while(r.next()) {
123
 	while(r.next()) {
123
 		int ver;
124
 		int ver;
124
 		r>>ver;
125
 		r>>ver;
125
 		if(ver==v1) {
126
 		if(ver==v1) {
126
-			r>>t1>>c1>>s1>>c.title;
127
+			r>>t1>>c1>>p2>>s1>>c.title;
127
 		}
128
 		}
128
 		else {
129
 		else {
129
-			r>>t2>>c2>>s2;
130
+			r>>t2>>c2>>p2>>s2;
130
 		}
131
 		}
131
 		count++;
132
 		count++;
132
 	}
133
 	}
150
 		std::vector<std::string> Y=split(c2);
151
 		std::vector<std::string> Y=split(c2);
151
 		diff::diff(X,Y,c.content_diff_content);
152
 		diff::diff(X,Y,c.content_diff_content);
152
 	}
153
 	}
154
+	if(p1!=p2) {
155
+		c.pad_url_diff=true;
156
+		std::vector<std::string> X=split(p1);
157
+		std::vector<std::string> Y=split(p2);
158
+		diff::diff(X,Y,c.pad_url_diff_content);
159
+	}
153
 	if(s1!=s2) {
160
 	if(s1!=s2) {
154
 		c.sidebar_diff=true;
161
 		c.sidebar_diff=true;
155
 		std::vector<std::string> X=split(s1);
162
 		std::vector<std::string> X=split(s1);
156
 		std::vector<std::string> Y=split(s2);
163
 		std::vector<std::string> Y=split(s2);
157
 		diff::diff(X,Y,c.sidebar_diff_content);
164
 		diff::diff(X,Y,c.sidebar_diff_content);
158
 	}
165
 	}
159
-	if(t1==t2 && c1==c2 && s1==s2) 
166
+	if(t1==t2 && c1==c2 && p1==p2 && s1==s2)
160
 		c.no_diff=true;
167
 		c.no_diff=true;
161
 	master::ini(c);
168
 	master::ini(c);
162
 	render("diff",c);
169
 	render("diff",c);
218
 {
225
 {
219
 	this->slug=slug;
226
 	this->slug=slug;
220
 	std::string key="article_"+locale_name+":"+slug;
227
 	std::string key="article_"+locale_name+":"+slug;
221
-	if(cache().fetch_page(key))
222
-		return;
228
+    // if(cache().fetch_page(key))
229
+    //  return;
223
 	content::page c;
230
 	content::page c;
224
 
231
 
225
 	cppdb::session sql(conn);
232
 	cppdb::session sql(conn);
282
 {
289
 {
283
 	cppdb::session sql(conn);
290
 	cppdb::session sql(conn);
284
 	cppdb::result r;
291
 	cppdb::result r;
285
-	r=sql<<	"SELECT title,content,sidebar,users_only "
292
+	r=sql<<	"SELECT title,content,pad_url,sidebar,users_only "
286
 		"FROM pages WHERE lang=? AND slug=?" << locale_name << slug << cppdb::row;
293
 		"FROM pages WHERE lang=? AND slug=?" << locale_name << slug << cppdb::row;
287
 	if(!r.empty()) {
294
 	if(!r.empty()) {
288
-		std::string title,content,sidebar;
295
+		std::string title,content,pad_url,sidebar;
289
 		int users_only;
296
 		int users_only;
290
-		r >> title >> content >> sidebar >> users_only;
297
+		r >> title >> content >> pad_url >> sidebar >> users_only;
291
 		form.title.value(title);
298
 		form.title.value(title);
292
 		form.content.value(content);
299
 		form.content.value(content);
300
+		form.pad_url.value(pad_url);
293
 		form.sidebar.value(sidebar);
301
 		form.sidebar.value(sidebar);
294
 		form.users_only.value(users_only);
302
 		form.users_only.value(users_only);
295
 		return true;
303
 		return true;
310
 	std::tm t = booster::ptime::local_time(booster::ptime::now());
318
 	std::tm t = booster::ptime::local_time(booster::ptime::now());
311
 	wi.users.auth();
319
 	wi.users.auth();
312
 	if(id!=-1) {
320
 	if(id!=-1) {
313
-		sql<<	"UPDATE pages SET content=?,title=?,sidebar=?,users_only=? "
321
+		sql<<	"UPDATE pages SET content=?,title=?,pad_url=?,sidebar=?,users_only=? "
314
 			"WHERE lang=? AND slug=?"
322
 			"WHERE lang=? AND slug=?"
315
-				<< form.content.value() << form.title.value() 
323
+				<< form.content.value() << form.title.value() << form.pad_url.value()
316
 				<< form.sidebar.value() << form.users_only.value() 
324
 				<< form.sidebar.value() << form.users_only.value() 
317
 				<< locale_name << slug << cppdb::exec;
325
 				<< locale_name << slug << cppdb::exec;
318
 	}
326
 	}
319
 	else {
327
 	else {
320
 		cppdb::statement s;
328
 		cppdb::statement s;
321
-		s=sql<<	"INSERT INTO pages(lang,slug,title,content,sidebar,users_only) "
322
-			"VALUES(?,?,?,?,?,?)"
329
+		s=sql<<	"INSERT INTO pages(lang,slug,title,content,pad_url,sidebar,users_only) "
330
+			"VALUES(?,?,?,?,?,?,?)"
323
 			<< locale_name << slug
331
 			<< locale_name << slug
324
 			<< form.title.value()
332
 			<< form.title.value()
325
 			<< form.content.value()
333
 			<< form.content.value()
334
+			<< form.pad_url.value()
326
 			<< form.sidebar.value()
335
 			<< form.sidebar.value()
327
 			<< form.users_only.value();
336
 			<< form.users_only.value();
328
 		s.exec();
337
 		s.exec();
329
 		id=s.sequence_last("pages_id_seq");
338
 		id=s.sequence_last("pages_id_seq");
330
 	}
339
 	}
331
-	sql<<	"INSERT INTO history(id,version,created,title,content,sidebar,author) "
340
+	sql<<	"INSERT INTO history(id,version,created,title,content,pad_url,sidebar,author) "
332
 		"SELECT ?,"
341
 		"SELECT ?,"
333
 		"	(SELECT COALESCE(MAX(version),0)+1 FROM history WHERE id=?),"
342
 		"	(SELECT COALESCE(MAX(version),0)+1 FROM history WHERE id=?),"
334
-		"	?,?,?,?,?"
343
+		"	?,?,?,?,?,?"
335
 			<< id << id << t 
344
 			<< id << id << t 
336
 			<< form.title.value()
345
 			<< form.title.value()
337
 			<< form.content.value()
346
 			<< form.content.value()
347
+			<< form.pad_url.value()
338
 			<< form.sidebar.value()
348
 			<< form.sidebar.value()
339
 			<< wi.users.username 
349
 			<< wi.users.username 
340
 			<< cppdb::exec;
350
 			<< cppdb::exec;
373
 		if(c.form.preview.value()) {
383
 		if(c.form.preview.value()) {
374
 			c.title=c.form.title.value();
384
 			c.title=c.form.title.value();
375
 			c.content=c.form.content.value();
385
 			c.content=c.form.content.value();
386
+			c.pad_url=c.form.pad_url.value();
376
 			c.sidebar=c.form.sidebar.value();
387
 			c.sidebar=c.form.sidebar.value();
377
 		}
388
 		}
378
 	}
389
 	}
384
 {
395
 {
385
 	cppdb::session sql(conn);
396
 	cppdb::session sql(conn);
386
 	cppdb::result r;
397
 	cppdb::result r;
387
-	r=sql<<	"SELECT history.title,history.content,history.sidebar,pages.users_only "
398
+	r=sql<<	"SELECT history.title,history.content,history.pad_url,history.sidebar,pages.users_only "
388
 		"FROM pages "
399
 		"FROM pages "
389
 		"JOIN history ON pages.id=history.id "
400
 		"JOIN history ON pages.id=history.id "
390
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
401
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
391
 		<<locale_name<<slug<<ver<<cppdb::row;
402
 		<<locale_name<<slug<<ver<<cppdb::row;
392
 	if(!r.empty()) {
403
 	if(!r.empty()) {
393
-		std::string title,content,sidebar;
404
+		std::string title,content,pad_url,sidebar;
394
 		int uonly;
405
 		int uonly;
395
-		r >> title >> content >> sidebar >> uonly;
406
+		r >> title >> content >> pad_url >> sidebar >> uonly;
396
 		form.title.value(title);
407
 		form.title.value(title);
397
 		form.content.value(content);
408
 		form.content.value(content);
409
+		form.pad_url.value(pad_url);
398
 		form.sidebar.value(sidebar);
410
 		form.sidebar.value(sidebar);
399
 		form.users_only.value(uonly);
411
 		form.users_only.value(uonly);
400
 		return true;
412
 		return true;
409
 	int id=atoi(sid.c_str());
421
 	int id=atoi(sid.c_str());
410
 	cppdb::result r;
422
 	cppdb::result r;
411
 	cppdb::session sql(conn);
423
 	cppdb::session sql(conn);
412
-	r=sql<<	"SELECT history.title,history.content,history.sidebar,history.created "
424
+	r=sql<<	"SELECT history.title,history.content,history.pad_url,history.sidebar,history.created "
413
 		"FROM pages "
425
 		"FROM pages "
414
 		"JOIN history ON pages.id=history.id "
426
 		"JOIN history ON pages.id=history.id "
415
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
427
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"

+ 5
- 3
src/page_content.h View File

11
 	apps::wiki *w;
11
 	apps::wiki *w;
12
 	cppcms::widgets::text title;
12
 	cppcms::widgets::text title;
13
 	cppcms::widgets::textarea content;
13
 	cppcms::widgets::textarea content;
14
+	cppcms::widgets::text pad_url;
14
 	cppcms::widgets::textarea sidebar;
15
 	cppcms::widgets::textarea sidebar;
15
 	cppcms::widgets::submit save;
16
 	cppcms::widgets::submit save;
16
 	cppcms::widgets::submit save_cont;
17
 	cppcms::widgets::submit save_cont;
24
 
25
 
25
 struct page : public master {
26
 struct page : public master {
26
 	std::string title,content;
27
 	std::string title,content;
27
-	std::string sidebar;
28
+	std::string pad_url,sidebar;
28
 	std::string edit_link;
29
 	std::string edit_link;
29
 	std::string history_link;
30
 	std::string history_link;
30
 };
31
 };
62
 	std::string edit_v1,edit_v2;
63
 	std::string edit_v1,edit_v2;
63
 	int v1,v2;
64
 	int v1,v2;
64
 	diff_t content_diff_content;
65
 	diff_t content_diff_content;
66
+	diff_t pad_url_diff_content;
65
 	diff_t sidebar_diff_content;
67
 	diff_t sidebar_diff_content;
66
 	std::string title,title_1,title_2;
68
 	std::string title,title_1,title_2;
67
-	bool title_diff,content_diff,sidebar_diff,no_versions,no_diff;
69
+	bool title_diff,content_diff,pad_url_diff,sidebar_diff,no_versions,no_diff;
68
 	diff() : 
70
 	diff() : 
69
-		title_diff(false),content_diff(false),
71
+		title_diff(false),content_diff(false),pad_url_diff(false),
70
 		sidebar_diff(false),no_versions(false),
72
 		sidebar_diff(false),no_versions(false),
71
 		no_diff(false)
73
 		no_diff(false)
72
 	{
74
 	{

+ 4
- 0
templates/page.tmpl View File

111
 		<h2><% gt "Content" %>:</h2>
111
 		<h2><% gt "Content" %>:</h2>
112
 		<% include show_diff(content_diff_content) %>
112
 		<% include show_diff(content_diff_content) %>
113
 	<% end %>
113
 	<% end %>
114
+	<% if pad_url_diff %>
115
+		<h2><% gt "Pad URL" %>:</h2>
116
+		<% include show_diff(pad_url_diff_content) %>
117
+	<% end %>
114
 	<% if sidebar_diff %>
118
 	<% if sidebar_diff %>
115
 		<h2><% gt "Sidebar" %>:</h2>
119
 		<h2><% gt "Sidebar" %>:</h2>
116
 		<% include show_diff(sidebar_diff_content) %>
120
 		<% include show_diff(sidebar_diff_content) %>

Loading…
Cancel
Save