Example #1
0
 function testTextFormattingRules()
 {
     global $request;
     $pagename = 'Help/TextFormattingRules';
     $this->_ensure_loaded($pagename);
     $dbi = $request->getDbh();
     $p = $dbi->getPage($pagename);
     $r = $p->getCurrentRevision();
     $c = $r->getContent();
     $section = extractSection('Synopsis', $c, $pagename, 1);
     $this->assertTrue(strstr(join("", $section), "TextFormattingRules%%%"));
 }
Example #2
0
 /** 
  * handles the arguments: section, sectionhead, lines, words, bytes,
  * for UnfoldSubpages, IncludePage, ...
  */
 function extractParts($c, $pagename, $args)
 {
     extract($args);
     if ($section) {
         $c = extractSection($section, $c, $pagename, $quiet, $sectionhead);
     }
     if ($lines) {
         $c = array_slice($c, 0, $lines);
         $c[] = sprintf(_(" ... first %d lines"), $bytes);
     }
     if ($words) {
         $c = firstNWordsOfContent($words, $c);
     }
     if ($bytes) {
         $ct = implode("\n", $c);
         // one string
         if (strlen($ct) > $bytes) {
             $ct = substr($c, 0, $bytes);
             $c = array($ct, sprintf(_(" ... first %d bytes"), $bytes));
         }
     }
     $ct = implode("\n", $c);
     // one string
     return $ct;
 }
Example #3
0
 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));
 }
Example #4
0
 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);
 }
Example #5
0
 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;
 }
Example #6
0
 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;
 }
Example #7
0
 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);
 }