]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/purgepage.php
Implemented action=purge
[SourceForge/phpwiki.git] / lib / purgepage.php
1 <?php
2 rcs_id('$Id: purgepage.php,v 1.26 2004/12/20 12:12:31 rurban Exp $');
3 require_once('lib/Template.php');
4
5 function PurgePage (&$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         $purgeB = Button('submit:verify', _("Purge Page"), 'wikiadmin');
23         $cancelB = Button('submit:cancel', _("Cancel"), 'button'); // use generic wiki button look
24
25         $html = HTML(HTML::p(fmt("You are about to purge '%s'!", $pagelink)),
26                      HTML::form(array('method' => 'post',
27                                       'action' => $request->getPostURL()),
28                                 HiddenInputs(array('currentversion' => $version,
29                                                    'pagename' => $page->getName(),
30                                                    'action' => 'purge')),
31                                 
32                                 HTML::div(array('class' => 'toolbar'),
33                                           $purgeB,
34                                           $WikiTheme->getButtonSeparator(),
35                                           $cancelB)),
36                      HTML::hr()
37                      );
38         $sample = HTML::div(array('class' => 'transclusion'));
39         // simple and fast preview expanding only newlines
40         foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) {
41             $sample->pushContent($s, HTML::br());
42         }
43         $html->pushContent(HTML::div(array('class' => 'wikitext'), 
44                                      $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 purge process, someone has saved a new version of %s.  Please check to make sure you still want to permanently purge the page from the database.", $pagelink)));
49     }
50     else {
51         // Real purge.
52         $pagename = $page->getName();
53         $dbi = $request->getDbh();
54         $dbi->purgePage($pagename);
55         $dbi->touch();
56         $html = HTML::div(array('class' => 'feedback'), fmt("Purged page '%s' successfully.", $pagename));
57     }
58
59     GeneratePage($html, _("Purge Page"));
60 }
61
62 // For emacs users
63 // Local Variables:
64 // mode: php
65 // tab-width: 8
66 // c-basic-offset: 4
67 // c-hanging-comment-ender-p: nil
68 // indent-tabs-mode: nil
69 // End:
70 ?>