]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/editpage.php
Incorporates code from ViewSource plugin when editing a page that is locked.
[SourceForge/phpwiki.git] / lib / editpage.php
1 <?php
2 rcs_id('$Id: editpage.php,v 1.21 2002-01-13 20:41:26 carstenklapp Exp $');
3
4 require_once('lib/transform.php');
5 require_once('lib/Template.php');
6
7 function editPage($dbi, $request) {
8     // editpage relies on $pagename, $version
9     $pagename = $request->getArg('pagename');
10     $version  = $request->getArg('version');
11     
12     $page    = $dbi->getPage($pagename);
13     $current = $page->getCurrentRevision();
14
15     if ($version === false) {
16         $selected = $current;
17     }
18     else {
19         $selected = $page->getRevision($version);
20         if (!$selected)
21             NoSuchRevision($page, $version); // noreturn
22     }
23
24     global $user;               // FIXME: make this non-global.
25     if ($page->get('locked') && !$user->is_admin()) {
26         // Perhaps this can be worked into display.php. It would be nice if:
27         // 'Note: You are viewing an old revision of this page. "View the current version".'
28         // would link to "View source of the current version".
29         // Also the <h1> is hard-coded in brwose.html / editpage.html
30         // so we can't get a nice title like "Page source for %s".
31         if ($version) {
32             $link = QElement('a',
33                              array('href' =>
34                                    WikiURL($pagename,
35                                            array('version' => $version))),$pagename);
36         } else {
37             $link = LinkExistingWikiWord($pagename);
38         }
39         $html = QElement('p');
40         $html .= QElement('strong', _("Note:")) . " ";
41         $html .= sprintf(_("%s has been locked by the administrator and cannot be edited."), $link);
42         $html .= "\n";
43
44         $template = new WikiTemplate('BROWSE');
45         $template->replace('TITLE', sprintf(_("Page source for %s"), $pagename));
46         $template->replace('EDIT_FAIL_MESSAGES', $html
47                            . QElement('hr', array('noshade' => 'noshade'))
48                            . "\n");
49         $prefs = $user->getPreferences();
50         $template->replace('CONTENT', 
51                            Element('p',
52                                    QElement('textarea',
53                                             array('class'  => 'wikiedit',
54                                                   'rows'   => $prefs['edit_area.height'],
55                                                   'cols'   => $prefs['edit_area.width'],
56                                                   'wrap'   => 'virtual',
57                                                   'readonly' => true),
58                                             $selected->getPackedContent())));
59         $template->setPageRevisionTokens($selected);
60
61         require_once("lib/display.php");
62         $template->qreplace('PAGE_DESCRIPTION', GleanDescription($selected));
63         echo $template->getExpansion();
64         flush();
65         ExitWiki ("");
66     }
67
68
69     $age = time() - $current->get('mtime');
70     $minor_edit = ( $age < MINOR_EDIT_TIMEOUT && $current->get('author') == $user->id() );
71
72     $formvars = array('content'     => htmlspecialchars($selected->getPackedContent()),
73                       'minor_edit'  => $minor_edit ? 'checked' : '',
74                       'version'     => $selected->getVersion(),
75                       'editversion' => $current->getVersion(),
76                       'summary'     => '',
77                       'convert'     => '',
78                       'pagename'    => htmlspecialchars($pagename));
79
80     $template = new WikiTemplate('EDITPAGE');
81     $template->setPageRevisionTokens($selected);
82     $template->replace('FORMVARS', $formvars);
83     echo $template->getExpansion();
84 }
85
86 // Local Variables:
87 // mode: php
88 // tab-width: 8
89 // c-basic-offset: 4
90 // c-hanging-comment-ender-p: nil
91 // indent-tabs-mode: nil
92 // End:   
93 ?>