Esempio n. 1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (empty($page) && empty($prefix) && empty($suffix)) {
         return '';
     }
     if ($prefix) {
         $suffix = false;
         $descrip = fmt("Page names with prefix '%s'", $prefix);
     } elseif ($suffix) {
         $descrip = fmt("Page names with suffix '%s'", $suffix);
     } elseif ($page) {
         $words = preg_split('/[\\s:-;.,]+/', SplitPagename($page));
         $words = preg_grep('/\\S/', $words);
         $prefix = reset($words);
         $suffix = end($words);
         $descrip = fmt("These pages share an initial or final title word with '%s'", WikiLink($page, 'auto'));
     }
     // Search for pages containing either the suffix or the prefix.
     $search = $match = array();
     if (!empty($prefix)) {
         $search[] = $this->_quote($prefix);
         $match[] = '^' . preg_quote($prefix, '/');
     }
     if (!empty($suffix)) {
         $search[] = $this->_quote($suffix);
         $match[] = preg_quote($suffix, '/') . '$';
     }
     if ($search) {
         $query = new TextSearchQuery(join(' OR ', $search));
     } else {
         $query = new NullTextSearchQuery();
     }
     // matches nothing
     $match_re = '/' . join('|', $match) . '/';
     $pagelist = new PageList($info, $exclude, $args);
     if (!$noheader) {
         $pagelist->setCaption($descrip);
     }
     $pages = $dbi->titleSearch($query);
     while ($page = $pages->next()) {
         $name = $page->getName();
         if (!preg_match($match_re, $name)) {
             continue;
         }
         $pagelist->addPage($page);
     }
     return $pagelist;
 }
Esempio n. 2
0
 function box($args = false, $request = false, $basepage = false)
 {
     if (!$request) {
         $request =& $GLOBALS['request'];
     }
     if (!isset($args['limit'])) {
         $args['limit'] = 15;
     }
     $args['format'] = 'box';
     $args['show_minor'] = false;
     $args['show_major'] = true;
     $args['show_deleted'] = 'sometimes';
     $args['show_all'] = false;
     $args['days'] = 90;
     return $this->makeBox(WikiLink($this->getName(), '', SplitPagename($this->getName())), $this->format($this->getChanges($request->_dbi, $args), $args));
 }
Esempio n. 3
0
 function item_properties($rev)
 {
     $page = $rev->getPage();
     $pagename = $page->getName();
     return array('title' => SplitPagename($pagename), 'description' => $this->summary($rev), 'link' => $this->pageURL($rev));
 }
