Permalink
Browse files

tidy/organize the code a little bit. Add a confirmation dialog on out…

…line deletes. Refactor messages to take a message slug instead of the actual text. Add CSS stuff.
  • Loading branch information...
1 parent 3940929 commit e979c03638d7f98b1b218f08089fb5c55b50df07 @Whiteknight committed Nov 13, 2010
Showing with 170 additions and 94 deletions.
  1. +9 −1 BookDesigner.i18n.php
  2. +121 −93 BookDesigner_body.php
  3. +40 −0 designer.css
View
@@ -45,8 +45,16 @@
'bookdesigner-optheaderstyle' => 'Headers:',
'bookdesigner-optautogenerate' => 'Autogenerate',
'bookdesigner-publishbutton' => 'Publish Book!',
- 'bookdesigner-savebutton' => 'Save',
+ 'bookdesigner-savebutton' => 'Save Outline',
'bookdesigner-loadbutton' => 'Load',
+ 'bookdesigner-backnav' => 'Back',
+ 'bookdesigner-error' => 'Error:',
+ 'bookdesigner-errload' => 'Could not load outline',
+ 'bookdesigner-msgdeleted' => 'Outline successfully deleted',
+ 'bookdesigner-errdeleted' => 'Outline could not be deleted',
+ 'bookdesigner-msgsaved' => 'Outline saved successfully',
+ 'bookdesigner-errauthenticate' => 'You must be logged in and have <b>buildbook</b> permission to created books using this tool.',
+ 'bookdesigner-reallydelete' => 'Really delete this outline?',
'bookdesigner-defaultheader' => <<<EOHEADER
<div style="border: 1px solid #AAAAAA; background-color: #F8F8F8; padding: 5px; margin: auto; width: 95%">
<center>
View
@@ -11,6 +11,8 @@ function __construct() {
protected $validuser = false;
protected $titlepage = null;
+ # HELPER METHODS
+
function validateUser()
{
global $wgUser;
@@ -22,17 +24,64 @@ function validateUser()
return $this->validuser;
}
- function createOnePage($bookname, $path, $text) {
+ function GetMessage($msgname) {
+ return wfMsg('bookdesigner-' . $msgname);
+ }
+
+ function showMessage($msg) {
global $wgOut, $wgScriptPath;
- $title = Title::newFromText($path);
- $article = new Article($title);
- $article->doEdit($text, "Creating page for book '{$bookname}'. " .
- "Automated page creation by BookDesigner");
- return $title;
+ $text =<<<EOD
+<div class="VBDMessageDiv">
+ {$this->GetMessage($msg)}
+ <br />
+ <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner">
+ {$this->GetMessage('backnav')}
+ </a>
+</div>
+EOD;
+ $wgOut->addHTML($text);
}
- function GetMessage($msgname) {
- return wfMsg('bookdesigner-' . $msgname);
+ function showErrorMessage($msg) {
+ global $wgOut, $wgScriptPath;
+ $text =<<<EOD
+<div class="VBDErrorMessageDiv">
+ <span class="VBDErrorSpan">{$this->GetMessage("error")}</span>
+ {$this->GetMessage($msg)}
+ <br />
+ <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner">
+ {$this->GetMessage('backnav')}
+ </a>
+</div>
+EOD;
+ $wgOut->addHTML($text);
+ }
+
+ function loadJSAndCSS() {
+ global $wgScriptPath, $wgOut;
+ $jspath = "$wgScriptPath/extensions/BookDesigner";
+ $wgOut->addScriptFile($jspath . "/bookpage.js");
+ $wgOut->addScriptFile($jspath . "/pagehead.js");
+ $wgOut->addScriptFile($jspath . "/designer.js");
+ $this->addCSSFile("designer.css");
+ }
+
+ function getVersion() {
+ global $wg_VBDExtensionVersion;
+ return $wg_VBDExtensionVersion;
+ }
+
+ function addCSSFile($file) {
+ global $wgScriptPath, $wgOut;
+ $csspath = "$wgScriptPath/extensions/BookDesigner";
+ if(method_exists($wgOut, "addExtensionStyle")) {
+ $wgOut->addExtensionStyle($csspath . "/" . $file);
+ } else {
+ # This is a hack for older MediaWiki (1.14 and below?).
+ # addStyle prepends "$wgScriptPath/skins/" to the front,
+ # so we need to navigate to the correct place
+ $wgOut->addStyle("../extensions/BookDesigner/" . $file);
+ }
}
# Main function, this is where execution starts
@@ -43,16 +92,15 @@ function execute($par) {
global $wgRequest, $wgOut;
$this->setHeaders();
$wgOut->setPageTitle("Book Designer");
+ $this->loadJSAndCSS();
+ $mode = "outline";
+ $outlineid = 0;
if (!$this->validateUser()) {
- $this->showAuthenticationError();
+ $this->showErrorMessage('errauthenticate');
return;
}
- $this->loadJSAndCSS();
- $mode = "outline";
- $outlineid = 0;
-
if(isset($par)) {
$parts = explode('/', $par, 2);
$mode = $parts[0];
@@ -68,8 +116,10 @@ function execute($par) {
} else if ($submit == $this->GetMessage("savebutton"))
$this->saveOutline();
}
- else if ($mode == 'publish') $this->reallyPublishOutline();
- else $this->unknownModeError('post', $mode, $title);
+ else if ($mode == 'publish')
+ $this->reallyPublishOutline();
+ else
+ $this->unknownModeError('post', $mode, $title);
}
else {
# TODO: we've specified a book name, load that book into the outline
@@ -79,20 +129,37 @@ function execute($par) {
$this->displayMainOutline("");
return;
}
- else if ($mode == 'loadoutline') $this->loadOutline($outlineid);
- else if ($mode == 'deleteoutline') $this->deleteOutline($outlineid);
- else $this->unknownModeError('show', $mode, $title);
+ else if ($mode == 'loadoutline' && isset($outlineid))
+ $this->loadOutline($outlineid);
+ else if ($mode == 'deleteoutline' && isset($outlineid))
+ $this->deleteOutline($outlineid);
+ else
+ $this->unknownModeError('show', $mode, $title);
}
}
+ function unknownModeError($type, $mode) {
+ global $wgOut;
+ $text = <<<EOD
+<p>
+ <span style='color: red; font-weight: bold;'>Error:</span>
+ Could not {$type} with mode {$mode}
+</p>
+
+EOD;
+ $wgOut->addHTML($text);
+ }
+
+ # LOAD/SAVE/DELETE FUNCTIONS
+
function loadOutline($outlineid) {
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('bookdesigner_outlines', array("user_id", "outline"), 'id=' . $outlineid);
if ($dbr->numRows($res) == 1) {
$row = $dbr->fetchObject($res);
$this->displayMainOutline($row->outline);
}
- else $this->showMessage("Could not load outline");
+ else $this->showErrorMessage("errload");
}
function deleteOutline($outlineid) {
@@ -103,8 +170,9 @@ function deleteOutline($outlineid) {
$dbw->delete('bookdesigner_outlines', array(
'id' => $outlineid
));
- $this->showMessage("Outline deleted");
- } else $this->showMessage("Could not delete outline");
+ $this->showMessage("msgdeleted");
+ } else
+ $this->showMessage("errdeleted");
}
function saveOutline() {
@@ -120,46 +188,10 @@ function saveOutline() {
'bookname' => $this->titlepage->name(),
'outline' => $text
));
- $this->showMessage("Outline " . $this->titlepage->name() . " saved");
+ $this->showMessage('msgsaved');
}
- function showMessage($msg) {
- global $wgOut, $wgScriptPath;
- $text =<<<EOD
-<div>
- {$msg}
- <br />
- <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner">Back</a>
-</div>
-EOD;
- $wgOut->addHTML($text);
- }
-
- function showauthenticationError() {
- global $wgOut;
- $text = <<<EOT
-<div>
- <p>
- <span style='color: darkred; font-weight: bold'>Error:</span>
- You must be logged in and have 'buildbook' permission to created
- books using this tool.
- </p>
-</div>
-EOT;
- $wgOut->addHTML($text);
- }
-
- function unknownModeError($type, $mode) {
- global $wgOut;
- $text = <<<EOD
-<p>
- <span style='color: red; font-weight: bold;'>Error:</span>
- Could not {$type} with mode {$mode}
-</p>
-
-EOD;
- $wgOut->addHTML($text);
- }
+ # VERIFY OUTLINE BEFORE PUBLISH FUNCTIONS
function verifyPublishOutline() {
global $wgRequest;
@@ -239,6 +271,8 @@ function showPageSinglePageConfirmation($idx, $page) {
$wgOut->addHTML($text);
}
+ # PUBLISH OUTLINE TO BOOK
+
function reallyPublishOutline() {
global $wgRequest, $wgOut;;
$numpages = $wgRequest->getInt('VBDTotalPageCount');
@@ -263,6 +297,15 @@ function reallyPublishOutline() {
# is an admin)
}
+ function createOnePage($bookname, $path, $text) {
+ global $wgOut, $wgScriptPath;
+ $title = Title::newFromText($path);
+ $article = new Article($title);
+ $article->doEdit($text, "Creating page for book '{$bookname}'. " .
+ "Automated page creation by BookDesigner");
+ return $title;
+ }
+
function showPageNotCreatedMessage($path) {
global $wgOut;
$text = <<<EOT
@@ -288,32 +331,7 @@ function showPageCreatedMessage($path, $title) {
$wgOut->addHTML($text);
}
- function loadJSAndCSS() {
- global $wgScriptPath, $wgOut;
- $jspath = "$wgScriptPath/extensions/BookDesigner";
- $wgOut->addScriptFile($jspath . "/bookpage.js");
- $wgOut->addScriptFile($jspath . "/pagehead.js");
- $wgOut->addScriptFile($jspath . "/designer.js");
- $this->addCSSFile("designer.css");
- }
-
- function getVersion() {
- global $wg_VBDExtensionVersion;
- return $wg_VBDExtensionVersion;
- }
-
- function addCSSFile($file) {
- global $wgScriptPath, $wgOut;
- $csspath = "$wgScriptPath/extensions/BookDesigner";
- if(method_exists($wgOut, "addExtensionStyle")) {
- $wgOut->addExtensionStyle($csspath . "/" . $file);
- } else {
- # This is a hack for older MediaWiki (1.14 and below?).
- # addStyle prepends "$wgScriptPath/skins/" to the front,
- # so we need to navigate to the correct place
- $wgOut->addStyle("../extensions/BookDesigner/" . $file);
- }
- }
+ # MAIN OUTLINE FUNCTIONS
function displayMainOutline($inittext) {
global $wgOut, $wgScriptPath;
@@ -354,6 +372,13 @@ function displayMainOutline($inittext) {
existing outline. -->
<input type="submit" name="btnSubmit" value="{$this->GetMessage('publishbutton')}" />
<div id="VBDOutlineManager">
+ <script type="text/javascript">
+ function really_delete(id) {
+ var url = "{$wgScriptPath}/index.php?title=Special:BookDesigner/deleteoutline/" + id;
+ if(confirm("{$this->GetMessage('reallydelete')}"))
+ document.location = url;
+ }
+ </script>
<input type="submit" name="btnSubmit" value="{$this->GetMessage('savebutton')}" />
EOD;
$wgOut->addHTML($text);
@@ -372,15 +397,18 @@ function getSavedOutlines() {
$res = $dbr->select('bookdesigner_outlines', array('id', 'savedate', 'bookname'), 'user_id=' . $wgUser->getId());
while($row = $dbr->fetchObject($res)) {
$text = <<<EOD
- <div class="WBVSavedOutlineEntry">
+ <div class="VBDSavedOutlineEntry">
<b>{$row->bookname}</b>: {$row->savedate}
- <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner/loadoutline/{$row->id}">
- Load
- </a>
- &mdash;
- <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner/deleteoutline/{$row->id}">
- Delete
- </a>
+ <br />
+ <div class="VBDSavedOutlineCommands">
+ <a href="{$wgScriptPath}/index.php?title=Special:BookDesigner/loadoutline/{$row->id}">
+ Load
+ </a>
+ &mdash;
+ <a href="javascript: really_delete({$row->id})">
+ Delete
+ </a>
+ </div>
</div>
EOD;
$wgOut->addHTML($text);
View
@@ -71,3 +71,43 @@ div#VBDSaveLoadDiv {
background-color: #F8F8F8;
padding: 5px;
}
+
+div.VBDMessageDiv {
+ width: 95%;
+ margin: auto;
+ padding: 5px;
+ border: 1px solid #AAAAAA;
+ background-color: #F8F8F8;
+}
+
+div.VBDErrorMessageDiv {
+ width: 95%;
+ margin: auto;
+ padding: 5px;
+ border: 1px solid #BB9999;
+ background-color: #F8EEEE;
+}
+
+span.VBDErrorSpan {
+ font-weight: bold;
+ color: darkred;
+}
+
+div#VBDOutlineManager {
+ margin-top: 2em;
+ background-color: #F8F8F8;
+ border: 1px solid #AAAAAA;
+ padding: 5px;
+ width: 60%;
+}
+
+div.VBDSavedOutlineEntry {
+ background-color: #FFFFFF;
+ margin-bottom: 5px;
+ padding: 3px;
+ border: 1px solid #AAAAAA;
+}
+
+div.VBDSavedOutlineCommands {
+ margin-left: 3em;
+}

0 comments on commit e979c03

Please sign in to comment.