]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/removepage.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / removepage.php
1 <?php
2
3 require_once 'lib/Template.php';
4
5 function RemovePage (&$request) {
6     global $WikiTheme;
7
8     $page = $request->getPage();
9     $pagelink = WikiLink($page);
10
11     if ($request->getArg('cancel')) {
12         $request->redirect(WikiURL($page,
13                            array('warningmsg' => _('Remove cancelled'))));
14         // noreturn
15     }
16
17     $current = $page->getCurrentRevision();
18
19     if (!$current or !($version = $current->getVersion())) {
20         $html = HTML::p(array('class' => 'error'), _("Sorry, this page does not exist."));
21     }
22     elseif (!$request->isPost() || !$request->getArg('verify')) {
23
24         $removeB = Button('submit:verify', _("Remove Page"), 'wikiadmin');
25         $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look
26
27         $fieldset = HTML::fieldset(HTML::legend(_('Confirm removal')),
28                                    HTML::p(fmt("You are about to remove '%s'!", $pagelink)),
29                      HTML::form(array('method' => 'post',
30                                       'action' => $request->getPostURL()),
31                                 HiddenInputs(array('currentversion' => $version,
32                                                    'pagename' => $page->getName(),
33                                                    'action' => 'remove')),
34                                 HTML::div(array('class' => 'toolbar'),
35                                           $removeB,
36                                           $WikiTheme->getButtonSeparator(),
37                                           $cancelB))
38                      );
39         $sample = HTML::div(array('class' => 'transclusion'));
40         // simple and fast preview expanding only newlines
41         foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) {
42             $sample->pushContent($s, HTML::br());
43         }
44         $html = HTML($fieldset, HTML::div(array('class' => 'wikitext'), $sample));
45     }
46     elseif ($request->getArg('currentversion') != $version) {
47         $html = HTML(HTML::p(array('class' => 'error'), (_("Someone has edited the page!"))),
48                      HTML::p(fmt("Since you started the deletion process, someone has saved a new version of %s.  Please check to make sure you still want to permanently remove the page from the database.", $pagelink)));
49     }
50     else {
51         // Real delete.
52         $pagename = $page->getName();
53         $dbi = $request->getDbh();
54         $dbi->deletePage($pagename);
55         $dbi->touch();
56         $html = HTML::p(array('class' => 'feedback'), fmt("Removed page '%s' successfully.", $pagename));
57     }
58
59     GeneratePage($html, _("Remove Page"));
60 }
61
62 // Local Variables:
63 // mode: php
64 // tab-width: 8
65 // c-basic-offset: 4
66 // c-hanging-comment-ender-p: nil
67 // indent-tabs-mode: nil
68 // End: