Beispiel #1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request, false);
     $page =& $args['page'];
     if (ENABLE_AJAX) {
         if ($args['state']) {
             $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage);
         } else {
             $html = HTML(HTML::p(array('class' => 'transclusion-title'), fmt(" %s :", WikiLink($page))), HTML::div(array('class' => 'transclusion'), ''));
         }
         $ajaxuri = WikiURL($page, array('format' => 'xml'));
     } else {
         $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage);
     }
     $header = $html->_content[0];
     $body = $html->_content[1];
     $id = 'DynInc-' . MangleXmlIdentifier($page);
     $body->setAttr('id', $id . '-body');
     $png = $WikiTheme->_findData('images/folderArrow' . ($args['state'] ? 'Open' : 'Closed') . '.png');
     $icon = HTML::img(array('id' => $id . '-img', 'src' => $png, 'onclick' => ENABLE_AJAX ? "showHideAsync('" . $ajaxuri . "','{$id}')" : "showHideFolder('{$id}')", 'alt' => _("Click to hide/show"), 'title' => _("Click to hide/show")));
     $header = HTML::p(array('class' => 'transclusion-title', 'style' => "text-decoration: none;"), $icon, fmt(" %s :", WikiLink($page)));
     if ($args['state']) {
         // show base
         $body->setAttr('style', 'display:block');
         return HTML($header, $body);
     } else {
         // do not show base
         $body->setAttr('style', 'display:none');
         if (ENABLE_AJAX) {
             return HTML($header, $body);
         } else {
             return HTML($header, $body);
         }
         // sync (load but display:none)
     }
 }
