Exemple #1
0
 function _DebugPrintArray(&$array)
 {
     $html = HTML();
     foreach ($array as $line) {
         ob_start();
         print_r($line);
         $s = HTML::pre(ob_get_contents());
         ob_end_clean();
         $html->pushContent($s);
     }
     return $html;
 }
Exemple #2
0
 function _match($text, $regexps, $repeat)
 {
     // If one of the regexps is an empty string, php will crash here:
     // sf.net: Fatal error: Allowed memory size of 8388608 bytes exhausted
     //         (tried to allocate 634 bytes)
     if (_INLINE_OPTIMIZATION) {
         // disabled, wrong
         // So we try to minize memory usage, by looping explicitly,
         // and storing only those regexp which actually match.
         // There may be more than one, so we have to find the longest,
         // and match inside until the shortest is empty.
         $matched = array();
         $matched_ind = array();
         for ($i = 0; $i < count($regexps); $i++) {
             if (!trim($regexps[$i])) {
                 trigger_error("empty regexp {$i}", E_USER_WARNING);
                 continue;
             }
             $pat = "/ ( . {$repeat} ) ( " . $regexps[$i] . " ) /x";
             if (preg_match($pat, $text, $_m)) {
                 $m = $_m;
                 // FIXME: prematch, postmatch is wrong
                 $matched[] = $regexps[$i];
                 $matched_ind[] = $i;
                 $regexp_ind = $i;
             }
         }
         // To overcome ANCHORED:
         // We could sort by longest match and iterate over these.
         if (empty($matched)) {
             return false;
         }
     }
     $match = new RegexpSet_match();
     // Optimization: if the matches are only "$" and another, then omit "$"
     if (!_INLINE_OPTIMIZATION or count($matched) > 2) {
         assert(!empty($repeat));
         assert(!empty($regexps));
         // We could do much better, if we would know the matching markup for the
         // longest regexp match:
         $hugepat = "/ ( . {$repeat} ) ( (" . join(')|(', $regexps) . ") ) /Asx";
         // Proposed premature optimization 1:
         //$hugepat= "/ ( . $repeat ) ( (" . join(')|(', array_values($matched)) . ") ) /Asx";
         if (!preg_match($hugepat, $text, $m)) {
             return false;
         }
         // Proposed premature optimization 1:
         //$match->regexp_ind = $matched_ind[count($m) - 4];
         $match->regexp_ind = count($m) - 4;
     } else {
         $match->regexp_ind = $regexp_ind;
     }
     $match->postmatch = substr($text, strlen($m[0]));
     $match->prematch = $m[1];
     $match->match = $m[2];
     /* DEBUGGING */
     if (DEBUG & _DEBUG_PARSER) {
         static $_already_dumped = 0;
         if (!$_already_dumped) {
             var_dump($regexps);
             if (_INLINE_OPTIMIZATION) {
                 var_dump($matched);
             }
             var_dump($matched_ind);
         }
         $_already_dumped = 1;
         PrintXML(HTML::dl(HTML::dt("input"), HTML::dd(HTML::pre($text)), HTML::dt("regexp"), HTML::dd(HTML::pre($match->regexp_ind, ":", $regexps[$match->regexp_ind])), HTML::dt("prematch"), HTML::dd(HTML::pre($match->prematch)), HTML::dt("match"), HTML::dd(HTML::pre($match->match)), HTML::dt("postmatch"), HTML::dd(HTML::pre($match->postmatch))));
     }
     return $match;
 }
Exemple #3
0
 function _dump_template()
 {
     $lines = explode("\n", $this->_munge_input($this->_tmpl));
     $pre = HTML::pre();
     $n = 1;
     foreach ($lines as $line) {
         $pre->pushContent(fmt("%4d  %s\n", $n++, $line));
     }
     $pre->printXML();
 }
