| | @@ -2,11 +2,11 @@ |
| 2 | 2 | ** Copyright (c) 2009 D. Richard Hipp |
| 3 | 3 | ** |
| 4 | 4 | ** This program is free software; you can redistribute it and/or |
| 5 | 5 | ** modify it under the terms of the Simplified BSD License (also |
| 6 | 6 | ** known as the "2-Clause License" or "FreeBSD License".) |
| 7 | | - |
| 7 | +** |
| 8 | 8 | ** This program is distributed in the hope that it will be useful, |
| 9 | 9 | ** but without any warranty; without even the implied warranty of |
| 10 | 10 | ** merchantability or fitness for a particular purpose. |
| 11 | 11 | ** |
| 12 | 12 | ** Author contact information: |
| | @@ -53,10 +53,15 @@ |
| 53 | 53 | { "Black & White, Menu on Left", "black_and_white", 0 }, |
| 54 | 54 | { "Plain Gray, No Logo", "plain_gray", 0 }, |
| 55 | 55 | { "Khaki, No Logo", "khaki", 0 }, |
| 56 | 56 | }; |
| 57 | 57 | |
| 58 | +/* |
| 59 | +** A skin consists of four "files" named here: |
| 60 | +*/ |
| 61 | +static const char *azSkinFile[] = { "css", "header", "footer", "details" }; |
| 62 | + |
| 58 | 63 | /* |
| 59 | 64 | ** Alternative skins can be specified in the CGI script or by options |
| 60 | 65 | ** on the "http", "ui", and "server" commands. The alternative skin |
| 61 | 66 | ** name must be one of the aBuiltinSkin[].zLabel names. If there is |
| 62 | 67 | ** a match, that alternative is used. |
| | @@ -64,10 +69,11 @@ |
| 64 | 69 | ** The following static variable holds the name of the alternative skin, |
| 65 | 70 | ** or NULL if the skin should be as configured. |
| 66 | 71 | */ |
| 67 | 72 | static struct BuiltinSkin *pAltSkin = 0; |
| 68 | 73 | static char *zAltSkinDir = 0; |
| 74 | +static int iDraftSkin = 0; |
| 69 | 75 | |
| 70 | 76 | /* |
| 71 | 77 | ** Skin details are a set of key/value pairs that define display |
| 72 | 78 | ** attributes of the skin that cannot be easily specified using CSS |
| 73 | 79 | ** or that need to be known on the server-side. |
| | @@ -100,10 +106,14 @@ |
| 100 | 106 | int i; |
| 101 | 107 | Blob err = BLOB_INITIALIZER; |
| 102 | 108 | if( strchr(zName, '/')!=0 ){ |
| 103 | 109 | zAltSkinDir = fossil_strdup(zName); |
| 104 | 110 | return 0; |
| 111 | + } |
| 112 | + if( sqlite3_strglob("draft[1-9]", zName)==0 ){ |
| 113 | + skin_use_draft(zName[5] - '0'); |
| 114 | + return 0; |
| 105 | 115 | } |
| 106 | 116 | for(i=0; i<count(aBuiltinSkin); i++){ |
| 107 | 117 | if( fossil_strcmp(aBuiltinSkin[i].zLabel, zName)==0 ){ |
| 108 | 118 | pAltSkin = &aBuiltinSkin[i]; |
| 109 | 119 | return 0; |
| | @@ -126,18 +136,33 @@ |
| 126 | 136 | if( zSkin ){ |
| 127 | 137 | char *zErr = skin_use_alternative(zSkin); |
| 128 | 138 | if( zErr ) fossil_fatal("%s", zErr); |
| 129 | 139 | } |
| 130 | 140 | } |
| 141 | + |
| 142 | +/* |
| 143 | +** Use one of the draft skins. |
| 144 | +*/ |
| 145 | +void skin_use_draft(int i){ |
| 146 | + iDraftSkin = i; |
| 147 | +} |
| 131 | 148 | |
| 132 | 149 | /* |
| 133 | 150 | ** The following routines return the various components of the skin |
| 134 | 151 | ** that should be used for the current run. |
| 152 | +** |
| 153 | +** zWhat is one of: "css", "header", "footer", "details". |
| 135 | 154 | */ |
| 136 | 155 | const char *skin_get(const char *zWhat){ |
| 137 | 156 | const char *zOut; |
| 138 | 157 | char *z; |
| 158 | + if( iDraftSkin ){ |
| 159 | + z = mprintf("draft%d-%s", iDraftSkin, zWhat); |
| 160 | + zOut = db_get(z, 0); |
| 161 | + fossil_free(z); |
| 162 | + if( zOut ) return zOut; |
| 163 | + } |
| 139 | 164 | if( zAltSkinDir ){ |
| 140 | 165 | char *z = mprintf("%s/%s.txt", zAltSkinDir, zWhat); |
| 141 | 166 | if( file_isfile(z, ExtFILE) ){ |
| 142 | 167 | Blob x; |
| 143 | 168 | blob_read_from_file(&x, z, ExtFILE); |
| | @@ -311,30 +336,29 @@ |
| 311 | 336 | ** Memory to hold the returned string is obtained from malloc. |
| 312 | 337 | */ |
| 313 | 338 | static char *getSkin(const char *zName){ |
| 314 | 339 | const char *z; |
| 315 | 340 | char *zLabel; |
| 316 | | - static const char *azType[] = { "css", "header", "footer", "details" }; |
| 317 | 341 | int i; |
| 318 | 342 | Blob val; |
| 319 | 343 | blob_zero(&val); |
| 320 | | - for(i=0; i<count(azType); i++){ |
| 344 | + for(i=0; i<count(azSkinFile); i++){ |
| 321 | 345 | if( zName ){ |
| 322 | | - zLabel = mprintf("skins/%s/%s.txt", zName, azType[i]); |
| 346 | + zLabel = mprintf("skins/%s/%s.txt", zName, azSkinFile[i]); |
| 323 | 347 | z = builtin_text(zLabel); |
| 324 | 348 | fossil_free(zLabel); |
| 325 | 349 | }else{ |
| 326 | | - z = db_get(azType[i], 0); |
| 350 | + z = db_get(azSkinFile[i], 0); |
| 327 | 351 | if( z==0 ){ |
| 328 | | - zLabel = mprintf("skins/default/%s.txt", azType[i]); |
| 352 | + zLabel = mprintf("skins/default/%s.txt", azSkinFile[i]); |
| 329 | 353 | z = builtin_text(zLabel); |
| 330 | 354 | fossil_free(zLabel); |
| 331 | 355 | } |
| 332 | 356 | } |
| 333 | 357 | blob_appendf(&val, |
| 334 | 358 | "REPLACE INTO config(name,value,mtime) VALUES(%Q,%Q,now());\n", |
| 335 | | - azType[i], z |
| 359 | + azSkinFile[i], z |
| 336 | 360 | ); |
| 337 | 361 | } |
| 338 | 362 | return blob_str(&val); |
| 339 | 363 | } |
| 340 | 364 | |
| | @@ -355,11 +379,11 @@ |
| 355 | 379 | style_header("Rename A Skin"); |
| 356 | 380 | if( ex ){ |
| 357 | 381 | @ <p><span class="generalError">There is already another skin |
| 358 | 382 | @ named "%h(zNewName)". Choose a different name.</span></p> |
| 359 | 383 | } |
| 360 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"><div> |
| 384 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"><div> |
| 361 | 385 | @ <table border="0"><tr> |
| 362 | 386 | @ <tr><td align="right">Current name:<td align="left"><b>%h(zOldName)</b> |
| 363 | 387 | @ <tr><td align="right">New name:<td align="left"> |
| 364 | 388 | @ <input type="text" size="35" name="newname" value="%h(zNewName)"> |
| 365 | 389 | @ <tr><td><td> |
| | @@ -395,11 +419,11 @@ |
| 395 | 419 | style_header("Save Current Skin"); |
| 396 | 420 | if( ex ){ |
| 397 | 421 | @ <p><span class="generalError">There is already another skin |
| 398 | 422 | @ named "%h(zNewName)". Choose a different name.</span></p> |
| 399 | 423 | } |
| 400 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"><div> |
| 424 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"><div> |
| 401 | 425 | @ <table border="0"><tr> |
| 402 | 426 | @ <tr><td align="right">Name for this skin:<td align="left"> |
| 403 | 427 | @ <input type="text" size="35" name="svname" value="%h(zNewName)"> |
| 404 | 428 | @ <tr><td><td> |
| 405 | 429 | @ <input type="submit" name="save" value="Save"> |
| | @@ -417,23 +441,23 @@ |
| 417 | 441 | ); |
| 418 | 442 | return 0; |
| 419 | 443 | } |
| 420 | 444 | |
| 421 | 445 | /* |
| 422 | | -** WEBPAGE: setup_skin |
| 446 | +** WEBPAGE: setup_skin_admin |
| 423 | 447 | ** |
| 424 | | -** Show a list of available skins with buttons for selecting which |
| 425 | | -** skin to use. Requires Admin privilege. |
| 448 | +** Administrative actions on skins. For administrators only. |
| 426 | 449 | */ |
| 427 | | -void setup_skin(void){ |
| 450 | +void setup_skin_admin(void){ |
| 428 | 451 | const char *z; |
| 429 | 452 | char *zName; |
| 430 | 453 | char *zErr = 0; |
| 431 | 454 | const char *zCurrent = 0; /* Current skin */ |
| 432 | 455 | int i; /* Loop counter */ |
| 433 | 456 | Stmt q; |
| 434 | 457 | int seenCurrent = 0; |
| 458 | + int once; |
| 435 | 459 | |
| 436 | 460 | login_check_credentials(); |
| 437 | 461 | if( !g.perm.Setup ){ |
| 438 | 462 | login_needed(0); |
| 439 | 463 | return; |
| | @@ -445,11 +469,11 @@ |
| 445 | 469 | } |
| 446 | 470 | |
| 447 | 471 | /* Process requests to delete a user-defined skin */ |
| 448 | 472 | if( P("del1") && (zName = skinVarName(P("sn"), 1))!=0 ){ |
| 449 | 473 | style_header("Confirm Custom Skin Delete"); |
| 450 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"><div> |
| 474 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"><div> |
| 451 | 475 | @ <p>Deletion of a custom skin is a permanent action that cannot |
| 452 | 476 | @ be undone. Please confirm that this is what you want to do:</p> |
| 453 | 477 | @ <input type="hidden" name="sn" value="%h(P("sn"))" /> |
| 454 | 478 | @ <input type="submit" name="del2" value="Confirm - Delete The Skin" /> |
| 455 | 479 | @ <input type="submit" name="cancel" value="Cancel - Do Not Delete" /> |
| | @@ -458,10 +482,16 @@ |
| 458 | 482 | style_footer(); |
| 459 | 483 | return; |
| 460 | 484 | } |
| 461 | 485 | if( P("del2")!=0 && (zName = skinVarName(P("sn"), 1))!=0 ){ |
| 462 | 486 | db_multi_exec("DELETE FROM config WHERE name=%Q", zName); |
| 487 | + } |
| 488 | + if( P("draftdel")!=0 ){ |
| 489 | + const char *zDraft = P("name"); |
| 490 | + if( sqlite3_strglob("draft[1-9]",zDraft)==0 ){ |
| 491 | + db_multi_exec("DELETE FROM config WHERE name GLOB '%q-*'", zDraft); |
| 492 | + } |
| 463 | 493 | } |
| 464 | 494 | if( skinRename() ) return; |
| 465 | 495 | if( skinSave(zCurrent) ) return; |
| 466 | 496 | |
| 467 | 497 | /* The user pressed one of the "Install" buttons. */ |
| | @@ -506,36 +536,20 @@ |
| 506 | 536 | |
| 507 | 537 | style_header("Skins"); |
| 508 | 538 | if( zErr ){ |
| 509 | 539 | @ <p style="color:red">%h(zErr)</p> |
| 510 | 540 | } |
| 511 | | - @ <p>A "skin" is a combination of |
| 512 | | - @ <a href="setup_skinedit?w=0">CSS</a>, |
| 513 | | - @ <a href="setup_skinedit?w=2">Header</a>, |
| 514 | | - @ <a href="setup_skinedit?w=1">Footer</a>, and |
| 515 | | - @ <a href="setup_skinedit?w=3">Details</a> |
| 516 | | - @ that determines the look and feel |
| 517 | | - @ of the web interface.</p> |
| 518 | | - @ |
| 519 | | - if( pAltSkin ){ |
| 520 | | - @ <p class="generalError"> |
| 521 | | - @ This page is generated using an skin override named |
| 522 | | - @ "%h(pAltSkin->zLabel)". You can change the skin configuration |
| 523 | | - @ below, but the changes will not take effect until the Fossil server |
| 524 | | - @ is restarted without the override.</p> |
| 525 | | - @ |
| 526 | | - } |
| 527 | | - @ <h2>Available Skins:</h2> |
| 528 | 541 | @ <table border="0"> |
| 542 | + @ <tr><td colspan=4><h2>Built-in Skins:</h2></td></th> |
| 529 | 543 | for(i=0; i<count(aBuiltinSkin); i++){ |
| 530 | 544 | z = aBuiltinSkin[i].zDesc; |
| 531 | 545 | @ <tr><td>%d(i+1).<td>%h(z)<td> <td> |
| 532 | 546 | if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){ |
| 533 | 547 | @ (Currently In Use) |
| 534 | 548 | seenCurrent = 1; |
| 535 | 549 | }else{ |
| 536 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"> |
| 550 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"> |
| 537 | 551 | @ <input type="hidden" name="sn" value="%h(z)" /> |
| 538 | 552 | @ <input type="submit" name="load" value="Install" /> |
| 539 | 553 | if( pAltSkin==&aBuiltinSkin[i] ){ |
| 540 | 554 | @ (Current override) |
| 541 | 555 | } |
| | @@ -546,16 +560,22 @@ |
| 546 | 560 | db_prepare(&q, |
| 547 | 561 | "SELECT substr(name, 6), value FROM config" |
| 548 | 562 | " WHERE name GLOB 'skin:*'" |
| 549 | 563 | " ORDER BY name" |
| 550 | 564 | ); |
| 565 | + once = 1; |
| 551 | 566 | while( db_step(&q)==SQLITE_ROW ){ |
| 552 | 567 | const char *zN = db_column_text(&q, 0); |
| 553 | 568 | const char *zV = db_column_text(&q, 1); |
| 554 | 569 | i++; |
| 570 | + if( once ){ |
| 571 | + once = 0; |
| 572 | + @ <tr><td colspan=4><h2>Skins saved as "skin:*' entries \ |
| 573 | + @ in the CONFIG table:</h2></td></tr> |
| 574 | + } |
| 555 | 575 | @ <tr><td>%d(i).<td>%h(zN)<td> <td> |
| 556 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"> |
| 576 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"> |
| 557 | 577 | if( fossil_strcmp(zV, zCurrent)==0 ){ |
| 558 | 578 | @ (Currently In Use) |
| 559 | 579 | seenCurrent = 1; |
| 560 | 580 | }else{ |
| 561 | 581 | @ <input type="submit" name="load" value="Install"> |
| | @@ -566,28 +586,52 @@ |
| 566 | 586 | @ </form></tr> |
| 567 | 587 | } |
| 568 | 588 | db_finalize(&q); |
| 569 | 589 | if( !seenCurrent ){ |
| 570 | 590 | i++; |
| 571 | | - @ <tr><td>%d(i).<td><i>Current Configuration</i><td> <td> |
| 572 | | - @ <form action="%s(g.zTop)/setup_skin" method="post"> |
| 573 | | - @ <input type="submit" name="save" value="Save"> |
| 591 | + @ <tr><td colspan=4><h2>Current skin in css/header/footer/details entries \ |
| 592 | + @ in the CONFIG table:</h2></td></tr> |
| 593 | + @ <tr><td>%d(i).<td><i>Current</i><td> <td> |
| 594 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"> |
| 595 | + @ <input type="submit" name="save" value="Backup"> |
| 574 | 596 | @ </form> |
| 575 | 597 | } |
| 598 | + db_prepare(&q, |
| 599 | + "SELECT DISTINCT substr(name, 1, 6) FROM config" |
| 600 | + " WHERE name GLOB 'draft[1-9]-*'" |
| 601 | + " ORDER BY name" |
| 602 | + ); |
| 603 | + once = 1; |
| 604 | + while( db_step(&q)==SQLITE_ROW ){ |
| 605 | + const char *zN = db_column_text(&q, 0); |
| 606 | + i++; |
| 607 | + if( once ){ |
| 608 | + once = 0; |
| 609 | + @ <tr><td colspan=4><h2>Draft skins stored as "draft[1-9]-*' entries \ |
| 610 | + @ in the CONFIG table:</h2></td></tr> |
| 611 | + } |
| 612 | + @ <tr><td>%d(i).<td>%h(zN)<td> <td> |
| 613 | + @ <form action="%s(g.zTop)/setup_skin_admin" method="post"> |
| 614 | + @ <input type="submit" name="draftdel" value="Delete"> |
| 615 | + @ <input type="hidden" name="name" value="%h(zN)"> |
| 616 | + @ </form></tr> |
| 617 | + } |
| 618 | + db_finalize(&q); |
| 619 | + |
| 576 | 620 | @ </table> |
| 577 | 621 | style_footer(); |
| 578 | 622 | db_end_transaction(0); |
| 579 | 623 | } |
| 580 | 624 | |
| 581 | | - |
| 582 | 625 | /* |
| 583 | 626 | ** WEBPAGE: setup_skinedit |
| 584 | 627 | ** |
| 585 | 628 | ** Edit aspects of a skin determined by the w= query parameter. |
| 586 | | -** Requires Admin privileges. |
| 629 | +** Requires Setup privileges. |
| 587 | 630 | ** |
| 588 | | -** w=N -- 0=CSS, 1=footer, 2=header, 3=details |
| 631 | +** w=NUM -- 0=CSS, 1=footer, 2=header, 3=details |
| 632 | +** sk=NUM -- the draft skin number |
| 589 | 633 | */ |
| 590 | 634 | void setup_skinedit(void){ |
| 591 | 635 | static const struct sSkinAddr { |
| 592 | 636 | const char *zFile; |
| 593 | 637 | const char *zTitle; |
| | @@ -599,39 +643,61 @@ |
| 599 | 643 | /* 3 */ { "details", "Display Details", "Details", }, |
| 600 | 644 | }; |
| 601 | 645 | const char *zBasis; |
| 602 | 646 | const char *zContent; |
| 603 | 647 | char *zDflt; |
| 648 | + char *zKey; |
| 649 | + char *zTitle; |
| 650 | + int iSkin; |
| 604 | 651 | int ii; |
| 605 | 652 | int j; |
| 606 | 653 | |
| 607 | 654 | login_check_credentials(); |
| 655 | + |
| 656 | + /* Figure out which skin we are editing */ |
| 657 | + iSkin = atoi(PD("sk","1")); |
| 658 | + if( iSkin<1 || iSkin>9 ) iSkin = 1; |
| 659 | + |
| 660 | + /* Check that the user is authorized to edit this skin. */ |
| 608 | 661 | if( !g.perm.Setup ){ |
| 609 | | - login_needed(0); |
| 610 | | - return; |
| 662 | + char *zAllowedEditors = db_get_mprintf("draft%d-users", "", iSkin); |
| 663 | + Glob *pAllowedEditors; |
| 664 | + if( zAllowedEditors[0] ){ |
| 665 | + pAllowedEditors = glob_create(zAllowedEditors); |
| 666 | + if( !glob_match(pAllowedEditors, zAllowedEditors) ){ |
| 667 | + login_needed(0); |
| 668 | + return; |
| 669 | + } |
| 670 | + glob_free(pAllowedEditors); |
| 671 | + } |
| 611 | 672 | } |
| 673 | + |
| 674 | + /* figure out which file is to be edited */ |
| 612 | 675 | ii = atoi(PD("w","0")); |
| 613 | 676 | if( ii<0 || ii>count(aSkinAttr) ) ii = 0; |
| 677 | + zKey = mprintf("draft%d-%s", iSkin, aSkinAttr[ii].zFile); |
| 678 | + zTitle = mprintf("%s for Draft%d", aSkinAttr[ii].zTitle, iSkin); |
| 679 | + |
| 614 | 680 | zBasis = PD("basis","default"); |
| 615 | 681 | zDflt = mprintf("skins/%s/%s.txt", zBasis, aSkinAttr[ii].zFile); |
| 616 | 682 | db_begin_transaction(); |
| 617 | 683 | if( P("revert")!=0 ){ |
| 618 | 684 | db_multi_exec("DELETE FROM config WHERE name=%Q", aSkinAttr[ii].zFile); |
| 619 | 685 | cgi_replace_parameter(aSkinAttr[ii].zFile, builtin_text(zDflt)); |
| 620 | 686 | } |
| 621 | | - style_header("%s", aSkinAttr[ii].zTitle); |
| 687 | + style_header("%s", zTitle); |
| 622 | 688 | for(j=0; j<count(aSkinAttr); j++){ |
| 623 | 689 | if( j==ii ) continue; |
| 624 | 690 | style_submenu_element(aSkinAttr[j].zSubmenu, |
| 625 | | - "%R/setup_skinedit?w=%d&basis=%h",j,zBasis); |
| 691 | + "%R/setup_skinedit?w=%d&basis=%h&sk=%d",j,zBasis,iSkin); |
| 626 | 692 | } |
| 627 | | - style_submenu_element("Skins", "%R/setup_skin"); |
| 628 | 693 | @ <form action="%s(g.zTop)/setup_skinedit" method="post"><div> |
| 629 | 694 | login_insert_csrf_secret(); |
| 630 | 695 | @ <input type='hidden' name='w' value='%d(ii)'> |
| 631 | | - @ <h2>Edit %s(aSkinAttr[ii].zTitle):</h2> |
| 632 | | - zContent = textarea_attribute("", 10, 80, aSkinAttr[ii].zFile, |
| 696 | + @ <input type='hidden' name='sk' value='%d(iSkin)'> |
| 697 | + @ <h2>Edit %s(zTitle):</h2> |
| 698 | + zContent = textarea_attribute("", 10, 80, zKey, |
| 633 | 699 | aSkinAttr[ii].zFile, builtin_text(zDflt), 0); |
| 634 | 700 | @ <br /> |
| 635 | 701 | @ <input type="submit" name="submit" value="Apply Changes" /> |
| 636 | 702 | @ <hr /> |
| 637 | 703 | @ Baseline: <select size='1' name='basis'> |
| | @@ -668,5 +734,292 @@ |
| 668 | 734 | } |
| 669 | 735 | @ </div></form> |
| 670 | 736 | style_footer(); |
| 671 | 737 | db_end_transaction(0); |
| 672 | 738 | } |
| 739 | + |
| 740 | +/* |
| 741 | +** Try to initialize draft skin iSkin to the built-in or preexisting |
| 742 | +** skin named by zTemplate. |
| 743 | +*/ |
| 744 | +static void skin_initialize_draft(int iSkin, const char *zTemplate){ |
| 745 | + int i; |
| 746 | + if( zTemplate==0 ) return; |
| 747 | + if( strcmp(zTemplate, "current")==0 ){ |
| 748 | + for(i=0; i<count(azSkinFile); i++){ |
| 749 | + db_set_mprintf("draft%d-%s", db_get(azSkinFile[i],""), 0, |
| 750 | + iSkin, azSkinFile[i]); |
| 751 | + } |
| 752 | + return; |
| 753 | + } |
| 754 | + for(i=0; i<count(aBuiltinSkin); i++){ |
| 755 | + if( strcmp(zTemplate, aBuiltinSkin[i].zLabel)==0 ){ |
| 756 | + for(i=0; i<count(azSkinFile); i++){ |
| 757 | + char *zKey = mprintf("skins/%s/%s.txt", zTemplate, azSkinFile[i]); |
| 758 | + db_set_mprintf("draft%d-%s", builtin_text(zKey), 0, |
| 759 | + iSkin, azSkinFile[i]); |
| 760 | + } |
| 761 | + return; |
| 762 | + } |
| 763 | + } |
| 764 | +} |
| 765 | + |
| 766 | +/* |
| 767 | +** Publish the draft skin iSkin as the new default. |
| 768 | +*/ |
| 769 | +static void skin_publish(int iSkin){ |
| 770 | + char *zCurrent; /* SQL description of the current skin */ |
| 771 | + char *zBuiltin; /* SQL description of a built-in skin */ |
| 772 | + int i; |
| 773 | + int seen = 0; /* True if no need to make a backup */ |
| 774 | + |
| 775 | + /* Check to see if the current skin is already saved. If it is, there |
| 776 | + ** is no need to create a backup */ |
| 777 | + zCurrent = getSkin(0); |
| 778 | + for(i=0; i<count(aBuiltinSkin); i++){ |
| 779 | + zBuiltin = getSkin(aBuiltinSkin[i].zLabel); |
| 780 | + if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){ |
| 781 | + seen = 1; |
| 782 | + break; |
| 783 | + } |
| 784 | + } |
| 785 | + if( !seen ){ |
| 786 | + seen = db_exists("SELECT 1 FROM config WHERE name GLOB 'skin:*'" |
| 787 | + " AND value=%Q", zCurrent); |
| 788 | + } |
| 789 | + if( !seen ){ |
| 790 | + db_multi_exec( |
| 791 | + "INSERT INTO config(name,value,mtime) VALUES(" |
| 792 | + " strftime('skin:Backup On %%Y-%%m-%%d %%H:%%M:%%S')," |
| 793 | + " %Q,now())", zCurrent |
| 794 | + ); |
| 795 | + } |
| 796 | + |
| 797 | + /* Publish draft iSkin */ |
| 798 | + for(i=0; i<count(azSkinFile); i++){ |
| 799 | + char *zNew = db_get_mprintf("draft%d-%s", "", iSkin, azSkinFile[i]); |
| 800 | + db_set(azSkinFile[i], zNew, 0); |
| 801 | + } |
| 802 | +} |
| 803 | + |
| 804 | +/* |
| 805 | +** WEBPAGE: setup_skin |
| 806 | +** |
| 807 | +** Generate a page showing the steps needed to customize a skin. |
| 808 | +*/ |
| 809 | +void setup_skin(void){ |
| 810 | + int i; /* Loop counter */ |
| 811 | + int iSkin; /* Which draft skin is being edited */ |
| 812 | + int isSetup; /* True for an administrator */ |
| 813 | + int isEditor; /* Others authorized to make edits */ |
| 814 | + char *zAllowedEditors; /* Who may edit the draft skin */ |
| 815 | + char *zBase; /* Base URL for draft under test */ |
| 816 | + static const char *azTestPages[] = { |
| 817 | + "home", |
| 818 | + "timeline", |
| 819 | + "dir?ci=tip", |
| 820 | + "dir?ci=tip&type=tree", |
| 821 | + "brlist", |
| 822 | + "info/trunk", |
| 823 | + }; |
| 824 | + |
| 825 | + /* Figure out which skin we are editing */ |
| 826 | + iSkin = atoi(PD("sk","1")); |
| 827 | + if( iSkin<1 || iSkin>9 ) iSkin = 1; |
| 828 | + |
| 829 | + /* Figure out if the current user is allowed to make administrative |
| 830 | + ** changes and/or edits |
| 831 | + */ |
| 832 | + login_check_credentials(); |
| 833 | + zAllowedEditors = db_get_mprintf("draft%d-users", "", iSkin); |
| 834 | + if( g.perm.Setup ){ |
| 835 | + isSetup = isEditor = 1; |
| 836 | + }else{ |
| 837 | + Glob *pAllowedEditors; |
| 838 | + isSetup = isEditor = 0; |
| 839 | + if( zAllowedEditors[0] ){ |
| 840 | + pAllowedEditors = glob_create(zAllowedEditors); |
| 841 | + isEditor = glob_match(pAllowedEditors, zAllowedEditors); |
| 842 | + glob_free(pAllowedEditors); |
| 843 | + } |
| 844 | + } |
| 845 | + |
| 846 | + /* Initialize the skin, if requested and authorized. */ |
| 847 | + if( P("init3")!=0 && isEditor ){ |
| 848 | + skin_initialize_draft(iSkin, P("initskin")); |
| 849 | + } |
| 850 | + if( P("submit2")!=0 && isSetup ){ |
| 851 | + db_set_mprintf("draft%d-users", PD("editors",""), 0, iSkin); |
| 852 | + zAllowedEditors = db_get_mprintf("draft%d-users", "", iSkin); |
| 853 | + } |
| 854 | + |
| 855 | + /* Publish the draft skin */ |
| 856 | + if( P("pub7")!=0 && PB("pub7ck1") && PB("pub7ck2") ){ |
| 857 | + skin_publish(iSkin); |
| 858 | + } |
| 859 | + |
| 860 | + style_header("Customize Skin"); |
| 861 | + |
| 862 | + @ <p>Customize the look of this Fossil repository by making changes |
| 863 | + @ to the CSS, Header, Footer, and Detail Settings in one of nine "draft" |
| 864 | + @ configurations. Then, after verifying that all is working correctly, |
| 865 | + @ publish the draft to become the new main Skin.<p> |
| 866 | + @ |
| 867 | + @ <a name='step1'></a> |
| 868 | + @ <h1>Step 1: Identify Which Draft To Use</h1> |
| 869 | + @ |
| 870 | + @ <p>The main skin of Fossil cannot be edited directly. Instead, |
| 871 | + @ edits are made to one of nine draft skins. A draft skin can then |
| 872 | + @ be published to become the default skin. |
| 873 | + @ Nine separate drafts are available to facilitate A/B testing.</p> |
| 874 | + @ |
| 875 | + @ <form method='POST' action='%R/setup_skin#step2' id='f01'> |
| 876 | + @ <p class='skinInput'>Draft skin to edit: |
| 877 | + @ <select size='1' name='sk' onchange='gebi("f01").submit()'> |
| 878 | + for(i=1; i<=9; i++){ |
| 879 | + if( i==iSkin ){ |
| 880 | + @ <option value='%d(i)' selected>draft%d(i)</option> |
| 881 | + }else{ |
| 882 | + @ <option value='%d(i)'>draft%d(i)</option> |
| 883 | + } |
| 884 | + } |
| 885 | + @ </select> |
| 886 | + @ </p> |
| 887 | + @ |
| 888 | + @ <a name='step2'></a> |
| 889 | + @ <h1>Step 2: Authenticate</h1> |
| 890 | + @ |
| 891 | + if( isSetup ){ |
| 892 | + @ <p>As an administrator, you can make any edits you like to this or |
| 893 | + @ any other skin. You can also authorized other users to edit this |
| 894 | + @ skin. Any user whose login name matches the comma-separate list |
| 895 | + @ of GLOB expressions below is given special permission to edit |
| 896 | + @ the draft%d(iSkin) skin: |
| 897 | + @ |
| 898 | + @ <form method='POST' action='%R/setup_skin#step2' id='f02'> |
| 899 | + @ <p class='skinInput'> |
| 900 | + @ <input type='hidden' name='sk' value='%d(iSkin)'> |
| 901 | + @ Authorized editors for skin draft%d(iSkin): |
| 902 | + @ <input type='text' name='editors' value='%h(zAllowedEditors)'\ |
| 903 | + @ width='40'> |
| 904 | + @ <input type='submit' name='submit2' value='Change'> |
| 905 | + @ </p> |
| 906 | + @ </form> |
| 907 | + }else if( isEditor ){ |
| 908 | + @ <p>You are authorized to make changes to the draft%d(iSkin) skin. |
| 909 | + @ Continue to the <a href='#step3'>next step</a>.</p> |
| 910 | + }else{ |
| 911 | + @ <p>You are not authorized to make changes to the draft%d(iSkin) |
| 912 | + @ skin. Contact the administrator of this Fossil repository for |
| 913 | + @ further information.</p> |
| 914 | + } |
| 915 | + @ |
| 916 | + @ <a name='step3'></a> |
| 917 | + @ <h1>Step 3: Initialize The Draft</h1> |
| 918 | + @ |
| 919 | + if( !isEditor ){ |
| 920 | + @ <p>You are not allowed to initialize draft%(iSkin). Contact |
| 921 | + @ the administrator for this repository for more information. |
| 922 | + }else{ |
| 923 | + @ <p>Initialize the draft%d(iSkin) skin to one of the built-in skins |
| 924 | + @ or a preexisting skin, to use as a baseline.</p> |
| 925 | + @ |
| 926 | + @ <form method='POST' action='%R/setup_skin#step4' id='f03'> |
| 927 | + @ <p class='skinInput'> |
| 928 | + @ <input type='hidden' name='sk' value='%d(iSkin)'> |
| 929 | + @ Initialize skin <b>draft%d(iSkin)</b> using |
| 930 | + @ <select size='1' name='initskin'> |
| 931 | + @ <option value='current'>Currently In Use</option> |
| 932 | + for(i=0; i<count(aBuiltinSkin); i++){ |
| 933 | + @ <option value='%s(aBuiltinSkin[i].zLabel)'>\ |
| 934 | + @ %h(aBuiltinSkin[i].zDesc) (built-in)</option> |
| 935 | + } |
| 936 | + @ </select> |
| 937 | + @ <input type='submit' name='init3' value='Go'> |
| 938 | + @ </p> |
| 939 | + @ </form> |
| 940 | + } |
| 941 | + @ |
| 942 | + @ <a name='step4'></a> |
| 943 | + @ <h1>Step 4: Make Edits</h1> |
| 944 | + @ |
| 945 | + if( !isEditor ){ |
| 946 | + @ <p>You are not authorized to make edits to the draft%d(iSkin) skin. |
| 947 | + @ Contact the administrator of this Fossil repository for help.</p> |
| 948 | + }else{ |
| 949 | + @ <p>Edit the components of the draft%d(iSkin) skin: |
| 950 | + @ <ul> |
| 951 | + @ <li><a href='%R/setup_skinedit?w=0&sk=%d(iSkin)' target='_blank'>CSS</a> |
| 952 | + @ <li><a href='%R/setup_skinedit?w=2&sk=%d(iSkin)' target='_blank'>\ |
| 953 | + @ Header</a> |
| 954 | + @ <li><a href='%R/setup_skinedit?w=1&sk=%d(iSkin)' target='_blank'>\ |
| 955 | + @ Footer</a> |
| 956 | + @ <li><a href='%R/setup_skinedit?w=3&sk=%d(iSkin)' target='_blank'>\ |
| 957 | + @ Details</a> |
| 958 | + @ </ul> |
| 959 | + } |
| 960 | + @ |
| 961 | + @ <a name='step5'></a> |
| 962 | + @ <h1>Step 5: Verify The Draft Skin</h1> |
| 963 | + @ |
| 964 | + @ <p>To test this draft skin, insert text "/draft%d(iSkin)/" just before the |
| 965 | + @ operation name in the URL. Here are a few links to try: |
| 966 | + @ <ul> |
| 967 | + if( iDraftSkin && sqlite3_strglob("*/draft[1-9]", g.zBaseURL)==0 ){ |
| 968 | + zBase = mprintf("%.*s/draft%d", (int)strlen(g.zBaseURL)-7,g.zBaseURL,iSkin); |
| 969 | + }else{ |
| 970 | + zBase = mprintf("%s/draft%d", g.zBaseURL, iSkin); |
| 971 | + } |
| 972 | + for(i=0; i<count(azTestPages); i++){ |
| 973 | + @ <li><a href='%s(zBase)/%s(azTestPages[i])' target='_blank'>\ |
| 974 | + @ %s(zBase)/%s(azTestPages[i])</a> |
| 975 | + } |
| 976 | + fossil_free(zBase); |
| 977 | + @ </ul> |
| 978 | + @ |
| 979 | + @ <p>You will probably need to press Reload on your browser before any |
| 980 | + @ CSS changes will take effect.</p> |
| 981 | + @ |
| 982 | + @ <a hame='step6'></a> |
| 983 | + @ <h1>Step 6: Interate</h1> |
| 984 | + @ |
| 985 | + @ <p>Repeat <a href='#step4'>step 4</a> and |
| 986 | + @ <a href='#step5'>step 5</a> as many times as necessary to create |
| 987 | + @ a production-ready skin. |
| 988 | + @ |
| 989 | + @ <a name='step7'></a> |
| 990 | + @ <h1>Step 7: Publish</h1> |
| 991 | + @ |
| 992 | + if( !g.perm.Setup ){ |
| 993 | + @ <p>Only administrators are allowed to publish draft skins. Contact |
| 994 | + @ an administrator to get this "draft%d(iSkin)" skin published.</p> |
| 995 | + }else{ |
| 996 | + @ <p>When the draft%d(iSkin) skin is ready for production use, |
| 997 | + @ make it the default scan by clicking the acknowledgements and |
| 998 | + @ pressing the button below:</p> |
| 999 | + @ |
| 1000 | + @ <form method='POST' action='%R/setup_skin#step7'> |
| 1001 | + @ <p class='skinInput'> |
| 1002 | + @ <input type='hidden' name='sk' value='%d(iSkin)'> |
| 1003 | + @ <input type='checkbox' name='pub7ck1' value='yes'>\ |
| 1004 | + @ Skin draft%d(iSkin) has been testing and found ready for production.<br> |
| 1005 | + @ <input type='checkbox' name='pub7ck2' value='yes'>\ |
| 1006 | + @ The current skin should be overwritten with draft%d(iSkin).<br> |
| 1007 | + @ <input type='submit' name='pub7' value='Publish Draft%d(iSkin)'> |
| 1008 | + @ </p></form> |
| 1009 | + @ |
| 1010 | + @ <p>You will probably need to press Reload on your browser after |
| 1011 | + @ publishing the new skin.</p> |
| 1012 | + } |
| 1013 | + @ |
| 1014 | + @ <a name='step8'></a> |
| 1015 | + @ <h1>Step 8: Cleanup and Undo Actions</h1> |
| 1016 | + @ |
| 1017 | + if( !g.perm.Setup ){ |
| 1018 | + @ <p>Administrators can optionally remove save legacy skins, or |
| 1019 | + @ undo a prior publish |
| 1020 | + }else{ |
| 1021 | + @ <p>Visit the <a href='%R/setup_skin_admin'>Skin Admin</a> page |
| 1022 | + @ for cleanup and recovery actions. |
| 1023 | + } |
| 1024 | + style_footer(); |
| 1025 | +} |
| 673 | 1026 | |