From b66816f09ee8bbeab0f6f9d1de7c2c2f7085c2f5 Mon Sep 17 00:00:00 2001 From: dairiki Date: Mon, 21 Jan 2002 06:55:47 +0000 Subject: [PATCH] More infiltration of new object-based HTML generation. (I've probably broken some things, sorry... I'll work on more cleanup tomorrow.) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@1420 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/ErrorManager.php | 9 +- lib/HtmlElement.php | 179 ++++++++++++++++++++-- lib/Template.php | 28 ++-- lib/Theme.php | 92 +++++------ lib/WikiPlugin.php | 4 +- lib/XmlElement.php | 144 +++++++++++------ lib/diff.php | 154 ++++++++++--------- lib/difflib.php | 13 +- lib/display.php | 15 +- lib/editpage.php | 14 +- lib/main.php | 3 +- lib/plugin/BackLinks.php | 95 ++++++++---- lib/plugin/Calendar.php | 107 ++++++------- lib/plugin/FullTextSearch.php | 30 ++-- lib/plugin/HelloWorld.php | 7 +- lib/plugin/IncludePage.php | 17 +- lib/plugin/LikePages.php | 37 ++--- lib/plugin/MostPopular.php | 44 +++--- lib/plugin/PageHistory.php | 68 ++++---- lib/plugin/RecentChanges.php | 83 +++++----- lib/plugin/TitleSearch.php | 28 ++-- lib/plugin/_BackendInfo.php | 4 +- lib/savepage.php | 5 +- lib/stdlib.php | 28 ++-- lib/transform.php | 4 +- locale/Makefile | 4 +- themes/MacOSX/lib/RecentChanges.php | 18 +-- themes/MacOSX/themeinfo.php | 33 ++-- themes/Portland/templates/actionbar.tmpl | 10 +- themes/Portland/templates/editpage.tmpl | 58 ++++--- themes/Portland/templates/viewsource.tmpl | 7 +- themes/Portland/themeinfo.php | 25 +-- themes/default/templates/browse.tmpl | 4 +- themes/default/templates/editpage.tmpl | 47 +++--- themes/default/templates/signin.tmpl | 4 +- themes/default/templates/top.tmpl | 6 +- 36 files changed, 829 insertions(+), 599 deletions(-) diff --git a/lib/ErrorManager.php b/lib/ErrorManager.php index 70757007d..0f297a71f 100644 --- a/lib/ErrorManager.php +++ b/lib/ErrorManager.php @@ -1,4 +1,4 @@ - 'errors'), - QElement('h4', sprintf(_("PHP %s Warnings"), - PHP_VERSION)) - . $html); + return HTML::div(array('class' => 'errors'), + HTML::h4("PHP Warnings"), + new RawXml($html)); } /** diff --git a/lib/HtmlElement.php b/lib/HtmlElement.php index 0f8073936..3df737ee6 100644 --- a/lib/HtmlElement.php +++ b/lib/HtmlElement.php @@ -1,4 +1,4 @@ -printXML(); - } - - function asHTML () { - return $this->asXML(); - } }; class HTML { @@ -35,6 +27,31 @@ class HTML { } + function link (/*...*/) { + $el = new HtmlElement('link'); + $el->_init(func_get_args()); + return $el; + } + + function style (/*...*/) { + $el = new HtmlElement('style'); + $el->_init(func_get_args()); + return $el; + } + + function script (/*...*/) { + $el = new HtmlElement('script'); + $el->_init(func_get_args()); + return $el; + } + + function noscript (/*...*/) { + $el = new HtmlElement('noscript'); + $el->_init(func_get_args()); + return $el; + } + + function a (/*...*/) { $el = new HtmlElement('a'); $el->_init(func_get_args()); @@ -53,12 +70,132 @@ class HTML { return $el; } + function h1 (/*...*/) { + $el = new HtmlElement('h1'); + $el->_init(func_get_args()); + return $el; + } + + function h2 (/*...*/) { + $el = new HtmlElement('h2'); + $el->_init(func_get_args()); + return $el; + } + + function h3 (/*...*/) { + $el = new HtmlElement('h3'); + $el->_init(func_get_args()); + return $el; + } + + function h4 (/*...*/) { + $el = new HtmlElement('h4'); + $el->_init(func_get_args()); + return $el; + } + + function h5 (/*...*/) { + $el = new HtmlElement('h5'); + $el->_init(func_get_args()); + return $el; + } + + function h6 (/*...*/) { + $el = new HtmlElement('h6'); + $el->_init(func_get_args()); + return $el; + } + + function div (/*...*/) { + $el = new HtmlElement('div'); + $el->_init(func_get_args()); + return $el; + } + function p (/*...*/) { $el = new HtmlElement('p'); $el->_init(func_get_args()); return $el; } + function blockquote (/*...*/) { + $el = new HtmlElement('blockquote'); + $el->_init(func_get_args()); + return $el; + } + + function span (/*...*/) { + $el = new HtmlElement('span'); + $el->_init(func_get_args()); + return $el; + } + + function em (/*...*/) { + $el = new HtmlElement('em'); + $el->_init(func_get_args()); + return $el; + } + + function strong (/*...*/) { + $el = new HtmlElement('strong'); + $el->_init(func_get_args()); + return $el; + } + + function small (/*...*/) { + $el = new HtmlElement('small'); + $el->_init(func_get_args()); + return $el; + } + + function tt (/*...*/) { + $el = new HtmlElement('tt'); + $el->_init(func_get_args()); + return $el; + } + + function u (/*...*/) { + $el = new HtmlElement('u'); + $el->_init(func_get_args()); + return $el; + } + + function ul (/*...*/) { + $el = new HtmlElement('ul'); + $el->_init(func_get_args()); + return $el; + } + + function ol (/*...*/) { + $el = new HtmlElement('ol'); + $el->_init(func_get_args()); + return $el; + } + + function dl (/*...*/) { + $el = new HtmlElement('dl'); + $el->_init(func_get_args()); + return $el; + } + + function li (/*...*/) { + $el = new HtmlElement('li'); + $el->_init(func_get_args()); + return $el; + } + + function dt (/*...*/) { + $el = new HtmlElement('dt'); + $el->_init(func_get_args()); + return $el; + } + + function dd (/*...*/) { + $el = new HtmlElement('dd'); + $el->_init(func_get_args()); + return $el; + } + function table (/*...*/) { $el = new HtmlElement('table'); $el->_init(func_get_args()); @@ -71,6 +208,30 @@ class HTML { return $el; } + function td (/*...*/) { + $el = new HtmlElement('td'); + $el->_init(func_get_args()); + return $el; + } + + function th (/*...*/) { + $el = new HtmlElement('th'); + $el->_init(func_get_args()); + return $el; + } + + function form (/*...*/) { + $el = new HtmlElement('form'); + $el->_init(func_get_args()); + return $el; + } + + function input (/*...*/) { + $el = new HtmlElement('input'); + $el->_init(func_get_args()); + return $el; + } + function isEmptyTag($tag) { global $HTML_TagProperties; if (!isset($HTML_TagProperties[$tag])) diff --git a/lib/Template.php b/lib/Template.php index 4747fa5be..1b50e0cab 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -1,4 +1,4 @@ -_print($item); } } - elseif (is_object($val)) { - if (isa($val, 'Template')) { - // Expand sub-template with defaults from this template. - $val->printExpansion($this->_vars); - } - elseif (method_exists($val, 'printhtml')) { - $val->printHTML(); - } - elseif (method_exists($val, 'ashtml')) { - echo $val->asHTML(); - } - elseif (method_exists($val, 'asstring')) { - return htmlspecialchars($val->asString()); - } - } - else { - echo (string) $val; + elseif (isa($val, 'Template')) { + // Expand sub-template with defaults from this template. + $val->printExpansion($this->_vars); } + else + printXML($val); } /** @@ -115,6 +103,7 @@ class Template /** * Substitute text for tokens in template. * + * FIXME: this is now identical to Template::replace(); * @access public * * @param $token string Name of token to substitute for. @@ -124,7 +113,8 @@ class Template * to escape any special characters. */ function qreplace($varname, $value) { - $this->_vars[$varname] = htmlspecialchars($value); + //$this->_vars[$varname] = htmlspecialchars($value); + $this->_vars[$varname] = $value; } diff --git a/lib/Theme.php b/lib/Theme.php index 9a53510d7..93fb9faaf 100644 --- a/lib/Theme.php +++ b/lib/Theme.php @@ -1,4 +1,6 @@ -_autosplitWikiWords = $autosplit ? true : false; } - function getAutoSplitWikiWords() { - if (! @$this->_autosplitWikiWords) - $this->setAutosplitWikiWords(); - - return $this->_autosplitWikiWords; + function maybeSplitWikiWord ($wikiword) { + if ($this->_autosplitWikiWords) + return split_pagename($wikiword); + else + return $wikiword; } - function LinkExistingWikiWord($wikiword, $linktext = '', $version = false) { - if (empty($linktext)) { - $linktext = $wikiword; - if ($this->getAutoSplitWikiWords()) - $linktext = split_pagename($linktext); - $class = 'wiki'; - } + function linkExistingWikiWord($wikiword, $linktext = '', $version = false) { + if ($version !== false) + $url = WikiURL($wikiword, array('version' => $version)); else - $class = 'named-wiki'; + $url = WikiURL($wikiword); - $attr = array(); - if ($version !== false) - $attr['version'] = $version; + $link = HTML::a(array('href' => $url)); - return QElement('a', array('href' => WikiURL($wikiword, $attr), - 'class' => $class), - $linktext); + if (!empty($linktext)) { + $link->pushContent($linktext); + $link->setAttr('class', 'named-wiki'); + } + else { + $link->pushContent($this->maybeSplitWikiWord($wikiword)); + $link->setAttr('class', 'wiki'); + } + return $link; } - function LinkUnknownWikiWord($wikiword, $linktext = '') { - if (empty($linktext)) { - $linktext = $wikiword; - if ($this->getAutoSplitWikiWords()) - $linktext=split_pagename($linktext); - $class = 'wikiunknown'; - } else - $class = 'named-wikiunknown'; - - return Element('span', array('class' => $class), - QElement('a', - array('href' => WikiURL($wikiword, - array('action' => 'edit'))), - '?') . Element('u', $linktext)); - } + function linkUnknownWikiWord($wikiword, $linktext = '') { + $url = WikiURL($wikiword, array('action' => 'edit')); + $link = HTML::span(HTML::a(array('href' => $url), '?')); + if (!empty($linktext)) { + $link->pushContent(HTML::u($linktext)); + $link->setAttr('class', 'named-wikiunknown'); + } + else { + $link->pushContent(HTML::u($this->maybeSplitWikiWord($wikiword))); + $link->setAttr('class', 'wikiunknown'); + } + + return $link; + } //////////////////////////////////////////////////////////////// // @@ -241,14 +244,14 @@ class Theme { //////////////////////////////////////////////////////////////// function _CSSlink($title, $css_file, $media, $is_alt = false) { - $attr = array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet', - 'title' => $title, - 'type' => 'text/css', - 'charset' => CHARSET); - $attr['href'] = $this->_findData($css_file); + $link = HTML::link(array('rel' => $is_alt ? 'alternate stylesheet' : 'stylesheet', + 'title' => $title, + 'type' => 'text/css', + 'charset'=> CHARSET, + 'href' => $this->_findData($css_file))); if ($media) - $attr['media'] = $media; - return Element('link', $attr); + $link->setAttr('media', $media); + return $link; } function setDefaultCSS ($title, $css_file, $media = false) { @@ -265,9 +268,10 @@ class Theme { * @return string HTML for CSS. */ function getCSS () { - $css = "$this->_defaultCSS\n"; + $css[] = $this->_defaultCSS; if (!empty($this->_alternateCSS)) - $css .= join("\n", $this->_alternateCSS) . "\n"; + foreach ($this->_alternateCSS as $link) + $css[] = $link; return $css; } diff --git a/lib/WikiPlugin.php b/lib/WikiPlugin.php index de3ff2050..f7d9fe0ff 100644 --- a/lib/WikiPlugin.php +++ b/lib/WikiPlugin.php @@ -1,5 +1,5 @@ run($dbi, $plugin_args, $request); + return AsXml($plugin->run($dbi, $plugin_args, $request)); case 'plugin-link': return $plugin->makeLink($plugin_args, $request); case 'plugin-form': diff --git a/lib/XmlElement.php b/lib/XmlElement.php index 61cac3304..ae7c6246b 100644 --- a/lib/XmlElement.php +++ b/lib/XmlElement.php @@ -1,4 +1,4 @@ -_startTag() . ">"; - foreach ($this->_content as $c) { - if (is_object($c)) { - if (method_exists($c, 'printxml')) { - $c->printXML(); - continue; - } - elseif (method_exists($c, 'asstring')) - $c = $c->asString(); - } - echo $this->_quote($c); - } + foreach ($this->_content as $c) + PrintXML($c); echo "_tag>"; } } @@ -117,21 +108,19 @@ class XmlElement } $xml = "<" . $this->_startTag() . ">"; - foreach ($this->_content as $c) { - if (is_object($c)) { - if (method_exists($c, 'printxml')) { - $xml .= $c->asXML(); - continue; - } - elseif (method_exists($c, 'asstring')) - $c = $c->asString(); - } - $xml .= $this->_quote($c); - } + foreach ($this->_content as $c) + $xml .= AsXML($c); $xml .= "_tag>"; return $xml; } + function asString () { + $str = ''; + foreach ($this->_content as $c) + $val .= AsString($c); + return trim($str); + } + function _quote ($string) { return str_replace('<', '<', str_replace('>', '>', @@ -157,19 +146,23 @@ class RawXml { } } -class FormattedText extends RawXml { +class FormattedText { function FormattedText ($fs /* , ... */) { - if ($fs !== false) + if ($fs !== false) { $this->_init(func_get_args()); + } } function _init ($args) { - $fs = array_shift($args); - $qargs = array(); - - // PHP's sprintf doesn't support variable with specifiers, + $this->_fs = array_shift($args); + + // PHP's sprintf doesn't support variable width specifiers, // like sprintf("%*s", 10, "x"); --- so we won't either. - if (preg_match_all('/(?_fs, $m)) { + $this->_args = $args; + } + else { // Format string has '%2$s' style argument reordering. // PHP doesn't support this. if (preg_match('/(?_fs = preg_replace('/(?_fs); - // Reorder arguments appropriately. - // FIXME: pay attention to format type? (only quote %s args?) + $this->_args = array(); foreach($m[1] as $argnum) { if ($argnum < 1 || $argnum > count($args)) trigger_error(sprintf(_("%s: argument index out of range"), $argnum), E_USER_WARNING); - $qargs[] = asXML($args[$argnum - 1]); + $this->_args[] = $args[$argnum - 1]; } } - else { - // FIXME: pay attention to format type? (only quote %s args?) - foreach ($args as $arg) - $qargs[] = asXML($arg); - } + } - $fs = XmlElement::_quote($fs); - + function asXML () { + // Not all PHP's have vsprintf, so... + $args[] = XmlElement::_quote($this->_fs); + foreach ($this->_args as $arg) + $args[] = AsXML($arg); + return call_user_func_array('sprintf', $args); + } + + function printXML () { // Not all PHP's have vsprintf, so... - array_unshift($qargs, $fs); - $this->_xml = call_user_func_array('sprintf', $qargs); + $args[] = XmlElement::_quote($this->_fs); + foreach ($this->_args as $arg) + $args[] = AsXML($arg); + call_user_func_array('printf', $args); + } + + function asString() { + $args = $this->_args; + array_unshift($args, $this->_fs); + return call_user_func_array('sprintf', $args); } } -function asXML ($val) { - if (is_object($val) && method_exists($val, 'asxml')) - return $val->asXML(); - return XmlElement::_quote($val); +function PrintXML ($val) { + if (is_object($val)) { + if (method_exists($val, 'printxml')) + return $val->printXML(); + elseif (method_exists($val, 'asxml')) { + echo $val->asXML(); + return; + } + elseif (method_exists($val, 'asstring')) + $val = $val->asString(); + } + elseif (is_array($val)) { + foreach ($val as $x) + PrintXML($x); + } + + echo (string)XmlElement::_quote($val); } +function AsXML ($val) { + if (is_object($val)) { + if (method_exists($val, 'asxml')) + return $val->asXML(); + elseif (method_exists($val, 'asstring')) + $val = $val->asString(); + } + elseif (is_array($val)) { + $xml = ''; + foreach ($val as $x) + $xml .= AsXML($x); + return $xml; + } + + return XmlElement::_quote((string)$val); +} + +function AsString ($val) { + if (can($val, 'asString')) + return $val->asString(); + elseif (is_array($val)) { + $str = ''; + foreach ($val as $x) + $str .= AsString($x); + return $str; + } + return (string) $val; +} + + function fmt ($fs /* , ... */) { $s = new FormattedText(false); + $args = func_get_args(); - $fs = &$args[0]; - $fs = gettext($fs); + $args[0] = gettext($args[0]); $s->_init($args); return $s; } diff --git a/lib/diff.php b/lib/diff.php index 8e58724fc..cf879a597 100644 --- a/lib/diff.php +++ b/lib/diff.php @@ -1,5 +1,5 @@ \n"; + $this->_top = HTML::div(array('class' => 'diff')); } function _end_diff() { - echo "\n"; + $val = $this->_top; + unset($this->_top); + return $val; } function _start_block($header) { - echo "
\n"; - echo QElement('tt', $header); + $this->_block = HTML::div(array('class' => 'block'), + HTML::tt($header)); } function _end_block() { - echo "
\n"; + $this->_top->pushContent($this->_block); + unset($this->_block); } - function _lines($lines, $class, $prefix = ' ', $elem = false) { + function _lines($lines, $class, $prefix = false, $elem = false) { + if (!$prefix) + $prefix = new RawXml(' '); + foreach ($lines as $line) { if ($elem) - $line = QElement($elem, $line); - - echo Element('div', array('class' => $class), - Element('tt', array('class' => 'prefix'), $prefix) - . " $line ") . "\n"; + $line = new HtmlElement($elem, $line); + $this->_block->pushContent(HTML::div(array('class' => $class), + HTML::tt(array('class' => 'prefix'), + $prefix), + $line, + new RawXml(' '))); } } @@ -77,6 +84,13 @@ class HtmlUnifiedDiffFormatter extends UnifiedDiffFormatter $m); return array($m[0], $m[1]); } + + function _explode_raw($lines) { + $split = explode("\n", $lines); + foreach ($split as $key => $val) + $split[$key] = new RawXml($split[$key]); + return $split; + } function _changed($orig, $final) { list ($orig_words, $orig_stripped) = $this->_split($orig); @@ -100,8 +114,9 @@ class HtmlUnifiedDiffFormatter extends UnifiedDiffFormatter } } - $this->_lines(explode("\n", $orig), 'original', '-'); - $this->_lines(explode("\n", $final), 'final', '+'); + // FIXME: this is a hack + $this->_lines($this->_explode_raw($orig), 'original', '-'); + $this->_lines($this->_explode_raw($final), 'final', '+'); } } @@ -122,36 +137,39 @@ class TableUnifiedDiffFormatter extends HtmlUnifiedDiffFormatter } function _start_diff() { - echo "\n\n"; - } - function _end_diff() { - echo "
\n"; + $this->_top = HTML::table(array('width' => '100%', + 'class' => 'diff', + 'cellspacing' => 1, + 'cellpadding' => 1, + 'border' => 1)); } function _start_block($header) { - echo "\n"; - echo Element('tr', - Element('td', array('colspan' => 2), - QElement('tt', $header))) . "\n"; + $this->_block = HTML::table(array('width' => '100%', + 'class' => 'block', + 'cellspacing' => 0, + 'cellpadding' => 1, + 'border' => 0), + HTML::tr(HTML::td(array('colspan' => 2), + HTML::tt($header)))); } function _end_block() { - echo "
\n"; + $this->_top->pushContent(HTML::tr(HTML::td($this->_block))); + unset($this->_block); } function _lines($lines, $class, $prefix = ' ', $elem = false) { - $prefix = Element('td', array('class' => 'prefix', 'width' => "1%"), $prefix); + $prefix = HTML::td(array('class' => 'prefix', 'width' => "1%"), $prefix); foreach ($lines as $line) { if (! trim($line)) - $line = ' '; + $line = new RawXml(' '); elseif ($elem) - $line = QElement($elem, $line); - - echo Element('tr', array('valign' => 'top'), - $prefix . Element('td', array('class' => $class), - $line)) . "\n"; + $line = new HtmlElement($elem, $line); + $this->_block->pushContent(HTML::tr(array('valign' => 'top'), + $prefix, + HTML::td(array('class' => $class), + $line))); } } } @@ -163,24 +181,18 @@ function PageInfoRow ($pagename, $label, $rev) { global $Theme; - - $cols = QElement('td', array('align' => 'right'), $label); - + $row = HTML::tr(HTML::td(array('align' => 'right'), $label)); if ($rev) { $url = WikiURL($pagename, array('version' => $rev->getVersion())); - $linked_version = QElement('a', array('href' => $url), $rev->getVersion()); - $cols .= Element('td', - __sprintf("version %s",$linked_version)); - - $cols .= QElement('td', - __sprintf("last modified on %s", - $Theme->formatDateTime($rev->get('mtime')))); - $cols .= QElement('td', - __sprintf("by %s", $rev->get('author'))); + $linked_version = HTML::a(array('href' => $url), $rev->getVersion()); + $row->pushContent(HTML::td(fmt("version %s",$linked_version)), + HTML::td(fmt("last modified on %s", + $Theme->formatDateTime($rev->get('mtime')))), + HTML::td(fmt("by %s", $rev->get('author')))); } else { - $cols .= QElement('td', array('colspan' => '3'), _("None")); + $row->pushContent(HTML::td(array('colspan' => '3'), _("None"))); } - return Element('tr', $cols); + return $row; } function showDiff ($dbi, $request) { @@ -199,7 +211,7 @@ function showDiff ($dbi, $request) { if ($version) { if (!($new = $page->getRevision($version))) NoSuchRevision($page, $version); - $new_version = sprintf(_("version %d"), $version); + $new_version = fmt("version %d", $version); } else { $new = $page->getCurrentRevision(); @@ -209,7 +221,7 @@ function showDiff ($dbi, $request) { if (preg_match('/^\d+$/', $previous)) { if ( !($old = $page->getRevision($previous)) ) NoSuchRevision($page, $previous); - $old_version = sprintf(_("version %d"), $previous); + $old_version = fmt("version %d", $previous); $others = array('major', 'minor', 'author'); } else { @@ -243,16 +255,16 @@ function showDiff ($dbi, $request) { } $new_url = WikiURL($pagename, array('version' => $new->getVersion())); - $new_link = QElement('a', array('href' => $new_url), $new_version); + $new_link = HTML::a(array('href' => $new_url), $new_version); $old_url = WikiURL($pagename, array('version' => $old ? $old->getVersion() : 0)); - $old_link = QElement('a', array('href' => $old_url), $old_version); - $page_link = LinkExistingWikiWord($pagename); + $old_link = HTML::a(array('href' => $old_url), $old_version); + global $Theme; + $page_link = $Theme->linkExistingWikiWord($pagename); - $html = Element('p', - __sprintf("Differences between %s and %s of %s.", - $new_link, $old_link, $page_link)); + $html[] = HTML::p(fmt("Differences between %s and %s of %s.", + $new_link, $old_link, $page_link)); - $otherdiffs = array(); + $otherdiffs = HTML::p(_("Other diffs:")); $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author'=> _("Previous Author")); @@ -260,29 +272,29 @@ function showDiff ($dbi, $request) { $args = array('action' => 'diff', 'previous' => $other); if ($version) $args['version'] = $version; - $otherdiffs[] = QElement('a', array('href' => WikiURL($pagename, $args), - 'class' => 'wikiaction'), - $label[$other]); + if (count($otherdiffs->getContent()) > 1) + $otherdiffs->pushContent(", "); + else + $otherdiffs->pushContent(" "); + $otherdiffs->pushContent(HTML::a(array('href' => WikiURL($pagename, $args), + 'class' => 'wikiaction'), + $label[$other])); } - $html .= Element('p', - htmlspecialchars(_("Other diffs:")) - . " " . join(", ", $otherdiffs) . '.'); - + $html[] = $otherdiffs; + if ($old and $old->getVersion() == 0) $old = false; - $html .= Element('table', - PageInfoRow($pagename, _("Newer page:"), $new) - . PageInfoRow($pagename, _("Older page:"), $old)); - - + $html[] = HTML::Table(PageInfoRow($pagename, _("Newer page:"), $new), + PageInfoRow($pagename, _("Older page:"), $old)); + if ($new && $old) { $diff = new Diff($old->getContent(), $new->getContent()); if ($diff->isEmpty()) { - $html .= Element('hr'); - $html .= QElement('p', '[' . _("Versions are identical") . ']'); + $html[] = HTML::hr(); + $html[] = HTML::p('[', _("Versions are identical"), ']'); } else { // New CSS formatted unified diffs (ugly in NS4). @@ -290,13 +302,13 @@ function showDiff ($dbi, $request) { // Use this for old table-formatted diffs. //$fmt = new TableUnifiedDiffFormatter; - $html .= $fmt->format($diff); + $html[] = $fmt->format($diff); } } include_once('lib/Template.php'); echo GeneratePage('MESSAGE', $html, - sprintf(_("Diff: %s"), $pagename)); + sprintf(_("Diff: %s"), $pagename), $new); } // Local Variables: diff --git a/lib/difflib.php b/lib/difflib.php index 3805bf793..3abe29fba 100644 --- a/lib/difflib.php +++ b/lib/difflib.php @@ -1,5 +1,5 @@ leading_context_lines; $ntrail = $this->trailing_context_lines; - ob_start(); $this->_start_diff(); foreach ($diff->edits as $edit) { @@ -765,11 +764,7 @@ class DiffFormatter $y0, $yi - $y0, $block); - $this->_end_diff(); - - $val = ob_get_contents(); - ob_end_clean(); - return $val; + return $this->_end_diff(); } function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) { @@ -790,9 +785,13 @@ class DiffFormatter } function _start_diff() { + ob_start(); } function _end_diff() { + $val = ob_get_contents(); + ob_end_clean(); + return $val; } function _block_header($xbeg, $xlen, $ybeg, $ylen) { diff --git a/lib/display.php b/lib/display.php index e47817b27..4004532ef 100644 --- a/lib/display.php +++ b/lib/display.php @@ -1,7 +1,7 @@ setPageRevisionTokens($revision); $wrapper->qreplace('TITLE', $splitname); $wrapper->replace('HEADER', - QElement('a', - array('href' => WikiURL(_("BackLinks"), - array('page' => $pagename)), - 'class' => 'backlinks', - 'title' => $title_tooltip), - $splitname)); + HTML::a(array('href' => WikiURL(_("BackLinks"), + array('page' => $pagename)), + 'class' => 'backlinks', + 'title' => $title_tooltip), + $splitname)); $wrapper->qreplace('ROBOTS_META', 'index,follow'); $template = new WikiTemplate($tmpl); diff --git a/lib/editpage.php b/lib/editpage.php index ad1f2a055..743e35289 100644 --- a/lib/editpage.php +++ b/lib/editpage.php @@ -1,5 +1,5 @@ linkExistingWikiWord($pagename, '', $version); $wrapper = new WikiTemplate('top'); $wrapper->setPageRevisionTokens($selected); if ($page->get('locked') && !$user->isAdmin()) { $wrapper->qreplace('TITLE', sprintf(_("Page source for %s"), $pagename)); - $wrapper->replace('HEADER', sprintf(_("View Source: %s"), $pagelink)); + $wrapper->replace('HEADER', fmt("View Source: %s", $pagelink)); $template = new WikiTemplate('viewsource'); $do_preview = false; } else { $wrapper->qreplace('TITLE', sprintf(_("Edit: %s"), split_pagename($pagename))); - $wrapper->replace('HEADER', sprintf(_("Edit: %s"), $pagelink)); + $wrapper->replace('HEADER', fmt("Edit: %s", $pagelink)); $template = new WikiTemplate('editpage'); } @@ -53,13 +53,13 @@ function editPage($dbi, $request, $do_preview = false) { $age = time() - $current->get('mtime'); $minor_edit = ( $age < MINOR_EDIT_TIMEOUT && $current->get('author') == $user->getId() ); - $formvars = array('content' => htmlspecialchars($selected->getPackedContent()), + $formvars = array('content' => $selected->getPackedContent(), 'minor_edit' => $minor_edit, 'version' => $selected->getVersion(), 'editversion' => $current->getVersion(), 'summary' => '', 'convert' => '', - 'pagename' => htmlspecialchars($pagename)); + 'pagename' => $pagename); } $template->replace('FORMVARS', $formvars); diff --git a/lib/main.php b/lib/main.php index b25d96577..c90afac6b 100644 --- a/lib/main.php +++ b/lib/main.php @@ -1,5 +1,6 @@ getArgs($argstr, $request); - extract($args); + $this->_args = $this->getArgs($argstr, $request); + extract($this->_args); if (!$page) return ''; - + $p = $dbi->getPage($page); $backlinks = $p->getLinks(); - $lines = array(); - if ($info) { - $lines[] = $this->_tr(QElement('u', _(ucfirst($info))), - QElement('u', _("Page Name"))); - } + + if ($info) + $list = $this->_info_listing($backlinks); + else + $list = $this->_plain_listing($backlinks); + + if ($noheader) + return $list; + + global $Theme; + $pagelink = $Theme->linkExistingWikiWord($page); + + if ($list) + $head = fmt("These pages link to %s:", $pagelink); + else + $head = fmt("No pages link to %s.", $pagelink); + + $head = HTML::p($head); + + return array($head, $list); + } + + function _plain_listing ($backlinks) { + extract($this->_args); + + $ul = HTML::ul(); + $n = 0; while ($backlink = $backlinks->next()) { $name = $backlink->getName(); if ($exclude && $name == $exclude) continue; if (!$include_self && $name == $page) continue; - if ($info) { - $lines[] = $this->_tr($backlink->get($info), - LinkWikiWord($name)); - } else { - $lines[] = Element('li', LinkWikiWord($name)); - } + $ul->pushContent(HTML::li(_LinkWikiWord($name))); + $n++; } + return $n ? $ul : ''; + } - $html = ''; - if (!$noheader) { - $fs = $lines ? _("These pages link to %s:") : _("No pages link to %s."); - $header = sprintf(htmlspecialchars($fs), - LinkExistingWikiWord($page)); - $html = Element('p', $header) . "\n"; - } - - if ($info) { - $html .= Element('blockquote', - Element('table', array('cellpadding' => 0, - 'cellspacing' => 1, - 'border' => 0), - join("\n", $lines))); - return $html; - } else { - return $html . Element('ul', join("\n", $lines)); + function _info_listing ($backlinks) { + extract($this->_args); + + $tab = HTML::table(array('cellpadding' => 0, + 'cellspacing' => 1, + 'border' => 0)); + $tab->pushContent($this->_tr(HTML::u(_(ucfirst($info))), + HTML::u(_("Page Name")))); + $n = 0; + while ($backlink = $backlinks->next()) { + $name = $backlink->getName(); + if ($exclude && $name == $exclude) + continue; + if (!$include_self && $name == $page) + continue; + $tab->pushContent($this->_tr($backlink->get($info), + _LinkWikiWord($name))); + $n++; } + return $n ? HTML::blockquote($tab) : ''; } + function _tr ($col1, $col2) { - return "$col1  " - . "  $col2\n"; + return HTML::tr(HTML::td(array('align' => 'right'), + $col1, new RawXml('  ')), + HTML::td(new RawXml('  '), $col2)); } + + + }; diff --git a/lib/plugin/Calendar.php b/lib/plugin/Calendar.php index 60d2e8a8f..ab39917ae 100644 --- a/lib/plugin/Calendar.php +++ b/lib/plugin/Calendar.php @@ -1,5 +1,5 @@ $t['tm_mon'] + 1, 'year' => $t['tm_year'] + 1900)); - $prev = QElement('a', array('href' => $prev_url, - 'class' => 'cal-arrow', - 'title' => gettext("Previous Month")), - '<'); - $next = QElement('a', array('href' => $next_url, - 'class' => 'cal-arrow', - 'title' => gettext("Next Month")), - '>'); - - - $row = Element('td', array('align' => 'left'), $prev); - $row .= Element('td', array('align' => 'center'), - QElement('strong', array('class' => 'cal-header'), - strftime($args['month_format'], $time))); - $row .= Element('td', array('align' => 'right'), $next); - - $row = Element('table', array('width' => '100%'), - Element('tr', $row)); - - return Element('tr', Element('td', array('colspan' => 7, - 'align' => 'center'), - $row)); + $prev = HTML::a(array('href' => $prev_url, + 'class' => 'cal-arrow', + 'title' => gettext("Previous Month")), + '<'); + $next = HTML::a(array('href' => $next_url, + 'class' => 'cal-arrow', + 'title' => gettext("Next Month")), + '>'); + + + $row = HTML::tr(HTML::td(array('align' => 'left'), $prev), + HTML::td(array('align' => 'center'), + HTML::strong(array('class' => 'cal-header'), + strftime($args['month_format'], $time))), + HTML::td(array('align' => 'right'), $next)); + + return HTML::tr(HTML::td(array('colspan' => 7, + 'align' => 'center'), + HTML::table(array('width' => '100%'), $row))); } @@ -85,13 +82,14 @@ extends WikiPlugin assert($t['tm_wday'] == $start_wday); $fs = $this->args['wday_format']; + $row = HTML::tr(); for ($i = 0; $i < 7; $i++) { - $days[$i] = QElement('td', array('class' => 'cal-dayname', + $row->pushContent(HTML::td(array('class' => 'cal-dayname', 'align' => 'center'), - strftime($fs, $time)); + strftime($fs, $time))); $time += SECONDS_PER_DAY; } - return Element('tr', join('', $days)); + return $row; } function __date($dbi, $time) { @@ -102,22 +100,23 @@ extends WikiPlugin $t = localtime($time, 1); if ($dbi->isWikiPage($page_for_date)) { - $date = Element('a', array('class' => 'cal-day', - 'href' => WikiURL($page_for_date), - 'title' => $page_for_date), - QElement('strong', $t['tm_mday'])); + $date = HTML::a(array('class' => 'cal-day', + 'href' => WikiURL($page_for_date), + 'title' => $page_for_date), + HTML::strong($t['tm_mday'])); } else { - $date = QElement('a', - array('class' => 'cal-hide', - 'href' => WikiURL($page_for_date, - array('action' => 'edit')), - 'title' => sprintf(_("Edit %s"), $page_for_date)), - $t['tm_mday']); + $date = HTML::a(array('class' => 'cal-hide', + 'href' => WikiURL($page_for_date, + array('action' => 'edit')), + 'title' => sprintf(_("Edit %s"), $page_for_date)), + $t['tm_mday']); } - return Element('td', array('align' => 'center'), - " ${date} "); + return HTML::td(array('align' => 'center'), + new RawXml(" "), + $date, + new RawXml(" ")); } function run($dbi, $argstr, $request) { @@ -139,21 +138,27 @@ extends WikiPlugin 1, // mday (1-31) $args['year']); - $rows[] = $this->__header($request->getArg('pagename'), $time); - $rows[] = $this->__daynames($args['start_wday']); + $cal = HTML::table(array('cellspacing' => 0, + 'cellpadding' => 2, + 'class' => 'cal'), + $this->__header($request->getArg('pagename'), $time), + $this->__daynames($args['start_wday'])); + $row = HTML::tr(); + $t = localtime($time, 1); $col = (7 + $t['tm_wday'] - $args['start_wday']) % 7; - $row = $col > 0 ? Element('td', array('colspan' => $col)) : ''; + if ($col > 0) + $row->pushContent(HTML::td(array('colspan' => $col))); $done = false; while (!$done) { - $row .= $this->__date($dbi, $time); + $row->pushContent($this->__date($dbi, $time)); if (++$col % 7 == 0) { - $rows[] = Element('tr', $row); - $col = 0; - $row = ''; + $cal->pushContent($row); + $col = 0; + $row = HTML::tr(); } $time += SECONDS_PER_DAY; @@ -161,15 +166,11 @@ extends WikiPlugin $done = $t['tm_mday'] == 1; } - if ($row) { - $row .= Element('td', array('colspan' => (42 - $col) % 7)); - $rows[] = Element('tr', $row); + if ($row->getContent()) { + $row->pushContent(HTML::td(array('colspan' => (42 - $col) % 7))); + $cal->pushContent($row); } - - return Element('table', array('cellspacing' => 0, - 'cellpadding' => 2, - 'class' => 'cal'), - "\n" . join("\n", $rows) . "\n"); + return $cal; } }; diff --git a/lib/plugin/FullTextSearch.php b/lib/plugin/FullTextSearch.php index e03b01289..6e911b360 100644 --- a/lib/plugin/FullTextSearch.php +++ b/lib/plugin/FullTextSearch.php @@ -1,5 +1,5 @@ false, 'noheader' => false); } @@ -37,38 +36,39 @@ extends WikiPlugin $hilight_re = $query->getHighlightRegexp(); $count = 0; $found = 0; + + $list = HTML::dl(); + global $Theme; while ($page = $pages->next()) { $count++; $name = $page->getName(); - $lines[] = Element('dt', LinkExistingWikiWord($name)); + $list->pushContent(HTML::dt($Theme->linkExistingWikiWord($name))); if ($hilight_re) - $lines[] = $this->showhits($page, $hilight_re); + $list->pushContent($this->showhits($page, $hilight_re)); } + if (!$list->getContent()) + $list->pushContent(HTML::dd(_(""))); - $html = ''; - if (!$noheader) - $html .= QElement('p', - sprintf(_("Full text search results for '%s'"), $s)); - if (!$lines) - $lines[] = QElement('dd', _("")); - - $html .= Element('dl', join("\n", $lines)); - return $html; + if ($noheader) + return $list; + + return array(HTML::p(fmt("Full text search results for '%s'", $s)), + $list); } function showhits($page, $hilight_re) { $FS = &$GLOBALS['FieldSeparator']; $current = $page->getCurrentRevision(); $matches = preg_grep("/$hilight_re/i", $current->getContent()); - $html = ''; + $html = array(); foreach ($matches as $line) { $line = str_replace($FS, '', $line); $line = preg_replace("/$hilight_re/i", "${FS}OT\\0${FS}CT", $line); $line = htmlspecialchars($line); $line = str_replace("${FS}OT", '', $line); $line = str_replace("${FS}CT", '', $line); - $html .= Element('dd', Element('small', $line)) . "\n"; + $html[] = HTML::dd(HTML::small(new RawXml($line))); } return $html; } diff --git a/lib/plugin/HelloWorld.php b/lib/plugin/HelloWorld.php index bf06b5279..8b9a86f7f 100644 --- a/lib/plugin/HelloWorld.php +++ b/lib/plugin/HelloWorld.php @@ -1,5 +1,5 @@ @@ -107,12 +107,15 @@ extends WikiPlugin array_pop($included_pages); if ($quiet) return $content; - - return Element('p', array('class' => 'transclusion-title'), - sprintf(_("Included from %s"), - LinkExistingWikiWord($page))) - . Element('div', array('class' => 'transclusion'), - $content); + + $html[] = HTML::p(array('class' => 'transclusion-title'), + fmt("Included from %s", + $Theme->LinkExistingWikiWord($page))); + + $html[] = HTML::div(array('class' => 'transclusion'), + $content); + + return $html; } }; diff --git a/lib/plugin/LikePages.php b/lib/plugin/LikePages.php index fa202f8f2..f4ae4b00c 100644 --- a/lib/plugin/LikePages.php +++ b/lib/plugin/LikePages.php @@ -1,5 +1,5 @@ titleSearch($query); - $lines = array(); + $list = HTML::ul(); while ($page = $pages->next()) { $name = $page->getName(); if (!preg_match($match_re, $name)) continue; if (!empty($exclude) && $name == $exclude) continue; - $lines[] = Element('li', LinkWikiWord($name)); + $list->pushContent(HTML::li(_LinkWikiWord($name))); } - if ($lines) - $html .= Element('ul', join("\n", $lines)); - else - $html .= QElement('blockquote', gettext("")); - - return $html; + if (!$list->getContent()) + $list = HTML::blockquote(_("")); + + if ($noheader) + return $list; + return array(HTML::p($descrip), $list); } function _quote($str) { diff --git a/lib/plugin/MostPopular.php b/lib/plugin/MostPopular.php index 784c87e51..99a56917e 100644 --- a/lib/plugin/MostPopular.php +++ b/lib/plugin/MostPopular.php @@ -1,5 +1,5 @@ mostPopular($limit); - $lines[] = $this->_tr(QElement('u', _("Hits")), - QElement('u', _("Page Name"))); + $table = HTML::table(array('cellpadding' => 0, + 'cellspacing' => 1, + 'border' => 0), + $this->_tr(HTML::u(_("Hits")), + HTML::u(_("Page Name")))); while ($page = $pages->next()) { $hits = $page->get('hits'); if ($hits == 0) break; - $lines[] = $this->_tr($hits, - LinkWikiWord($page->getName())); + $table->pushContent($this->_tr($hits, + _LinkWikiWord($page->getName()))); } $pages->free(); + $table = HTML::blockquote($table); - $html = ''; - if (!$noheader) { - if ($limit > 0) - $msg = sprintf(_("The %s most popular pages of this wiki:"), $limit); - else - $msg = _("Visited pages on this wiki, ordered by popularity:"); - - $html .= QElement('p', $msg); - } - - - $html .= Element('blockquote', - Element('table', array('cellpadding' => 0, - 'cellspacing' => 1, - 'border' => 0), - join("\n", $lines))); - return $html; + if ($noheader) + return $table; + + if ($limit > 0) + $head = fmt("The %s most popular pages of this wiki:", $limit); + else + $head = _("Visited pages on this wiki, ordered by popularity:"); + return array(HTML::p($head), $table); } function _tr ($col1, $col2) { - return "$col1  " - . "  $col2\n"; + return HTML::tr(HTML::td(array('align' => 'right'), + $col1, new RawXml('  ')), + HTML::td(new RawXml('  '), $col2)); } }; diff --git a/lib/plugin/PageHistory.php b/lib/plugin/PageHistory.php index 4d151bd27..dad09b0a0 100644 --- a/lib/plugin/PageHistory.php +++ b/lib/plugin/PageHistory.php @@ -1,5 +1,5 @@ _args['page'])) - . "\n" . $this->rss_icon(); + global $Theme; + + return array(fmt("PageHistory for %s", + $Theme->linkExistingWikiWord($this->_args['page'])), + "\n", + $this->rss_icon()); } function _javascript($script) { - return Element('script', array('language' => 'JavaScript', - 'type' => 'text/javascript'), - ""); + return HTML::script(array('language' => 'JavaScript', + 'type' => 'text/javascript'), + new RawXml("")); } function description() { // Doesn't work (PHP bug?): $desc = parent::description() . "\n"; - $desc = _RecentChanges_HtmlFormatter::description() . "\n"; + $desc[] = _RecentChanges_HtmlFormatter::description() . "\n"; - $desc .= $this->_javascript(sprintf('document.write("%s");', - _("Check any two boxes to compare revisions."))); - $button = Element('input', array('type' => 'submit', - 'value' => _("compare revisions"))); - $desc .= Element('noscript', - sprintf(_("Check any two boxes then %s."), $button)); + $desc[] = $this->_javascript(sprintf('document.write("%s");', + _("Check any two boxes to compare revisions."))); + $button = HTML::input(array('type' => 'submit', + 'value' => _("compare revisions"))); + $desc[] = HTML::noscript(fmt("Check any two boxes then %s.", $button)); return $desc; } @@ -99,27 +101,27 @@ extends _RecentChanges_HtmlFormatter $pagename = $this->_args['page']; - $html[] = _RecentChanges_HtmlFormatter::format($changes); + $html = _RecentChanges_HtmlFormatter::format($changes); - $html[] = Element('input', array('type' => 'hidden', - 'name' => 'action', - 'value' => 'diff')); + $html[] = HTML::input(array('type' => 'hidden', + 'name' => 'action', + 'value' => 'diff')); if (USE_PATH_INFO) { $action = WikiURL($pagename); } else { $action = SCRIPT_NAME; - $html[] = Element('input', array('type' => 'hidden', - 'name' => 'pagename', - 'value' => $pagename)); + $html[] = HTML::input(array('type' => 'hidden', + 'name' => 'pagename', + 'value' => $pagename)); } - return Element('form', array('method' => 'get', - 'action' => $action, - 'name' => 'diff-select'), - join("\n", $html)) - . "\n" - . $this->_javascript(' + return array(HTML::form(array('method' => 'get', + 'action' => $action, + 'name' => 'diff-select'), + $html), + "\n", + $this->_javascript(' var diffCkBoxes = document.forms["diff-select"].elements["versions[]"]; function diffCkBox_onclick() { @@ -131,18 +133,18 @@ extends _RecentChanges_HtmlFormatter } for (i = 0; i < diffCkBoxes.length; i++) - diffCkBoxes[i].onclick = diffCkBox_onclick;'); + diffCkBoxes[i].onclick = diffCkBox_onclick;')); } function diffLink ($rev) { - return Element('input', array('type' => 'checkbox', - 'name' => 'versions[]', - 'value' => $rev->getVersion())); + return HTML::input(array('type' => 'checkbox', + 'name' => 'versions[]', + 'value' => $rev->getVersion())); } function pageLink ($rev) { - return QElement('a', array('href' => $this->pageURL($rev), 'class' => 'wiki'), - sprintf(_("Version %d"), $rev->getVersion())); + return HTML::a(array('href' => $this->pageURL($rev), 'class' => 'wiki'), + fmt("Version %d", $rev->getVersion())); } } diff --git a/lib/plugin/RecentChanges.php b/lib/plugin/RecentChanges.php index 0525118fa..fb2ab0930 100644 --- a/lib/plugin/RecentChanges.php +++ b/lib/plugin/RecentChanges.php @@ -1,5 +1,5 @@ $this->diffURL($rev), 'class' => 'wikiaction'), - _("(diff)")); + global $Theme; + return $Theme->makeButton(_("Diff"), $this->diffURL($rev), 'wikiaction'); } function pageLink ($rev) { $page = $rev->getPage(); - return QElement('a', array('href' => $this->pageURL($rev), 'class' => 'wiki'), - $page->getName()); + return HTML::a(array('href' => $this->pageURL($rev), 'class' => 'wiki'), + $page->getName()); } function authorLink ($rev) { $author = $rev->get('author'); if ( ($url = $this->authorURL($author)) ) - return QElement('a', array('href' => $url, 'class' => 'wiki'), $author); + return HTML::a(array('href' => $url, 'class' => 'wiki'), $author); else - return htmlspecialchars($author); + return $author; } function summaryAsHTML ($rev) { if ( !($summary = $this->summary($rev)) ) return ''; - $summary = do_transform($summary, 'LinkTransform'); - return Element('strong', array('class' => 'wiki-summary'), "[$summary]"); + return HTML::strong( array('class' => 'wiki-summary'), + "[", + do_transform($summary, 'LinkTransform'), + "]"); } function rss_icon () { global $request, $Theme; $rss_url = $request->getURLtoSelf(array('format' => 'rss')); - $button = $Theme->makeButton("RSS", $rss_url, 'rssicion'); - return $button->asHTML(); + return $Theme->makeButton("RSS", $rss_url, 'rssicion'); } function description () { @@ -143,71 +144,67 @@ extends _RecentChanges_Formatter if ($limit > 0) { if ($days > 0) - $desc = sprintf(_("The %d most recent %s during the past %.1f days are listed below."), - $limit, $edits, $days); + $desc = fmt("The %d most recent %s during the past %.1f days are listed below.", + $limit, $edits, $days); else - $desc = sprintf(_("The %d most recent %s are listed below."), - $limit, $edits); + $desc = fmt("The %d most recent %s are listed below.", + $limit, $edits); } else { if ($days > 0) - $desc = sprintf(_("The most recent %s during the past %.1f days are listed below."), - $edits, $days); + $desc = fmt("The most recent %s during the past %.1f days are listed below.", + $edits, $days); else - $desc = sprintf(_("All %s are listed below."), $edits); + $desc = fmt("All %s are listed below.", $edits); } - return htmlspecialchars($desc); + return $desc; } function title () { extract($this->_args); - return htmlspecialchars( $show_minor ? _("RecentEdits") : _("RecentChanges") ) . "\n" . $this->rss_icon(); + return array($show_minor ? _("RecentEdits") : _("RecentChanges"), + ' ', + $this->rss_icon()); } function format ($changes) { - $html[] = Element('h2', $this->title()); + $html[] = HTML::h2(false, $this->title()); if (($desc = $this->description())) - $html[] = Element('p', $desc); + $html[] = HTML::p(false, $desc); $last_date = ''; - $lines = array(); + $lines = false; while ($rev = $changes->next()) { if (($date = $this->date($rev)) != $last_date) { - if ($lines) { - $html[] = Element('ul', join("\n", $lines)); - $lines = array(); - } - $html[] = QElement('h3', $date); + if ($lines) + $html[] = $lines; + $html[] = HTML::h3($date); + $lines = HTML::ul(); $last_date = $date; } - - $lines[] = $this->format_revision($rev); + $lines->pushContent($this->format_revision($rev)); } if ($lines) - $html[] = Element('ul', join("\n", $lines)); - return join("\n", $html) . "\n"; + $html[] = $lines; + return $html; } function format_revision ($rev) { - if (!defined('RC_SEPARATOR_A')) define('RC_SEPARATOR_A', ''); - if (!defined('RC_SEPARATOR_B')) define('RC_SEPARATOR_B', '...'); - $class = 'rc-' . $this->importance($rev); - return Element('li', array('class' => $class), - implode(' ', array( $this->diffLink($rev), - $this->pageLink($rev), - $this->time($rev), - $this->summaryAsHTML($rev), - '...', - $this->authorLink($rev) ))); + return HTML::li(array('class' => $class), + $this->diffLink($rev), ' ', + $this->pageLink($rev), ' ', + $this->time($rev), ' ', + $this->summaryAsHTML($rev), + ' ... ', + $this->authorLink($rev)); } } - class _RecentChanges_RssFormatter extends _RecentChanges_Formatter { diff --git a/lib/plugin/TitleSearch.php b/lib/plugin/TitleSearch.php index b83216f8e..6162e6267 100644 --- a/lib/plugin/TitleSearch.php +++ b/lib/plugin/TitleSearch.php @@ -1,5 +1,5 @@ getArgs($argstr, $request); if (empty($args['s'])) return ''; @@ -32,26 +33,23 @@ extends WikiPlugin $query = new TextSearchQuery($s); $pages = $dbi->titleSearch($query); - $lines = array(); + $list = HTML::ul(); while ($page = $pages->next()) { $name = $page->getName(); - $lines[] = Element('li', LinkExistingWikiWord($name)); + $list->pushContent(HTML::li($Theme->linkExistingWikiWord($name))); $last_name = $name; } - if ($auto_redirect && count($lines) == 1) + if ($auto_redirect && count($list->getContent()) == 1) $request->redirect(WikiURL($last_name)); - - $html = ''; - if (!$noheader) - $html .= QElement('p', - sprintf(_("Title search results for '%s'"), $s)); - if ($lines) - $html .= Element('ul', join("\n", $lines)); - else - $html .= Element('dl', QElement('dd', _(""))); + if (!$list->getContent()) + $list = HTML::blockquote(_("")); + if ($noheader) + return $list; - return $html; + + return array(HTML::p(fmt("Title search results for '%s'", $s)), + $list); } }; diff --git a/lib/plugin/_BackendInfo.php b/lib/plugin/_BackendInfo.php index ac58c5363..038e3a79a 100644 --- a/lib/plugin/_BackendInfo.php +++ b/lib/plugin/_BackendInfo.php @@ -1,5 +1,5 @@ 2, 'cellspacing' => 0), $rows) . "\n"; - return $html; + return new RawXml($html); // FIXME: avoid RawXml. } }; diff --git a/lib/savepage.php b/lib/savepage.php index 0b6687319..151db3a40 100644 --- a/lib/savepage.php +++ b/lib/savepage.php @@ -1,4 +1,4 @@ -qreplace('TITLE', sprintf(_("Saved: %s"), $pagename)); - $wrapper->replace('HEADER', sprintf(_("Saved: %s"), LinkExistingWikiWord($pagename))); + $wrapper->replace('HEADER', fmt("Saved: %s", + $Theme->linkExistingWikiWord($pagename))); $wrapper->setPageRevisionTokens($newrevision); $template = new WikiTemplate('savepage'); diff --git a/lib/stdlib.php b/lib/stdlib.php index ff493b769..92b97c9c8 100644 --- a/lib/stdlib.php +++ b/lib/stdlib.php @@ -1,4 +1,4 @@ -asXML(); +} + +// This function will be renamed LinkWikiWord once changeover +// to object based HTML generation is complete. +function _LinkWikiWord($wikiword, $linktext = '', $version = false) { + global $dbi, $Theme; if ($dbi->isWikiPage($wikiword)) - return LinkExistingWikiWord($wikiword, $linktext); + $link = $Theme->linkExistingWikiWord($wikiword, $linktext, $version); else - global $Theme; - return $Theme->LinkUnknownWikiWord($wikiword, $linktext); + $link = $Theme->linkUnknownWikiWord($wikiword, $linktext); + return $link; } //This function will be deleted once all references to it are updated. function LinkExistingWikiWord($wikiword, $linktext = '', $version = false) { global $Theme; - return $Theme->LinkExistingWikiWord($wikiword, $linktext, $version); + $link = $Theme->linkExistingWikiWord($wikiword, $linktext, $version); + return $link->asXML(); } @@ -379,7 +387,8 @@ function ParseAndLink($bracketlink) { } else { $link['type'] = "wiki-unknown-$linktype"; global $Theme; - $link['link'] = $Theme->LinkUnknownWikiWord($URL, $linkname); + $uww = $Theme->linkUnknownWikiWord($URL, $linkname); + $link['link'] = $uww->asXML(); } return $link; @@ -698,8 +707,9 @@ function isa ($object, $class) { $lclass = strtolower($class); - return get_class($object) == strtolower($lclass) - || is_subclass_of($object, $lclass); + return is_object($object) + && ( get_class($object) == strtolower($lclass) + || is_subclass_of($object, $lclass) ); } /** Determine whether (possible) object has method. diff --git a/lib/transform.php b/lib/transform.php index 72037b042..67ede6108 100644 --- a/lib/transform.php +++ b/lib/transform.php @@ -1,4 +1,4 @@ -do_transform('', $lines); + return new RawXml($trfm->do_transform('', $lines)); } class LinkTransform diff --git a/locale/Makefile b/locale/Makefile index a868b0383..ac6a3f776 100644 --- a/locale/Makefile +++ b/locale/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.14 2002-01-20 23:04:12 carstenklapp Exp $ +# $Id: Makefile,v 1.15 2002-01-21 06:55:47 dairiki Exp $ # # locale/Makefile # @@ -15,7 +15,7 @@ po : # dependencies are auto-generated by 'make dep' , see below mo : # dependencies are auto-generated by 'make dep' , see below ${POT_FILE} : # dependencies are auto-generated by 'make dep' , see below - xgettext -L C++ -k_ -k__printf -k__sprintf -k__vsprintf -o $@ $^ + xgettext -L C++ -k_ -k__printf -k__sprintf -k__vsprintf -kfmt -o $@ $^ po/%.po : ${POT_FILE} test -f $@ || touch $@ diff --git a/themes/MacOSX/lib/RecentChanges.php b/themes/MacOSX/lib/RecentChanges.php index 6df82c30f..d67b77615 100644 --- a/themes/MacOSX/lib/RecentChanges.php +++ b/themes/MacOSX/lib/RecentChanges.php @@ -1,4 +1,4 @@ -importance($rev); - return Element('li', array('class' => $class), - implode(' ', array( $fmt->diffLink($rev), - $fmt->pageLink($rev), - $fmt->time($rev), - ' . . . ', - $fmt->summaryAsHTML($rev), - ' --', - $fmt->authorLink($rev) ))); + return HTML::li(array('class' => $class), + $fmt->diffLink($rev), ' ', + $fmt->pageLink($rev), ' ', + $fmt->time($rev), + ' . . . ', + $fmt->summaryAsHTML($rev), + ' -- ', + $fmt->authorLink($rev)); } class _MacOSX_RecentChanges_Formatter diff --git a/themes/MacOSX/themeinfo.php b/themes/MacOSX/themeinfo.php index 2c305435f..77b44fc0e 100644 --- a/themes/MacOSX/themeinfo.php +++ b/themes/MacOSX/themeinfo.php @@ -1,6 +1,6 @@ 'text/css'), - sprintf("\n", - $this->getImageURL('bgpaper8'))); + $css[] = HTML::style(array('type' => 'text/css'), + new RawXml(sprintf("\n", + $this->getImageURL('bgpaper8')))); //for non-browse pages, like former editpage, message etc. //$this->getImageURL('bggranular'))); return $css; @@ -76,19 +76,20 @@ class Theme_MacOSX extends Theme { return '_MacOSX_PageHistory_Formatter'; } - function LinkUnknownWikiWord($wikiword, $linktext = '') { - if (empty($linktext)) { - $linktext = $wikiword; - if ($this->getAutoSplitWikiWords()) - $linktext=split_pagename($linktext); - $class = 'wikiunknown'; - } else - $class = 'named-wikiunknown'; - - $qmark = $this->makeButton('?', WikiURL($wikiword, array('action' => 'edit'))); + function linkUnknownWikiWord($wikiword, $linktext = '') { + $url = WikiURL($wikiword, array('action' => 'edit')); + $link = HTML::span(HTML::a(array('href' => $url), '?')); + + if (!empty($linktext)) { + $link->unshiftContent(HTML::u($linktext)); + $link->setAttr('class', 'named-wikiunknown'); + } + else { + $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($wikiword))); + $link->setAttr('class', 'wikiunknown'); + } - return Element('span', array('class' => $class), - Element('u', $linktext) . $qmark->asHTML()); + return $link; } } diff --git a/themes/Portland/templates/actionbar.tmpl b/themes/Portland/templates/actionbar.tmpl index 317cede4a..4eb3c3381 100644 --- a/themes/Portland/templates/actionbar.tmpl +++ b/themes/Portland/templates/actionbar.tmpl @@ -1,5 +1,5 @@ - + makeActionButton("edit", _("View Source")); - $EditB = sprintf(_("%s of this page"),$EditB->asHTML()); + $EditB = fmt("%s of this page", $EditB); $mtime = $Theme->formatDateTime($revision->get('mtime')); // $PageHistoryB = $BF->makeLabelActionPageButton($mtime, _("PageHistory")); if ($IS_CURRENT) - $LastModifiedMsg = sprintf(_("(last edited %s)"), $PageHistoryB->asHTML()); + $LastModifiedMsg = fmt("(last edited %s)", $PageHistoryB); else - $LastModifiedMsg = __sprintf(_("(version %s, saved on %s)"), - $VERSION, $PageHistoryB->asHTML()); + $LastModifiedMsg = fmt("(version %s, saved on %s)", + $VERSION, $PageHistoryB); ?>
diff --git a/themes/Portland/templates/editpage.tmpl b/themes/Portland/templates/editpage.tmpl index aa060c542..32f37bbc2 100644 --- a/themes/Portland/templates/editpage.tmpl +++ b/themes/Portland/templates/editpage.tmpl @@ -1,28 +1,24 @@ - + 'text', - 'class' => 'wikitext', - 'name' => 'summary', - 'size' => 50, - 'value' => $FORMVARS['summary'])); +$SummaryInput = HTML::input(array('type' => 'text', + 'class' => 'wikitext', + 'name' => 'summary', + 'size' => 50, + 'value' => $FORMVARS['summary'])); - $MinorEditCb = Element('input', - array('type' => 'checkbox', - 'name' => 'minor_edit', - 'checked' => (bool) $FORMVARS['minor_edit'])); +$MinorEditCb = HTML::input(array('type' => 'checkbox', + 'name' => 'minor_edit', + 'checked' => (bool) $FORMVARS['minor_edit'])); - $PreviewB = Element('input', - array('type' => 'submit', - 'class' => 'button', - 'name' => 'preview', - 'value' => _("Preview"))); - $SaveB = Element('input', - array('type' => 'submit', - 'class' => 'button', - 'name' => 'save', - 'value' => _("Save"))); +$PreviewB = HTML::input(array('type' => 'submit', + 'class' => 'button', + 'name' => 'preview', + 'value' => _("Preview"))); +$SaveB = HTML::input(array('type' => 'submit', + 'class' => 'button', + 'name' => 'save', + 'value' => _("Save"))); $SignIn = new WikiTemplate('signin'); @@ -71,20 +67,20 @@

- + getId())) ?>
- + linkExistingWikiWord(_("RecentEdits"))) ?>

