Fossil

Check-in [18da05b903]
Login

Check-in [18da05b903]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Extended /builtin/filename to support /builtin/:filename for packing up cacheable bundles of page-specific code. /wikiedit, /fileedit, and /forumpost now serve their JS that way.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | ajax-wiki-editor
Files: files | file ages | folders
SHA3-256: 18da05b9033c73254623cc51d9712dfda06a251a9e5da5ad5fe0dc9a521416c9
User & Date: stephan 2020-07-31 16:14:43.254
Context
2020-07-31
16:40
Added style_emit_script_bundle() to simplify page-level bundle usage a small bit. /forumpost, /wikiedit, /fileedit now use that routine. ... (check-in: 0c233bc697 user: stephan tags: ajax-wiki-editor)
16:14
Extended /builtin/filename to support /builtin/:filename for packing up cacheable bundles of page-specific code. /wikiedit, /fileedit, and /forumpost now serve their JS that way. ... (check-in: 18da05b903 user: stephan tags: ajax-wiki-editor)
14:44
/wikiedit and /fileedit now dump all of their common static JS into a single SCRIPT tag instead of making numerous requests, per forum feedback. Fixed/expanded some of the newer script-emitting logic in style.c to handle these. wikiedit no longer mangles the page-level header. ... (check-in: a4b73fd081 user: stephan tags: ajax-wiki-editor)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/fileedit.c.
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
  fossil_free(zNewUuid);
  blob_reset(&err);
  blob_reset(&manifest);
  CheckinMiniInfo_cleanup(&cimi);
}

/*
** Emits all of the "core" static JS needed by /fileedit into a single
** SCRIPT tag.
**
** TODO: a common mechanism which will let us bundle this type of
** blob into a single cacheable request.
*/
static void fileedit_emit_js(void){
  style_emit_script_tag(0,0);
  style_emit_script_fossil_bootstrap(1);
  style_emit_script_builtin(1,0,"sbsdiff.js");
  style_emit_script_fetch(1,0);
  style_emit_script_tabs(1,0)/*also emits fossil.dom*/;
  style_emit_script_confirmer(1,0);
  style_emit_script_builtin(1, 0, "fossil.storage.js");
  /*
  ** Set up a JS-side mapping of the AJAX_RENDER_xyz values. This is
  ** used for dynamically toggling certain UI components on and off.
  ** Must come before fossil.page.fileedit.js.
  */
  ajax_emit_js_preview_modes(0);
  style_emit_script_builtin(1, 0, "fossil.page.fileedit.js");
  style_emit_script_tag(1,0);
}

/*
** WEBPAGE: fileedit
**
** Enables the online editing and committing of individual text files.
** Requires that the user have Write permissions.







|
|
|
<
<

|
<













<







1480
1481
1482
1483
1484
1485
1486
1487
1488
1489


1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504

1505
1506
1507
1508
1509
1510
1511
  fossil_free(zNewUuid);
  blob_reset(&err);
  blob_reset(&manifest);
  CheckinMiniInfo_cleanup(&cimi);
}

/*
** Emits all of the "core" static JS needed by /wikiedit into a single
** SCRIPT tag. Intended to be mapped to style.c:BundleEmitters with
** the name "fileedit.js".


*/
void fileedit_emit_js_bundle(void){

  style_emit_script_fossil_bootstrap(1);
  style_emit_script_builtin(1,0,"sbsdiff.js");
  style_emit_script_fetch(1,0);
  style_emit_script_tabs(1,0)/*also emits fossil.dom*/;
  style_emit_script_confirmer(1,0);
  style_emit_script_builtin(1, 0, "fossil.storage.js");
  /*
  ** Set up a JS-side mapping of the AJAX_RENDER_xyz values. This is
  ** used for dynamically toggling certain UI components on and off.
  ** Must come before fossil.page.fileedit.js.
  */
  ajax_emit_js_preview_modes(0);
  style_emit_script_builtin(1, 0, "fossil.page.fileedit.js");

}