Beispiel #2
0
function LinkBracketLink($bracketlink)
{
    // $bracketlink will start and end with brackets; in between will
    // be either a page name, a URL or both separated by a pipe.
    $wikicreolesyntax = false;
    if (string_starts_with($bracketlink, "[[") or string_starts_with($bracketlink, "#[[")) {
        $wikicreolesyntax = true;
        $bracketlink = str_replace("[[", "[", $bracketlink);
        $bracketlink = str_replace("]]", "]", $bracketlink);
    }
    // Strip brackets and leading space
    // bug#1904088  Some brackets links on 2 lines cause the parser to crash
    preg_match('/(\\#?) \\[\\s* (?: (.*?) \\s* (?<!' . ESCAPE_CHAR . ')(\\|) )? \\s* (.+?) \\s*\\]/x', str_replace("\n", " ", $bracketlink), $matches);
    if (count($matches) < 4) {
        // "[ personal\ninformation manager | PhpWiki:PersonalWiki ]"
        trigger_error(_("Invalid [] syntax ignored") . ": " . $bracketlink, E_USER_WARNING);
        return new Cached_Link();
    }
    list(, $hash, $label, $bar, $rawlink) = $matches;
    if ($wikicreolesyntax and $label) {
        $temp = $label;
        $label = $rawlink;
        $rawlink = $temp;
    }
    // Mediawiki compatibility: allow "Image:" and "File:"
    // as synonyms of "Upload:"
    if (string_starts_with($rawlink, "Image:")) {
        $rawlink = str_replace("Image:", "Upload:", $rawlink);
    }
    if (string_starts_with($rawlink, "File:")) {
        $rawlink = str_replace("File:", "Upload:", $rawlink);
    }
    $label = UnWikiEscape($label);
    /*
     * Check if the user has typed a explicit URL. This solves the
     * problem where the URLs have a ~ character, which would be stripped away.
     *   "[http:/server/~name/]" will work as expected
     *   "http:/server/~name/"   will NOT work as expected, will remove the ~
     */
    if (string_starts_with($rawlink, "http://") or string_starts_with($rawlink, "https://")) {
        $link = $rawlink;
        // Mozilla Browser URI Obfuscation Weakness 2004-06-14
        //   http://www.securityfocus.com/bid/10532/
        //   goodurl+"%2F%20%20%20."+badurl
        if (preg_match("/%2F(%20)+\\./i", $rawlink)) {
            $rawlink = preg_replace("/%2F(%20)+\\./i", "%2F.", $rawlink);
        }
    } else {
        $link = UnWikiEscape($rawlink);
    }
    /* Relatives links by Joel Schaubert.
     * Recognize [../bla] or [/bla] as relative links, without needing http://
     * but [ /link ] only if SUBPAGE_SEPERATOR is not "/".
     * Normally /Page links to the subpage /Page.
     */
    if (SUBPAGE_SEPARATOR == '/') {
        if (preg_match('/^\\.\\.\\//', $link)) {
            return new Cached_ExternalLink($link, $label);
        }
    } else {
        if (preg_match('/^(\\.\\.\\/|\\/)/', $link)) {
            return new Cached_ExternalLink($link, $label);
        }
    }
    // Handle "[[SandBox|{{image.jpg}}]]" and "[[SandBox|{{image.jpg|alt text}}]]"
    if (string_starts_with($label, "{{")) {
        $imgurl = substr($label, 2, -2);
        // Remove "{{" and "}}"
        $pipe = strpos($imgurl, '|');
        if ($pipe === false) {
            $label = LinkImage(getUploadDataPath() . $imgurl, $link);
        } else {
            list($img, $alt) = explode("|", $imgurl);
            $label = LinkImage(getUploadDataPath() . $img, $alt);
        }
    } else {
        // [label|link]
        // If label looks like a url to an image or object, we want an image link.
        if (isImageLink($label)) {
            $imgurl = $label;
            $intermap = getInterwikiMap();
            if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
                $imgurl = $intermap->link($label);
                $imgurl = $imgurl->getAttr('href');
            } elseif (!preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
                // local theme linkname like 'images/next.gif'.
                global $WikiTheme;
                $imgurl = $WikiTheme->getImageURL($imgurl);
            }
            // for objects (non-images) the link is taken as alt tag,
            // which is in return taken as alternative img
            $label = LinkImage($imgurl, $link);
        }
    }
    if ($hash) {
        // It's an anchor, not a link...
        $id = MangleXmlIdentifier($link);
        return HTML::a(array('name' => $id, 'id' => $id), $bar ? $label : $link);
    }
    if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (isImageLink($link) and empty($label)) {
            // patch #1348996 by Robert Litwiniec
            return LinkImage($link, $label);
        } else {
            return new Cached_ExternalLink($link, $label);
        }
    } elseif (substr($link, 0, 8) == 'phpwiki:') {
        return new Cached_PhpwikiURL($link, $label);
    } elseif (preg_match("/^ (\\w+) (:[:=]) (.*) \$/x", $link) and !isImageLink($link)) {
        return new Cached_SemanticLink($link, $label);
    } elseif (substr($link, 0, 1) == ':') {
        return new Cached_WikiLink($link, $label);
    } elseif (strstr($link, ':') and $intermap = getInterwikiMap() and preg_match("/^" . $intermap->getRegexp() . ":/", $link)) {
        // trigger_error("label: $label link: $link", E_USER_WARNING);
        if (empty($label) and isImageLink($link)) {
            // if without label => inlined image [File:xx.gif]
            $imgurl = $intermap->link($link);
            return LinkImage($imgurl->getAttr('href'), $link);
        }
        return new Cached_InterwikiLink($link, $label);
    } else {
        // Split anchor off end of pagename.
        if (preg_match('/\\A(.*)(?<!' . ESCAPE_CHAR . ')#(.*?)\\Z/', $rawlink, $m)) {
            list(, $rawlink, $anchor) = $m;
            $pagename = UnWikiEscape($rawlink);
            $anchor = UnWikiEscape($anchor);
            if (!$label) {
                $label = $link;
            }
        } else {
            $pagename = $link;
            $anchor = false;
        }
        return new Cached_WikiLink($pagename, $label, $anchor);
    }
}
Beispiel #3
0
 /**
  * HTML widget display
  *
  * This needs to be put in the <body> section of the page.
  *
  * @param pagename    Name of the page to rate
  * @param version     Version of the page to rate (may be "" for current)
  * @param imgPrefix   Prefix of the names of the images that display the rating
  *                    You can have two widgets for the same page displayed at
  *                    once iff the imgPrefix-s are different.
  * @param dimension   Id of the dimension to rate
  * @param small       Makes a smaller ratings widget if non-false
  *
  * Limitations: Currently this can only print the current users ratings.
  *              And only the widget, but no value (for buddies) also.
  */
 function RatingWidgetHtml($pagename, $version, $imgPrefix, $dimension, $small = false)
 {
     global $WikiTheme, $request;
     $imgId = MangleXmlIdentifier($pagename) . $imgPrefix;
     $actionImgName = $imgId . 'RateItAction';
     $dbi =& $GLOBALS['request']->_dbi;
     $version = $dbi->_backend->get_latest_version($pagename);
     //$rdbi =& $this->_rdbi;
     $rdbi = RatingsDb::getTheRatingsDb();
     // check if the imgPrefix icons exist.
     if (!$WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk0.png", true)) {
         $imgPrefix = '';
     }
     // Protect against 's, though not \r or \n
     $reImgPrefix = $this->_javascript_quote_string($imgPrefix);
     $reActionImgName = $this->_javascript_quote_string($actionImgName);
     $rePagename = $this->_javascript_quote_string($pagename);
     //$dimension = $args['pagename'] . "rat";
     $html = HTML::span(array("id" => $imgId));
     for ($i = 0; $i < 2; $i++) {
         $nk[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk" . $i . ".png");
         $none[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Rk" . $i . ".png");
     }
     $user = $request->getUser();
     $userid = $user->getId();
     //if (!isset($args['rating']))
     $rating = $rdbi->getRating($userid, $pagename, $dimension);
     if (!$rating) {
         $pred = $rdbi->getPrediction($userid, $pagename, $dimension);
     }
     for ($i = 1; $i <= 10; $i++) {
         $a1 = HTML::a(array('href' => 'javascript:click(\'' . $reActionImgName . '\',\'' . $rePagename . '\',\'' . $version . '\',\'' . $reImgPrefix . '\',\'' . $dimension . '\',' . $i / 2 . ')'));
         $img_attr = array();
         $img_attr['src'] = $nk[$i % 2];
         //if (!$rating and !$pred)
         //  $img_attr['src'] = $none[$i%2];
         $img_attr['name'] = $imgPrefix . $i;
         $img_attr['alt'] = $img_attr['name'];
         $img_attr['border'] = 0;
         $a1->pushContent(HTML::img($img_attr));
         $a1->addToolTip(_("Rate the topic of this page"));
         $html->pushContent($a1);
         //This adds a space between the rating smilies:
         // if (($i%2) == 0) $html->pushContent(' ');
     }
     $html->pushContent(HTML::Raw('&nbsp;'));
     $a0 = HTML::a(array('href' => 'javascript:click(\'' . $reActionImgName . '\',\'' . $rePagename . '\',\'' . $version . '\',\'' . $reImgPrefix . '\',\'' . $dimension . '\',\'X\')'));
     $msg = _("Cancel rating");
     $a0->pushContent(HTML::img(array('src' => $WikiTheme->getImageUrl("RateIt" . $imgPrefix . "Cancel"), 'name' => $imgPrefix . 'Cancel', 'alt' => $msg)));
     $a0->addToolTip($msg);
     $html->pushContent($a0);
     /*} elseif ($pred) {
           $msg = _("No opinion");
           $html->pushContent(HTML::img(array('src' => $WikiTheme->getImageUrl("RateItCancelN"),
                                              'name'=> $imgPrefix.'Cancel',
                                              'alt' => $msg)));
           //$a0->addToolTip($msg);
           //$html->pushContent($a0);
       }*/
     $img_attr = array();
     $img_attr['src'] = $WikiTheme->_findData("images/RateItAction.png");
     $img_attr['name'] = $actionImgName;
     $img_attr['alt'] = $img_attr['name'];
     //$img_attr['class'] = 'k' . $i;
     $img_attr['border'] = 0;
     $html->pushContent(HTML::img($img_attr));
     // Display the current rating if there is one
     if ($rating) {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',' . $rating . ',0)'));
     } elseif ($pred) {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',' . $pred . ',1)'));
     } else {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',0,0)'));
     }
     return $html;
 }
