function _testLink($wiki, $expected = null) { if (is_null($expected)) { $ta = $this->_tests(); $expected = $ta[$wiki]; } $xml = TransformInline($wiki); $this->assertTrue(isa($xml, 'XmlContent')); $expectobj = unserialize($expected); /* if (DEBUG & _DEBUG_VERBOSE) echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); */ $this->assertEquals($expectobj, $xml); }
function testLinks() { $uplink = 'http://' . (defined('SERVER_NAME') ? SERVER_NAME : '') . DATA_PATH . '/uploads/image.jpg'; $tests = array("[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ image.jpg | link ]" => check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}}i:2;s:0:"";}}' : 'o:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;o:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";o:11:"htmlelement":4:{s:8:"_content";a:1:{i:0;o:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:11:"_properties";i:4;}}s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:11:"_properties";i:6;}}i:2;s:0:"";}}', "[ Upload:image.jpg | link ]" => !check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:' . strlen($uplink) . ':"' . $uplink . '";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}' : 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:' . strlen($uplink) . ':"' . $uplink . '";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}}i:2;s:0:"";}}', "[ http://server/image.jpg | link ]" => !check_php_version(5) ? 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}' : 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}}i:2;s:0:"";}}', "[ label | http://server/link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | Upload:link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | phpwiki:action=link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"Cached_PhpwikiURL":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "Upload:image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', "http://server/image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', "http://server/link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', "[http:/server/~name/]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', "http:/server/~name/" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}'); //$i = 0; foreach ($tests as $wiki => $expected) { //print $i++ . " .. "; $xml = TransformInline($wiki); $this->assertTrue(isa($xml, 'XmlContent')); $actual = serialize($xml); if (!check_php_version(5)) { $expected = strtolower($expected); $actual = strtolower($actual); } $this->assertEquals($expected, $actual); } }
function finish() { $content = TransformInline(trim($this->_text)); $p = new Block_HtmlElement('p', false, $content); $p->setTightness($this->_tight_top, $this->_tight_bot); return $p; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if (!$file) { return $this->error(sprintf(_("A required argument '%s' is missing."), 'file')); } if (!$display) { return $this->error(sprintf(_("A required argument '%s' is missing."), 'display')); } $dir = getcwd(); chdir(PHPWIKI_DIR); // sanify $file name if (!file_exists($file)) { trigger_error("file \"{$file}\" not found", E_USER_WARNING); } $realfile = realpath($file); if (!string_starts_with($realfile, realpath(getUploadDataPath()))) { return $this->error("invalid path \"{$file}\""); } else { $isuploaded = 1; } $s = array(); $modes = explode(",", $display); foreach ($modes as $mode) { switch ($mode) { case 'version': $s[] = $this->exeversion($file); break; case 'size': $s[] = filesize($file); break; case 'phonysize': $s[] = $this->phonysize(filesize($file)); break; case 'date': $s[] = strftime("%x %X", filemtime($file)); break; case 'mtime': $s[] = filemtime($file); break; case 'name': $s[] = basename($file); break; case 'path': $s[] = $file; break; case 'dirname': $s[] = dirname($file); break; case 'magic': $s[] = $this->magic($file); break; case 'mime-typ': $s[] = $this->mime_type($file); break; case 'link': if ($isuploaded) { $s[] = "[Upload:" . basename($file) . "]"; } else { $s[] = "[" . basename($file) . "]"; } break; default: return $this->error(sprintf(_("Unsupported argument: %s=%s"), 'display', $mode)); break; } } chdir($dir); if (!$format) { $format = ''; foreach ($s as $x) { $format .= " %s"; } } array_unshift($s, $format); // $x, array($i,$j) => sprintf($x, $i, $j) $result = call_user_func_array("sprintf", $s); if (in_array('link', $modes)) { require_once "lib/InlineParser.php"; return TransformInline($result); } else { return $result; } }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; include_once 'lib/InlineParser.php'; $table = array(); $lines = preg_split('/\\s*?\\n\\s*/', $argstr); foreach ($lines as $line) { if (!$line) { continue; } $line = trim($line); // If line ends with a '|', remove it if ($line[strlen($line) - 1] == '|') { $line = substr($line, 0, -1); } if ($line[0] != '|') { // trigger_error(sprintf(_("Line %s does not begin with a '|'."), $line), E_USER_WARNING); } else { $table[] = $this->_parse_row($line, $basepage); } } $nbrows = sizeof($table); // If table is empty, do not generate table markup if ($nbrows == 0) { return HTML::raw(''); } $nbcols = sizeof($table[0]); for ($i = 0; $i < $nbrows; $i++) { for ($j = 0; $j < $nbcols; $j++) { if (preg_match('/@@/', $table[$i][$j])) { $table[$i][$j] = compute_tablecell($table, $i, $j, $nbrows, $nbcols); } } } $htmltable = HTML::table(array('class' => "bordered")); foreach ($table as $row) { $htmlrow = HTML::tr(); foreach ($row as $cell) { if ($cell && $cell[0] == '=') { $cell = trim(substr($cell, 1)); $htmlrow->pushContent(HTML::th(TransformInline($cell, 2.0, $basepage))); } else { if (is_numeric($cell)) { $htmlrow->pushContent(HTML::td(array('style' => "text-align:right"), $cell)); } else { $htmlrow->pushContent(HTML::td(TransformInline($cell, 2.0, $basepage))); } } } $htmltable->pushContent($htmlrow); } return $htmltable; }
function ConvertAfter($text) { return TransformInline($text); }
function _quote($heading) { if (TOC_FULL_SYNTAX) { $theading = TransformInline($heading); if ($theading) { return preg_quote($theading->asXML(), "/"); } else { return XmlContent::_quote(preg_quote($heading, "/")); } } else { return XmlContent::_quote(preg_quote($heading, "/")); } }
function _match(&$input, $m) { if (substr($m->match, 1, 4) == 'span') { $tag = 'span'; } else { $tag = 'div'; } // without last > $argstr = substr(trim(substr($m->match, strlen($tag) + 1)), 0, -1); $pos = $input->getPos(); $pi = $content = $m->postmatch; while (!preg_match('/^(.*)\\<\\/' . $tag . '\\>(.*)$/i', $pi, $me)) { if ($pi != $content) { $content .= "\n{$pi}"; } if (($pi = $input->nextLine()) === false) { $input->setPos($pos); return false; } } if ($pi != $content) { $content .= $me[1]; } else { $content = $me[1]; } $input->advance(); if (strstr($content, "\n")) { $content = TransformText($content); } else { $content = TransformInline($content); } if (!$argstr) { $args = false; } else { $args = array(); while (preg_match("/(\\w+)=(.+)/", $argstr, $m)) { $k = $m[1]; $v = $m[2]; if (preg_match("/^\"(.+?)\"(.*)\$/", $v, $m)) { $v = $m[1]; $argstr = $m[2]; } else { preg_match("/^(\\s+)(.*)\$/", $v, $m); $v = $m[1]; $argstr = $m[2]; } if (trim($k) and trim($v)) { $args[$k] = $v; } } } $this->_element = new Block_HtmlElement($tag, $args, $content); return true; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (!$file) { return $this->error(sprintf(_("A required argument '%s' is missing."), 'file')); } if (!$display) { return $this->error(sprintf(_("A required argument '%s' is missing."), 'display')); } if (string_starts_with($file, "Upload:")) { $file = preg_replace("/^Upload:(.*)\$/", getUploadFilePath() . "\\1", $file); $is_Upload = 1; } $dir = getcwd(); if (defined('PHPWIKI_DIR')) { chdir(PHPWIKI_DIR); } if (!file_exists($file)) { if ($quiet) { return HTML::raw(''); } else { return $this->error(sprintf(_("File '%s' not found."), $file)); } } // sanify $file name $realfile = realpath($file); // Hmm, allow ADMIN to check a local file? Only if its locked if (string_starts_with($realfile, realpath(getUploadDataPath()))) { $isuploaded = 1; } else { $page = $dbi->getPage($basepage); $user = $request->getUser(); if ($page->getOwner() != ADMIN_USER or !$page->get('locked')) { // For convenience we warn the admin if ($quiet and $user->isAdmin()) { return HTML::span(array('title' => _("Output suppressed. FileInfoPlugin with local files require a locked page.")), HTML::em(_("page not locked"))); } else { return $this->error("Invalid path \"{$file}\". Only ADMIN can allow local paths, and the page must be locked."); } } } $s = array(); $modes = explode(",", $display); foreach ($modes as $mode) { switch ($mode) { case 'version': $s[] = $this->exeversion($file); break; case 'size': $s[] = filesize($file); break; case 'phonysize': $s[] = $this->phonysize(filesize($file)); break; case 'date': $s[] = strftime("%x %X", filemtime($file)); break; case 'mtime': $s[] = filemtime($file); break; case 'owner': $o = posix_getpwuid(fileowner($file)); $s[] = $o['name']; break; case 'group': $o = posix_getgrgid(filegroup($file)); $s[] = $o['name']; break; case 'name': $s[] = basename($file); break; case 'path': $s[] = $file; break; case 'dirname': $s[] = dirname($file); break; case 'magic': $s[] = $this->magic($file); break; case 'mime-typ': $s[] = $this->mime_type($file); break; case 'link': if ($is_Upload) { $s[] = " [" . $args['file'] . "]"; } elseif ($isuploaded) { // will fail with user uploads $s[] = " [Upload:" . basename($file) . "]"; } else { $s[] = " [" . basename($file) . "] "; } break; default: if (!$quiet) { return $this->error(sprintf(_("Unsupported argument: %s=%s"), 'display', $mode)); } else { return HTML::raw(''); } break; } } chdir($dir); if (!$format) { $format = ''; foreach ($s as $x) { $format .= " %s"; } } array_unshift($s, $format); // $x, array($i,$j) => sprintf($x, $i, $j) $result = call_user_func_array("sprintf", $s); if (in_array('link', $modes)) { require_once "lib/InlineParser.php"; return TransformInline($result, 2, $basepage); } else { return HTML::raw($result); } }
function _parse_row($line, $basepage) { $brkt_link = "\\[ .*? [^]\\s] .*? \\]"; $cell_content = "(?: [^[] | " . ESCAPE_CHAR . "\\[ | {$brkt_link} )*?"; preg_match_all("/(\\|+) (v*) ([<>^]?) \\s* ({$cell_content}) \\s* (?=\\||\$)/x", $line, $matches, PREG_SET_ORDER); $row = HTML::tr(); foreach ($matches as $m) { $attr = array(); if (strlen($m[1]) > 1) { $attr['colspan'] = strlen($m[1]); } if (strlen($m[2]) > 0) { $attr['rowspan'] = strlen($m[2]) + 1; } if ($m[3] == '^') { $attr['align'] = 'center'; } else { if ($m[3] == '>') { $attr['align'] = 'right'; } else { $attr['align'] = 'left'; } } // Assume new-style inline markup. $content = TransformInline($m[4], 2.0, $basepage); $row->pushContent(HTML::td($attr, HTML::raw(' '), $content, HTML::raw(' '))); } return $row; }
function run($dbi, $argstr, &$request, $basepage) { $this->vars = array(); $args = $this->getArgs($argstr, $request); $vars = $args['vars'] ? $args['vars'] : $this->vars; $page = $args['page']; if ($page) { // Expand relative page names. $page = new WikiPageName($page, $basepage); $page = $page->name; } if (!$page) { return $this->error(_("no page specified")); } // If "Template:$page" exists, use it // else if "Template/$page" exists, use it // else use "$page" if ($dbi->isWikiPage("Template:" . $page)) { $page = "Template:" . $page; } elseif ($dbi->isWikiPage("Template/" . $page)) { $page = "Template/" . $page; } // Protect from recursive inclusion. A page can include itself once static $included_pages = array(); if (in_array($page, $included_pages)) { return $this->error(sprintf(_("recursive inclusion of page %s"), $page)); } // Check if page exists if (!$dbi->isWikiPage($page)) { return $this->error(sprintf(_("Page '%s' does not exist"), $page)); } // Check if user is allowed to get the Page. if (!mayAccessPage('view', $page)) { return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $page)); } $p = $dbi->getPage($page); if ($args['rev']) { $r = $p->getRevision($args['rev']); if (!$r) { return $this->error(sprintf(_("%s(%d): no such revision"), $page, $args['rev'])); } } else { $r = $p->getCurrentRevision(); } $initial_content = $r->getPackedContent(); $content = $r->getContent(); // follow redirects if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $content), $m)) { // Strip quotes (simple or double) from page name if any if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) { $m[1] = substr($m[1], 1, -1); } // trap recursive redirects if (in_array($m[1], $included_pages)) { return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page . ' => ' . $m[1])); } $page = $m[1]; $p = $dbi->getPage($page); $r = $p->getCurrentRevision(); $initial_content = $r->getPackedContent(); } if ($args['section']) { $c = explode("\n", $initial_content); $c = extractSection($args['section'], $c, $page, $quiet, $args['sectionhead']); $initial_content = implode("\n", $c); } // exclude from expansion if (preg_match('/<noinclude>.+<\\/noinclude>/s', $initial_content)) { $initial_content = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $initial_content); } // only in expansion $initial_content = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $initial_content); $this->doVariableExpansion($initial_content, $vars, $basepage, $request); array_push($included_pages, $page); // If content is single-line, call TransformInline, else call TransformText $initial_content = trim($initial_content, "\n"); if (preg_match("/\n/", $initial_content)) { include_once 'lib/BlockParser.php'; $content = TransformText($initial_content, $r->get('markup'), $page); } else { include_once 'lib/InlineParser.php'; $content = TransformInline($initial_content, $r->get('markup'), $page); } array_pop($included_pages); return $content; }