Esempio n. 4
0
function displayPage(&$request, $template = false)
{
    global $WikiTheme, $pv;
    $pagename = $request->getArg('pagename');
    $version = $request->getArg('version');
    $page = $request->getPage();
    if ($version) {
        $revision = $page->getRevision($version);
        if (!$revision) {
            NoSuchRevision($request, $page, $version);
        }
    } else {
        $revision = $page->getCurrentRevision();
    }
    if (isSubPage($pagename)) {
        $pages = explode(SUBPAGE_SEPARATOR, $pagename);
        $last_page = array_pop($pages);
        // deletes last element from array as side-effect
        $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
        $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
        array_shift($pages);
        foreach ($pages as $p) {
            if ($pv != 2) {
                //Add the Backlink in page title
                $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
            } else {
                // Remove Backlinks
                $pageheader->pushContent(HTML::h1($pagename));
            }
            $first_pages .= $p . SUBPAGE_SEPARATOR;
        }
        if ($pv != 2) {
            $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page));
            $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        } else {
            $backlink = HTML::h1($pagename);
        }
        $pageheader->pushContent($backlink);
    } else {
        if ($pv != 2) {
            $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename));
            $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        } else {
            $pageheader = HTML::h1($pagename);
            //Remove Backlinks
        }
        if ($request->getArg('frame')) {
            $pageheader->setAttr('target', '_top');
        }
    }
    // {{{ Codendi hook to insert stuff between navbar and header
    $eM =& EventManager::instance();
    $ref_html = '';
    $crossref_fact = new CrossReferenceFactory($pagename, ReferenceManager::REFERENCE_NATURE_WIKIPAGE, GROUP_ID);
    $crossref_fact->fetchDatas();
    if ($crossref_fact->getNbReferences() > 0) {
        $ref_html .= '<h3>' . $GLOBALS['Language']->getText('cross_ref_fact_include', 'references') . '</h3>';
        $ref_html .= $crossref_fact->getHTMLDisplayCrossRefs();
    }
    $additional_html = false;
    $eM->processEvent('wiki_before_content', array('html' => &$additional_html, 'group_id' => GROUP_ID, 'wiki_page' => $pagename));
    if ($additional_html) {
        $beforeHeader = HTML();
        $beforeHeader->pushContent($additional_html);
        $beforeHeader->pushContent(HTML::raw($ref_html));
        $toks['BEFORE_HEADER'] = $beforeHeader;
    } else {
        $beforeHeader = HTML();
        $beforeHeader->pushContent(HTML::raw($ref_html));
        $toks['BEFORE_HEADER'] = $beforeHeader;
    }
    // }}} /Codendi hook
    $pagetitle = SplitPagename($pagename);
    if ($redirect_from = $request->getArg('redirectfrom')) {
        $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from)));
        // abuse the $redirected template var for some status update notice
    } elseif ($request->getArg('errormsg')) {
        $redirect_message = $request->getArg('errormsg');
        $request->setArg('errormsg', false);
    }
    $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime')));
    /*
        // FIXME: This is also in the template...
        if ($request->getArg('action') != 'pdf' and !headers_sent()) {
          // FIXME: enable MathML/SVG/... support
          if (ENABLE_XHTML_XML
                 and (!isBrowserIE()
                      and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
                header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
            else
                header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
        }
    */
    $page_content = $revision->getTransformedContent();
    // if external searchengine (google) referrer, highlight the searchterm
    // FIXME: move that to the transformer?
    // OR: add the searchhightplugin line to the content?
    if ($result = isExternalReferrer($request)) {
        if (DEBUG and !empty($result['query'])) {
            //$GLOBALS['SearchHighlightQuery'] = $result['query'];
            /* simply add the SearchHighlight plugin to the top of the page. 
               This just parses the wikitext, and doesn't highlight the markup */
            include_once 'lib/WikiPlugin.php';
            $loader = new WikiPluginLoader();
            $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup);
            if ($xml and is_array($xml)) {
                foreach (array_reverse($xml) as $line) {
                    array_unshift($page_content->_content, $line);
                }
                array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query'])));
            }
            if (0) {
                /* Parse the transformed (mixed HTML links + strings) lines?
                     This looks like overkill.
                   */
                require_once "lib/TextSearchQuery.php";
                $query = new TextSearchQuery($result['query']);
                $hilight_re = $query->getHighlightRegexp();
                //$matches = preg_grep("/$hilight_re/i", $revision->getContent());
                // FIXME!
                for ($i = 0; $i < count($page_content->_content); $i++) {
                    $found = false;
                    $line = $page_content->_content[$i];
                    if (is_string($line)) {
                        while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) {
                            $found = true;
                            $line = substr($line, strlen($m[0]));
                            $html[] = $m[1];
                            // prematch
                            $html[] = HTML::strong(array('class' => 'search-term'), $m[2]);
                            // match
                        }
                    }
                    if ($found) {
                        $html[] = $line;
                        // postmatch
                        $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html);
                    }
                }
            }
        }
    }
    $toks['CONTENT'] = new Template('browse', $request, $page_content);
    $toks['TITLE'] = $pagetitle;
    // <title> tag
    $toks['HEADER'] = $pageheader;
    // h1 with backlink
    $toks['revision'] = $revision;
    if (!empty($redirect_message)) {
        $toks['redirected'] = $redirect_message;
    }
    $toks['ROBOTS_META'] = 'index,follow';
    $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
    $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
    if (!$template) {
        $template = new Template('html', $request);
    }
    $template->printExpansion($toks);
    $page->increaseHitCount();
    if ($request->getArg('action') != 'pdf') {
        $request->checkValidators();
    }
    flush();
}
Esempio n. 5
0
/**
 * For dumping pages as html to a file.
 */