Beispiel #4
0
function LinkBracketLink($bracketlink)
{
    // $bracketlink will start and end with brackets; in between will
    // be either a page name, a URL or both separated by a pipe.
    // strip brackets and leading space
    // FIXME: \n inside [] will lead to errors
    preg_match('/(\\#?) \\[\\s* (?: (.*?) \\s* (?<!' . ESCAPE_CHAR . ')(\\|) )? \\s* (.+?) \\s*\\]/x', $bracketlink, $matches);
    if (count($matches) < 4) {
        trigger_error(_("Invalid [] syntax ignored") . ": " . $bracketlink, E_USER_WARNING);
        return new Cached_Link();
    }
    list(, $hash, $label, $bar, $rawlink) = $matches;
    $label = UnWikiEscape($label);
    /*
     * Check if the user has typed a explicit URL. This solves the
     * problem where the URLs have a ~ character, which would be stripped away.
     *   "[http:/server/~name/]" will work as expected
     *   "http:/server/~name/"   will NOT work as expected, will remove the ~
     */
    if (strstr($rawlink, "http://") or strstr($rawlink, "https://")) {
        $link = $rawlink;
        // Mozilla Browser URI Obfuscation Weakness 2004-06-14
        //   http://www.securityfocus.com/bid/10532/
        //   goodurl+"%2F%20%20%20."+badurl
        if (preg_match("/%2F(%20)+\\./i", $rawlink)) {
            $rawlink = preg_replace("/%2F(%20)+\\./i", "%2F.", $rawlink);
        }
    } else {
        $link = UnWikiEscape($rawlink);
    }
    /* Relatives links by Joel Schaubert.
     * Recognize [../bla] or [/bla] as relative links, without needing http://
     */
    /* if (preg_match('/^(\.\.\/|\/)/', $link)) {
           return new Cached_ExternalLink($link, $label);
       }*/
    // [label|link]
    // if label looks like a url to an image, we want an image link.
    if (isImageLink($label)) {
        $imgurl = $label;
        $intermap = getInterwikiMap();
        if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
            $imgurl = $intermap->link($label);
            $imgurl = $imgurl->getAttr('href');
        } elseif (!preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
            // local theme linkname like 'images/next.gif'.
            global $WikiTheme;
            $imgurl = $WikiTheme->getImageURL($imgurl);
        }
        $label = LinkImage($imgurl, $link);
    }
    if ($hash) {
        // It's an anchor, not a link...
        $id = MangleXmlIdentifier($link);
        return HTML::a(array('name' => $id, 'id' => $id), $bar ? $label : $link);
    }
    if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (isImageLink($link)) {
            return LinkImage($link, $label);
        } else {
            return new Cached_ExternalLink($link, $label);
        }
    } elseif (preg_match("/^phpwiki:/", $link)) {
        return new Cached_PhpwikiURL($link, $label);
    } elseif (strstr($link, ':') and $intermap = getInterwikiMap() and preg_match("/^" . $intermap->getRegexp() . ":/", $link)) {
        // trigger_error("label: $label link: $link", E_USER_WARNING);
        if (empty($label) and isImageLink($link)) {
            // if without label => inlined image [File:xx.gif]
            $imgurl = $intermap->link($link);
            return LinkImage($imgurl->getAttr('href'), $label);
        }
        return new Cached_InterwikiLink($link, $label);
    } else {
        // Split anchor off end of pagename.
        if (preg_match('/\\A(.*)(?<!' . ESCAPE_CHAR . ')#(.*?)\\Z/', $rawlink, $m)) {
            list(, $rawlink, $anchor) = $m;
            $pagename = UnWikiEscape($rawlink);
            $anchor = UnWikiEscape($anchor);
            if (!$label) {
                $label = $link;
            }
        } else {
            $pagename = $link;
            $anchor = false;
        }
        return new Cached_WikiLink($pagename, $label, $anchor);
    }
}
Beispiel #5
0
/**
 * Generates a valid URL for a given Wiki pagename.
 * @param mixed $pagename If a string this will be the name of the Wiki page to link to.
 * 			  If a WikiDB_Page object function will extract the name to link to.
 * 			  If a WikiDB_PageRevision object function will extract the name to link to.
 * @param array $args
 * @param boolean $get_abs_url Default value is false.
 * @return string The absolute URL to the page passed as $pagename.
 */