Exemple #4
0
 /**
  * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
  * also used in plugin/EditMetaData
  */
 function _fixupData(&$data, $prefix = '')
 {
     if (!is_array($data)) {
         return;
     }
     global $request;
     $user = $request->getUser();
     foreach ($data as $key => $val) {
         $fullkey = $prefix . '[' . $key . ']';
         if (is_integer($key)) {
         } elseif ($key == 'passwd' and !$user->isAdmin()) {
             $data[$key] = $val ? _("<not displayed>") : _("<empty>");
         } elseif ($key and $key == '_cached_html') {
             $val = TransformedText::unpack($val);
             ob_start();
             print_r($val);
             $data[$key] = HTML::pre(ob_get_contents());
             ob_end_clean();
         } elseif (is_bool($val)) {
             $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
         } elseif (is_string($val) && (substr($val, 0, 2) == 'a:' or substr($val, 0, 2) == 'O:')) {
             // how to indent this table?
             $val = unserialize($val);
             $this->_fixupData($val, $fullkey);
             $data[$key] = HTML::table(array('border' => 1, 'cellpadding' => 2, 'cellspacing' => 0), $this->_showhash(false, $val, $fullkey));
         } elseif (is_array($val)) {
             // how to indent this table?
             $this->_fixupData($val, $fullkey);
             $data[$key] = HTML::table(array('border' => 1, 'cellpadding' => 2, 'cellspacing' => 0), $this->_showhash(false, $val, $fullkey));
         } elseif (is_object($val)) {
             // how to indent this table?
             ob_start();
             print_r($val);
             $val = HTML::pre(ob_get_contents());
             ob_end_clean();
             $data[$key] = HTML::table(array('border' => 1, 'cellpadding' => 2, 'cellspacing' => 0), $this->_showhash(false, $val, $fullkey));
         } elseif ($key and $key == '%content') {
             if ($val === true) {
                 $val = '<true>';
             } elseif (strlen($val) > 40) {
                 $val = substr($val, 0, 40) . " ...";
             }
             $data[$key] = $val;
         }
     }
     unset($data['%pagedata']);
     // problem in backend
 }
Exemple #5
0
 function run($dbi, $argstr, $request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if ($pagename) {
         // Expand relative page names.
         $page = new WikiPageName($pagename, $basepage);
         $pagename = $page->name;
     }
     if (!$pagename) {
         return $this->error(_("no page specified"));
     }
     // Get the links page contents
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     $content = $current->getContent();
     // Prepare the button to trigger dumping
     $dump_url = $request->getURLtoSelf(array("file" => "tube.bib"));
     global $WikiTheme;
     $dump_button = $WikiTheme->makeButton("To File", $dump_url, 'foo');
     $html = HTML::div(array('class' => 'bib', 'align' => 'left'));
     $html->pushContent($dump_button, ' ');
     $list = HTML::pre(array('name' => 'biblist', 'id' => 'biblist', 'class' => 'bib'));
     // Let's find the subpages
     if ($articles = $this->extractArticles($content)) {
         foreach ($articles as $h) {
             // Now let's get the bibtex information from that subpage
             $subpage = $dbi->getPage($h);
             $subversion = $subpage->getCurrentRevision();
             $subcontent = $subversion->getContent();
             $bib = $this->extractBibTeX($subcontent, "@", "}");
             // ...and finally just push the bibtex data to page
             $foo = implode("\n", $bib);
             $bar = $foo . "\n\n";
             $list->pushContent(HTML::raw($bar));
         }
     }
     $html->pushContent($list);
     if ($request->getArg('file')) {
         // Yes, we want to dump this somewhere
         // Get the contents of this page
         $p = $dbi->getPage($pagename);
         $c = $p->getCurrentRevision();
         $pagedata = $c->getContent();
         $this->dumpFile($pagedata, $request->getArg('file'));
     }
     return $html;
 }
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $source =& $this->source;
     if (empty($syntax)) {
         return $this->error(_("Syntax language not specified."));
     }
     if (!empty($source)) {
         $args = "";
         if (defined('HIGHLIGHT_DATA_DIR')) {
             $args .= " --data-dir " . HIGHLIGHT_DATA_DIR;
         }
         if ($number != 0) {
             $args .= " -l";
         }
         if ($wrap != 0) {
             $args .= " -V";
         }
         $html = HTML();
         if (!empty($color) and !preg_match('/^[\\w-]+$/', $color)) {
             $html->pushContent($this->error(fmt("invalid %s ignored", 'color')));
             $color = false;
         }
         if (!empty($color)) {
             $args .= " --style {$color} -c " . FindFile("uploads") . "/highlight-{$color}.css";
         }
         if (!empty($style)) {
             $args .= " -F {$style}";
         }
         $commandLine = HIGHLIGHT_EXE . "{$args} -q -X -f -S {$syntax}";
         if (check_php_version(4, 3, 0)) {
             $code = $this->newFilterThroughCmd($source, $commandLine);
         } else {
             $code = $this->oldFilterThroughCmd($source, $commandLine);
         }
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $pre = HTML::pre(HTML::raw($code));
         $pre->setAttr('class', 'tightenable top bottom');
         $html->pushContent($pre);
         $css = $GLOBALS['WikiTheme']->_CSSlink('', empty($color) ? 'highlight.css' : "uploads/highlight-{$color}.css", '');
         return HTML($css, $html);
     } else {
         return $this->error(fmt("empty source"));
     }
 }