function GeneratePageasXML($content, $title, $page_revision = false, $args = false)
{
    global $request;
    if (!is_array($args)) {
        $args = array();
    }
    $content->_basepage = $title;
    $args['CONTENT'] = $content;
    $args['TITLE'] = SplitPagename($title);
    $args['revision'] = $page_revision;
    if (!isset($args['HEADER'])) {
        $args['HEADER'] = SplitPagename($title);
    }
    global $HIDE_TOOLBARS, $NO_BASEHREF, $HTML_DUMP;
    $HIDE_TOOLBARS = true;
    $HTML_DUMP = true;
    $html = asXML(new Template('htmldump', $request, $args));
    $HIDE_TOOLBARS = false;
    $HTML_DUMP = false;
    return $html;
}
Esempio n. 6
0
 function channel_properties()
 {
     global $request;
     $rc_url = WikiURL($request->getArg('pagename'), false, 'absurl');
     $title = sprintf(_("%s: %s"), WIKI_NAME, SplitPagename($this->_args['page']));
     return array('title' => $title, 'dc:description' => _("History of changes."), 'link' => $rc_url, 'dc:date' => Iso8601DateTime(time()));
 }
Esempio n. 7
0
 function maybeSplitWikiWord($wikiword)
 {
     if ($this->_autosplitWikiWords) {
         return SplitPagename($wikiword);
     } else {
         return $wikiword;
     }
 }