function WikiURL($pagename, $args = '', $get_abs_url = false)
{
    global $request, $WikiTheme;
    $anchor = false;
    if (is_object($pagename)) {
        if (isa($pagename, 'WikiDB_Page')) {
            $pagename = $pagename->getName();
        } elseif (isa($pagename, 'WikiDB_PageRevision')) {
            $page = $pagename->getPage();
            $args['version'] = $pagename->getVersion();
            $pagename = $page->getName();
        } elseif (isa($pagename, 'WikiPageName')) {
            $anchor = $pagename->anchor;
            $pagename = $pagename->name;
        } else {
            // php5
            $anchor = $pagename->anchor;
            $pagename = $pagename->name;
        }
    }
    if (!$get_abs_url and DEBUG and $request->getArg('start_debug')) {
        if (!$args) {
            $args = 'start_debug=' . $request->getArg('start_debug');
        } elseif (is_array($args)) {
            $args['start_debug'] = $request->getArg('start_debug');
        } else {
            $args .= '&start_debug=' . $request->getArg('start_debug');
        }
    }
    if (is_array($args)) {
        $enc_args = array();
        foreach ($args as $key => $val) {
            // avoid default args
            if (USE_PATH_INFO and $key == 'pagename') {
            } elseif ($key == 'action' and $val == 'browse') {
            } elseif (!is_array($val)) {
                // ugly hack for getURLtoSelf() which also takes POST vars
                $enc_args[] = urlencode($key) . '=' . urlencode($val);
            }
        }
        $args = join('&', $enc_args);
    }
    if (USE_PATH_INFO or !empty($WikiTheme->HTML_DUMP_SUFFIX)) {
        $url = $get_abs_url ? SERVER_URL . VIRTUAL_PATH . "/" : "";
        $base = preg_replace('/%2f/i', '/', rawurlencode($pagename));
        $url .= $base;
        if (!empty($WikiTheme->HTML_DUMP_SUFFIX)) {
            if (!empty($WikiTheme->VALID_LINKS) and $request->getArg('action') == 'pdf') {
                if (!in_array($pagename, $WikiTheme->VALID_LINKS)) {
                    $url = '';
                } else {
                    $url = $base . $WikiTheme->HTML_DUMP_SUFFIX;
                }
            } else {
                $url .= $WikiTheme->HTML_DUMP_SUFFIX;
                if ($args) {
                    $url .= "?{$args}";
                }
            }
        } else {
            if ($args) {
                $url .= "?{$args}";
            }
        }
    } else {
        $url = $get_abs_url ? SERVER_URL . SCRIPT_NAME : basename(SCRIPT_NAME);
        $url .= "?pagename=" . rawurlencode($pagename);
        if ($args) {
            $url .= "&{$args}";
        }
    }
    if ($anchor) {
        $url .= "#" . MangleXmlIdentifier($anchor);
    }
    return $url;
}
Beispiel #6
0
 function run($dbi, $argstr, $request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     $caption = _("All pages with all links in this wiki (%d total):");
     if (!empty($args['owner'])) {
         $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], $args['limit']);
         if ($args['owner']) {
             $caption = fmt("List of pages owned by [%s] (%d total):", WikiLink($args['owner'], 'if_known'), count($pages));
         }
     } elseif (!empty($args['author'])) {
         $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], $args['limit']);
         if ($args['author']) {
             $caption = fmt("List of pages last edited by [%s] (%d total):", WikiLink($args['author'], 'if_known'), count($pages));
         }
     } elseif (!empty($args['creator'])) {
         $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], $args['limit']);
         if ($args['creator']) {
             $caption = fmt("List of pages created by [%s] (%d total):", WikiLink($args['creator'], 'if_known'), count($pages));
         }
     } else {
         if (!$request->getArg('count')) {
             $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude_from']);
         } else {
             $args['count'] = $request->getArg('count');
         }
         $pages = $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit'], $args['exclude_from']);
     }
     if ($args['format'] == 'html') {
         $args['types']['links'] = new _PageList_Column_LinkDatabase_links('links', _("Links"), 'left');
         $pagelist = new PageList($args['info'], $args['exclude_from'], $args);
         if (!$args['noheader']) {
             $pagelist->setCaption($caption);
         }
         return $pagelist;
     } elseif ($args['format'] == 'text') {
         $request->discardOutput();
         $request->buffer_output(false);
         if (!headers_sent()) {
             header("Content-Type: text/plain");
         }
         $request->checkValidators();
         while ($page = $pages->next()) {
             echo $page->getName();
             $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
             while ($link = $links->next()) {
                 echo " ", $link->getName();
             }
             echo "\n";
         }
         flush();
         if (empty($WikiTheme->DUMP_MODE)) {
             $request->finish();
         }
     } elseif ($args['format'] == 'xml') {
         // For hypergraph.jar. Best dump it to a local sitemap.xml periodically
         global $WikiTheme, $charset;
         $currpage = $request->getArg('pagename');
         $request->discardOutput();
         $request->buffer_output(false);
         if (!headers_sent()) {
             header("Content-Type: text/xml");
         }
         $request->checkValidators();
         echo "<?xml version=\"1.0\" encoding=\"{$charset}\"?>";
         // As applet it prefers only "GraphXML.dtd", but then we must copy it to the webroot.
         $dtd = $WikiTheme->_findData("GraphXML.dtd");
         echo "<!DOCTYPE GraphXML SYSTEM \"{$dtd}\">\n";
         echo "<GraphXML xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
         echo "<graph id=\"", MangleXmlIdentifier(WIKI_NAME), "\">\n";
         echo '<style><line tag="node" class="main" colour="#ffffff"/><line tag="node" class="child" colour="blue"/><line tag="node" class="relation" colour="green"/></style>', "\n\n";
         while ($page = $pages->next()) {
             $pageid = MangleXmlIdentifier($page->getName());
             $pagename = $page->getName();
             echo "<node name=\"{$pageid}\"";
             if ($pagename == $currpage) {
                 echo " class=\"main\"";
             }
             echo "><label>{$pagename}</label>";
             echo "<dataref><ref xlink:href=\"", WikiURL($pagename, '', true), "\"/></dataref></node>\n";
             $links = $page->getPageLinks(false, $args['sortby'], $args['limit'], $args['exclude']);
             while ($link = $links->next()) {
                 $edge = MangleXmlIdentifier($link->getName());
                 echo "<edge source=\"{$pageid}\" target=\"{$edge}\" />\n";
             }
             echo "\n";
         }
         echo "</graph>\n";
         echo "</GraphXML>\n";
         if (empty($WikiTheme->DUMP_MODE)) {
             unset($GLOBALS['ErrorManager']->_postponed_errors);
             $request->finish();
         }
     } else {
         return $this->error(fmt("Unsupported format argument %s", $args['format']));
     }
 }