Exemple #7
0
 function disabled($message = '')
 {
     $html[] = HTML::div(array('class' => 'title'), fmt("Plugin %s disabled.", $this->getName()), ' ', $message);
     $html[] = HTML::pre($this->_pi);
     return HTML::div(array('class' => 'disabled-plugin'), $html);
 }
Exemple #8
0
 function _approval_form(&$request, $args, $moderation, $pass = '******')
 {
     $header = HTML::h3(_("Please approve or reject this request:"));
     $loader = new WikiPluginLoader();
     $BackendInfo = $loader->getPlugin("_BackendInfo");
     $table = HTML::table(array('border' => 1, 'cellpadding' => 2, 'cellspacing' => 0));
     $content = $table;
     $diff = '';
     if ($moderation['args']['action'] == 'edit') {
         $pagename = $moderation['args']['pagename'];
         $p = $request->_dbi->getPage($pagename);
         $rev = $p->getCurrentRevision(true);
         $curr_content = $rev->getPackedContent();
         $new_content = $moderation['args']['edit']['content'];
         include_once "lib/difflib.php";
         $diff2 = new Diff($curr_content, $new_content);
         $fmt = new UnifiedDiffFormatter();
         $diff = $pagename . " Current Version " . Iso8601DateTime($p->get('mtime')) . "\n";
         $diff .= $pagename . " Edited Version " . Iso8601DateTime($moderation['timestamp']) . "\n";
         $diff .= $fmt->format($diff2);
     }
     $content->pushContent($BackendInfo->_showhash("Request", array('User' => $moderation['userid'], 'When' => CTime($moderation['timestamp']), 'Pagename' => $pagename, 'Action' => $moderation['args']['action'], 'Diff' => HTML::pre($diff))));
     $content_dbg = $table;
     $myargs = $args;
     $BackendInfo->_fixupData($myargs);
     $content_dbg->pushContent($BackendInfo->_showhash("raw request args", $myargs));
     $BackendInfo->_fixupData($moderation);
     $content_dbg->pushContent($BackendInfo->_showhash("raw moderation data", $moderation));
     $reason = HTML::div(_("Reason: "), HTML::textarea(array('name' => 'reason')));
     $approve = Button('submit:ModeratedPage[approve]', _("Approve"), $pass == 'approve' ? 'wikiadmin' : 'button');
     $reject = Button('submit:ModeratedPage[reject]', _("Reject"), $pass == 'reject' ? 'wikiadmin' : 'button');
     $args['action'] = _("ModeratedPage");
     return HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), $header, $content, HTML::p(""), $content_dbg, $reason, ENABLE_PAGEPERM ? '' : HiddenInputs(array('require_authority_for_post' => WIKIAUTH_ADMIN)), HiddenInputs($args), $pass == 'approve' ? HTML::p($approve, $reject) : HTML::p($reject, $approve));
 }
Exemple #9
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $source =& $this->source;
     if (empty($syntax)) {
         return $this->error(_("Syntax language not specified."));
     }
     if (!empty($source)) {
         $args = "";
         if (defined('HIGHLIGHT_DATA_DIR')) {
             $args .= " --data-dir " . HIGHLIGHT_DATA_DIR;
         }
         if ($number != 0) {
             $args .= " -l";
         }
         if ($wrap != 0) {
             $args .= " -V";
         }
         $html = HTML();
         if (!empty($color) and !preg_match('/^[\\w-]+$/', $color)) {
             $html->pushContent($this->error(fmt("invalid %s ignored", 'color')));
             $color = false;
         }
         if (!empty($color)) {
             $args .= " --style {$color} --inline-css";
         }
         if (!empty($style)) {
             $args .= " -F {$style}";
         }
         $commandLine = HIGHLIGHT_EXE . "{$args} -q -X -f -S {$syntax}";
         $code = $this->newFilterThroughCmd($source, $commandLine);
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $pre = HTML::pre(HTML::raw($code));
         $html->pushContent($pre);
         return HTML($html);
     } else {
         return $this->error(fmt("empty source"));
     }
 }
Exemple #10
0
 function pre($what = null, $attributes = null)
 {
     return HTML::pre($what, $attributes);
 }