/*
** WEBPAGE: fileedit
**
** Enables the online editing and committing of individual text files.
** Requires that the user have Write permissions.
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
      blob_appendf(&endScript,"}");
    }
    blob_appendf(&endScript,");\n");
  }

  blob_reset(&err);
  CheckinMiniInfo_cleanup(&cimi);
  fileedit_emit_js();
  if(blob_size(&endScript)>0){
    style_emit_script_tag(0,0);
    CX("\n(function(){\n");
    CX("try{\n%b}\n"
       "catch(e){"
       "fossil.error(e); console.error('Exception:',e);"
       "}\n",







|







1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
      blob_appendf(&endScript,"}");
    }
    blob_appendf(&endScript,");\n");
  }

  blob_reset(&err);
  CheckinMiniInfo_cleanup(&cimi);
  style_emit_script_builtin(0, 0, ":fileedit.js");
  if(blob_size(&endScript)>0){
    style_emit_script_tag(0,0);
    CX("\n(function(){\n");
    CX("try{\n%b}\n"
       "catch(e){"
       "fossil.error(e); console.error('Exception:',e);"
       "}\n",
Changes to src/forum.c.
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
    @ </div>
  }
  forumthread_delete(pThread);
  return target;
}

/*
** The first time this is called, it emits SCRIPT tags to load various
** forum-related JavaScript. Ideally it should be called near the end
** of the page, immediately before the call to style_footer() (which
** closes the document's <BODY> and <HTML> tags). Calls after the first
** are a no-op.
*/
static void forum_emit_page_js(){
  static int once = 0;
  if(0==once){
    once = 1;
    style_load_js("forum.js");
    style_emit_script_fossil_bootstrap(0);
    style_emit_script_dom(0, 1);
    style_emit_script_builtin(0, 1, "fossil.page.forumpost.js");
  }
}

/*
** WEBPAGE: forumpost
**
** Show a single forum posting. The posting is shown in context with
** it's entire thread.  The selected posting is enclosed within







|
<
<
<
|

|
<
<
<
|
|
|
|
<







747
748
749
750
751
752
753
754



755
756
757



758
759
760
761

762
763
764
765
766
767
768
    @ </div>
  }
  forumthread_delete(pThread);
  return target;
}

/*
** Callback for use with style.c:BundleEmitters. Emits all JS code



** required by this page.
*/
void forum_emit_js_bundle(void){



  style_emit_script_builtin(1, 0, "forum.js");
  style_emit_script_fossil_bootstrap(1);
  style_emit_script_dom(1, 0);
  style_emit_script_builtin(1, 0, "fossil.page.forumpost.js");

}

/*
** WEBPAGE: forumpost
**
** Show a single forum posting. The posting is shown in context with
** it's entire thread.  The selected posting is enclosed within
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
    style_submenu_element("Complete Thread", "%R/%s/%s?t=a", g.zPath, zName);
    forum_display_history(froot, fpid, 1);
  }else{
    style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
    style_submenu_element("Unformatted", "%R/%s/%s?t=r", g.zPath, zName);
    forum_display_hierarchical(froot, fpid);
  }
  forum_emit_page_js();
  style_footer();
}

/*
** Return true if a forum post should be moderated.
*/
static int forum_need_moderation(void){







|







885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
    style_submenu_element("Complete Thread", "%R/%s/%s?t=a", g.zPath, zName);
    forum_display_history(froot, fpid, 1);
  }else{
    style_submenu_element("Chronological", "%R/%s/%s?t=c", g.zPath, zName);
    style_submenu_element("Unformatted", "%R/%s/%s?t=r", g.zPath, zName);
    forum_display_hierarchical(froot, fpid);
  }
  style_emit_script_builtin(0, 0, ":forum.js");
  style_footer();
}

/*
** Return true if a forum post should be moderated.
*/
static int forum_need_moderation(void){
Changes to src/forum.js.
12
13
14
15
16
17
18
19
  if(x[0]){
    var w = window.innerHeight;
    var h = x[0].scrollHeight;
    var y = absoluteY(x[0]);
    if( w>h ) y = y + (h-w)/2;
    if( y>0 ) window.scrollTo(0, y);
  }
})()







|
12
13
14
15
16
17
18
19
  if(x[0]){
    var w = window.innerHeight;
    var h = x[0].scrollHeight;
    var y = absoluteY(x[0]);
    if( w>h ) y = y + (h-w)/2;
    if( y>0 ) window.scrollTo(0, y);
  }
})();
Changes to src/style.c.
1124
1125
1126
1127
1128
1129
1130




















































1131
1132
1133
1134
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
  image_url_var("logo");
  image_url_var("background");
  Th_Render(blob_str(&css));

  /* Tell CGI that the content returned by this page is considered cacheable */
  g.isConst = 1;
}





















































