function run($dbi, $argstr, &$request, $basepage) { if (!$basepage) { return $this->error("{$basepage} unset?"); } include_once "lib/BlockParser.php"; $page = $request->getPage($basepage); return HTML::div(array('class' => 'boxright'), TransformText($argstr)); }
function showDiff(&$request) { $pagename = $request->getArg('pagename'); if (is_array($versions = $request->getArg('versions'))) { // Version selection from pageinfo.php display: rsort($versions); list($version, $previous) = $versions; } else { $version = $request->getArg('version'); $previous = $request->getArg('previous'); } // abort if page doesn't exist $dbi = $request->getDbh(); $page = $request->getPage(); $current = $page->getCurrentRevision(false); if ($current->getVersion() < 1) { $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown')))); require_once 'lib/Template.php'; GeneratePage($html, sprintf(_("Diff: %s"), $pagename), false); return; //early return } if ($version) { if (!($new = $page->getRevision($version))) { NoSuchRevision($request, $page, $version); } $new_version = fmt("version %d", $version); } else { $new = $current; $new_version = _("current version"); } if (preg_match('/^\\d+$/', $previous)) { if (!($old = $page->getRevision($previous))) { NoSuchRevision($request, $page, $previous); } $old_version = fmt("version %d", $previous); $others = array('major', 'minor', 'author'); } else { switch ($previous) { case 'author': $old = $new; while ($old = $page->getRevisionBefore($old)) { if ($old->get('author') != $new->get('author')) { break; } } $old_version = _("revision by previous author"); $others = array('major', 'minor'); break; case 'minor': $previous = 'minor'; $old = $page->getRevisionBefore($new); $old_version = _("previous revision"); $others = array('major', 'author'); break; case 'major': default: $old = $new; while ($old && $old->get('is_minor_edit')) { $old = $page->getRevisionBefore($old); } if ($old) { $old = $page->getRevisionBefore($old); } $old_version = _("predecessor to the previous major change"); $others = array('minor', 'author'); break; } } $new_link = WikiLink($new, '', $new_version); $old_link = $old ? WikiLink($old, '', $old_version) : $old_version; $page_link = WikiLink($page); $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link))); $otherdiffs = HTML::p(_("Other diffs:")); $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author")); foreach ($others as $other) { $args = array('action' => 'diff', 'previous' => $other); if ($version) { $args['version'] = $version; } if (count($otherdiffs->getContent()) > 1) { $otherdiffs->pushContent(", "); } else { $otherdiffs->pushContent(" "); } $otherdiffs->pushContent(Button($args, $label[$other])); } $html->pushContent($otherdiffs); if ($old and $old->getVersion() == 0) { $old = false; } $html->pushContent(HTML::Table(PageInfoRow(_("Newer page:"), $new, $request, empty($version)), PageInfoRow(_("Older page:"), $old, $request, false))); if ($new && $old) { $diff = new Diff($old->getContent(), $new->getContent()); if ($diff->isEmpty()) { $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical."))); // If two consecutive versions have the same content, it is because the page was // renamed, or metadata changed: ACL, owner, markup. // We give the reason by printing the summary. if ($new->getVersion() - $old->getVersion() == 1) { $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary'))); } } else { $fmt = new HtmlUnifiedDiffFormatter(); $html->pushContent($fmt->format($diff)); } $html->pushContent(HTML::hr(), HTML::h2($new_version)); require_once "lib/BlockParser.php"; $html->pushContent(TransformText($new, $new->get('markup'), $pagename)); } require_once 'lib/Template.php'; GeneratePage($html, sprintf(_("Diff: %s"), $pagename), $new); }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request); extract($args); if ($Longitude === '') { return $this->error(fmt("%s parameter missing", "'Longitude'")); } if ($Latitude === '') { return $this->error(fmt("%s parameter missing", "'Latitude'")); } $maps = JavaScript('', array('src' => "http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY)); $id = GenerateId("googlemap"); switch ($MapType) { case "Satellite": $type = "_SATELLITE_TYPE"; break; case "Map": $type = "_MAP_TYPE"; break; case "Hybrid": $type = "_HYBRID_TYPE"; break; default: return $this->error(sprintf(_("invalid argument %s"), $MapType)); } $div = HTML::div(array('id' => $id, 'style' => 'width: ' . $width . '; height: ' . $height)); // TODO: Check for multiple markers or polygons if (!$InfoText) { $Marker = false; } // Create a marker whose info window displays the given text if ($Marker) { if ($InfoText) { include_once "lib/BlockParser.php"; $page = $dbi->getPage($request->getArg('pagename')); $rev = $page->getCurrentRevision(false); $markup = $rev->get('markup'); $markertext = TransformText($InfoText, $markup, $basepage); } $markerjs = JavaScript("\nfunction createMarker(point, text) {\n var marker = new GMarker(point);\n var html = text + \"<br><br><font size='-1'>[" . _("new window") . "]</font>\";\n GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});\n return marker;\n}"); } $run = JavaScript("\nvar map = new GMap(document.getElementById('" . $id . "'));\n" . ($SmallMapControl ? "map.addControl(new GSmallMapControl());\n" : "map.addControl(new GLargeMapControl());\n") . "\nmap.addControl(new GMapTypeControl());\nmap.centerAndZoom(new GPoint(" . $Longitude . ", " . $Latitude . "), " . $ZoomFactor . ");\nmap.setMapType(" . $type . ");" . ($Marker ? "\nvar point = new GPoint(" . $Longitude . "," . $Latitude . ");\nvar marker = createMarker(point, '" . $markertext->asXml() . "'); map.addOverlay(marker);" : "")); if ($Marker) { return HTML($markerjs, $maps, $div, $run); } else { return HTML($maps, $div, $run); } }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); $page = $dbi->getPage($pagename); $current = $page->getCurrentRevision(); $source = $current->getPackedContent(); if (empty($source)) { return $this->error(fmt("empty source")); } if ($basepage == _("SpellCheck")) { return $this->error(fmt("Cannot SpellCheck myself")); } $lang = $page->get('lang'); if (empty($lang)) { $lang = $GLOBALS['LANG']; } $html = HTML(); if (!function_exists('pspell_new_config')) { // use the aspell commandline interface include_once "lib/WikiPluginCached.php"; $args = ""; $source = preg_replace("/^/m", "^", $source); if (ASPELL_DATA_DIR) { $args .= " --data-dir=" . ASPELL_DATA_DIR; } // MAYBE TODO: do we have the language dictionary? $args .= " --lang=" . $lang; // use -C or autosplit wikiwords in the text $commandLine = ASPELL_EXE . " -a -C {$args} "; $cache = new WikiPluginCached(); $code = $cache->filterThroughCmd($source, $commandLine); if (empty($code)) { return $this->error(fmt("Couldn't start commandline '%s'", $commandLine)); } $sugg = array(); foreach (preg_split("/\n/", $code) as $line) { if (preg_match("/^& (\\w+) \\d+ \\d+: (.+)\$/", $line, $m)) { $sugg[$m[1]] = preg_split("/, /", $m[2]); } } /*$pre = HTML::pre(HTML::raw($code)); $html->pushContent($pre);*/ } else { $sugg = pspell_check($source, $lang); } //$html->pushContent(HTML::hr(),HTML::h1(_("Spellcheck"))); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } } else { $revision = $page->getCurrentRevision(); } $GLOBALS['request']->setArg('suggestions', $sugg); include_once "lib/BlockParser.php"; $ori_html = TransformText($revision, $revision->get('markup'), $page); $GLOBALS['request']->setArg('suggestions', false); $html->pushContent($ori_html, HTML::hr(), HTML::h1(_("SpellCheck result"))); $list = HTML::ul(); foreach ($sugg as $word => $suggs) { $w = HTML::span(array('class' => 'spell-wrong'), $word); // TODO: optional replace-link. jscript or request button with word replace. $r = HTML(); foreach ($suggs as $s) { $r->pushContent(HTML::a(array('class' => 'spell-sugg', 'href' => "javascript:do_replace('{$word}','{$s}')"), $s), ", "); } $list->pushContent(HTML::li($w, ": ", $r)); } $html->pushContent($list); return $html; }
function _date($dbi, $time) { $args =& $this->args; $date_string = strftime($args['date_format'], $time); $page_for_date = $args['prefix'] . SUBPAGE_SEPARATOR . $date_string; $t = localtime($time, 1); $td = HTML::td(array('align' => 'center')); if ($dbi->isWikiPage($page_for_date)) { // Extract the page contents for this date $p = $dbi->getPage($page_for_date); $r = $p->getCurrentRevision(); $c = $r->getContent(); include_once 'lib/BlockParser.php'; $content = TransformText(implode("\n", $c), $r->get('markup')); $link = HTML::a(array('class' => 'cal-hide', 'href' => WikiURL($page_for_date, array('action' => 'edit')), 'title' => sprintf(_("Edit %s"), $page_for_date)), $date_string); $this->_links[] = $page_for_date; $a = array(HTML::dt($link), HTML::dd($content)); } else { $a = array(); } return $a; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if ($page) { // Expand relative page names. $page = new WikiPageName($page, $basepage); $page = $page->name; } if (!$page) { return $this->error(_("no page specified")); } // A page can include itself once (this is needed, e.g., when editing // TextFormattingRules). static $included_pages = array(); if (in_array($page, $included_pages)) { return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $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 ($rev) { $r = $p->getRevision($rev); if (!$r) { return $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev)); } } else { $r = $p->getCurrentRevision(); } $c = $r->getContent(); // follow redirects if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $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(); $c = $r->getContent(); // array of lines } $ct = $this->extractParts($c, $page, $args); // exclude from expansion if (preg_match('/<noinclude>.+<\\/noinclude>/s', $ct)) { $ct = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $ct); } // only in expansion $ct = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $ct); array_push($included_pages, $page); include_once 'lib/BlockParser.php'; $content = TransformText($ct, $r->get('markup'), $page); array_pop($included_pages); if ($quiet) { return $content; } return HTML(HTML::p(array('class' => 'transclusion-title'), fmt("Included from %s", WikiLink($page))), HTML::div(array('class' => 'transclusion'), false, $content)); }
function run($dbi, $argstr, &$request, $basepage) { include_once "lib/BlockParser.php"; // MediawikiTablePlugin markup is new. $markup = 2.0; // We allow the compact Mediawiki syntax with: // - multiple cells on the same line (separated by "||"), // - multiple header cells on the same line (separated by "!!"). $argstr = str_replace("||", "\n| ", $argstr); $argstr = str_replace("!!", "\n! ", $argstr); $lines = preg_split('/\\n/', $argstr); $table = HTML::table(); // We always generate an Id for the table. // This is convenient for tables of class "sortable". // If user provides an Id, the generated Id will be overwritten below. $table->setAttr("id", GenerateId("MediawikiTable")); if (substr($lines[0], 0, 2) == "{|") { // Start of table $lines[0] = substr($lines[0], 2); } if ($lines[0][0] != '|' and $lines[0][0] != '!') { $line = array_shift($lines); $attrs = parse_attributes($line); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } if (count($lines) == 1) { // empty table, we only have closing "|}" line return HTML::raw(''); } foreach ($lines as $line) { if (substr($line, 0, 2) == "|}") { // End of table continue; } if (substr($line, 0, 2) == "|-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); unset($cell); } if (isset($thead)) { $thead->pushContent($row); $table->pushContent($thead); unset($thead); $tbody = HTML::tbody(); } else { $tbody->pushContent($row); } } $row = HTML::tr(); $attrs = parse_attributes(substr($line, 2)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } // Table summary if (substr($line, 0, 2) == "|=") { $line = substr($line, 2); $table->setAttr("summary", trim($line)); } // Table caption if (substr($line, 0, 2) == "|+") { $caption = HTML::caption(); $line = substr($line, 2); $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe)) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "align", "lang"))) { $caption->setAttr($key, $value); } } $line = substr($line, $pospipe + 1); } $caption->pushContent(trim($line)); $table->pushContent($caption); } if ((substr($line, 0, 1) == "|" or substr($line, 0, 1) == "!") and isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); } if (substr($line, 0, 1) == "!") { $cell = HTML::th(); // Header $thead = HTML::thead(); } else { $cell = HTML::td(); if (!isset($tbody)) { $tbody = HTML::tbody(); } } $line = substr($line, 1); // If there is a "|" in the line, the start of line // (before the "|") is made of attributes. // The end of the line (after the "|") is the cell content // This is not true if the pipe is inside [], {{}} or {{{}}} // | [foo|bar] // The following cases must work: // | foo // | [foo|bar] // | class="xxx" | foo // | class="xxx" | [foo|bar] // | {{tmpl|arg=val}} // | {{image.png|alt}} // | {{{ xxx | yyy }}} $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); $poscurly = strpos($line, "{"); if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe) && ($poscurly === false || $poscurly > $pospipe)) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } $line = substr($line, $pospipe + 1); if (is_numeric(trim($line))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($line))); } else { $cell->pushContent(TransformText(trim($line), $markup, $basepage)); } continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\\>", "?>", $line); $line = str_replace("\\~", "~", $line); if (empty($content)) { $content = ''; } $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } } $row->pushContent($cell); } $tbody->pushContent($row); $table->pushContent($tbody); } return $table; }
function _transform($text) { include_once 'lib/BlockParser.php'; return TransformText($text, $this->_markup); }
function run($dbi, $argstr, &$request, $basepage) { static $included_pages = false; if (!$included_pages) { $included_pages = array($basepage); } $args = $this->getArgs($argstr, $request); extract($args); $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob'); $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude); //if ($sortby) // $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude)); //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false, // $sortby, $limit, $exclude); if (is_string($exclude) and !is_array($exclude)) { $exclude = PageList::explodePageList($exclude, false, false, $limit); } $content = HTML(); include_once 'lib/BlockParser.php'; $i = 0; while ($page = $subpages->next()) { $cpagename = $page->getName(); if ($maxpages and $i++ > $maxpages) { return $content; } if (in_array($cpagename, $exclude)) { continue; } // A page cannot include itself. Avoid doublettes. if (in_array($cpagename, $included_pages)) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename))); continue; } // Check if user is allowed to get the Page. if (!mayAccessPage('view', $cpagename)) { return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename)); } // trap any remaining nonexistant subpages if ($page->exists()) { $r = $page->getCurrentRevision(); $c = $r->getContent(); // array of lines // follow redirects if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $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)) { if (!$quiet) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename . ' => ' . $m[1]))); } continue; } $cpagename = $m[1]; // Check if user is allowed to get the Page. if (!mayAccessPage('view', $cpagename)) { return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename)); } $page = $dbi->getPage($cpagename); $r = $page->getCurrentRevision(); $c = $r->getContent(); // array of lines } // moved to IncludePage $ct = $this->extractParts($c, $cpagename, $args); array_push($included_pages, $cpagename); if ($smalltitle) { $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename)); // get last subpage name // Use _("%s: %s") instead of .": ". for French punctuation $ct = TransformText(sprintf(_("%s: %s"), "[{$pname}|{$cpagename}]", $ct), $r->get('markup'), $cpagename); } else { $ct = TransformText($ct, $r->get('markup'), $cpagename); } array_pop($included_pages); if (!$smalltitle) { $content->pushContent(HTML::p(array('class' => $quiet ? '' : 'transclusion-title'), fmt("Included from %s:", WikiLink($cpagename)))); } $content->pushContent(HTML(HTML::div(array('class' => $quiet ? '' : 'transclusion'), false, $ct))); } } if (!isset($cpagename)) { return $this->error(sprintf(_("%s has no subpages defined."), $pagename)); } return $content; }
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")); } // 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)); } $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(); $c = explode("\n", $initial_content); if ($args['section']) { $c = extractSection($args['section'], $c, $page, $quiet, $args['sectionhead']); $initial_content = implode("\n", $c); } if (preg_match('/<noinclude>.+<\\/noinclude>/s', $initial_content)) { $initial_content = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $initial_content); } $this->doVariableExpansion($initial_content, $vars, $basepage, $request); array_push($included_pages, $page); include_once 'lib/BlockParser.php'; $content = TransformText($initial_content, $r->get('markup'), $page); array_pop($included_pages); return HTML::div(array('class' => 'template'), $content); }
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; }
function _getValue($page_handle, &$revision_handle) { if (!$revision_handle or (!$revision_handle->_data['%content'] or $revision_handle->_data['%content'] === true)) { $revision_handle = $page_handle->getCurrentRevision(true); } if ($this->_field == 'hi_content') { if (!empty($revision_handle->_data['%pagedata'])) { $revision_handle->_data['%pagedata']['_cached_html'] = ''; } $search = $this->search; $score = ''; if (is_object($page_handle) and !empty($page_handle->score)) { $score = $page_handle->score; } elseif (is_array($page_handle) and !empty($page_handle['score'])) { $score = $page_handle['score']; } $hilight_re = $this->hilight_re; // use the TextSearchQuery highlighter if ($search and $hilight_re) { $matches = preg_grep("/{$hilight_re}/i", $revision_handle->getContent()); $html = array(); foreach (array_slice($matches, 0, 5) as $line) { $line = WikiPlugin_FullTextSearch::highlight_line($line, $hilight_re); $html[] = HTML::p(HTML::small(array('class' => 'search-context'), $line)); } if ($score) { $html[] = HTML::small(sprintf("... [%0.1f]", $score)); } return $html; } // Remove special characters so that highlighting works $search = preg_replace('/^[\\^\\*]/', '', $search); $search = preg_replace('/[\\^\\*]$/', '', $search); $c =& $revision_handle->getPackedContent(); if ($search and ($i = strpos(strtolower($c), strtolower($search))) !== false) { $l = strlen($search); $j = max(0, $i - $this->bytes / 2); return HTML::div(array('style' => 'font-size:x-small'), HTML::div(array('class' => 'transclusion'), HTML::span(($j ? '...' : '') . substr($c, $j, $j ? $this->bytes / 2 : $i)), HTML::span(array("style" => "background:yellow"), substr($c, $i, $l)), HTML::span(substr($c, $i + $l, $this->bytes / 2) . "..." . " " . ($score ? sprintf("[%0.1f]", $score) : "")))); } else { if (strpos($c, " ") !== false) { $c = ""; } else { $c = sprintf(_("%s not found"), '»' . $search . '«'); } return HTML::div(array('style' => 'font-size:x-small', 'align' => 'center'), $c . " " . ($score ? sprintf("[%0.1f]", $score) : "")); } } elseif (($len = strlen($c)) > $this->bytes) { $c = substr($c, 0, $this->bytes); } include_once 'lib/BlockParser.php'; // false --> don't bother processing hrefs for embedded WikiLinks $ct = TransformText($c, $revision_handle->get('markup'), false); if (empty($pagelist->_sortby[$this->_field])) { unset($revision_handle->_data['%pagedata']['_cached_html']); } return HTML::div(array('style' => 'font-size:x-small'), HTML::div(array('class' => 'transclusion'), $ct), ($this->parent->_columns_seen['size'] or !$len) ? "" : ByteFormatter($len, true)); }
function run($dbi, $argstr, &$request, $basepage) { static $included_pages = false; if (!$included_pages) { $included_pages = array($basepage); } $args = $this->getArgs($argstr, $request); extract($args); $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob'); $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude); //if ($sortby) // $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude)); //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false, // $sortby, $limit, $exclude); if (is_string($exclude) and !is_array($exclude)) { $exclude = PageList::explodePageList($exclude, false, false, $limit); } $content = HTML(); include_once 'lib/BlockParser.php'; $i = 0; while ($page = $subpages->next()) { $cpagename = $page->getName(); if ($maxpages and $i++ > $maxpages) { return $content; } if (in_array($cpagename, $exclude)) { continue; } // A page cannot include itself. Avoid doublettes. if (in_array($cpagename, $included_pages)) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename))); continue; } // trap any remaining nonexistant subpages if ($page->exists()) { $r = $page->getCurrentRevision(); $c = $r->getContent(); // array of lines // trap recursive redirects if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\w+)\\s+\\?' . '>/', implode("\n", $c), $m)) { if (in_array($m[1], $included_pages)) { if (!$quiet) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename . ' => ' . $m[1]))); } continue; } } if ($section) { $c = extractSection($section, $c, $cpagename, $quiet, $sectionhead); } if ($lines) { $c = array_slice($c, 0, $lines) . sprintf(_(" ... first %d lines"), $bytes); } if ($words) { $c = firstNWordsOfContent($words, $c); } if ($bytes) { if (strlen($c) > $bytes) { $c = substr($c, 0, $bytes) . sprintf(_(" ... first %d bytes"), $bytes); } } $ct = implode("\n", $c); // one string array_push($included_pages, $cpagename); if ($smalltitle) { $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename)); // get last subpage name // Use _("%s: %s") instead of .": ". for French punctuation $ct = TransformText(sprintf(_("%s: %s"), "[{$pname}|{$cpagename}]", $ct), $r->get('markup'), $cpagename); } else { $ct = TransformText($ct, $r->get('markup'), $cpagename); } array_pop($included_pages); if (!$smalltitle) { $content->pushContent(HTML::p(array('class' => $quiet ? '' : 'transclusion-title'), fmt("Included from %s:", WikiLink($cpagename)))); } $content->pushContent(HTML(HTML::div(array('class' => $quiet ? '' : 'transclusion'), false, $ct))); } } if (!$cpagename) { return $this->error(sprintf(_("%s has no subpages defined."), $pagename)); } return $content; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if ($page) { // Expand relative page names. $page = new WikiPageName($page, $basepage); $page = $page->name; } if (!$page) { return $this->error(_("no page specified")); } // A page can include itself once (this is needed, e.g., when editing // TextFormattingRules). static $included_pages = array(); if (in_array($page, $included_pages)) { return $this->error(sprintf(_("recursive inclusion of page %s"), $page)); } $p = $dbi->getPage($page); if ($rev) { $r = $p->getRevision($rev); if (!$r) { return $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev)); } } else { $r = $p->getCurrentRevision(); } $c = $r->getContent(); if ($section) { $c = extractSection($section, $c, $page, $quiet, $sectionhead); } if ($lines) { $c = array_slice($c, 0, $lines); } if ($words) { $c = firstNWordsOfContent($words, $c); } array_push($included_pages, $page); include_once 'lib/BlockParser.php'; $content = TransformText(implode("\n", $c), $r->get('markup'), $page); array_pop($included_pages); if ($quiet) { return $content; } return HTML(HTML::p(array('class' => 'transclusion-title'), fmt("Included from %s", WikiLink($page))), HTML::div(array('class' => 'transclusion'), false, $content)); }
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; }
/** * Handler to convert the Wiki Markup to HTML before editing. * This will be converted back by WysiwygEdit_ConvertAfter if required. * *text* => '<b>text<b>' */ function ConvertBefore($text) { require_once "lib/BlockParser.php"; $xml = TransformText($text, 2.0, $GLOBALS['request']->getArg('pagename')); return $xml->AsXML(); }
function _getValue($page_handle, &$revision_handle) { if (!$revision_handle or (!$revision_handle->_data['%content'] or $revision_handle->_data['%content'] === true)) { $revision_handle = $page_handle->getCurrentRevision(true); } // Not sure why implode is needed here, I thought // getContent() already did this, but it seems necessary. $c = implode("\n", $revision_handle->getContent()); if (empty($pagelist->_sortby[$this->_field])) { unset($revision_handle->_data['%content']); } if ($this->_field == 'hi_content') { global $HTTP_POST_VARS; unset($revision_handle->_data['%pagedata']['_cached_html']); $search = $HTTP_POST_VARS['admin_replace']['from']; if ($search and $i = strpos($c, $search)) { $l = strlen($search); $j = max(0, $i - $this->bytes / 2); return HTML::div(array('style' => 'font-size:x-small'), HTML::div(array('class' => 'transclusion'), HTML::span(substr($c, $j, $this->bytes / 2)), HTML::span(array("style" => "background:yellow"), $search), HTML::span(substr($c, $i + $l, $this->bytes / 2)))); } else { $c = sprintf(_("%s not found"), '»' . $search . '«'); return HTML::div(array('style' => 'font-size:x-small', 'align' => 'center'), $c); } } elseif (($len = strlen($c)) > $this->bytes) { $c = substr($c, 0, $this->bytes); } include_once 'lib/BlockParser.php'; // false --> don't bother processing hrefs for embedded WikiLinks $ct = TransformText($c, $revision_handle->get('markup'), false); if (empty($pagelist->_sortby[$this->_field])) { unset($revision_handle->_data['%pagedata']['_cached_html']); } return HTML::div(array('style' => 'font-size:x-small'), HTML::div(array('class' => 'transclusion'), $ct), ($this->parent->_columns_seen['size'] or !$len) ? "" : ByteFormatter($len, true)); }
function run($dbi, $argstr, &$request, $basepage) { include_once 'lib/BlockParser.php'; $args = $this->getArgs($argstr, $request, false); extract($args); if (!$page) { return ''; } $this->_pagename = $page; $out = ''; // get rid of this $html = HTML(); if (empty($exclude)) { $exclude = array(); } if (!$include_self) { $exclude[] = $page; } $this->ExcludedPages = empty($exclude) ? "" : "^(?:" . join("|", $exclude) . ")"; $this->_default_limit = str_pad('', 3, '*'); if (is_numeric($reclimit)) { if ($reclimit < 0) { $reclimit = 0; } if ($reclimit > 10) { $reclimit = 10; } $limit = str_pad('', $reclimit + 2, '*'); } else { $limit = '***'; } //Fixme: override given arg $description = $this->getDescription(); if (!$noheader) { $out = $this->getDescription() . " " . sprintf(_("(max. recursion level: %d)"), $reclimit) . ":\n\n"; $html->pushContent(TransformText($out, 1.0, $page)); } $pagelist = new PageList($info, $exclude); $p = $dbi->getPage($page); $pagearr = array(); if ($direction == 'back') { $pagearr = $this->recursivelyGetBackLinks($p, $pagearr, "*", $limit); } else { $this->dbi = $dbi; $this->initialpage = $page; $this->firstreversed = $firstreversed; $this->excludeunknown = $excludeunknown; $pagearr = $this->recursivelyGetLinks($p, $pagearr, "*", $limit); } reset($pagearr); if (!empty($includepages)) { // disallow direct usage, only via child class IncludeSiteMap if (!isa($this, "WikiPlugin_IncludeSiteMap")) { $includepages = ''; } if (!is_string($includepages)) { $includepages = ' '; } // avoid plugin loader problems $loader = new WikiPluginLoader(); $plugin = $loader->getPlugin('IncludePage', false); $nothing = ''; } while (list($key, $link) = each($pagearr)) { if (!empty($includepages)) { $a = substr_count($key, '*'); $indenter = str_pad($nothing, $a); //$request->setArg('IncludePage', 1); // quote linkname, by Stefan Schorn $plugin_args = 'page=\'' . $link->getName() . '\' ' . $includepages; $pagehtml = $plugin->run($dbi, $plugin_args, $request, $basepage); $html->pushContent($pagehtml); //$html->pushContent( HTML(TransformText($indenter, 1.0, $page), $pagehtml)); //$out .= $indenter . $pagehtml . "\n"; } else { $out .= $key . "\n"; } } if (empty($includepages)) { return TransformText($out, 2.0, $page); } else { return $html; } }
function convert() { require_once "lib/BlockParser.php"; $xmlcontent = TransformText($this->_wikitext, 2.0, $this->_request->getArg('pagename')); $this->_html = $xmlcontent->AsXML(); $this->replace_inside_html(); }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; include_once "lib/BlockParser.php"; // RichTablePlugin markup is new. $markup = 2.0; $lines = preg_split('/\\n/', $argstr); $table = HTML::table(); if ($lines[0][0] == '*') { $line = substr(array_shift($lines), 1); $attrs = $this->_parse_attr($line); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } foreach ($lines as $line) { if (substr($line, 0, 1) == "-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { $cell->pushContent(TransformText($content, $markup, $basepage)); unset($content); } $row->pushContent($cell); unset($cell); } $table->pushContent($row); } $row = HTML::tr(); $attrs = $this->_parse_attr(substr($line, 1)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } if (substr($line, 0, 1) == "|" and isset($row)) { if (isset($cell)) { if (isset($content)) { $cell->pushContent(TransformText($content, $markup, $basepage)); unset($content); } $row->pushContent($cell); } $cell = HTML::td(); $line = substr($line, 1); if ($line[0] == "*") { $attrs = $this->_parse_attr(substr($line, 1)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\\>", "?>", $line); $line = str_replace("\\~", "~", $line); if (empty($content)) { $content = ''; } $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) { $cell->pushContent(TransformText($content)); } $row->pushContent($cell); } $table->pushContent($row); } return $table; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if ($page) { // Expand relative page names. $page = new WikiPageName($page, $basepage); $page = $page->name; } if (!$page) { return $this->error(_("no page specified")); } // 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)); } $p = $dbi->getPage($page); if ($rev) { $r = $p->getRevision($rev); if (!$r) { return $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev)); } } else { $r = $p->getCurrentRevision(); } $initial_content = $r->getPackedContent(); $c = explode("\n", $initial_content); if ($section) { $c = extractSection($section, $c, $page, $quiet, $sectionhead); $initial_content = implode("\n", $c); } if (preg_match('/<noinclude>.+<\\/noinclude>/s', $initial_content)) { $initial_content = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $initial_content); } if (preg_match('/%%\\w+%%/', $initial_content)) { $var = array(); if (!empty($vars)) { foreach (split("&", $vars) as $pair) { list($key, $val) = split("=", $pair); $var[$key] = $val; } } $thispage = $dbi->getPage($basepage); // pagename is not overridable if (empty($var['pagename'])) { $var['pagename'] = $page; } // those are overridable if (empty($var['mtime']) and preg_match('/%%mtime%%/', $initial_content)) { $thisrev = $thispage->getCurrentRevision(false); $var['mtime'] = $GLOBALS['WikiTheme']->formatDateTime($thisrev->get('mtime')); } if (empty($var['ctime']) and preg_match('/%%ctime%%/', $initial_content)) { if ($first = $thispage->getRevision(1, false)) { $var['ctime'] = $GLOBALS['WikiTheme']->formatDateTime($first->get('mtime')); } } if (empty($var['author']) and preg_match('/%%author%%/', $initial_content)) { $var['author'] = $thispage->getAuthor(); } if (empty($var['owner']) and preg_match('/%%owner%%/', $initial_content)) { $var['owner'] = $thispage->getOwner(); } if (empty($var['creator']) and preg_match('/%%creator%%/', $initial_content)) { $var['creator'] = $thispage->getCreator(); } foreach (array("SERVER_URL", "DATA_PATH", "SCRIPT_NAME", "PHPWIKI_BASE_URL") as $c) { // constants are not overridable if (preg_match('/%%' . $c . '%%/', $initial_content)) { $var[$c] = constant($c); } } if (preg_match('/%%BASE_URL%%/', $initial_content)) { $var['BASE_URL'] = PHPWIKI_BASE_URL; } foreach ($var as $key => $val) { $initial_content = preg_replace("/%%{$key}%%/", $val, $initial_content); } } array_push($included_pages, $page); include_once 'lib/BlockParser.php'; $content = TransformText($initial_content, $r->get('markup'), $page); array_pop($included_pages); return HTML::div(array('class' => 'template'), $content); }