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

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

@@ -0,0 +1,9 @@
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,12 +16,14 @@ page_form::page_form(apps::wiki *_w):
16 16
 {
17 17
 	title.message(_("Title"));
18 18
 	content.message(_("Content"));
19
+	pad_url.message(_("Pad URL"));
19 20
 	sidebar.message(_("Sidebar"));
20 21
 	save.value(_("Save"));
21 22
 	save_cont.value(_("Save and Continue"));
22 23
 	preview.value(_("Preview"));
23 24
 	fields.add(title);
24 25
 	fields.add(content);
26
+	fields.add(pad_url);
25 27
 	fields.add(sidebar);
26 28
 	buttons.add(save);
27 29
 	buttons.add(save_cont);
@@ -32,7 +34,6 @@ page_form::page_form(apps::wiki *_w):
32 34
 	users_only.help(_("Disable editing by visitors"));
33 35
 	users_only.error_message(_("Please Login"));
34 36
 	title.non_empty();
35
-	content.non_empty();
36 37
 	content.rows(25);
37 38
 	content.cols(60);
38 39
 	sidebar.rows(10);
@@ -113,20 +114,20 @@ void page::diff(std::string slug,std::string sv1,std::string sv2)
113 114
 	c.v2=v2;
114 115
 	c.edit_v1=edit_version_url(v1);
115 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 118
 		"JOIN history ON pages.id=history.id "
118 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 122
 	int count=0;
122 123
 	while(r.next()) {
123 124
 		int ver;
124 125
 		r>>ver;
125 126
 		if(ver==v1) {
126
-			r>>t1>>c1>>s1>>c.title;
127
+			r>>t1>>c1>>p2>>s1>>c.title;
127 128
 		}
128 129
 		else {
129
-			r>>t2>>c2>>s2;
130
+			r>>t2>>c2>>p2>>s2;
130 131
 		}
131 132
 		count++;
132 133
 	}
@@ -150,13 +151,19 @@ void page::diff(std::string slug,std::string sv1,std::string sv2)
150 151
 		std::vector<std::string> Y=split(c2);
151 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 160
 	if(s1!=s2) {
154 161
 		c.sidebar_diff=true;
155 162
 		std::vector<std::string> X=split(s1);
156 163
 		std::vector<std::string> Y=split(s2);
157 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 167
 		c.no_diff=true;
161 168
 	master::ini(c);
162 169
 	render("diff",c);
@@ -218,8 +225,8 @@ void page::display(std::string slug)
218 225
 {
219 226
 	this->slug=slug;
220 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 230
 	content::page c;
224 231
 
225 232
 	cppdb::session sql(conn);
@@ -282,14 +289,15 @@ bool page::load(content::page_form &form)
282 289
 {
283 290
 	cppdb::session sql(conn);
284 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 293
 		"FROM pages WHERE lang=? AND slug=?" << locale_name << slug << cppdb::row;
287 294
 	if(!r.empty()) {
288
-		std::string title,content,sidebar;
295
+		std::string title,content,pad_url,sidebar;
289 296
 		int users_only;
290
-		r >> title >> content >> sidebar >> users_only;
297
+		r >> title >> content >> pad_url >> sidebar >> users_only;
291 298
 		form.title.value(title);
292 299
 		form.content.value(content);
300
+		form.pad_url.value(pad_url);
293 301
 		form.sidebar.value(sidebar);
294 302
 		form.users_only.value(users_only);
295 303
 		return true;
@@ -310,31 +318,33 @@ void page::save(int id,content::page_form &form,cppdb::session &sql)
310 318
 	std::tm t = booster::ptime::local_time(booster::ptime::now());
311 319
 	wi.users.auth();
312 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 322
 			"WHERE lang=? AND slug=?"
315
-				<< form.content.value() << form.title.value() 
323
+				<< form.content.value() << form.title.value() << form.pad_url.value()
316 324
 				<< form.sidebar.value() << form.users_only.value() 
317 325
 				<< locale_name << slug << cppdb::exec;
318 326
 	}
319 327
 	else {
320 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 331
 			<< locale_name << slug
324 332
 			<< form.title.value()
325 333
 			<< form.content.value()
334
+			<< form.pad_url.value()
326 335
 			<< form.sidebar.value()
327 336
 			<< form.users_only.value();
328 337
 		s.exec();
329 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 341
 		"SELECT ?,"
333 342
 		"	(SELECT COALESCE(MAX(version),0)+1 FROM history WHERE id=?),"
334
-		"	?,?,?,?,?"
343
+		"	?,?,?,?,?,?"
335 344
 			<< id << id << t 
336 345
 			<< form.title.value()
337 346
 			<< form.content.value()
347
+			<< form.pad_url.value()
338 348
 			<< form.sidebar.value()
339 349
 			<< wi.users.username 
340 350
 			<< cppdb::exec;
@@ -373,6 +383,7 @@ bool page::edit_on_post(content::edit_page &c)
373 383
 		if(c.form.preview.value()) {
374 384
 			c.title=c.form.title.value();
375 385
 			c.content=c.form.content.value();
386
+			c.pad_url=c.form.pad_url.value();
376 387
 			c.sidebar=c.form.sidebar.value();
377 388
 		}
378 389
 	}
@@ -384,17 +395,18 @@ bool page::load_history(int ver,content::page_form &form)
384 395
 {
385 396
 	cppdb::session sql(conn);
386 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 399
 		"FROM pages "
389 400
 		"JOIN history ON pages.id=history.id "
390 401
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"
391 402
 		<<locale_name<<slug<<ver<<cppdb::row;
392 403
 	if(!r.empty()) {
393
-		std::string title,content,sidebar;
404
+		std::string title,content,pad_url,sidebar;
394 405
 		int uonly;
395
-		r >> title >> content >> sidebar >> uonly;
406
+		r >> title >> content >> pad_url >> sidebar >> uonly;
396 407
 		form.title.value(title);
397 408
 		form.content.value(content);
409
+		form.pad_url.value(pad_url);
398 410
 		form.sidebar.value(sidebar);
399 411
 		form.users_only.value(uonly);
400 412
 		return true;
@@ -409,7 +421,7 @@ void page::display_ver(std::string slug,std::string sid)
409 421
 	int id=atoi(sid.c_str());
410 422
 	cppdb::result r;
411 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 425
 		"FROM pages "
414 426
 		"JOIN history ON pages.id=history.id "
415 427
 		"WHERE pages.lang=? AND pages.slug=? AND history.version=?"

+ 5
- 3
src/page_content.h View File

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

+ 4
- 0
templates/page.tmpl View File

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

Loading…
Cancel
Save