/*
** WEBPAGE: builtin
** URL:  builtin/FILENAME
**
** Return the built-in text given by FILENAME.  This is used internally 
** by many Fossil web pages to load built-in javascript files.
**
** If the id= query parameter is present, then Fossil assumes that the
** result is immutable and sets a very large cache retention time (1 year).

*/
void page_builtin_text(void){
  Blob out;
  const char *zName = P("name");
  const char *zTxt = 0;
  const char *zId = P("id");
  int nId;







  if( zName ) zTxt = builtin_text(zName);


  if( zTxt==0 ){
    cgi_set_status(404, "Not Found");
    @ File "%h(zName)" not found
    return;
  }
  if( sqlite3_strglob("*.js", zName)==0 ){
    cgi_set_content_type("application/javascript");
  }else{
    cgi_set_content_type("text/plain");
  }
  if( zId && (nId = (int)strlen(zId))>=8 && strncmp(zId,MANIFEST_UUID,nId)==0 ){
    g.isConst = 1;
  }else{
    etag_check(0,0);
  }

  blob_init(&out, zTxt, -1);
  cgi_set_content(&out);

}

/*
** All possible capabilities
*/
static const char allCap[] = 
  "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








|
|
>





|

>
>
>
>
>
>
>
|
>
>















>
|
|
>







1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
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
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
  image_url_var("logo");
  image_url_var("background");
  Th_Render(blob_str(&css));

  /* Tell CGI that the content returned by this page is considered cacheable */
  g.isConst = 1;
}

/*
** Maps a "bundle" name to a callback which emits the text of that
** bundle. For use in consolidating scripts for certain pages into a
** single cacheable request.
*/
typedef struct {
  const char * zName; /* Name of the bundle (maps to /builtin/:NAME) */
  void (*xEmit)(void); /* Emits amalgamated text output for this
                          bundle */
} BundleEmitter;
/*
** Map each required bundle here...
*/
static const BundleEmitter BundleEmitters[] = {
/* Keep these sorted for bsearch() */
{"fileedit.js", fileedit_emit_js_bundle},
{"forum.js", forum_emit_js_bundle},
{"wikiedit.js", wikiedit_emit_js_bundle}
};

/*
** Comparison function for bsearch() for searching a BundleEmitter
** list for a matching name.
*/
static int cmp_builtin_bundle_name(const void *a, const void *b){
  const BundleEmitter * rA = (const BundleEmitter*)a;
  const BundleEmitter * rB = (const BundleEmitter*)b;
  return fossil_strcmp(rA->zName, rB->zName);
}

/*
** Internal helper for /builtin/FILENAME for dispatching "bundles"
** of amalgamated text (primarily JS) code.
**
** Returns true if it finds a bundle matcing the given name, else
** false. On success it outputs the amalgamated bundle without any
** sort of wrapper, e.g. SCRIPT tag
*/
static int page_builtin_text_bundle(const char * zFilename){
  const BundleEmitter * pBH;
  BundleEmitter needle = {zFilename, 0};

  pBH = (const BundleEmitter *)bsearch(&needle, BundleEmitters,
                                       count(BundleEmitters),
                                       sizeof BundleEmitters[0],
                                       cmp_builtin_bundle_name);
  if(pBH!=0){
    pBH->xEmit();
  }
  return pBH!=0;
}

/*
** WEBPAGE: builtin
** URL:  builtin/FILENAME
**
** Return the built-in text given by FILENAME.  This is used internally 
** by many Fossil web pages to load built-in javascript files.
**
** If the id= or cache= query parameter is present, then Fossil
** assumes that the result is immutable and sets a very large cache
** retention time (1 year).
*/
void page_builtin_text(void){
  Blob out;
  const char *zName = P("name");
  const char *zTxt = 0;
  const char *zId = PD("id",P("cache"));
  int nId;
  int isBundle = 0;

  if( zName ){
    if(':'==zName[0]){
      isBundle = 1;
      zTxt = page_builtin_text_bundle(zName+1) ? "" : NULL;
    }else{
      zTxt = builtin_text(zName);
    }
  }
  if( zTxt==0 ){
    cgi_set_status(404, "Not Found");
    @ File "%h(zName)" not found
    return;
  }
  if( sqlite3_strglob("*.js", zName)==0 ){
    cgi_set_content_type("application/javascript");
  }else{
    cgi_set_content_type("text/plain");
  }
  if( zId && (nId = (int)strlen(zId))>=8 && strncmp(zId,MANIFEST_UUID,nId)==0 ){
    g.isConst = 1;
  }else{
    etag_check(0,0);
  }
  if(isBundle==0){
    blob_init(&out, zTxt, -1);
    cgi_set_content(&out);
  }
}

