Fossil SCM
Add a screen to prompt the user for the name of a new wiki page.
Commit
aa573547364950615afd709d834882c5ee558adc
Parent
dec4685720199ad…
1 file changed
+54
-9
+54
-9
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -48,10 +48,23 @@ | ||
| 48 | 48 | } |
| 49 | 49 | if( z[i-1]==' ' ) return 0; |
| 50 | 50 | if( i<3 || i>100 ) return 0; |
| 51 | 51 | return 1; |
| 52 | 52 | } |
| 53 | + | |
| 54 | +/* | |
| 55 | +** Output rules for well-formed wiki pages | |
| 56 | +*/ | |
| 57 | +static void well_formed_wiki_name_rules(void){ | |
| 58 | + @ <ul> | |
| 59 | + @ <li> Must not begin or end with a space. | |
| 60 | + @ <li> Must not contain any control characters, including tab or | |
| 61 | + @ newline. | |
| 62 | + @ <li> Must not have two or more spaces in a row internally. | |
| 63 | + @ <li> Must be between 3 and 100 characters in length. | |
| 64 | + @ </ul> | |
| 65 | +} | |
| 53 | 66 | |
| 54 | 67 | /* |
| 55 | 68 | ** Check a wiki name. If it is not well-formed, then issue an error |
| 56 | 69 | ** and return true. If it is well-formed, return false. |
| 57 | 70 | */ |
| @@ -58,17 +71,11 @@ | ||
| 58 | 71 | static int check_name(const char *z){ |
| 59 | 72 | if( !wiki_name_is_wellformed(z) ){ |
| 60 | 73 | style_header("Wiki Page Name Error"); |
| 61 | 74 | @ The wiki name "<b>%h(z)</b>" is not well-formed. Rules for |
| 62 | 75 | @ wiki page names: |
| 63 | - @ <ul> | |
| 64 | - @ <li> Must not begin or end with a space. | |
| 65 | - @ <li> Must not contain any control characters, including tab or | |
| 66 | - @ newline. | |
| 67 | - @ <li> Must not have two or more spaces in a row internally. | |
| 68 | - @ <li> Must be between 3 and 100 characters in length. | |
| 69 | - @ </ul> | |
| 76 | + well_formed_wiki_name_rules(); | |
| 70 | 77 | style_footer(); |
| 71 | 78 | return 1; |
| 72 | 79 | } |
| 73 | 80 | return 0; |
| 74 | 81 | } |
| @@ -139,10 +146,13 @@ | ||
| 139 | 146 | @ pages. </li> |
| 140 | 147 | @ <li> <a href="%s(g.zBaseURL)/wiki_rules">Formatting rules</a> for |
| 141 | 148 | @ wiki.</li> |
| 142 | 149 | @ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a> |
| 143 | 150 | @ to experiment.</li> |
| 151 | + if( g.okNewWiki ){ | |
| 152 | + @ <li> Create a <a href="%s(g.zBaseURL)/wikinew">new wiki page</a>.</li> | |
| 153 | + } | |
| 144 | 154 | @ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a> |
| 145 | 155 | @ available on this server.</li> |
| 146 | 156 | @ </ul> |
| 147 | 157 | style_footer(); |
| 148 | 158 | return; |
| @@ -319,10 +329,45 @@ | ||
| 319 | 329 | if( !isSandbox ){ |
| 320 | 330 | manifest_clear(&m); |
| 321 | 331 | } |
| 322 | 332 | style_footer(); |
| 323 | 333 | } |
| 334 | + | |
| 335 | +/* | |
| 336 | +** WEBPAGE: wikinew | |
| 337 | +** URL /wikinew | |
| 338 | +** | |
| 339 | +** Prompt the user to enter the name of a new wiki page. Then redirect | |
| 340 | +** to the wikiedit screen for that new page. | |
| 341 | +*/ | |
| 342 | +void wikinew_page(void){ | |
| 343 | + const char *zName; | |
| 344 | + login_check_credentials(); | |
| 345 | + if( !g.okNewWiki ){ | |
| 346 | + login_needed(); | |
| 347 | + return; | |
| 348 | + } | |
| 349 | + zName = PD("name",""); | |
| 350 | + if( zName[0] && wiki_name_is_wellformed(zName) ){ | |
| 351 | + cgi_redirectf("wikiedit?name=%T", zName); | |
| 352 | + } | |
| 353 | + style_header("Create A New Wiki Page"); | |
| 354 | + @ <p>Rules for wiki page names: | |
| 355 | + well_formed_wiki_name_rules(); | |
| 356 | + @ </p> | |
| 357 | + @ <form method="POST" action="%s(g.zBaseURL)/wikinew"> | |
| 358 | + @ <p>Name of new wiki page: | |
| 359 | + @ <input type="text" width="35" name="name" value="%h(zName)"> | |
| 360 | + @ <input type="submit" value="Create"> | |
| 361 | + @ </p></form> | |
| 362 | + if( zName[0] ){ | |
| 363 | + @ <p><b><font color="red"> | |
| 364 | + @ "%h(zName)" is not a valid wiki page name!</font></b></p> | |
| 365 | + } | |
| 366 | + style_footer(); | |
| 367 | +} | |
| 368 | + | |
| 324 | 369 | |
| 325 | 370 | /* |
| 326 | 371 | ** Append the wiki text for an remark to the end of the given BLOB. |
| 327 | 372 | */ |
| 328 | 373 | static void appendRemark(Blob *p){ |
| @@ -429,11 +474,11 @@ | ||
| 429 | 474 | } |
| 430 | 475 | if( P("cancel")!=0 ){ |
| 431 | 476 | cgi_redirectf("wiki?name=%T", zPageName); |
| 432 | 477 | return; |
| 433 | 478 | } |
| 434 | - zHtmlPageName = mprintf("Append Comment To: %h", zPageName); | |
| 479 | + zHtmlPageName = mprintf("Append Comment To: %s", zPageName); | |
| 435 | 480 | style_header(zHtmlPageName); |
| 436 | 481 | if( P("preview")!=0 ){ |
| 437 | 482 | Blob preview; |
| 438 | 483 | blob_zero(&preview); |
| 439 | 484 | appendRemark(&preview); |
| @@ -467,11 +512,11 @@ | ||
| 467 | 512 | /* |
| 468 | 513 | ** Function called to output extra text at the end of each line in |
| 469 | 514 | ** a wiki history listing. |
| 470 | 515 | */ |
| 471 | 516 | static void wiki_history_extra(int rid){ |
| 472 | - @ <a href="%s(g.zTop)/wdiff?name=%h(zWikiPageName)&a=%d(rid)">[diff]</a> | |
| 517 | + @ <a href="%s(g.zTop)/wdiff?name=%t(zWikiPageName)&a=%d(rid)">[diff]</a> | |
| 473 | 518 | } |
| 474 | 519 | |
| 475 | 520 | /* |
| 476 | 521 | ** WEBPAGE: whistory |
| 477 | 522 | ** URL: /whistory?name=PAGENAME |
| 478 | 523 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -48,10 +48,23 @@ | |
| 48 | } |
| 49 | if( z[i-1]==' ' ) return 0; |
| 50 | if( i<3 || i>100 ) return 0; |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | ** Check a wiki name. If it is not well-formed, then issue an error |
| 56 | ** and return true. If it is well-formed, return false. |
| 57 | */ |
| @@ -58,17 +71,11 @@ | |
| 58 | static int check_name(const char *z){ |
| 59 | if( !wiki_name_is_wellformed(z) ){ |
| 60 | style_header("Wiki Page Name Error"); |
| 61 | @ The wiki name "<b>%h(z)</b>" is not well-formed. Rules for |
| 62 | @ wiki page names: |
| 63 | @ <ul> |
| 64 | @ <li> Must not begin or end with a space. |
| 65 | @ <li> Must not contain any control characters, including tab or |
| 66 | @ newline. |
| 67 | @ <li> Must not have two or more spaces in a row internally. |
| 68 | @ <li> Must be between 3 and 100 characters in length. |
| 69 | @ </ul> |
| 70 | style_footer(); |
| 71 | return 1; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| @@ -139,10 +146,13 @@ | |
| 139 | @ pages. </li> |
| 140 | @ <li> <a href="%s(g.zBaseURL)/wiki_rules">Formatting rules</a> for |
| 141 | @ wiki.</li> |
| 142 | @ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a> |
| 143 | @ to experiment.</li> |
| 144 | @ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a> |
| 145 | @ available on this server.</li> |
| 146 | @ </ul> |
| 147 | style_footer(); |
| 148 | return; |
| @@ -319,10 +329,45 @@ | |
| 319 | if( !isSandbox ){ |
| 320 | manifest_clear(&m); |
| 321 | } |
| 322 | style_footer(); |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | ** Append the wiki text for an remark to the end of the given BLOB. |
| 327 | */ |
| 328 | static void appendRemark(Blob *p){ |
| @@ -429,11 +474,11 @@ | |
| 429 | } |
| 430 | if( P("cancel")!=0 ){ |
| 431 | cgi_redirectf("wiki?name=%T", zPageName); |
| 432 | return; |
| 433 | } |
| 434 | zHtmlPageName = mprintf("Append Comment To: %h", zPageName); |
| 435 | style_header(zHtmlPageName); |
| 436 | if( P("preview")!=0 ){ |
| 437 | Blob preview; |
| 438 | blob_zero(&preview); |
| 439 | appendRemark(&preview); |
| @@ -467,11 +512,11 @@ | |
| 467 | /* |
| 468 | ** Function called to output extra text at the end of each line in |
| 469 | ** a wiki history listing. |
| 470 | */ |
| 471 | static void wiki_history_extra(int rid){ |
| 472 | @ <a href="%s(g.zTop)/wdiff?name=%h(zWikiPageName)&a=%d(rid)">[diff]</a> |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | ** WEBPAGE: whistory |
| 477 | ** URL: /whistory?name=PAGENAME |
| 478 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -48,10 +48,23 @@ | |
| 48 | } |
| 49 | if( z[i-1]==' ' ) return 0; |
| 50 | if( i<3 || i>100 ) return 0; |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | ** Output rules for well-formed wiki pages |
| 56 | */ |
| 57 | static void well_formed_wiki_name_rules(void){ |
| 58 | @ <ul> |
| 59 | @ <li> Must not begin or end with a space. |
| 60 | @ <li> Must not contain any control characters, including tab or |
| 61 | @ newline. |
| 62 | @ <li> Must not have two or more spaces in a row internally. |
| 63 | @ <li> Must be between 3 and 100 characters in length. |
| 64 | @ </ul> |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | ** Check a wiki name. If it is not well-formed, then issue an error |
| 69 | ** and return true. If it is well-formed, return false. |
| 70 | */ |
| @@ -58,17 +71,11 @@ | |
| 71 | static int check_name(const char *z){ |
| 72 | if( !wiki_name_is_wellformed(z) ){ |
| 73 | style_header("Wiki Page Name Error"); |
| 74 | @ The wiki name "<b>%h(z)</b>" is not well-formed. Rules for |
| 75 | @ wiki page names: |
| 76 | well_formed_wiki_name_rules(); |
| 77 | style_footer(); |
| 78 | return 1; |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| @@ -139,10 +146,13 @@ | |
| 146 | @ pages. </li> |
| 147 | @ <li> <a href="%s(g.zBaseURL)/wiki_rules">Formatting rules</a> for |
| 148 | @ wiki.</li> |
| 149 | @ <li> Use the <a href="%s(g.zBaseURL)/wiki?name=Sandbox">Sandbox</a> |
| 150 | @ to experiment.</li> |
| 151 | if( g.okNewWiki ){ |
| 152 | @ <li> Create a <a href="%s(g.zBaseURL)/wikinew">new wiki page</a>.</li> |
| 153 | } |
| 154 | @ <li> <a href="%s(g.zBaseURL)/wcontent">List of All Wiki Pages</a> |
| 155 | @ available on this server.</li> |
| 156 | @ </ul> |
| 157 | style_footer(); |
| 158 | return; |
| @@ -319,10 +329,45 @@ | |
| 329 | if( !isSandbox ){ |
| 330 | manifest_clear(&m); |
| 331 | } |
| 332 | style_footer(); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | ** WEBPAGE: wikinew |
| 337 | ** URL /wikinew |
| 338 | ** |
| 339 | ** Prompt the user to enter the name of a new wiki page. Then redirect |
| 340 | ** to the wikiedit screen for that new page. |
| 341 | */ |
| 342 | void wikinew_page(void){ |
| 343 | const char *zName; |
| 344 | login_check_credentials(); |
| 345 | if( !g.okNewWiki ){ |
| 346 | login_needed(); |
| 347 | return; |
| 348 | } |
| 349 | zName = PD("name",""); |
| 350 | if( zName[0] && wiki_name_is_wellformed(zName) ){ |
| 351 | cgi_redirectf("wikiedit?name=%T", zName); |
| 352 | } |
| 353 | style_header("Create A New Wiki Page"); |
| 354 | @ <p>Rules for wiki page names: |
| 355 | well_formed_wiki_name_rules(); |
| 356 | @ </p> |
| 357 | @ <form method="POST" action="%s(g.zBaseURL)/wikinew"> |
| 358 | @ <p>Name of new wiki page: |
| 359 | @ <input type="text" width="35" name="name" value="%h(zName)"> |
| 360 | @ <input type="submit" value="Create"> |
| 361 | @ </p></form> |
| 362 | if( zName[0] ){ |
| 363 | @ <p><b><font color="red"> |
| 364 | @ "%h(zName)" is not a valid wiki page name!</font></b></p> |
| 365 | } |
| 366 | style_footer(); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /* |
| 371 | ** Append the wiki text for an remark to the end of the given BLOB. |
| 372 | */ |
| 373 | static void appendRemark(Blob *p){ |
| @@ -429,11 +474,11 @@ | |
| 474 | } |
| 475 | if( P("cancel")!=0 ){ |
| 476 | cgi_redirectf("wiki?name=%T", zPageName); |
| 477 | return; |
| 478 | } |
| 479 | zHtmlPageName = mprintf("Append Comment To: %s", zPageName); |
| 480 | style_header(zHtmlPageName); |
| 481 | if( P("preview")!=0 ){ |
| 482 | Blob preview; |
| 483 | blob_zero(&preview); |
| 484 | appendRemark(&preview); |
| @@ -467,11 +512,11 @@ | |
| 512 | /* |
| 513 | ** Function called to output extra text at the end of each line in |
| 514 | ** a wiki history listing. |
| 515 | */ |
| 516 | static void wiki_history_extra(int rid){ |
| 517 | @ <a href="%s(g.zTop)/wdiff?name=%t(zWikiPageName)&a=%d(rid)">[diff]</a> |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | ** WEBPAGE: whistory |
| 522 | ** URL: /whistory?name=PAGENAME |
| 523 |