Beispiel #7
0
 function extractHeaders(&$content, &$markup, $backlink = 0, $counter = 0, $levels = false, $basepage = '')
 {
     if (!$levels) {
         $levels = array(1, 2);
     }
     $tocCounter = $this->_initTocCounter();
     reset($levels);
     sort($levels);
     $headers = array();
     $j = 0;
     for ($i = 0; $i < count($content); $i++) {
         foreach ($levels as $level) {
             if ($level < 1 or $level > 3) {
                 continue;
             }
             if (preg_match('/^\\s*(!{' . $level . ',' . $level . '})([^!].*)$/', $content[$i], $match)) {
                 $this->_tocCounter($tocCounter, $level);
                 if (!strstr($content[$i], '#[')) {
                     $s = trim($match[2]);
                     // Remove escape char from toc titles.
                     $s = str_replace('~', '', $s);
                     $anchor = $this->_nextAnchor($s);
                     $manchor = MangleXmlIdentifier($anchor);
                     $texts = $s;
                     if ($counter) {
                         $texts = $this->_getCounter($tocCounter, $level) . ' - ' . $s;
                     }
                     $headers[] = array('text' => $texts, 'anchor' => $anchor, 'level' => $level);
                     // Change original wikitext, but that is useless art...
                     $content[$i] = $match[1] . " #[|{$manchor}][{$s}|#TOC]";
                     // And now change the to be printed markup (XmlTree):
                     // Search <hn>$s</hn> line in markup
                     /* Url for backlink */
                     $url = WikiURL(new WikiPageName($basepage, false, "TOC"));
                     $j = $this->searchHeader($markup->_content, $j, $s, $match[1], $hstart, $hend, $markup->_basepage);
                     if ($j and isset($markup->_content[$j])) {
                         $x = $markup->_content[$j];
                         $qheading = $this->_quote($s);
                         if ($counter) {
                             $counterString = $this->_getCounter($tocCounter, $level);
                         }
                         if ($hstart === 0 && is_string($markup->_content[$j])) {
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "<a href=\"{$url}\" name=\"{$manchor}\">{$counterString}</a> - \$2";
                                 } else {
                                     $anchorString = "<a href=\"{$url}\" name=\"{$manchor}\">\$2</a>";
                                 }
                             } else {
                                 $anchorString = "<a name=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             if ($x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$2\$3", $x, 1)) {
                                 if ($backlink) {
                                     $x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$3", $markup->_content[$j], 1);
                                 }
                                 $markup->_content[$j] = $x;
                             }
                         } else {
                             $x = $markup->_content[$hstart];
                             $h = $this->_getHeader($match[1]);
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "\$1<a href=\"{$url}\" name=\"{$manchor}\">{$counterString}</a> - ";
                                 } else {
                                     /* Not possible to make a backlink on a
                                      * title with a WikiWord */
                                     $anchorString = "\$1<a name=\"{$manchor}\"></a>";
                                 }
                             } else {
                                 $anchorString = "\$1<a name=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $x, 1);
                             if ($backlink) {
                                 $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $markup->_content[$hstart], 1);
                             }
                             $markup->_content[$hstart] = $x;
                         }
                     }
                 }
             }
         }
     }
     return $headers;
 }