/*
** All possible capabilities
*/
static const char allCap[] = 
  "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";
1638
1639
1640
1641
1642
1643
1644



1645



1646
1647
1648
1649
1650
1651
1652
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a
** build-time-dependent cache-buster value.
*/
void style_emit_script_builtin(int asInline, int addScripTag,
                               char const * zName){
  if(asInline){



    CX("%s", builtin_text(zName));



  }else{
    char * zFullName = mprintf("builtin/%s",zName);
    const char * zHash = fossil_exe_id();
    CX("<script src='%R/%T?cache=%.8s'></script>\n",
       zFullName, zHash);
    fossil_free(zFullName);
  }







>
>
>

>
>
>







1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a
** build-time-dependent cache-buster value.
*/
void style_emit_script_builtin(int asInline, int addScripTag,
                               char const * zName){
  if(asInline){
    if(addScripTag){
      style_emit_script_tag(0,0);
    }
    CX("%s", builtin_text(zName));
    if(addScripTag){
      style_emit_script_tag(1,0);
    }
  }else{
    char * zFullName = mprintf("builtin/%s",zName);
    const char * zHash = fossil_exe_id();
    CX("<script src='%R/%T?cache=%.8s'></script>\n",
       zFullName, zHash);
    fossil_free(zFullName);
  }
Changes to src/wiki.c.
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
    return;
  }
  pRoute->xCallback();
}

/*
** Emits all of the "core" static JS needed by /wikiedit into a single
** SCRIPT tag.
**
** TODO: a common mechanism which will let us bundle this type of
** blob into a single cacheable request.
*/
static void wikiedit_emit_js(void){
  style_emit_script_tag(0,0);
  style_emit_script_fossil_bootstrap(1);
  style_emit_script_builtin(1,0,"sbsdiff.js");
  style_emit_script_fetch(1, 0);
  style_emit_script_tabs(1,0)/*also emits fossil.dom*/;
  style_emit_script_confirmer(1,0);
  style_emit_script_builtin(1, 0, "fossil.storage.js");
  style_emit_script_builtin(1, 0, "fossil.page.wikiedit.js");
  style_emit_script_tag(1,0);
}

/*
** WEBPAGE: wikiedit
** URL: /wikedit?name=PAGENAME
**
** The main front-end for the Ajax-based wiki editor app. Passing







|
|
<
<

|
<







<







1059
1060
1061
1062
1063
1064
1065
1066
1067


1068
1069

1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
    return;
  }
  pRoute->xCallback();
}

/*
** Emits all of the "core" static JS needed by /wikiedit into a single
** SCRIPT tag. Intended to be mapped to style.c:BundleEmitters with
** the name "wikiedit.js".


*/
void wikiedit_emit_js_bundle(void){

  style_emit_script_fossil_bootstrap(1);
  style_emit_script_builtin(1,0,"sbsdiff.js");
  style_emit_script_fetch(1, 0);
  style_emit_script_tabs(1,0)/*also emits fossil.dom*/;
  style_emit_script_confirmer(1,0);
  style_emit_script_builtin(1, 0, "fossil.storage.js");
  style_emit_script_builtin(1, 0, "fossil.page.wikiedit.js");

}

/*
** WEBPAGE: wikiedit
** URL: /wikedit?name=PAGENAME
**
** The main front-end for the Ajax-based wiki editor app. Passing
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
       "the repo with endless test runs. Any attempt to save the "
       "sandbox page will fail.</p>");
    CX("<hr><h3>Wiki Name Rules</h3>");
    well_formed_wiki_name_rules();
    CX("</div>"/*#wikiedit-tab-save*/);
  }

  wikiedit_emit_js();

  /* Dynamically populate the editor... */
  style_emit_script_tag(0,0);
  CX("\nfossil.onPageLoad(function(){\n");
  CX("const P = fossil.page;\n"
     "try{\n");
  if(found){







|







1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
       "the repo with endless test runs. Any attempt to save the "
       "sandbox page will fail.</p>");
    CX("<hr><h3>Wiki Name Rules</h3>");
    well_formed_wiki_name_rules();
    CX("</div>"/*#wikiedit-tab-save*/);
  }

  style_emit_script_builtin(0, 0, ":wikiedit.js");

  /* Dynamically populate the editor... */
  style_emit_script_tag(0,0);
  CX("\nfossil.onPageLoad(function(){\n");
  CX("const P = fossil.page;\n"
     "try{\n");
  if(found){