Esempio n. 8
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if ($pageTextLabel == null && $category != null && $group == null) {
         $group = $category;
     }
     if ($category == null || $pageTextLabel == null) {
         return HTML::div(array('class' => "error"), "PreferencesApp Error: You must declare at least parameters category and pageTextLabel.");
     }
     $dbi = $request->getDbh();
     $rdbi = RatingsDb::getTheRatingsDb();
     $CATEGORY = $category;
     $PAGE_TEXT_LABEL = $pageTextLabel;
     $NEUTRAL_RATING = (int) $neutralRating;
     $active_user = $request->getUser();
     $active_userid = $active_user->_userid;
     $html = HTML();
     $html->pushContent("");
     //Load participating Users
     $users_array = array();
     if ($group != null) {
         $users_array = getMembers($group, $rdbi);
     } else {
         $people_iter = $rdbi->sql_get_users_rated();
         while ($people_array = $people_iter->next()) {
             $users_array[] = $people_array['pagename'];
         }
     }
     $people = array();
     foreach ($users_array as $person_indv) {
         if ($declareBudget == "true") {
             $get_array = getPageTextData($person_indv, $dbi, $PAGE_TEXT_LABEL, "cans");
             if (count($get_array) == 1) {
                 $cans_text = $get_array[0];
                 if (is_numeric($cans_text) && $cans_text >= 0) {
                     $canBudget[$person_indv] = $cans_text;
                     //Load the persons budget
                 } else {
                     $canBudget[$person_indv] = 0;
                 }
                 $people[] = $person_indv;
             }
         } else {
             $canBudget[$person_indv] = $lockedBudget;
             $people[] = $person_indv;
         }
     }
     if (count($people) < 1) {
         return fmt("Nobody has used %s on their homepage", $PAGE_TEXT_LABEL);
     }
     //Get all pages from Category
     $pageids = array();
     $category_page = $dbi->getPage($CATEGORY);
     $iter = $category_page->getLinks();
     while ($item = $iter->next()) {
         array_push($pageids, $item->getName());
     }
     $ratingTotals = array();
     foreach ($people as $person) {
         $ratings_iter = $rdbi->sql_get_rating(0, $person, $pageids);
         $ratingTotals[$person] = 0;
         while ($ratings_array = $ratings_iter->next()) {
             $can_rating = $ratings_array['ratingvalue'];
             if ($can_rating >= $NEUTRAL_RATING) {
                 $ratingTotals[$person] += $can_rating;
             }
         }
     }
     //Generate numbers
     $canTotals = array();
     $peopleTotals = array();
     foreach ($pageids as $soda) {
         $canTotals[$soda] = 0;
     }
     foreach ($people as $person) {
         foreach ($pageids as $soda) {
             $peopleTotals[$person][$soda] = 0;
         }
     }
     foreach ($people as $person) {
         foreach ($pageids as $page) {
             $can_rating_iter = $rdbi->sql_get_rating(0, $person, $page);
             $can_rating_array = $can_rating_iter->next();
             $can_rating = $can_rating_array['ratingvalue'];
             if ($can_rating >= $NEUTRAL_RATING) {
                 $calc = $can_rating / $ratingTotals[$person] * $canBudget[$person];
                 if ($roundCalc == "true") {
                     $adjustedCans = round($calc);
                 } else {
                     $adjustedCans = round($calc, 2);
                 }
                 $peopleTotals[$person][$page] = $adjustedCans;
                 $canTotals[$page] = $canTotals[$page] + $adjustedCans;
             }
         }
     }
     $outputArray = array();
     foreach ($people as $person) {
         foreach ($pageids as $page) {
             $outputArray[$person][$page] = 0;
         }
     }
     $table = HTML::table(array('cellpadding' => '5', 'cellspacing' => '1', 'border' => '0'));
     $tr = HTML::tr();
     $td = HTML::td(array('bgcolor' => '#FFFFFF'));
     $td->pushContent(" ");
     $tr->pushContent($td);
     foreach ($people as $person) {
         $td = HTML::td(array('bgcolor' => '#FFFFFF'));
         $td->pushContent(HTML::a(array('href' => WikiURL($person), 'class' => 'wiki'), SplitPagename($person)));
         //$td->pushContent(WikiLink(" $person "));
         $tr->pushContent($td);
     }
     $td = HTML::td(array('bgcolor' => '#FFFFFF'));
     $td->pushContent(_("Total Units"));
     $tr->pushContent($td);
     $td = HTML::td(array('bgcolor' => '#FFFFFF'));
     $td->pushContent(_("Total Voters"));
     $tr->pushContent($td);
     $table->pushContent($tr);
     for ($i = 0; $i < count($pageids); $i++) {
         $total_cans = 0;
         for ($j = 0; $j < count($people); $j++) {
             $td = HTML::td(array('align' => 'right'));
             $cans_per_soda = $peopleTotals[$people[$j]][$pageids[$i]];
             $total_cans = $total_cans + $cans_per_soda;
             $outputArray[$people[$j]][$pageids[$i]] = $cans_per_soda;
         }
     }
     foreach ($people as $person) {
         $min_soda = "";
         $min_cans = 9999999;
         //9 million, serving as "infinity"
         $total_cans = 0;
         foreach ($pageids as $page) {
             $cur_soda_cans = $outputArray[$person][$page];
             if ($cur_soda_cans < $min_cans && $cur_soda_cans > 0) {
                 $min_cans = $cur_soda_cans;
                 $min_soda = $page;
             }
             $total_cans = $total_cans + $cur_soda_cans;
         }
         if ($total_cans != $canBudget[$person] && $total_cans > 0) {
             $diff = $canBudget[$person] - $total_cans;
             $outputArray[$person][$min_soda] = $outputArray[$person][$min_soda] + $diff;
         }
     }
     for ($i = 0; $i < count($pageids); $i++) {
         $tr = HTML::tr();
         $td = HTML::td(array('align' => 'left', 'bgcolor' => '#f7f7f7'));
         $td->pushContent(HTML::a(array('href' => WikiURL($pageids[$i]), 'class' => 'wiki'), SplitPagename($pageids[$i])));
         $tr->pushContent($td);
         $total_cans = 0;
         $total_voters = 0;
         for ($j = 0; $j < count($people); $j++) {
             $td = HTML::td(array('align' => 'right', 'bgcolor' => '#f7f7f7'));
             $output = $outputArray[$people[$j]][$pageids[$i]];
             $total_cans = $total_cans + $output;
             if ($output == "") {
                 $output = "-";
             } else {
                 $total_voters++;
             }
             $td->pushContent($output);
             $tr->pushContent($td);
         }
         if ($total_cans == "") {
             $total_cans = "-";
         }
         if ($total_voters == "") {
             $total_voters = "-";
         }
         $td = HTML::td(array('align' => 'right'));
         $td->pushContent($total_cans);
         $tr->pushContent($td);
         $td = HTML::td(array('align' => 'right'));
         $td->pushContent($total_voters);
         $tr->pushContent($td);
         $table->pushContent($tr);
     }
     $tr = HTML::tr();
     $td = HTML::td(array('align' => 'left'));
     $td->pushContent(HTML::strong(_("Total Budget")));
     $tr->pushContent($td);
     $cans_total = 0;
     $total_voters = 0;
     for ($i = 0; $i < count($people); $i++) {
         $td = HTML::td(array('align' => 'right'));
         $cans_for_soda = 0;
         foreach ($pageids as $page) {
             $cans_for_soda = $cans_for_soda + $outputArray[$people[$i]][$page];
         }
         $cans = $cans_for_soda;
         $cans_total = $cans_total + $cans;
         if ($cans == "") {
             $cans = "-";
         } else {
             $total_voters++;
         }
         $td->pushContent(HTML::strong($cans));
         $tr->pushContent($td);
     }
     $td = HTML::td(array('align' => 'right'));
     $td->pushContent(HTML::strong($cans_total));
     $tr->pushContent($td);
     $td = HTML::td(array('align' => 'right'));
     $td->pushContent(HTML::strong($total_voters));
     $tr->pushContent($td);
     $table->pushContent($tr);
     $table2 = HTML::table(array('bgcolor' => '#dedfdf'));
     $table2->pushContent(HTML::tr(HTML::td($table)));
     $html->pushContent($table2);
     return $html;
 }