\n" ._("You can change the size of the editing area in %s."), - LinkExistingWikiWord(_("UserPreferences"))); -?>
+ // FIXME: convert this to use the IncludePage plugin. ?> +linkExistingWikiWord(_("GoodStyle"))) ?> +
+linkExistingWikiWord(_("UserPreferences"))) ?> +
diff --git a/themes/Portland/templates/viewsource.tmpl b/themes/Portland/templates/viewsource.tmpl index 7b896a0e0..e48c29cec 100644 --- a/themes/Portland/templates/viewsource.tmpl +++ b/themes/Portland/templates/viewsource.tmpl @@ -1,5 +1,5 @@ - +

@@ -21,10 +21,9 @@ $PageHistoryB = $ButtonFactory->makeLabelActionPageButton($mtime, _("PageHistory")); if ($IS_CURRENT) - $LastModifiedMsg = sprintf(_("(last edited %s)"), $PageHistoryB->asHTML()); + $LastModifiedMsg = fmt("(last edited %s)", $PageHistoryB); else - $LastModifiedMsg = __sprintf(_("(version %s, saved on %s)"), - $VERSION, $PageHistoryB->asHTML()); + $LastModifiedMsg = fmt("(version %s, saved on %s)", $VERSION, $PageHistoryB); ?> diff --git a/themes/Portland/themeinfo.php b/themes/Portland/themeinfo.php index c2f2cbb06..40b8a9377 100644 --- a/themes/Portland/themeinfo.php +++ b/themes/Portland/themeinfo.php @@ -1,5 +1,5 @@ getAutoSplitWikiWords()) - $linktext=split_pagename($linktext); - $class = 'wikiunknown'; - } else - $class = 'named-wikiunknown'; + $url = WikiURL($wikiword, array('action' => 'edit')); + $link = HTML::span(HTML::a(array('href' => $url), '?')); - return Element('span', array('class' => $class), - Element('u', $linktext) - . Element('a', array('href' => WikiURL($wikiword, array('action' => 'edit'))), - '?')); + if (!empty($linktext)) { + $link->unshiftContent(HTML::u($linktext)); + $link->setAttr('class', 'named-wikiunknown'); + } + else { + $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($wikiword))); + $link->setAttr('class', 'wikiunknown'); + } + + return $link; } } diff --git a/themes/default/templates/browse.tmpl b/themes/default/templates/browse.tmpl index 7b3e6f623..5de013871 100644 --- a/themes/default/templates/browse.tmpl +++ b/themes/default/templates/browse.tmpl @@ -1,6 +1,6 @@ - - +formatDateTime($revision->get('mtime')); if ($IS_CURRENT) $LastModifiedMsg = sprintf(_("Last edited on %s."), $mtime); diff --git a/themes/default/templates/editpage.tmpl b/themes/default/templates/editpage.tmpl index 0b1d8b537..ed5416109 100644 --- a/themes/default/templates/editpage.tmpl +++ b/themes/default/templates/editpage.tmpl @@ -1,5 +1,5 @@ - +

