From: Geoffrey T. D. <da...@us...> - 2002-01-07 23:26:27
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory usw-pr-cvs1:/tmp/cvs-serv5356/lib/plugin Modified Files: ViewMarkup.php Log Message: Display page source in a <textarea>. This make for easy cutting/pasting, and also displays the source in a format identical to that seen when editing the page. Also other minor cleanups and changes: No need to talk to backend directly, just use the WikiDB API. Support for viewing source of previous revisions. Added a couple points of discussion to the comments: * I don't like the name ViewMarkup. * This code could be merged with the EditPage code. Index: ViewMarkup.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/ViewMarkup.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** ViewMarkup.php 2001/12/31 08:30:36 1.3 --- ViewMarkup.php 2002/01/07 23:26:25 1.4 *************** *** 21,25 **** function getDefaultArguments() { ! return array('page' => false); } --- 21,26 ---- function getDefaultArguments() { ! return array('page' => false, ! 'rev' => false); } *************** *** 27,61 **** function run($dbi, $argstr, $request) { $args = $this->getArgs($argstr, $request); ! extract($args); ! if (empty($page)) return ''; //fetch the latest version of the page. Should this be made to //work when viewing an old revision of a page too? ! $backend = &$dbi->_backend; ! $version = $backend->get_latest_version($page); ! $vdata = $backend->get_versiondata($page, $version, true); ! $content = &$vdata['%content']; - $html = QElement('h2', - sprintf(_("Revealing WikiMarkup for page '%s':"), urlencode($page))); - - /* only good for WikiMarkup with few newlines */ - //$html .= Element('pre', nl2br($content) ); - - /* only good for WikiMarkup with lots of newlines */ - //$html .= Element('pre', $content ); - - /* good for any WikiMarkup - but probably will not appear monospaced */ - //$html .= nl2br($content); - /* <tt> seems to be a good compromise in IE and OmniWeb it doesn't combine newlines and <br>, and renders monospaced */ ! $html .= Element('tt', nl2br($content)); ! return $html; } }; --- 28,81 ---- function run($dbi, $argstr, $request) { $args = $this->getArgs($argstr, $request); ! if (empty($args['page'])) return ''; //fetch the latest version of the page. Should this be made to //work when viewing an old revision of a page too? ! $page = $dbi->getPage($args['page']); ! if (empty($args['rev'])) { ! $rev = $page->getCurrentRevision(); ! $link = QElement('a', ! array('href' => WikiURL($args['page'])), ! $args['page']); ! } ! else { ! $rev = $page->getRevision($args['rev']); ! ! if (!$rev) { ! return QElement('p', array('class' => 'error'), ! __sprintf("I'm sorry. Version %d of %s is not in my database.", ! $args['rev'], $args['page'])); ! } ! $link = QElement('a', ! array('href' => ! WikiURL($args['page'], ! array('version' => $args['rev']))), ! __sprintf("version %d of %s", ! $args['rev'], $args['page'])); ! } ! $html = Element('h2', __sprintf("Page source for %s", $link)); /* <tt> seems to be a good compromise in IE and OmniWeb it doesn't combine newlines and <br>, and renders monospaced */ ! //$html .= Element('tt', nl2br(htmlspecialchars($rev->getPackedContent()))); ! /* Display page source in a <textarea>: ! * o Same appearance as when editing page. ! * o Easiest to cut and paste from. ! */ ! global $user; ! $prefs = $user->getPreferences(); ! $html .= Element('p', ! QElement('textarea', ! array('class' => 'wikiedit', ! 'rows' => $prefs['edit_area.height'], ! 'cols' => $prefs['edit_area.width'], ! 'wrap' => 'virtual', ! 'readonly' => true), ! $rev->getPackedContent())); + return $html; } }; |