Esempio n. 9
0
function displayPage(&$request, $template = false)
{
    global $WikiTheme;
    global $robots;
    $pagename = $request->getArg('pagename');
    $version = $request->getArg('version');
    $page = $request->getPage();
    if ($version) {
        $revision = $page->getRevision($version);
        if (!$revision) {
            NoSuchRevision($request, $page, $version);
        }
        /* Tell Google (and others) to ignore old versions of pages */
        $robots = "noindex,nofollow";
        $toks['ROBOTS_META'] = $robots;
    } else {
        $revision = $page->getCurrentRevision();
    }
    $format = $request->getArg('format');
    if ($format == 'xml') {
        // fast ajax: include page content asynchronously
        global $charset;
        header("Content-Type: text/xml");
        echo "<", "?xml version=\"1.0\" encoding=\"{$charset}\"?", ">\n";
        // DOCTYPE html needed to allow unencoded entities like &nbsp; without !CDATA[]
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n";
        if ($page->exists()) {
            header("Last-Modified: " . Rfc1123DateTime($revision->get('mtime')));
            $request->cacheControl();
            $request->setArg('format', '');
            $page_content = $revision->getTransformedContent();
            $page_content->printXML();
            $request->_is_buffering_output = false;
            // avoid wrong Content-Length with errors
            $request->finish();
        } else {
            $request->cacheControl();
            echo '<div style="display:none;" />';
            $request->_is_buffering_output = false;
            // avoid wrong Content-Length with errors
            $request->finish();
            exit;
        }
    }
    if (isSubPage($pagename)) {
        $pages = explode(SUBPAGE_SEPARATOR, $pagename);
        $last_page = array_pop($pages);
        // deletes last element from array as side-effect
        $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
        $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
        array_shift($pages);
        foreach ($pages as $p) {
            $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
            $first_pages .= $p . SUBPAGE_SEPARATOR;
        }
        $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page));
        $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        $pageheader->pushContent($backlink);
    } else {
        $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename));
        $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        if ($request->getArg('frame')) {
            $pageheader->setAttr('target', '_top');
        }
    }
    $pagetitle = SplitPagename($pagename);
    if ($redirect_from = $request->getArg('redirectfrom')) {
        $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from)));
        // abuse the $redirected template var for some status update notice
    } elseif ($request->getArg('errormsg')) {
        $redirect_message = $request->getArg('errormsg');
        $request->setArg('errormsg', false);
    }
    $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime')));
    /*
        // FIXME: This is also in the template...
        if ($request->getArg('action') != 'pdf' and !headers_sent()) {
          // FIXME: enable MathML/SVG/... support
          if (ENABLE_XHTML_XML
                 and (!isBrowserIE()
                      and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
                header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
            else
                header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
        }
    */
    $toks['TITLE'] = $pagetitle;
    // <title> tag
    $toks['HEADER'] = $pageheader;
    // h1 with backlink
    $toks['revision'] = $revision;
    // On external searchengine (google) referrer, highlight the searchterm and
    // pass through the Searchhighlight actionpage.
    if ($result = isExternalReferrer($request)) {
        if (!empty($result['query'])) {
            if (ENABLE_SEARCHHIGHLIGHT) {
                $request->_searchhighlight = $result;
                $request->appendValidators(array('%mtime' => time()));
                // force no cache(?)
                // Should be changed to check the engine and search term only
                // $request->setArg('nocache', 1);
                $page_content = new TransformedText($revision->getPage(), $revision->getPackedContent(), $revision->getMetaData());
                /* Now add the SearchHighlight plugin to the top of the page, in memory only.
                		   You can parametrize this by changing the SearchHighlight action page.
                		*/
                if ($actionpage = $request->findActionPage('SearchHighlight')) {
                    $actionpage = $request->getPage($actionpage);
                    $actionrev = $actionpage->getCurrentRevision();
                    $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
                    $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime')));
                    $toks['SEARCH_ENGINE'] = $result['engine'];
                    $toks['SEARCH_ENGINE_URL'] = $result['engine_url'];
                    $toks['SEARCH_TERM'] = $result['query'];
                    //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink
                    $actioncontent = new TransformedText($actionrev->getPage(), $actionrev->getPackedContent(), $actionrev->getMetaData());
                    // prepend the actionpage in front of the hightlighted content
                    $toks['CONTENT'] = HTML($actioncontent, $page_content);
                }
            }
        } else {
            $page_content = $revision->getTransformedContent();
        }
    } else {
        $page_content = $revision->getTransformedContent();
    }
    /* Check for special pagenames, which are no actionpages. */
    /*
    if ( $pagename == _("RecentVisitors")) {
        $robots = "noindex,follow";
        $toks['ROBOTS_META'] = $robots;
    } else
    */
    if ($pagename == _("SandBox")) {
        $robots = "noindex,nofollow";
        $toks['ROBOTS_META'] = $robots;
    } else {
        if (isActionPage($pagename)) {
            // AllPages must not be indexed, but must be followed to get all pages
            $robots = "noindex,follow";
            $toks['ROBOTS_META'] = $robots;
        } else {
            if (!isset($toks['ROBOTS_META'])) {
                $robots = "index,follow";
                $toks['ROBOTS_META'] = $robots;
            }
        }
    }
    if (!isset($toks['CONTENT'])) {
        $toks['CONTENT'] = new Template('browse', $request, $page_content);
    }
    if (!empty($redirect_message)) {
        $toks['redirected'] = $redirect_message;
    }
    // Massive performance problem parsing at run-time into all xml objects
    // looking for p's. Should be optional, if not removed at all.
    //$toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
    $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
    if (!$template) {
        $template = new Template('html', $request);
    }
    // Handle other formats: So far we had html only.
    // xml is requested by loaddump, rss is handled by RecentChanges,
    // pdf is a special action, but should be a format to dump multiple pages
    // if the actionpage plugin returns a pagelist.
    // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb.
    /* Only single page versions. rss only if not already handled by RecentChanges.
     */
    if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') {
        $template->printExpansion($toks);
    } else {
        // No pagelist here. Single page version only
        require_once "lib/PageList.php";
        $pagelist = new PageList();
        $pagelist->addPage($page);
        if ($format == 'pdf') {
            require_once "lib/pdf.php";
            $request->setArg('format', '');
            ConvertAndDisplayPdfPageList($request, $pagelist);
            // time-sorted rdf a la RecentChanges
        } elseif (in_array($format, array("rss91", "rss2", "rss", "atom"))) {
            //$request->setArg('format','');
            if ($pagename == _("RecentChanges")) {
                $template->printExpansion($toks);
            } else {
                require_once "lib/plugin/RecentChanges.php";
                $plugin = new WikiPlugin_RecentChanges();
                $args = $request->getArgs();
                return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
            }
        } elseif ($format == 'rdf') {
            // all semantic relations and attributes
            require_once "lib/SemanticWeb.php";
            $rdf = new RdfWriter($request, $pagelist);
            $rdf->format();
        } elseif ($format == 'owl') {
            // or daml?
            require_once "lib/SemanticWeb.php";
            $rdf = new OwlWriter($request, $pagelist);
            $rdf->format();
        } elseif ($format == 'json') {
            // include page content asynchronously
            $request->setArg('format', '');
            if ($page->exists()) {
                $content = $page_content->asXML();
            } else {
                $content = '';
            }
            $req_args = $request->args;
            unset($req_args['format']);
            // no meta-data so far, just the content
            $json = array('content' => $content, 'args' => $req_args, 'phpwiki-version' => PHPWIKI_VERSION);
            if (loadPhpExtension('json')) {
                $json_enc = json_encode($json);
            } else {
                require_once "lib/pear/JSON.php";
                $j = new Services_JSON();
                $json_enc = $j->encode($json);
            }
            header("Content-Type: application/json");
            die($json_enc);
        } else {
            if (!in_array($pagename, array(_("LinkDatabase")))) {
                trigger_error(sprintf(_("Unsupported argument: %s=%s"), "format", $format), E_USER_WARNING);
            }
            $template->printExpansion($toks);
        }
    }
    $page->increaseHitCount();
    if ($request->getArg('action') != 'pdf') {
        $request->checkValidators();
        flush();
    }
    return '';
}
Esempio n. 10
0
/**
 * For dumping pages as html to a file.
 * Used for action=dumphtml,action=ziphtml,format=pdf,format=xml
 */