@@ -31,28 +31,24 @@ cols="" wrap="virtual"> 'text', - 'class' => 'wikitext', - 'name' => 'summary', - 'size' => 50, - 'value' => $FORMVARS['summary'])); +$SummaryInput = HTML::input(array('type' => 'text', + 'class' => 'wikitext', + 'name' => 'summary', + 'size' => 50, + 'value' => $FORMVARS['summary'])); - $MinorEditCb = Element('input', - array('type' => 'checkbox', - 'name' => 'minor_edit', - 'checked' => (bool) $FORMVARS['minor_edit'])); +$MinorEditCb = HTML::input(array('type' => 'checkbox', + 'name' => 'minor_edit', + 'checked' => (bool) $FORMVARS['minor_edit'])); - $PreviewB = Element('input', - array('type' => 'submit', - 'class' => 'button', - 'name' => 'preview', +$PreviewB = HTML::input(array('type' => 'submit', + 'class' => 'button', + 'name' => 'preview', 'value' => _("Preview"))); - $SaveB = Element('input', - array('type' => 'submit', - 'class' => 'button', - 'name' => 'save', - 'value' => _("Save"))); +$SaveB = HTML::input(array('type' => 'submit', + 'class' => 'button', + 'name' => 'save', + 'value' => _("Save"))); $SignIn = new WikiTemplate('signin'); @@ -76,9 +72,9 @@ - isSignedIn()) - printf(_("Author will be logged as %s."), - QElement('em', $USERID)); ?> + isSignedIn() + ? '' + : fmt("Author will be logged as %s.", HTML::em($USERID)) ?> @@ -89,12 +85,13 @@ * A table is used for proper image to text alignment when * a theme uses image buttons. */ ?> +  ".$UserPrefsB->asHTML().""); ?>  + " ".$UserPrefsB->asXML().""); ?>   ".$GoodStyleB->asHTML()." "); ?> + " ".$GoodStyleB->asXML()." "); ?>
diff --git a/themes/default/templates/signin.tmpl b/themes/default/templates/signin.tmpl index 4afaa6336..ee1587e7d 100644 --- a/themes/default/templates/signin.tmpl +++ b/themes/default/templates/signin.tmpl @@ -1,5 +1,5 @@ - + getButtonSeparator(); @@ -21,7 +21,7 @@ isSignedIn()) { ?> - + getId())) ?>