Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | [c541b6e734] Add cli for attaching to wiki pages and tech notes |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | technoteattachcli |
Files: | files | file ages | folders |
SHA1: |
b208bf75777604dcd86eff9a8e546806 |
User & Date: | dave.vines 2016-01-02 10:46:44.956 |
Context
2016-01-02
| ||
10:49 | [c541b6e734] Correct merge ... (check-in: 85aa2a6f user: dave.vines tags: technoteattachcli) | |
10:46 | [c541b6e734] Add cli for attaching to wiki pages and tech notes ... (check-in: b208bf75 user: dave.vines tags: technoteattachcli) | |
10:34 | Create new branch named "technoteattachcli" ... (check-in: 5712fa8f user: dave.vines tags: technoteattachcli (unpublished)) | |
Changes
Changes to src/attach.c.
︙ | ︙ | |||
244 245 246 247 248 249 250 251 252 253 254 255 256 257 | rid = content_put(pAttach); db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d);", rid); db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid); } manifest_crosslink(rid, pAttach, MC_NONE); } /* ** WEBPAGE: attachadd ** Add a new attachment. ** ** tkt=TICKETUUID ** page=WIKIPAGE | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | rid = content_put(pAttach); db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d);", rid); db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid); } manifest_crosslink(rid, pAttach, MC_NONE); } /* ** Commit a new attachment into the repository */ void attach_commit( const char *zName, /* The filename of the attachment */ const char *zTarget, /* The artifact uuid to attach to */ const char *aContent, /* The content of the attachment */ int szContent, /* The length of the attachment */ int needModerator, /* Moderate the attachment? */ const char *zComment /* The comment for the attachment */ ){ Blob content; Blob manifest; Blob cksum; char *zUUID; char *zDate; int rid; int i, n; int addCompress = 0; Manifest *pManifest; db_begin_transaction(); blob_init(&content, aContent, szContent); pManifest = manifest_parse(&content, 0, 0); manifest_destroy(pManifest); blob_init(&content, aContent, szContent); if( pManifest ){ blob_compress(&content, &content); addCompress = 1; } rid = content_put_ex(&content, 0, 0, 0, needModerator); zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); blob_zero(&manifest); for(i=n=0; zName[i]; i++){ if( zName[i]=='/' || zName[i]=='\\' ) n = i+1; } zName += n; if( zName[0]==0 ) zName = "unknown"; blob_appendf(&manifest, "A %F%s %F %s\n", zName, addCompress ? ".gz" : "", zTarget, zUUID); while( fossil_isspace(zComment[0]) ) zComment++; n = strlen(zComment); while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } if( n>0 ){ blob_appendf(&manifest, "C %#F\n", n, zComment); } zDate = date_in_standard_format("now"); blob_appendf(&manifest, "D %s\n", zDate); blob_appendf(&manifest, "U %F\n", login_name()); md5sum_blob(&manifest, &cksum); blob_appendf(&manifest, "Z %b\n", &cksum); attach_put(&manifest, rid, needModerator); assert( blob_is_reset(&manifest) ); db_end_transaction(0); } /* ** WEBPAGE: attachadd ** Add a new attachment. ** ** tkt=TICKETUUID ** page=WIKIPAGE |
︙ | ︙ | |||
320 321 322 323 324 325 326 | zTkt, zTkt); } if( zFrom==0 ) zFrom = mprintf("%s/home", g.zTop); if( P("cancel") ){ cgi_redirect(zFrom); } if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct()) ){ | < < < < < < < < < < < < < < < < < < < < < < | | < < < < < < < < < < | < | < < < < < < < < < < < < | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | zTkt, zTkt); } if( zFrom==0 ) zFrom = mprintf("%s/home", g.zTop); if( P("cancel") ){ cgi_redirect(zFrom); } if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct()) ){ int needModerator = (zTkt!=0 && ticket_need_moderation(0)) || (zPage!=0 && wiki_need_moderation(0)); const char *zComment = PD("comment", ""); attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); cgi_redirect(zFrom); } style_header("Add Attachment"); if( !goodCaptcha ){ @ <p class="generalError">Error: Incorrect security code.</p> } @ <h2>Add Attachment To %s(zTargetType)</h2> |
︙ | ︙ |
Changes to src/info.c.
︙ | ︙ | |||
1381 1382 1383 1384 1385 1386 1387 | if( cnt>0 ){ @ Also attachment "%h(zFilename)" to }else{ @ Attachment "%h(zFilename)" to } objType |= OBJTYPE_ATTACHMENT; if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){ | > > > | | | | > > > > > > > > > > > > > > > | 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 | if( cnt>0 ){ @ Also attachment "%h(zFilename)" to }else{ @ Attachment "%h(zFilename)" to } objType |= OBJTYPE_ATTACHMENT; if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){ if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", zTarget) ){ if( g.perm.Hyperlink && g.anon.RdTkt ){ @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>] }else{ @ ticket [%S(zTarget)] } }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", zTarget) ){ if( g.perm.Hyperlink && g.anon.RdWiki ){ @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>] }else{ @ tech note [%S(zTarget)] } }else{ if( g.perm.Hyperlink && g.anon.RdWiki ){ @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] }else{ @ wiki page [%h(zTarget)] } } }else{ if( g.perm.Hyperlink && g.anon.RdWiki ){ @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] }else{ @ wiki page [%h(zTarget)] } |
︙ | ︙ |
Changes to src/wiki.c.
︙ | ︙ | |||
1135 1136 1137 1138 1139 1140 1141 | db_end_transaction(0); return 1; } /* ** COMMAND: wiki* ** | | | | | | > > > > | 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 | db_end_transaction(0); return 1; } /* ** COMMAND: wiki* ** ** Usage: %fossil wiki (export|create|commit|list) WikiName ** ** Run various subcommands to work with wiki entries or tech notes. ** ** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ] ** ** Sends the latest version of either the PAGENAME wiki entry ** or the DATETIME tech note to the given file or standard ** output. One of PAGENAME or DATETIME must be specified. ** ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS? ** ** Create a new or commit changes to an existing wiki page or ** technote from FILE or from standard input. ** ** Options: ** -M|--mimetype TEXT-FORMAT The mime type of the update defaulting ** defaulting to the type used by the ** previous version of the page or (for ** new pages) text/x-fossil-wiki. ** -t|--technote DATETIME Specifies the timestamp of the technote ** to be created or updated. ** --technote-tags TAGS The set of tags for a technote. ** --technote-bgcolor COLOR The color used for the technote on the ** timeline. ** ** %fossil wiki list ?-technote? ** %fossil wiki ls ?-technote? ** ** Lists all wiki entries, one per line, ordered ** case-insensitively by name. The --technote flag ** specifies that technotes will be listed instead of ** the wiki entries, which will be listed in order ** timestamp. ** ** %fossil wiki attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME ] ** ** Add an attachment to an existing wiki page or tech note. One of ** PAGENAME or DATETIME must be specified. */ void wiki_cmd(void){ int n; db_find_and_open_repository(0, 0); if( g.argc<3 ){ goto wiki_cmd_usage; } |
︙ | ︙ | |||
1191 1192 1193 1194 1195 1196 1197 | const char *zFile; /* Name of the output file (0=stdout) */ const char *zETime; /* The name of the technote to export */ int rid; /* Artifact ID of the wiki page */ int i; /* Loop counter */ char *zBody = 0; /* Wiki page content */ Blob body; /* Wiki page content */ Manifest *pWiki = 0; /* Parsed wiki page content */ | < | 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | const char *zFile; /* Name of the output file (0=stdout) */ const char *zETime; /* The name of the technote to export */ int rid; /* Artifact ID of the wiki page */ int i; /* Loop counter */ char *zBody = 0; /* Wiki page content */ Blob body; /* Wiki page content */ Manifest *pWiki = 0; /* Parsed wiki page content */ zETime = find_option("technote","t",1); if( !zETime ){ if( (g.argc!=4) && (g.argc!=5) ){ usage("export PAGENAME ?FILE?"); } zPageName = g.argv[3]; rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" |
︙ | ︙ | |||
1329 1330 1331 1332 1333 1334 1335 | ); } while( db_step(&q)==SQLITE_ROW ){ const char *zName = db_column_text(&q, 0); fossil_print( "%s\n",zName); } db_finalize(&q); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 | ); } while( db_step(&q)==SQLITE_ROW ){ const char *zName = db_column_text(&q, 0); fossil_print( "%s\n",zName); } db_finalize(&q); }else if( strncmp(g.argv[2],"attachment",n)==0 ){ int n3 = strlen(g.argv[3]); if( n3==0 ){ usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); } if( strncmp(g.argv[3],"add",n3)==0 ){ const char *zPageName; /* Name of the wiki page to attach to */ const char *zFile; /* Name of the file to be attached */ const char *zETime; /* The name of the technote to attach to */ Manifest *pWiki = 0; /* Parsed wiki page content */ char *zBody = 0; /* Wiki page content */ int rid; const char *zTarget; /* Target of the attachment */ Blob content; /* The content of the attachment */ zETime = find_option("technote","t",1); if( !zETime ){ if( g.argc!=6 ){ usage("attachment add PAGENAME FILENAME"); } zPageName = g.argv[4]; rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x" " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'" " ORDER BY x.mtime DESC LIMIT 1", zPageName ); if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){ zBody = pWiki->zWiki; } if( zBody==0 ){ fossil_fatal("wiki page [%s] not found",zPageName); } zTarget = zPageName; zFile = g.argv[5]; }else{ if( g.argc!=5 ){ usage("attachment add FILENAME --technote DATETIME"); } rid = db_int(0, "SELECT objid FROM event" " WHERE datetime(mtime)=datetime('%q') AND type='e'" " ORDER BY mtime DESC LIMIT 1", zETime ); if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){ zBody = pWiki->zWiki; } if( zBody==0 ){ fossil_fatal("technote [%s] not found",zPageName); } zTarget = db_text(0, "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')", rid ); zFile = g.argv[4]; } blob_read_from_file(&content, zFile); user_select(); attach_commit( zFile, /* The filename of the attachment */ zTarget, /* The artifact uuid to attach to */ blob_buffer(&content), /* The content of the attachment */ blob_size(&content), /* The length of the attachment */ 0, /* No need to moderate the attachment */ "" /* Empty attachment comment */ ); if( !zETime ){ fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName); }else{ fossil_print("Attached %s to tech note %s.\n", zFile, zETime); } }else{ usage("attachment add ?PAGENAME? FILENAME [-t|--technote DATETIME]"); } }else{ goto wiki_cmd_usage; } return; wiki_cmd_usage: usage("export|create|commit|list|attachment ..."); } |