]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/removepage.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / removepage.php
1 <?php
2 // rcs_id('$Id$');
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)); // noreturn
13     }
14
15     $current = $page->getCurrentRevision();
16
17     if (!$current or !($version = $current->getVersion())) {
18         $html = HTML::p(array('class' => 'error'), _("Sorry, this page does not exist."));
19     }
20     elseif (!$request->isPost() || !$request->getArg('verify')) {
21
22         $removeB = Button('submit:verify', _("Remove Page"), 'wikiadmin');
23         $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look
24
25         $fieldset = HTML::fieldset(HTML::p(fmt("You are about to remove '%s'!", $pagelink)),
26                      HTML::form(array('method' => 'post',
27                                       'action' => $request->getPostURL()),
28                                 HiddenInputs(array('currentversion' => $version,
29                                                    'pagename' => $page->getName(),
30                                                    'action' => 'remove')),
31                                 HTML::div(array('class' => 'toolbar'),
32                                           $removeB,
33                                           $WikiTheme->getButtonSeparator(),
34                                           $cancelB))
35                      );
36         $sample = HTML::div(array('class' => 'transclusion'));
37         // simple and fast preview expanding only newlines
38         foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) {
39             $sample->pushContent($s, HTML::br());
40         }
41         $html = HTML($fieldset, HTML::div(array('class' => 'wikitext'), $sample));
42     }
43     elseif ($request->getArg('currentversion') != $version) {
44         $html = HTML(HTML::p(array('class' => 'error'), (_("Someone has edited the page!"))),
45                      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)));
46     }
47     else {
48         // Real delete.
49         $pagename = $page->getName();
50         $dbi = $request->getDbh();
51         $dbi->deletePage($pagename);
52         $dbi->touch();
53         $html = HTML::div(array('class' => 'feedback'), fmt("Removed page '%s' successfully.", $pagename));
54     }
55
56     GeneratePage($html, _("Remove Page"));
57 }
58
59 // Local Variables:
60 // mode: php
61 // tab-width: 8
62 // c-basic-offset: 4
63 // c-hanging-comment-ender-p: nil
64 // indent-tabs-mode: nil
65 // End:
66 ?>