function GeneratePageasXML($content, $title, $page_revision = false, $args = false)
{
    global $request;
    if (!is_array($args)) {
        $args = array();
    }
    $content->_basepage = $title;
    $args['CONTENT'] = $content;
    $args['TITLE'] = SplitPagename($title);
    $args['revision'] = $page_revision;
    if (!isset($args['HEADER'])) {
        $args['HEADER'] = SplitPagename($title);
    }
    global $HIDE_TOOLBARS, $NO_BASEHREF, $WikiTheme;
    $HIDE_TOOLBARS = true;
    if (!$WikiTheme->DUMP_MODE) {
        $WikiTheme->DUMP_MODE = 'HTML';
    }
    // FIXME: unfatal errors and login requirements
    $html = asXML(new Template('htmldump', $request, $args));
    $HIDE_TOOLBARS = false;
    //$WikiTheme->DUMP_MODE = false;
    return $html;
}
Esempio n. 11
0
 function box($args = false, $request = false, $basepage = false, $do_save = false)
 {
     if (!$request) {
         $request =& $GLOBALS['request'];
     }
     if (!isset($args['limit'])) {
         $args['limit'] = 12;
     }
     $args['format'] = 'box';
     $args['show_minor'] = false;
     $args['show_major'] = true;
     $args['show_deleted'] = 'sometimes';
     $args['show_all'] = false;
     $args['days'] = 90;
     $cache = $this->newCache();
     if (is_array($args)) {
         ksort($args);
     }
     $argscopy = $args;
     unset($argscopy['limit']);
     $this->_args =& $args;
     $this->_type = $this->getPluginType();
     $this->_static = false;
     /* OLD: */
     //list($id, $url) = $this->genUrl($cache, $args);
     /* NEW: This cache entry needs an update on major changes.
      * So we should rather use an unique ID, because there will only be
      * one global cached box.
      */
     $id = $cache->generateId(serialize(array("RecentChangesCachedBox", $argscopy)));
     $content = $cache->get($id, 'imagecache');
     if ($do_save || !$content || !$content['html']) {
         $this->resetError();
         $plugin = new WikiPlugin_RecentChanges();
         $title = WikiLink($this->getName(), '', SplitPagename($this->getName()));
         $changes = $plugin->getChanges($request->_dbi, $args);
         $content['html'] = $this->makeBox($title, $plugin->format($changes, $args));
         if ($errortext = $this->getError()) {
             $this->printError($errortext, 'html');
             return HTML();
         }
         $do_save = true;
     }
     if ($do_save) {
         $content['args'] = md5($this->_pi);
         $expire = $this->getExpire($request->_dbi, $content['args'], $request);
         $cache->save($id, $content, $expire, 'imagecache');
     }
     if ($content['html']) {
         return $content['html'];
     }
     return HTML();
 }