Beispiel #8
0
 function extractHeaders(&$content, &$markup, $backlink = 0, $counter = 0, $levels = false, $firstlevelstyle = 'number', $basepage = '')
 {
     if (!$levels) {
         $levels = array(1, 2);
     }
     $tocCounter = $this->_initTocCounter();
     reset($levels);
     sort($levels);
     $headers = array();
     $j = 0;
     $insidetable = false;
     for ($i = 0; $i < count($content); $i++) {
         if (preg_match('/^\\s*{\\|/', $content[$i])) {
             $insidetable = true;
             continue;
         }
         if (preg_match('/^\\s*\\|}/', $content[$i])) {
             $insidetable = false;
             continue;
         }
         if ($insidetable) {
             continue;
         }
         foreach ($levels as $level) {
             if ($level < 1 or $level > 5) {
                 continue;
             }
             $phpwikiclassiclevel = 4 - $level;
             $wikicreolelevel = $level + 1;
             $trim = trim($content[$i]);
             if (strpos($trim, '=') === 0 && preg_match('/^\\s*(={' . $wikicreolelevel . ',' . $wikicreolelevel . '})([^=].*)$/', $content[$i], $match) or strpos($trim, '!') === 0 && preg_match('/^\\s*(!{' . $phpwikiclassiclevel . ',' . $phpwikiclassiclevel . '})([^!].*)$/', $content[$i], $match)) {
                 $this->_tocCounter($tocCounter, $level);
                 if (!strstr($content[$i], '#[')) {
                     $s = trim($match[2]);
                     // If it is Wikicreole syntax, remove '='s at the end
                     if (string_starts_with($match[1], "=")) {
                         $s = trim($s, "=");
                         $s = trim($s);
                     }
                     $anchor = $this->_nextAnchor($s);
                     $manchor = MangleXmlIdentifier($anchor);
                     $texts = $s;
                     if ($counter) {
                         $texts = $this->_getCounter($tocCounter, $level, $firstlevelstyle) . ' ' . $s;
                     }
                     $headers[] = array('text' => $texts, 'anchor' => $anchor, 'level' => $level);
                     // Change original wikitext, but that is useless art...
                     $content[$i] = $match[1] . " #[|{$manchor}][{$s}|#TOC]";
                     // And now change the to be printed markup (XmlTree):
                     // Search <hn>$s</hn> line in markup
                     /* Url for backlink */
                     $url = WikiURL(new WikiPageName($basepage, false, "TOC"));
                     $j = $this->searchHeader($markup->_content, $j, $s, $match[1], $hstart, $hend, $markup->_basepage);
                     if ($j and isset($markup->_content[$j])) {
                         $x = $markup->_content[$j];
                         $qheading = $this->_quote($s);
                         if ($counter) {
                             $counterString = $this->_getCounter($tocCounter, $level, $firstlevelstyle);
                         }
                         if ($hstart === 0 && is_string($markup->_content[$j])) {
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "<a href=\"{$url}\" id=\"{$manchor}\">{$counterString}</a> - \$2";
                                 } else {
                                     $anchorString = "<a href=\"{$url}\" id=\"{$manchor}\">\$2</a>";
                                 }
                             } else {
                                 $anchorString = "<a id=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             if ($x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$2\$3", $x, 1)) {
                                 if ($backlink) {
                                     $x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$3", $markup->_content[$j], 1);
                                 }
                                 $markup->_content[$j] = $x;
                             }
                         } else {
                             $x = $markup->_content[$hstart];
                             $h = $this->_getHeader($match[1]);
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "\$1<a href=\"{$url}\" id=\"{$manchor}\">{$counterString}</a> - ";
                                 } else {
                                     /* Not possible to make a backlink on a
                                      * title with a WikiWord */
                                     $anchorString = "\$1<a id=\"{$manchor}\"></a>";
                                 }
                             } else {
                                 $anchorString = "\$1<a id=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $x, 1);
                             if ($backlink) {
                                 $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $markup->_content[$hstart], 1);
                             }
                             $markup->_content[$hstart] = $x;
                         }
                     }
                 }
             }
         }
     }
     return $headers;
 }