Exemple #11
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     // allow plugin-form
     if (!empty($s)) {
         $page = $s;
     }
     if (!$page) {
         return '';
     }
     if (!$dbi->isWikiPage($page)) {
         return fmt("Page %s not found.", WikiLink($page, 'unknown'));
     }
     $p = $dbi->getPage($page);
     include_once "lib/loadsave.php";
     $mailified = MailifyPage($p, $format == 'backup' ? 99 : 1);
     // fixup_headers massages the page dump headers depending on
     // the 'format' argument, 'normal'(default) or 'forcvs'.
     //
     // Normal: Don't add X-Rcs-Id, add unique Message-Id, don't
     // strip any fields from Content-Type.
     //
     // ForCVS: Add empty X-Rcs-Id, strip attributes from
     // Content-Type field: "author", "version", "lastmodified",
     // "author_id", "hits".
     $this->pagename = $page;
     $this->generateMessageId($mailified);
     if ($format == 'forcvs') {
         $this->fixup_headers_forcvs($mailified);
     } else {
         // backup or normal
         $this->fixup_headers($mailified);
     }
     if ($download) {
         // TODO: we need a way to hook into the generated headers, to override
         // Content-Type, Set-Cookie, Cache-control, ...
         $request->discardOutput();
         // Hijack the http request from PhpWiki.
         ob_end_clean();
         // clean up after hijacking $request
         //ob_end_flush(); //debugging
         Header("Content-disposition: attachment; filename=\"" . FilenameForPage($page) . "\"");
         // Read charset from generated page itself.
         // Inconsequential at the moment, since loadsave.php
         // always generates headers
         $charset = $p->get('charset');
         if (!$charset) {
             $charset = $GLOBALS['charset'];
         }
         // We generate 3 Content-Type headers! first in loadsave,
         // then here and the mimified string $mailified also has it!
         Header("Content-Type: text/plain; name=\"" . FilenameForPage($page) . "\"; charset=\"" . $charset . "\"");
         $request->checkValidators();
         // let $request provide last modifed & etag
         Header("Content-Id: <" . $this->MessageId . ">");
         // be nice to http keepalive~s
         // FIXME: he length is wrong BTW. must strip the header.
         Header("Content-Length: " . strlen($mailified));
         // Here comes our prepared mime file
         echo $mailified;
         exit;
         // noreturn! php exits.
         return;
     }
     // We are displaing inline preview in a WikiPage, so wrap the
     // text if it is too long--unless quoted-printable (TODO).
     $mailified = safe_wordwrap($mailified, 70);
     $dlcvs = Button(array('action' => $this->getName(), 'format' => 'forcvs', 'download' => true), _("Download for CVS"), $page);
     $dl = Button(array('action' => $this->getName(), 'download' => true), _("Download for backup"), $page);
     $dlall = Button(array('action' => $this->getName(), 'format' => 'backup', 'download' => true), _("Download all revisions for backup"), $page);
     $h2 = HTML::h2(fmt("Preview: Page dump of %s", WikiLink($page, 'auto')));
     global $WikiTheme;
     if (!($Sep = $WikiTheme->getButtonSeparator())) {
         $Sep = " ";
     }
     if ($format == 'forcvs') {
         $desc = _("(formatted for PhpWiki developers as pgsrc template, not for backing up)");
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName()), _("Preview as normal format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page));
     } elseif ($format == 'backup') {
         $desc = _("(formatted for backing up: all revisions)");
         // all revisions
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => ''), _("Preview as normal format"), $page));
     } else {
         $desc = _("(normal formatting: latest revision only)");
         $altpreviewbuttons = HTML(Button(array('action' => $this->getName(), 'format' => 'forcvs'), _("Preview as developer format"), $page), $Sep, Button(array('action' => $this->getName(), 'format' => 'backup'), _("Preview as backup format"), $page));
     }
     $warning = HTML(_("Please use one of the downloadable versions rather than copying and pasting from the above preview.") . " " . _("The wordwrap of the preview doesn't take nested markup or list indentation into consideration!") . " ", HTML::em(_("PhpWiki developers should manually inspect the downloaded file for nested markup before rewrapping with emacs and checking into CVS.")));
     return HTML($h2, HTML::em($desc), HTML::pre($mailified), $altpreviewbuttons, HTML::div(array('class' => 'errors'), HTML::strong(_("Warning:")), " ", $warning), $dl, $Sep, $dlall, $Sep, $dlcvs);
 }