Permalink
Browse files

cleanup i18n messages. Create some new functions to encapsulate vario…

…us behaviors and options. Add new options to create standard pages (eventually with pre-formatted text). Cleanup code in BookDesigner_body.
  • Loading branch information...
1 parent aa57798 commit 17b9e7ad52b0b292253ac190594749a068d32549 @Whiteknight committed Jan 12, 2010
Showing with 120 additions and 45 deletions.
  1. +16 −15 BookDesigner.i18n.php
  2. +104 −30 BookDesigner_body.php
View
@@ -24,22 +24,23 @@
</ol>
EOQSI
,
- 'bookdesigner-show' => 'Show',
- 'bookdesigner-hide' => 'Hide',
- 'bookdesigner-options' => 'Options',
- 'bookdesigner-optsbook' => 'Book Options',
- 'bookdesigner-optusenamespace' => 'Use Alternate Namespace',
- 'bookdesigner-optuseuserspace' => 'Create In User Namespace',
+ 'bookdesigner-show' => 'Show',
+ 'bookdesigner-hide' => 'Hide',
+ 'bookdesigner-options' => 'Options',
+ 'bookdesigner-optsbook' => 'Book Options',
+ 'bookdesigner-optusenamespace' => 'Specify Namespace',
+ 'bookdesigner-optuseuserspace' => 'Create In User Namespace',
'bookdesigner-optintroductionpage' => 'Create Introduction Page',
- 'bookdesigner-optresourcespage' => 'Create Resources Page',
- 'bookdesigner-optlicensingpage' => 'Create Licensing Page',
- 'bookdesigner-optspage' => 'Page Options',
- 'bookdesigner-optcreateleaf' => 'Create Leaf Pages',
- 'bookdesigner-optnumberpages' => 'Number Pages',
- 'bookdesigner-optstemplate' => 'Template Options',
- 'bookdesigner-optheadertemplate' => 'Include Header Template',
- 'bookdesigner-optautogentemplate' => 'Autogenerate Header Template',
- 'bookdesigner-publishbutton' => 'Publish Book!',
+ 'bookdesigner-optresourcespage' => 'Create Resources Page',
+ 'bookdesigner-optlicensingpage' => 'Create Licensing Page',
+ 'bookdesigner-optspage' => 'Page Options',
+ 'bookdesigner-optcreateleaf' => 'Create Leaf Pages',
+ 'bookdesigner-optnumberpages' => 'Number Pages',
+ 'bookdesigner-optstemplate' => 'Template Options',
+ 'bookdesigner-optheadertemplate' => 'Include Header Template',
+ 'bookdesigner-optfootertemplate' => 'Include Footer Template',
+ 'bookdesigner-optautogenerate' => 'Autogenerate',
+ 'bookdesigner-publishbutton' => 'Publish Book!',
'bookdesigner-jserror' => <<<EOJSERROR
JavaScript is not working, or designer.js could not be found.
View
@@ -9,13 +9,16 @@ function __construct() {
protected $debug = false;
// Internal values. Don't modify them, they get set at runtime
- protected $bookname = "";
- protected $createleaves = false;
- protected $usetemplates = false;
- protected $numberpages = false;
- protected $usenamespace = false;
- protected $autogentemp = false;
- protected $namespace = "";
+ protected $bookname = "";
+ protected $createleaves = false;
+ protected $usetemplates = false;
+ protected $numberpages = false;
+ protected $usenamespace = false;
+ protected $autogentemp = false;
+ protected $createintroduction = false;
+ protected $createresources = false;
+ protected $createlicensing = false;
+ protected $namespace = "";
// Quick and dirty debugging utilities. The value of $this->debug determines whether
// we print something. These functions can probably disappear soon since the
@@ -31,17 +34,66 @@ function _dbgl($word)
$this->_dbg($word . "<br/>");
}
+ function GetHeaderTemplateTag()
+ {
+ return $this->usetemplates ? "{{" . $this->bookname . "}}\n\n" : "";
+ }
+
+ function GetFooterTemplateTag()
+ {
+ return "";
+ }
+
+ function GetCreateFlag($isroot)
+ {
+ $create = $this->createleaves || $isroot;
+ $this->_dbgl("Creating leaf page: " . ($createleaf ? "1" : "0"));
+ return $create;
+ }
+
+ function CreateIntroduction($isroot)
+ {
+ if ($isroot && $this->createintroduction) {
+ $text = $this->GetHeaderTemplateTag() . $this->GetFooterTemplateTag();
+ $this->CreateOnePage($this->bookname . "/Introduction", $text, "Creating Introduction page");
+ return "*[[" . $this->bookname . "/Introduction|Introduction]]\n";
+ }
+ return "";
+ }
+ function CreateResources($isroot)
+ {
+ if ($isroot && $this->createresources) {
+ $text = $this->GetHeaderTemplateTag() . $this->GetFooterTemplateTag();
+ $this->CreateOnePage($this->bookname . "/Resources", $text, "Creating Resources page");
+ return "*[[" . $this->bookname . "/Resources|Resources]]\n";
+ }
+ return "";
+ }
+ function CreateLicensing($isroot)
+ {
+ if ($isroot && $this->createlicensing) {
+ $text = $this->GetHeaderTemplateTag() . $this->GetFooterTemplateTag();
+ $this->CreateOnePage($this->bookname . "/Licensing", $text, "Creating Licensing page");
+ return "*[[" . $this->bookname . "/Licensing|Licensing]]\n";
+ }
+ return "";
+ }
+
// Home-brewed recursive descent parser. Yes there are better ways of doing
// this, and yes this is ugly and stupid and ugly. Whatever, this is what
// we have.
+ // [] contain lists of pages. {} contain lists of headings. Each page has[]{}
+ // and each heading has only []. Each bare line of text inside a set of brackets
+ // is that type of thing. Empty lines are ignored.
function parseBookPage($page, $path, $lines, $idx)
{
global $wgOut, $wgScriptPath;
- $pagetext = $this->usetemplates ? "{{" . $this->bookname . "}}\n\n" : "";
- $createleaf = $this->createleaves || ($idx == 1);
+ $isroot = ($idx == 1);
$subpagenum = 0;
- $this->_dbgl("Creating leaf page: " . ($createleaf?"1":"0"));
- // First, read out the subpages
+ $pagetext = $this->GetHeaderTemplateTag() . $this->CreateIntroduction($isroot);
+ $createleaf = $this->GetCreateFlag($isroot);
+
+ // Loop over all subpages inside [] brackets
for($i = $idx; $i < sizeof($lines); $i++) {
$line = rtrim($lines[$i]);
$this->_dbg("Line " . $i . ": " . $line . "> ");
@@ -71,7 +123,8 @@ function parseBookPage($page, $path, $lines, $idx)
}
}
$pagetext .= "\n";
- // Second, read out the headings
+
+ // Loop over all headings inside {} brackets
for($i = $idx; $i < sizeof($lines); $i++) {
$line = rtrim($lines[$i]);
$this->_dbg("Line " . $i . ": " . $line . "> ");
@@ -84,7 +137,7 @@ function parseBookPage($page, $path, $lines, $idx)
continue;
}
if($line == '}') {
- $this->_dbgl("Breaking subpage loop");
+ $this->_dbgl("Breaking heading loop");
$idx = $i;
break;
}
@@ -114,23 +167,33 @@ function parseBookPage($page, $path, $lines, $idx)
$i = $this->parseBookPage($line2, $newpath, $lines, $i + 1);
}
}
+
+ // Get the rest of the text, most of which is optional
+ $pagetext = $pagetext .
+ $this->CreateResources($isroot) .
+ $this->CreateLicensing($isroot) .
+ $this->GetFooterTemplateTag();
+
// We've parsed all direct subpages and all headings (and all subpages
// of those). We have all the information we need now to actually create
// this page. Page name is in $path. Page text is in $pagetext
- //$wgOut->addHTML("<h2>" . $page . "</h2>");
- //$wgOut->addHTML("<b>" . $path . "</b>");
- //$wgOut->addHTML("<pre>" . $pagetext . "</pre>");
- // We only create the page if (1) we opt to create all pages, (2) the page contains subpages,
- // (3) the page contains headings, or (4) it is the main page.
- if ($createleaf) {
- $title = Title::newFromText($path);
- $article = new Article($title);
- $article->doEdit($pagetext, "Creating new book automatically");
- $wgOut->addHTML("Created <a href=\"$wgScriptPath/index.php?title=$path\">$path</a><br/>");
- }
+ // We only create the page if (1) we opt to create all pages, (2) the
+ // page contains subpages, (3) the page contains headings, or (4) it is
+ // the main page.
+ if ($createleaf)
+ $this->CreateOnePage($path, $pagetext, "Creating new book automatically");
return $idx;
}
+ function CreateOnePage($path, $text, $comment)
+ {
+ global $wgOut, $wgScriptPath;
+ $title = Title::newFromText($path);
+ $article = new Article($title);
+ $article->doEdit($text, $comment);
+ $wgOut->addHTML("Created <a href=\"$wgScriptPath/index.php?title=$path\">$path</a><br/>");
+ }
+
// Build the header template
function generateHeaderTemplate( $bookname ) {
global $wgOut, $wgScriptPath;
@@ -170,8 +233,17 @@ function getOptions() {
$this->namespace = $this->usenamespace ? $wgRequest->getText("optNamespace") . ":" : "";
$this->_dbgl("Use Namespace: " . ($this->usenamespace ? "1" : "0") . " " . $this->namespace);
- $this->autogentemp = $wgRequest->getCheck("optAutogenTemplate");
+ $this->autogentemp = $wgRequest->getCheck("optAutogenHeaderTemplate");
$this->_dbgl("Autogenerate Template: " . ($this->autogenemp ? "1" : "0"));
+
+ $this->createintroduction = $wgRequest->getCheck("optIntroductionPage");
+ $this->_dbgl("Create Introduction Page: " . ($this->createintroduction ? "1" : "0"));
+
+ $this->createresources = $wgRequest->getCheck("optResourcesPage");
+ $this->_dbgl("Create Resources Page: " . ($this->createresources ? "1" : "0"));
+
+ $this->createlicensing = $wgRequest->getCheck("optLicensingPage");
+ $this->_dbgl("Create Licensing Page: " . ($this->createlicensing ? "1" : "0"));
}
function GetMessage($msgname) {
@@ -251,17 +323,19 @@ function execute( $par ) {
<input type="checkbox" name="optUseNamespace">{$this->GetMessage('optusenamespace')}:</input><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="optNamespace"/><br>
<input type="checkbox" name="optUseUserSpace" disabled>{$this->GetMessage('optuseuserspace')}</input><br>
- <input type="checkbox" name="optIntroductionPage" disabled>{$this->GetMessage('optintroductionpage')}</input><br>
- <input type="checkbox" name="optResourcesPage" disabled>{$this->GetMessage('optresourcespage')}</input><br>
- <input type="checkbox" name="optLicensingPage" disabled>{$this->GetMessage('optlicensingpage')}</input><br>
+ <input type="checkbox" name="optIntroductionPage">{$this->GetMessage('optintroductionpage')}</input><br>
+ <input type="checkbox" name="optResourcesPage">{$this->GetMessage('optresourcespage')}</input><br>
+ <input type="checkbox" name="optLicensingPage">{$this->GetMessage('optlicensingpage')}</input><br>
<b>{$this->GetMessage('optspage')}</b><br>
<input type="checkbox" name="optCreateLeaves" checked>{$this->GetMessage('optcreateleaf')}</input><br>
<input type="checkbox" name="optNumberPages">{$this->GetMessage('optnumberpages')}</input><br>
<b>{$this->GetMessage('optstemplate')}</b><br>
- <input type="checkbox" name="optHeaderTemplate" checked>{$this->GetMessage('optheadertemplate')}</input><br>
- <input type="checkbox" name="optAutogenTemplate">{$this->GetMessage('optautogentemplate')}</input><br>
+ <input type="checkbox" name="optHeaderTemplate" checked>{$this->GetMessage('optheadertemplate')}</input>
+ <input type="checkbox" name="optAutogenHeaderTemplate">{$this->GetMessage('optautogenerate')}</input><br>
+ <input type="checkbox" name="optFooterTemplate" disabled>{$this->GetMessage('optfootertemplate')}</input>
+ <input type="checkbox" name="optAutogenFooterTemplate" disabled>{$this->GetMessage('optautogenerate')}</input><br>
<!-- TODO: Add a <select> item here with a list of auto-generate template styles -->
</div>
</div>

0 comments on commit 17b9e7a

Please sign in to comment.