Esempio n. 12
0
function displayPage(&$request, $template = false)
{
    global $WikiTheme;
    $pagename = $request->getArg('pagename');
    $version = $request->getArg('version');
    $page = $request->getPage();
    if ($version) {
        $revision = $page->getRevision($version);
        if (!$revision) {
            NoSuchRevision($request, $page, $version);
        }
        /* Tell Google (and others) to ignore old versions of pages */
        $toks['ROBOTS_META'] = "noindex,nofollow";
    } else {
        $revision = $page->getCurrentRevision();
    }
    if (isSubPage($pagename)) {
        $pages = explode(SUBPAGE_SEPARATOR, $pagename);
        $last_page = array_pop($pages);
        // deletes last element from array as side-effect
        $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
        $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
        array_shift($pages);
        foreach ($pages as $p) {
            $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
            $first_pages .= $p . SUBPAGE_SEPARATOR;
        }
        $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page));
        $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        $pageheader->pushContent($backlink);
    } else {
        $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename));
        $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        if ($request->getArg('frame')) {
            $pageheader->setAttr('target', '_top');
        }
    }
    $pagetitle = SplitPagename($pagename);
    if ($redirect_from = $request->getArg('redirectfrom')) {
        $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from)));
        // abuse the $redirected template var for some status update notice
    } elseif ($request->getArg('errormsg')) {
        $redirect_message = $request->getArg('errormsg');
        $request->setArg('errormsg', false);
    }
    $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime')));
    /*
        // FIXME: This is also in the template...
        if ($request->getArg('action') != 'pdf' and !headers_sent()) {
          // FIXME: enable MathML/SVG/... support
          if (ENABLE_XHTML_XML
                 and (!isBrowserIE()
                      and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
                header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
            else
                header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
        }
    */
    $page_content = $revision->getTransformedContent();
    // if external searchengine (google) referrer, highlight the searchterm
    // FIXME: move that to the transformer?
    // OR: add the searchhightplugin line to the content?
    if ($result = isExternalReferrer($request)) {
        if (DEBUG and !empty($result['query'])) {
            //$GLOBALS['SearchHighlightQuery'] = $result['query'];
            /* simply add the SearchHighlight plugin to the top of the page. 
               This just parses the wikitext, and doesn't highlight the markup */
            include_once 'lib/WikiPlugin.php';
            $loader = new WikiPluginLoader();
            $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup);
            if ($xml and is_array($xml)) {
                foreach (array_reverse($xml) as $line) {
                    array_unshift($page_content->_content, $line);
                }
                array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query'])));
            }
            if (0) {
                /* Parse the transformed (mixed HTML links + strings) lines?
                     This looks like overkill.
                   */
                require_once "lib/TextSearchQuery.php";
                $query = new TextSearchQuery($result['query']);
                $hilight_re = $query->getHighlightRegexp();
                //$matches = preg_grep("/$hilight_re/i", $revision->getContent());
                // FIXME!
                for ($i = 0; $i < count($page_content->_content); $i++) {
                    $found = false;
                    $line = $page_content->_content[$i];
                    if (is_string($line)) {
                        while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) {
                            $found = true;
                            $line = substr($line, strlen($m[0]));
                            $html[] = $m[1];
                            // prematch
                            $html[] = HTML::strong(array('class' => 'search-term'), $m[2]);
                            // match
                        }
                    }
                    if ($found) {
                        $html[] = $line;
                        // postmatch
                        $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html);
                    }
                }
            }
        }
    }
    /* Check for special pagenames */
    /*
    if ( $pagename == _("RecentChanges") 
         || $pagename == _("RecentEdits")
         || $pagename == _("RecentVisitors")) {
        $toks['ROBOTS_META']="noindex,follow";
    } else
    */
    if ($pagename == _("SandBox")) {
        $toks['ROBOTS_META'] = "noindex,nofollow";
    } else {
        if (!isset($toks['ROBOTS_META'])) {
            $toks['ROBOTS_META'] = "index,follow";
        }
    }
    $toks['CONTENT'] = new Template('browse', $request, $page_content);
    $toks['TITLE'] = $pagetitle;
    // <title> tag
    $toks['HEADER'] = $pageheader;
    // h1 with backlink
    $toks['revision'] = $revision;
    if (!empty($redirect_message)) {
        $toks['redirected'] = $redirect_message;
    }
    $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
    $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
    if (!$template) {
        $template = new Template('html', $request);
    }
    $template->printExpansion($toks);
    $page->increaseHitCount();
    if ($request->getArg('action') != 'pdf') {
        $request->checkValidators();
    }
    flush();
}