Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 687 lines (632 sloc) 25.099 kb
adc5ebe @Whiteknight initial commit, add files to repo
authored
1 <?php
2 class BookDesigner extends SpecialPage {
3 function __construct() {
4 parent::__construct( 'BookDesigner' );
5 wfLoadExtensionMessages('BookDesigner');
6 }
7
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
8 # set this to true to enable debugging output.
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
9 protected $debug = false;
adc5ebe @Whiteknight initial commit, add files to repo
authored
10
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
11 # Internal values. Don't modify them, they get set at runtime
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
12 protected $options = array(
13 "CreateLeaves" => true,
14 "UseHeader" => true,
15 "UseFooter" => false,
16 "NumberPages" => false,
17 "UseNamespace" => false,
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
18 "UseIntroduction" => true,
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
19 "UseResources" => false,
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
20 "UseLicensing" => true,
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
21 );
22 protected $namespace = "";
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
23 protected $bookname = "";
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
24 protected $pagelinktmpl = "* [[$1|$2]]";
25 protected $chapterlinktmpl = "* [[$1|$2]]";
26 protected $sectionheadtmpl = "== $1 ==";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
27
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
28 function getOption($name) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
29 return $this->options[$name];
30 }
31
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
32 function getOptionCheckbox($name) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
33 return $this->options[$name] ? "checked" : "";
34 }
35
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
36 function setOption($name, $value) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
37 $this->options[$name] = $value;
38 }
39
40 function getHeaderTemplateTag() {
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
41 return $this->getOption('UseHeader') ? "{{" . $this->bookname . "}}" : "";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
42 }
43
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
44 function getPageHeadText($isroot) {
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
45 $text = $this->getHeaderTemplateTag() . "\n\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
46 if ($isroot && $this->getOption('UseIntroduction'))
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
47 $text .=
48 $this->GetPageLinkWikiText($this->bookname . "/Introduction", "Introduction")
49 . "\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
50 return $text;
51 }
52
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
53 function getPageFootText($isroot) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
54 $text = "\n\n";
55 if ($isroot && $this->getOption('UseResources'))
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
56 $text .= $this->getPageLinkWikiText($this->bookname . "/Resources", "Resources") . "\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
57 if ($isroot && $this->getOption('UseLicensing'))
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
58 $text .= $this->getPageLinkWikiText($this->bookname . "/Licensing", "Licensing") . "\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
59 return $text . $this->getFooterTemplateTag();
60 }
57962df @Whiteknight some misc cleanups to the php file
authored
61
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
62 function getPageLinkWikiText($path, $name) {
63 return str_replace(array('$1', '$2'), array($path, $name), $this->pagelinktmpl);
64 }
65
66 function getChapterLinkWikiText($path, $name) {
67 # TODO: Once we support it, change this to use chapterlinktmpl
68 return str_replace(array('$1', '$2'), array($path, $name), $this->pagelinktmpl);
69 }
70
71 function getSectionHeadWikiText($name) {
72 return str_replace('$1', $name, $this->sectionheadtmpl);
73 }
74
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
75 # Quick and dirty debugging utilities. The value of $this->debug determines
76 # whether we print something. These functions can probably disappear soon
77 # since the parseBookPage parser routine has been mostly tested.
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
78 function _dbg($word) {
adc5ebe @Whiteknight initial commit, add files to repo
authored
79 global $wgOut;
80 if($this->debug)
81 $wgOut->addHTML($word);
82 }
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
83 function _dbgl($word) {
adc5ebe @Whiteknight initial commit, add files to repo
authored
84 $this->_dbg($word . "<br/>");
85 }
86
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
87 function getFooterTemplateTag() {
88 # TODO: Add an option to specify a footer tag
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
89 return "";
90 }
91
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
92 function GetCreateFlag($isroot) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
93 $create = $this->getOption('CreateLeaves') || $isroot;
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
94 return $create;
95 }
96
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
97 function addPageToList(&$pagelist, $pagename, $fullname, $pagetext, $create) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
98 $pagelist[] = array(
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
99 "name" => $pagename,
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
100 "fullname" => $fullname,
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
101 "text" => $pagetext,
102 "create" => $create
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
103 );
104 $this->_dbgl("Adding page $fullname");
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
105 }
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
106
107 function getIntroductionPageText() {
108 return $this->GetHeaderTemplateTag() .
109 "\n\n" .
110 $this->GetFooterTemplateTag();
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
111 }
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
112
113 function getResourcesPageText() {
114 return $this->GetHeaderTemplateTag() .
115 "\n\n" .
116 $this->GetFooterTemplateTag();
117 }
118
119 function getLicensingPageText() {
120 return $this->GetHeaderTemplateTag() .
121 "\n\n" .
122 $this->GetFooterTemplateTag();
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
123 }
124
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
125 # Home-brewed recursive descent parser. Yes there are better ways of doing
126 # this, and yes this is ugly and stupid and ugly. Whatever, this is what
127 # we have.
128 # [] contain lists of pages. {} contain lists of headings. Each page has[]{}
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
129 # and each heading has only []. Each bare line of text inside a set of
130 # brackets is that type of thing. Empty lines are ignored.
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
131 function parseBookPage(&$pagelist, $page, $path, $lines, $idx) {
e23ad77 @Whiteknight use wgScriptPath for generated links to pages. bug report from mikeme…
authored
132 global $wgOut, $wgScriptPath;
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
133 $isroot = ($idx == 1);
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
134 $subpagenum = 0;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
135 $pagetext = $this->getPageHeadText($isroot);
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
136 $createpage = $this->GetCreateFlag($isroot);
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
137 # Loop over all subpages inside [] brackets
adc5ebe @Whiteknight initial commit, add files to repo
authored
138 for($i = $idx; $i < sizeof($lines); $i++) {
139 $line = rtrim($lines[$i]);
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
140 $this->_dbg("($path) Line $i: '$line'> ");
adc5ebe @Whiteknight initial commit, add files to repo
authored
141 if($line == '[') {
142 $this->_dbgl("Ignored");
143 continue;
144 }
145 if(strlen($line) == 0) {
146 $this->_dbgl("Ignored");
147 continue;
148 }
149 if($line == "]") {
150 $this->_dbgl("Breaking subpage loop");
151 $i++;
152 $idx = $i;
153 break;
154 }
155 else {
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
156 # We have a page name
adc5ebe @Whiteknight initial commit, add files to repo
authored
157 $this->_dbgl("Recurse");
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
158 $subpagenum++;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
159 $name = ($this->getOption('NumberPages') ? $subpagenum . ". " : "") . $line;
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
160 $createpage = TRUE;
161 $newpath = $path . "/" . $name;
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
162 $pagetext .= $this->getPageLinkWikiText($newpath, $name) . "\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
163 $i = $this->parseBookPage($pagelist, $name, $newpath, $lines, $i + 1);
adc5ebe @Whiteknight initial commit, add files to repo
authored
164 }
165 }
166 $pagetext .= "\n";
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
167
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
168 # Loop over all headings inside {} brackets
adc5ebe @Whiteknight initial commit, add files to repo
authored
169 for($i = $idx; $i < sizeof($lines); $i++) {
170 $line = rtrim($lines[$i]);
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
171 $this->_dbg("($path) Line $i: '$line'> ");
adc5ebe @Whiteknight initial commit, add files to repo
authored
172 if($line == '{') {
173 $this->_dbgl("Ignored");
174 continue;
175 }
176 if(strlen($line) == 0) {
177 $this->_dbgl("Ignored");
178 continue;
179 }
180 if($line == '}') {
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
181 $this->_dbgl("Breaking heading loop");
adc5ebe @Whiteknight initial commit, add files to repo
authored
182 $idx = $i;
183 break;
184 }
185 $this->_dbgl("Heading");
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
186 $createpage = TRUE;
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
187 $pagetext .= $this->getSectionHeadWikiText($line) . "\n\n";
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
188 # a heading can have pages under it, so enter another loop here to
189 # handle those pages.
adc5ebe @Whiteknight initial commit, add files to repo
authored
190 for($i++; $i < sizeof($lines); $i++) {
191 $line2 = rtrim($lines[$i]);
192 $this->_dbg("Line " . $i . ": " . $line2 . "> ");
193 if($line2 == '[') {
194 $this->_dbgl("Ignored");
195 continue;
196 }
197 if(strlen($line2) == 0) {
198 $this->_dbgl("Ignored");
199 continue;
200 }
201 if($line2 == ']') {
202 $this->_dbgl("Breaking heading-subpage loop");
203 break;
204 }
205 $this->_dbgl("Heading-Subpage");
206 $newpath = $path . "/" . $line2;
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
207 $pagetext .= $this->getPageLinkWikiText($newpath, $line2) . "\n";
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
208 $j = $i + 1;
209 $i = $this->parseBookPage($pagelist, $line2, $newpath, $lines, $i + 1);
adc5ebe @Whiteknight initial commit, add files to repo
authored
210 }
211 }
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
212
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
213 # Get the rest of the text, most of which is optional
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
214 $pagetext = $pagetext . $this->getPageFootText($isroot);
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
215
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
216 # We've parsed all direct subpages and all headings (and all subpages
217 # of those). We have all the information we need now to actually create
218 # this page. Page name is in $path. Page text is in $pagetext
219 # We only create the page if (1) we opt to create all pages, (2) the
220 # page contains subpages, (3) the page contains headings, or (4) it is
221 # the main page.
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
222 $this->addPageToList($pagelist, $page, $path, $pagetext, $createpage);
adc5ebe @Whiteknight initial commit, add files to repo
authored
223 return $idx;
224 }
225
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
226 function createOnePage($path, $text) {
17b9e7a @Whiteknight cleanup i18n messages. Create some new functions to encapsulate vario…
authored
227 global $wgOut, $wgScriptPath;
228 $title = Title::newFromText($path);
229 $article = new Article($title);
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
230 $article->doEdit($text, "Creating page for book '{$this->bookname}'. " .
231 "Automated page creation by BookDesigner");
232 return $title;
7af443d @Whiteknight several changes: General cleanup. Add option to autogenerate a header…
authored
233 }
234
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
235 # Returns an EXTREMELY basic text string for creating a header template.
236 # TODO: Make this less bare-bones
be93e66 @Whiteknight implement footer templates
authored
237 # TODO: Add Forward/Back links
238 # TODO: Use a message to set the default, instead of hard-coding it here.
239 function getDefaultHeaderTemplateText($bookname) {
240 $text = <<<EOD
241
242 <div style="border: 1px solid #AAAAAA; background-color: #F8F8F8; padding: 5px; margin: auto; width: 95%">
243 <center>
244 <big>'''[[$bookname]]'''</big>
245 </center>
246 </div>
247
248 EOD;
249 return $text;
250 }
251
252 # TODO: Make this less bare-bones
253 # TODO: Add Forward/Back links
254 # TODO: Use a message to set the default, instead of hard-coding it here.
255 function getDefaultFooterTemplateText($bookname) {
7af443d @Whiteknight several changes: General cleanup. Add option to autogenerate a header…
authored
256 $text = <<<EOD
257
258 <div style="border: 1px solid #AAAAAA; background-color: #F8F8F8; padding: 5px; margin: auto; width: 95%">
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
259 <center>
260 <big>'''[[$bookname]]'''</big>
261 </center>
7af443d @Whiteknight several changes: General cleanup. Add option to autogenerate a header…
authored
262 </div>
263
0e440bb @Whiteknight fix some sloppy errors I added. mikemerten++
authored
264 EOD;
7af443d @Whiteknight several changes: General cleanup. Add option to autogenerate a header…
authored
265 return $text;
266 }
267
5d64a05 @Whiteknight cleanup options handling and add a quick TODO note about authenticaion
authored
268 function getOptions() {
050a021 @Whiteknight re-fix the paths problem. Fix the autogen template code
authored
269 global $wgRequest;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
270 $this->setOption("CreateLeaves", $wgRequest->getCheck("optCreateLeaves"));
271 $this->setOption("UseHeader", $wgRequest->getCheck("optHeaderTemplate"));
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
272 $this->setOption("UseFooter", $wgRequest->getCheck("optFooterTemplate"));
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
273 $this->setOption("NumberPages", $wgRequest->getCheck("optNumberPages"));
274 $this->setOption("UseNamespace", $wgRequest->getCheck("optUseNamespace"));
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
275 $tmpl = $wgRequest->getText('optPageLinks');
276 if (isset($tmpl) && strlen($tmpl) > 0)
277 $this->pagelinktmpl = $tmpl;
278
279 $tmpl = $wgRequest->getText('optChapterLinks');
280 if (isset($tmpl) && strlen($tmpl) > 0)
281 $this->chapterlinktmpl = $tmpl;
282
283 $tmpl = $wgRequest->getText('optHeaderStyle');
284 if (isset($tmpl) && strlen($tmpl) > 0)
285 $this->sectionheadtmpl = $tmpl;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
286
287 $this->namespace = $this->getOption('UseNamespace')
288 ? $wgRequest->getText("optNamespace") . ":" : "";
289 $this->setOption('UseIntroduction', $wgRequest->getCheck("optIntroductionPage"));
290 $this->setOption('UseResources', $wgRequest->getCheck("optResourcesPage"));
291 $this->setOption('UseLicensing', $wgRequest->getCheck("optLicensingPage"));
5d64a05 @Whiteknight cleanup options handling and add a quick TODO note about authenticaion
authored
292 }
293
92d6526 @Whiteknight initial implementation of proper i18n message handling for the PHP-ba…
authored
294 function GetMessage($msgname) {
295 return wfMsg('bookdesigner-' . $msgname);
296 }
297
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
298 # Main function, this is where execution starts
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
299 function execute($par) {
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
300 # TODO: Validate that we are logged in. Also, create an option to
301 # require certain permissions (either admin, or a custom
302 # permission or something)
303 global $wgRequest, $wgOut;
adc5ebe @Whiteknight initial commit, add files to repo
authored
304 $this->setHeaders();
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
305 $wgOut->setPageTitle("Book Designer");
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
306 $this->loadJSAndCSS();
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
307
308 $mode = "outline";
309 $title = null;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
310
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
311 if(isset($par)) {
312 $parts = explode('/', $par, 2);
313 $mode = $parts[0];
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
314 #$title = $parts[1];
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
315 }
316 if($wgRequest->wasPosted()) {
317 if ($mode == 'verify') {
318 $this->verifyPublishOutline();
319 }
320 else if ($mode == 'publish') {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
321 $this->_dbgl("publish");
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
322 $this->reallyPublishOutline();
323 }
324 else {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
325 $this->_dbgl("post error");
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
326 $this->unknownModeError('post', $mode, $title);
327 }
328 }
329 else {
330 # TODO: we've specified a book name, load that book into the outline
331 # $mode == 'outline' creates an empty outline with "title"
332 # $mode == 'preload' attempts to load an existing outline
333 if (!isset($mode) || $mode == "" || $mode == "outline" || $mode == "preload") {
334 $this->displayMainOutline($mode, $title);
335 }
336 else {
337 $this->unknownModeError('show', $mode, $title);
338 }
339 }
340 }
341
342 function unknownModeError($type, $mode, $title) {
343 global $wgOut;
344 $title_extra = "";
345 if (isset($title)) {
346 $title_extra = "with arguments (" . $title . ")";
347 }
348 $text = <<<EOD
349 <p>
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
350 <span style='color: red; font-weight: bold;'>Error:</span>
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
351 Could not {$type} with mode {$mode} $title_extra
352 </p>
353
354 EOD;
355 $wgOut->addHTML($text);
356 }
357
358 function verifyPublishOutline() {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
359 global $wgRequest;
360 $text = $wgRequest->getText('VBDHiddenTextArea');
361 $lines = explode("\n", $text);
362 $this->bookname = $lines[0];
363 $this->getOptions();
364 $pagelist = array();
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
365 $this->parseBookPage($pagelist, $lines[0], $this->namespace . $lines[0], $lines, 1);
be93e66 @Whiteknight implement footer templates
authored
366 # TODO: Instead of hard-coding in a list of pages that can be added,
367 # Allow the site to specify a list of standard pages, and supply
368 # a text template to be used on those pages.
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
369 if ($this->getOption('UseHeader')) {
370 $this->addPageToList($pagelist, "Template:" . $this->bookname,
371 "Template:" . $this->bookname,
be93e66 @Whiteknight implement footer templates
authored
372 $this->getDefaultHeaderTemplateText($this->bookname),
373 true
374 );
375 }
376 if ($this->getOption('UseFooter')) {
377 $this->addPageToList($pagelist, "Template:" . $this->bookname . "/Footer",
378 "Template:" . $this->bookname . "/Footer",
379 $this->getDefaultFooterTemplateText($this->bookname),
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
380 true
381 );
382 }
383 if ($this->getOption('UseIntroduction')) {
384 $this->addPageToList($pagelist, "Introduction",
385 $this->bookname . "/Introduction",
386 $this->getIntroductionPageText(),
387 true
388 );
389 }
390 if ($this->getOption('UseResources')) {
391 $this->addPageToList($pagelist, "Resources",
392 $this->bookname . "/Resources",
393 $this->getResourcesPageText(),
394 true
395 );
396 }
397 if ($this->getOption('UseLicensing')) {
398 $this->addPageToList($pagelist, "Licensing",
399 $this->bookname . "/Licensing",
400 $this->getLicensingPageText(),
401 true
402 );
403 }
404 $this->showConfirmationPage($this->bookname, $pagelist);
405 }
406
407 function showConfirmationPage($bookname, $pagelist) {
54753f2 @Whiteknight cleanup. Remove old TODO notes. fix a bug in the create leaf pages fu…
authored
408 # TODO: detect if any pages already exist. Link to them if they do, and
409 # bring the issue to the attention of the user
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
410 global $wgOut, $wgScriptPath;
411 $jspath = "$wgScriptPath/extensions/BookDesigner";
412 $wgOut->addScriptFile($jspath . "/designer.js");
413 $this->addCSSFile("designer.css");
414 $i = 0;
415 $text = <<<EOT
416 <form action="{$wgScriptPath}/index.php?title=Special:BookDesigner/publish" method="POST">
417 <div>
418 <h2>
419 Confirm Pages for {$bookname}
420 </h2>
421 <p>
422 Below is a list of pages that will be created in your book. You can
423 select which pages to create, and you can modify the page text. You
424 cannot alter the structure of the book otherwise. Click
425 <b>Publish</b> if everything is ready to publish.
426 </p>
427 </div>
428 EOT;
429 $wgOut->addHTML($text);
430 $numpages = count($pagelist);
431 foreach ($pagelist as &$page) {
432 $this->showPageSinglePageConfirmation($i, $page["name"],
433 $page["fullname"], $page["text"], $page["create"]);
434 $i++;
435 }
436 $text = <<<EOT
437 <input type="submit" value="Publish" />
438 <a href="$wgScriptPath/index.php?title=Special:BookDesigner">
439 Cancel
440 </a>
441 <input type="hidden" name="VBDTotalPageCount" value="{$numpages}" />
442 <input type="hidden" name="VBDBookName" value="{$this->bookname}" />
443 </form>
444 EOT;
445 $wgOut->addHTML($text);
446 }
447
448 function showPageSinglePageConfirmation($idx, $name, $path, $text, $create) {
449 global $wgOut;
450 $checked = $create ? "checked" : "";
451 $text = <<<EOT
452 <div class="VBDConfirmPageDiv">
453 <input type="hidden" name="path_{$idx}" value="{$path}"/>
454 <input type="checkbox" name="confirm_{$idx}" {$checked}>
455 <span style='font-size: larger; font-weight: bold;'>
456 {$path}
457 </span>
458 </input>
459 [<a id="text_toggle_{$idx}"
460 onclick="vbd.ToggleGUIWidget('text_div_{$idx}', 'text_toggle_{$idx}');"><!--
461 -->{$this->GetMessage('show')}<!--
462 --></a>]
463
464 <div class="VBDPageTextDiv" id="text_div_{$idx}" style="display: none;">
465 <textarea name="text_{$idx}" rows="10">{$text}</textarea>
466 </div>
467 </div>
468 EOT;
469 $wgOut->addHTML($text);
470 }
471
472 function reallyPublishOutline() {
473 global $wgRequest, $wgOut;;
474 $numpages = $wgRequest->getInt('VBDTotalPageCount');
475 $this->bookname = $wgRequest->getText('VBDBookName');
476 $wgOut->addHTML("<ul>");
477 for ($i = 0; $i < $numpages; $i++) {
478 $path = $wgRequest->getText("path_{$i}");
479 $create = $wgRequest->getBool("confirm_{$i}");
480 $text = $wgRequest->getText("text_{$i}");
481 if (!$create) {
482 $this->showPageNotCreatedMessage($path);
483 } else {
484 $title = $this->createOnePage($path, $text);
485 $this->showPageCreatedMessage($path, $title);
486 }
487 }
488 $wgOut->addHTML("</ul>");
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
489 # TODO: Show statistics (number of pages created, total time, etc)
490 # here
491 # TODO: Show an "Oops!" delete/undo link here that goes back over
492 # the list of pages and deletes them all again (if the user
493 # is an admin)
494 }
495
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
496 function showPageNotCreatedMessage($path) {
497 global $wgOut;
498 $text = <<<EOT
499 <div class="VBDCreateIgnored">
500 <p>
501 Did not create $path
502 </p>
503 </div>
504 EOT;
505 $wgOut->addHTML($text);
506 }
507
508 function showPageCreatedMessage($path, $title) {
509 global $wgOut;
510 $url = $title->getFullURL();
511 $text = <<<EOT
512 <div class="VBDCreateSuccess">
513 <p>
514 Created <a href="{$url}">$path</a>
515 </p>
516 </div>
517 EOT;
518 $wgOut->addHTML($text);
519 }
520
521 function loadJSAndCSS() {
522 global $wgScriptPath, $wgOut;
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
523 $jspath = "$wgScriptPath/extensions/BookDesigner";
57962df @Whiteknight some misc cleanups to the php file
authored
524 $wgOut->addScriptFile($jspath . "/bookpage.js");
525 $wgOut->addScriptFile($jspath . "/pagehead.js");
526 $wgOut->addScriptFile($jspath . "/designer.js");
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
527 $this->addCSSFile("designer.css");
528 }
529
530 function addCSSFile($file) {
531 global $wgScriptPath, $wgOut;
532 $csspath = "$wgScriptPath/extensions/BookDesigner";
c4ad007 @Whiteknight code cleanup, especially in pagehead.js
authored
533 if(method_exists($wgOut, "addExtensionStyle")) {
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
534 $wgOut->addExtensionStyle($csspath . "/" . $file);
c4ad007 @Whiteknight code cleanup, especially in pagehead.js
authored
535 } else {
55b8299 @Whiteknight cleanups. Mostly whitespace
authored
536 # This is a hack for older MediaWiki (1.14 and below?).
537 # addStyle prepends "$wgScriptPath/skins/" to the front,
538 # so we need to navigate to the correct place
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
539 $wgOut->addStyle("../extensions/BookDesigner/" . $file);
c4ad007 @Whiteknight code cleanup, especially in pagehead.js
authored
540 }
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
541 }
542
543 function displayMainOutline() {
544 global $wgOut, $wgScriptPath;
adc5ebe @Whiteknight initial commit, add files to repo
authored
545
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
546 # TODO: Have a hidden field somewhere that we can hold a list of
547 # pages for pre-populating the outline.
548 $text = <<<EOD
adc5ebe @Whiteknight initial commit, add files to repo
authored
549
db22336 @Whiteknight begin massive refactor. I'm sure everything is broken
authored
550 <form action="{$wgScriptPath}/index.php?title=Special:BookDesigner/verify" method="POST">
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
551 <textarea name="VBDHiddenTextArea" id="VBDHiddenTextArea" style="display: none;">
552 </textarea>
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
553 <div id="VBDWelcomeSpan">
92d6526 @Whiteknight initial implementation of proper i18n message handling for the PHP-ba…
authored
554 {$this->GetMessage('welcome')}
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
555 </div>
556 <div id="VBDStatSpan"></div>
c4ad007 @Whiteknight code cleanup, especially in pagehead.js
authored
557 <div id="VBDInstructionSpan">
aa57798 @Whiteknight remove more dead code. Fix toggleable UI panes for consistency. Bump …
authored
558 <h2>
559 <span style="float: right; font-size: 67%;">
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
560 [<a id="VBDQuickStartToggle"
561 onclick="vbd.ToggleGUIWidget('VBDQuickStartInternal', 'VBDQuickStartToggle');"><!--
aa57798 @Whiteknight remove more dead code. Fix toggleable UI panes for consistency. Bump …
authored
562 -->{$this->GetMessage('hide')}<!--
563 --></a>]
564 </span>
565 {$this->GetMessage('qsistart')}
566 </h2>
567 <div id="VBDQuickStartInternal">
568 {$this->GetMessage('qsi')}
569 </div>
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
570 </div>
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
571 {$this->getOptionsWidget()}
572 <div id="VBDOutlineSpan">
573 {$this->GetMessage('jserror')}
574 </div>
575 <!-- TODO: Add another button here to "save" an incomplete outline to a page
576 somewhere in userspace, and maybe a button somewhere to "load" an
577 existing outline. -->
578 <input type="submit" value="{$this->GetMessage('publishbutton')}" /><br>
579 <!-- TODO: This is a temporary addition to aid in debugging. It shows the
580 intermediate code before it's transmitted to the server. This way if
581 there is some kind of a server error, we can save a copy of that
582 intermediate code to a safe place so when we are making a huge outline
583 we don't lose all that work. No i18n for debug stuff.
584 -->
585 <small>
586 <a href="#" onclick="document.getElementById('VBDHiddenTextArea').style.display = 'block';">
587 Show Intermediate Code
588 </a>
589 </small>
590 </form>
591
592 EOD;
593 $wgOut->addHTML($text);
594 }
595
596 function getOptionsWidget() {
597 $text = <<<EOD
598 <div id="VBDOptionsSpan">
17b8da7 @Whiteknight make the options box toggleable with JS magic. Start some code clean…
authored
599 <h2>
600 <span style="float: right; font-size: 67%;">
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
601 [<a id="VBDOptionsToggle"
602 onclick="vbd.ToggleGUIWidget('VBDOptionsInternal', 'VBDOptionsToggle');"><!--
aa57798 @Whiteknight remove more dead code. Fix toggleable UI panes for consistency. Bump …
authored
603 -->{$this->GetMessage('show')}<!--
604 --></a>]
17b8da7 @Whiteknight make the options box toggleable with JS magic. Start some code clean…
authored
605 </span>
92d6526 @Whiteknight initial implementation of proper i18n message handling for the PHP-ba…
authored
606 {$this->GetMessage('options')}
17b8da7 @Whiteknight make the options box toggleable with JS magic. Start some code clean…
authored
607 </h2>
608 <div id="VBDOptionsInternal" style="display: none;">
92d6526 @Whiteknight initial implementation of proper i18n message handling for the PHP-ba…
authored
609 <b>{$this->GetMessage('optsbook')}</b><br>
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
610 <input type="checkbox" name="optUseNamespace"
611 {$this->getOptionCheckbox('UseNamespace')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
612 {$this->GetMessage('optusenamespace')}:
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
613 </input>
614 <br>
615 <input type="text" style="margin-left: 6em;" name="optNamespace"
616 value="{$this->namespace}">
617 <br>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
618 <input type="checkbox" name="optUseUserSpace" disabled>
619 {$this->GetMessage('optuseuserspace')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
620 </input>
621 <br>
622 <input type="checkbox" name="optIntroductionPage"
623 {$this->getOptionCheckbox('UseIntroduction')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
624 {$this->GetMessage('optintroductionpage')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
625 </input>
626 <br>
627 <input type="checkbox" name="optResourcesPage"
628 {$this->getOptionCheckbox('UseResources')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
629 {$this->GetMessage('optresourcespage')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
630 </input>
631 <br>
632 <input type="checkbox" name="optLicensingPage"
633 {$this->getOptionCheckbox('UseLicensing')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
634 {$this->GetMessage('optlicensingpage')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
635 </input>
636 <br>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
637 <b>
638 {$this->GetMessage('optspage')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
639 </b>
640 <br>
641 <input type="checkbox" name="optCreateLeaves"
642 {$this->getOptionCheckbox('CreateLeaves')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
643 {$this->GetMessage('optcreateleaf')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
644 </input>
645 <br>
646 <input type="checkbox" name="optNumberPages"
647 {$this->getOptionCheckbox('NumberPages')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
648 {$this->GetMessage('optnumberpages')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
649 </input>
650 <br>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
651 <b>
652 {$this->GetMessage('optstemplate')}
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
653 </b>
654 <br>
655 <input type="checkbox" name="optHeaderTemplate"
656 {$this->getOptionCheckbox('UseHeader')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
657 {$this->GetMessage('optheadertemplate')}
658 </input>
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
659 <br>
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
660 <input type="checkbox" name="optFooterTemplate"
661 {$this->getOption('UseFooter')}>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
662 {$this->GetMessage('optfootertemplate')}
663 </input>
79d0308 @Whiteknight We don't autogenerate templates anymore, so remove those options. Tem…
authored
664 <br>
665 <b>
666 Formatting Options
667 </b>
668 <br>
669 Chapter Links:
670 <input type="text" name="optChapterLinks" value="{$this->chapterlinktmpl}" disabled/>
671 <br>
672 Page Links:
673 <input type="text" name="optPageLinks" value="{$this->pagelinktmpl}"/>
674 <br>
675 Headers:
676 <input type="text" name="optHeaderStyle" value="{$this->sectionheadtmpl}"/>
677 <br>
c65c926 @Whiteknight break up long lines, especially in comments. Reformat some of the inl…
authored
678 <!-- TODO: Add a <select> item here with a list of auto-generate
679 template styles -->
17b8da7 @Whiteknight make the options box toggleable with JS magic. Start some code clean…
authored
680 </div>
9745683 @Whiteknight a few major changes: Add options to avoid creating leaf nodes, number…
authored
681 </div>
adc5ebe @Whiteknight initial commit, add files to repo
authored
682 EOD;
31cbfce @Whiteknight Implement saving pages, and add some color to the results screen. Thi…
authored
683 return $text;
adc5ebe @Whiteknight initial commit, add files to repo
authored
684 }
685 }
686
Something went wrong with that request. Please try again.