Fossil SCM
Merge the hide-by-user hack into the forum-attach-moderated branch.
Commit
e76bd2893f44f58f835eb01613e0e934c5975f20d9fb7aab36d97d37ef719eee
Parent
61ef6678cc023fe…
2 files changed
+9
+51
M
src/db.c
+9
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -4927,10 +4927,19 @@ | ||
| 4927 | 4927 | /* |
| 4928 | 4928 | ** SETTING: http-port width=16 default=8080 |
| 4929 | 4929 | ** The default TCP/IP port number to use by the "server" |
| 4930 | 4930 | ** and "ui" commands. |
| 4931 | 4931 | */ |
| 4932 | +/* | |
| 4933 | +** SETTING: hide-by-user width=40 block-text | |
| 4934 | +** The VALUE of this setting is a list of GLOB patterns. On the /timeline | |
| 4935 | +** page, any check-in whose user login name matches one of these patterns | |
| 4936 | +** is treated as if it carried the "hidden" tag, and is omitted unless the | |
| 4937 | +** "unhide=on" query parameter is used. Example: bot-*,*-robot | |
| 4938 | +** The parsing rules are complex; see | |
| 4939 | +** https://fossil-scm.org/home/doc/trunk/www/globs.md#syntax | |
| 4940 | +*/ | |
| 4932 | 4941 | /* |
| 4933 | 4942 | ** SETTING: https-login boolean default=off |
| 4934 | 4943 | ** If true, then the Fossil web server will redirect unencrypted |
| 4935 | 4944 | ** login screen requests to HTTPS. |
| 4936 | 4945 | */ |
| 4937 | 4946 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -4927,10 +4927,19 @@ | |
| 4927 | /* |
| 4928 | ** SETTING: http-port width=16 default=8080 |
| 4929 | ** The default TCP/IP port number to use by the "server" |
| 4930 | ** and "ui" commands. |
| 4931 | */ |
| 4932 | /* |
| 4933 | ** SETTING: https-login boolean default=off |
| 4934 | ** If true, then the Fossil web server will redirect unencrypted |
| 4935 | ** login screen requests to HTTPS. |
| 4936 | */ |
| 4937 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -4927,10 +4927,19 @@ | |
| 4927 | /* |
| 4928 | ** SETTING: http-port width=16 default=8080 |
| 4929 | ** The default TCP/IP port number to use by the "server" |
| 4930 | ** and "ui" commands. |
| 4931 | */ |
| 4932 | /* |
| 4933 | ** SETTING: hide-by-user width=40 block-text |
| 4934 | ** The VALUE of this setting is a list of GLOB patterns. On the /timeline |
| 4935 | ** page, any check-in whose user login name matches one of these patterns |
| 4936 | ** is treated as if it carried the "hidden" tag, and is omitted unless the |
| 4937 | ** "unhide=on" query parameter is used. Example: bot-*,*-robot |
| 4938 | ** The parsing rules are complex; see |
| 4939 | ** https://fossil-scm.org/home/doc/trunk/www/globs.md#syntax |
| 4940 | */ |
| 4941 | /* |
| 4942 | ** SETTING: https-login boolean default=off |
| 4943 | ** If true, then the Fossil web server will redirect unencrypted |
| 4944 | ** login screen requests to HTTPS. |
| 4945 | */ |
| 4946 |
+51
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1237,10 +1237,46 @@ | ||
| 1237 | 1237 | @ FROM event CROSS JOIN blob |
| 1238 | 1238 | @ WHERE blob.rid=event.objid |
| 1239 | 1239 | ; |
| 1240 | 1240 | return zBase; |
| 1241 | 1241 | } |
| 1242 | + | |
| 1243 | +/* | |
| 1244 | +** SQL function: hidden_by_user(X) | |
| 1245 | +** | |
| 1246 | +** Return true if X matches one of the GLOB patterns in the "hide-by-user" | |
| 1247 | +** setting. | |
| 1248 | +*/ | |
| 1249 | +static void timeline_hidden_by_user_func( | |
| 1250 | + sqlite3_context *context, | |
| 1251 | + int argc, | |
| 1252 | + sqlite3_value **argv | |
| 1253 | +){ | |
| 1254 | + static Glob *pGlob = 0; | |
| 1255 | + static int isInit = 0; | |
| 1256 | + const char *zUser; | |
| 1257 | + if( !isInit ){ | |
| 1258 | + const char *zPat = db_get("hide-by-user", 0); | |
| 1259 | + pGlob = zPat ? glob_create(zPat) : 0; | |
| 1260 | + isInit = 1; | |
| 1261 | + } | |
| 1262 | + zUser = (const char*)sqlite3_value_text(argv[0]); | |
| 1263 | + sqlite3_result_int(context, | |
| 1264 | + pGlob!=0 && zUser!=0 && glob_match(pGlob, zUser)!=0); | |
| 1265 | +} | |
| 1266 | + | |
| 1267 | +/* | |
| 1268 | +** Register hidden_by_user() and return true if the "hide-by-user" | |
| 1269 | +** setting is non-empty. | |
| 1270 | +*/ | |
| 1271 | +static int timeline_enable_hide_by_user(void){ | |
| 1272 | + const char *zPat = db_get("hide-by-user", 0); | |
| 1273 | + if( zPat==0 || zPat[0]==0 ) return 0; | |
| 1274 | + sqlite3_create_function(g.db, "hidden_by_user", 1, SQLITE_UTF8, 0, | |
| 1275 | + timeline_hidden_by_user_func, 0, 0); | |
| 1276 | + return 1; | |
| 1277 | +} | |
| 1242 | 1278 | |
| 1243 | 1279 | /* |
| 1244 | 1280 | ** zDate is a localtime date. Insert records into the |
| 1245 | 1281 | ** "timeline" table to cause <hr> to be inserted on zDate. |
| 1246 | 1282 | */ |
| @@ -2261,10 +2297,15 @@ | ||
| 2261 | 2297 | blob_append_sql(&sql, |
| 2262 | 2298 | " AND NOT EXISTS(SELECT 1 FROM tagxref" |
| 2263 | 2299 | " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", |
| 2264 | 2300 | TAG_HIDDEN |
| 2265 | 2301 | ); |
| 2302 | + if( timeline_enable_hide_by_user() ){ | |
| 2303 | + blob_append_sql(&sql, | |
| 2304 | + " AND NOT (event.type='ci' AND hidden_by_user(coalesce(euser,user)))\n" | |
| 2305 | + ); | |
| 2306 | + } | |
| 2266 | 2307 | } |
| 2267 | 2308 | if( from_rid && !to_rid && (P("ft")!=0 || P("bt")!=0) ){ |
| 2268 | 2309 | const char *zTo = P("ft"); |
| 2269 | 2310 | if( zTo ){ |
| 2270 | 2311 | from_to_mode = 1; |
| @@ -3049,10 +3090,20 @@ | ||
| 3049 | 3090 | " FROM related_nodes, tagxref\n" |
| 3050 | 3091 | " WHERE tagid=%d AND tagtype>0\n" |
| 3051 | 3092 | " AND tagxref.rid=related_nodes.rid)", |
| 3052 | 3093 | TAG_HIDDEN |
| 3053 | 3094 | ); |
| 3095 | + if( timeline_enable_hide_by_user() ){ | |
| 3096 | + db_multi_exec( | |
| 3097 | + "DELETE FROM related_nodes\n" | |
| 3098 | + " WHERE rid IN (SELECT related_nodes.rid\n" | |
| 3099 | + " FROM related_nodes, event\n" | |
| 3100 | + " WHERE event.objid=related_nodes.rid\n" | |
| 3101 | + " AND event.type='ci'\n" | |
| 3102 | + " AND hidden_by_user(coalesce(euser,user)))" | |
| 3103 | + ); | |
| 3104 | + } | |
| 3054 | 3105 | } |
| 3055 | 3106 | } |
| 3056 | 3107 | } |
| 3057 | 3108 | if( (zType[0]=='w' && !g.perm.RdWiki) |
| 3058 | 3109 | || (zType[0]=='t' && !g.perm.RdTkt) |
| 3059 | 3110 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1237,10 +1237,46 @@ | |
| 1237 | @ FROM event CROSS JOIN blob |
| 1238 | @ WHERE blob.rid=event.objid |
| 1239 | ; |
| 1240 | return zBase; |
| 1241 | } |
| 1242 | |
| 1243 | /* |
| 1244 | ** zDate is a localtime date. Insert records into the |
| 1245 | ** "timeline" table to cause <hr> to be inserted on zDate. |
| 1246 | */ |
| @@ -2261,10 +2297,15 @@ | |
| 2261 | blob_append_sql(&sql, |
| 2262 | " AND NOT EXISTS(SELECT 1 FROM tagxref" |
| 2263 | " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", |
| 2264 | TAG_HIDDEN |
| 2265 | ); |
| 2266 | } |
| 2267 | if( from_rid && !to_rid && (P("ft")!=0 || P("bt")!=0) ){ |
| 2268 | const char *zTo = P("ft"); |
| 2269 | if( zTo ){ |
| 2270 | from_to_mode = 1; |
| @@ -3049,10 +3090,20 @@ | |
| 3049 | " FROM related_nodes, tagxref\n" |
| 3050 | " WHERE tagid=%d AND tagtype>0\n" |
| 3051 | " AND tagxref.rid=related_nodes.rid)", |
| 3052 | TAG_HIDDEN |
| 3053 | ); |
| 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | if( (zType[0]=='w' && !g.perm.RdWiki) |
| 3058 | || (zType[0]=='t' && !g.perm.RdTkt) |
| 3059 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1237,10 +1237,46 @@ | |
| 1237 | @ FROM event CROSS JOIN blob |
| 1238 | @ WHERE blob.rid=event.objid |
| 1239 | ; |
| 1240 | return zBase; |
| 1241 | } |
| 1242 | |
| 1243 | /* |
| 1244 | ** SQL function: hidden_by_user(X) |
| 1245 | ** |
| 1246 | ** Return true if X matches one of the GLOB patterns in the "hide-by-user" |
| 1247 | ** setting. |
| 1248 | */ |
| 1249 | static void timeline_hidden_by_user_func( |
| 1250 | sqlite3_context *context, |
| 1251 | int argc, |
| 1252 | sqlite3_value **argv |
| 1253 | ){ |
| 1254 | static Glob *pGlob = 0; |
| 1255 | static int isInit = 0; |
| 1256 | const char *zUser; |
| 1257 | if( !isInit ){ |
| 1258 | const char *zPat = db_get("hide-by-user", 0); |
| 1259 | pGlob = zPat ? glob_create(zPat) : 0; |
| 1260 | isInit = 1; |
| 1261 | } |
| 1262 | zUser = (const char*)sqlite3_value_text(argv[0]); |
| 1263 | sqlite3_result_int(context, |
| 1264 | pGlob!=0 && zUser!=0 && glob_match(pGlob, zUser)!=0); |
| 1265 | } |
| 1266 | |
| 1267 | /* |
| 1268 | ** Register hidden_by_user() and return true if the "hide-by-user" |
| 1269 | ** setting is non-empty. |
| 1270 | */ |
| 1271 | static int timeline_enable_hide_by_user(void){ |
| 1272 | const char *zPat = db_get("hide-by-user", 0); |
| 1273 | if( zPat==0 || zPat[0]==0 ) return 0; |
| 1274 | sqlite3_create_function(g.db, "hidden_by_user", 1, SQLITE_UTF8, 0, |
| 1275 | timeline_hidden_by_user_func, 0, 0); |
| 1276 | return 1; |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | ** zDate is a localtime date. Insert records into the |
| 1281 | ** "timeline" table to cause <hr> to be inserted on zDate. |
| 1282 | */ |
| @@ -2261,10 +2297,15 @@ | |
| 2297 | blob_append_sql(&sql, |
| 2298 | " AND NOT EXISTS(SELECT 1 FROM tagxref" |
| 2299 | " WHERE tagid=%d AND tagtype>0 AND rid=blob.rid)\n", |
| 2300 | TAG_HIDDEN |
| 2301 | ); |
| 2302 | if( timeline_enable_hide_by_user() ){ |
| 2303 | blob_append_sql(&sql, |
| 2304 | " AND NOT (event.type='ci' AND hidden_by_user(coalesce(euser,user)))\n" |
| 2305 | ); |
| 2306 | } |
| 2307 | } |
| 2308 | if( from_rid && !to_rid && (P("ft")!=0 || P("bt")!=0) ){ |
| 2309 | const char *zTo = P("ft"); |
| 2310 | if( zTo ){ |
| 2311 | from_to_mode = 1; |
| @@ -3049,10 +3090,20 @@ | |
| 3090 | " FROM related_nodes, tagxref\n" |
| 3091 | " WHERE tagid=%d AND tagtype>0\n" |
| 3092 | " AND tagxref.rid=related_nodes.rid)", |
| 3093 | TAG_HIDDEN |
| 3094 | ); |
| 3095 | if( timeline_enable_hide_by_user() ){ |
| 3096 | db_multi_exec( |
| 3097 | "DELETE FROM related_nodes\n" |
| 3098 | " WHERE rid IN (SELECT related_nodes.rid\n" |
| 3099 | " FROM related_nodes, event\n" |
| 3100 | " WHERE event.objid=related_nodes.rid\n" |
| 3101 | " AND event.type='ci'\n" |
| 3102 | " AND hidden_by_user(coalesce(euser,user)))" |
| 3103 | ); |
| 3104 | } |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | if( (zType[0]=='w' && !g.perm.RdWiki) |
| 3109 | || (zType[0]=='t' && !g.perm.RdTkt) |
| 3110 |