function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) { return ''; } extract($args); $query = new TextSearchQuery($s, $case_exact, $regex); $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $lines = array(); $hilight_re = $hilight ? $query->getHighlightRegexp() : false; $count = 0; $found = 0; if ($quiet) { // see how easy it is with PageList... $list = new PageList(false, $exclude, $args); while ($page = $pages->next() and (!$limit or $count < $limit)) { $list->addPage($page); } return $list; } // Todo: we should better define a new PageListDL class for dl/dt/dd lists // But the new column types must have a callback then. (showhits) // See e.g. WikiAdminSearchReplace for custom pagelist columns $list = HTML::dl(); if (!$limit or !is_int($limit)) { $limit = 0; } // expand all page wildcards to a list of pages which should be ignored if ($exclude) { $exclude = explodePageList($exclude); } while ($page = $pages->next() and (!$limit or $count < $limit)) { $name = $page->getName(); if ($exclude and in_array($name, $exclude)) { continue; } $count++; $list->pushContent(HTML::dt(WikiLink($name))); if ($hilight_re) { $list->pushContent($this->showhits($page, $hilight_re)); } unset($page); } if ($limit and $count >= $limit) { //todo: pager link to list of next matches $list->pushContent(HTML::dd(fmt("only %d pages displayed", $limit))); } if (!$list->getContent()) { $list->pushContent(HTML::dd(_("<no matches>"))); } if (!empty($pages->stoplisted)) { $list = HTML(HTML::p(fmt(_("Ignored stoplist words '%s'"), join(', ', $pages->stoplisted))), $list); } if ($noheader) { return $list; } return HTML(HTML::p(fmt("Full text search results for '%s'", $s)), $list); }
function testPageList() { // Completely empty PageList $columns = ""; $exclude = ""; $options = ""; $pl = new PageList($columns, $exclude, $options); $this->assertTrue($pl->isEmpty(), "empty"); $this->assertEquals(0, $pl->getTotal(), "count 0"); $cap = $pl->getCaption(); $this->assertTrue(empty($cap), "empty caption"); // PageList sorting $columns[] = 'pagename'; $pl = new PageList($columns, $exclude, $options); //global $request; $pl->addPage("foo"); $pl->addPage("blarg"); $this->assertEquals(2, $pl->getTotal(), "count 2"); //print_r($pl->getContent()); }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); // fix deprecated arg if (is_integer($pages)) { $numpages = $pages; $pages = false; // fix new pages handling in arg preprozessor. } elseif (is_array($pages)) { $numpages = (int) $pages[0]; if ($numpages > 0 and !$dbi->isWikiPage($numpages)) { $pages = false; } else { $numpages = 1; } } $allpages = $dbi->getAllPages(false, $sortby, $limit, $exclude); $pagearray = $allpages->asArray(); better_srand(); // Start with a good seed. if ($numpages == 1 && $pagearray) { $page = $pagearray[array_rand($pagearray)]; $pagename = $page->getName(); if ($redirect) { $request->redirect(WikiURL($pagename, false, 'absurl')); } // noreturn if ($hidename) { return WikiLink($pagename, false, _("RandomPage")); } else { return WikiLink($pagename); } } $numpages = min(max(1, (int) $numpages), 20, count($pagearray)); $pagelist = new PageList($info, $exclude, $args); $shuffle = array_rand($pagearray, $numpages); if (is_array($shuffle)) { foreach ($shuffle as $i) { if (isset($pagearray[$i])) { $pagelist->addPage($pagearray[$i]); } } } else { // if $numpages = 1 if (isset($pagearray[$shuffle])) { $pagelist->addPage($pagearray[$shuffle]); } } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (defined('DEBUG') && DEBUG && $debug) { $timer = new DebugTimer(); } $group = $request->getGroup(); if (method_exists($group, '_allUsers')) { $allusers = $group->_allUsers(); } else { $allusers = array(); } $args['count'] = count($allusers); // deleted pages show up as version 0. $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption(_("Authenticated users on this wiki (%d total):")); } if ($include_empty and empty($info)) { $pagelist->_addColumn('version'); } list($offset, $pagesize) = $pagelist->limit($args['limit']); if (!$pagesize) { $pagelist->addPageList($allusers); } else { for ($i = $offset; $i < $offset + $pagesize - 1; $i++) { if ($i >= $args['count']) { break; } $pagelist->addPage(trim($allusers[$i])); } } /* $page_iter = $dbi->getAllPages($include_empty, $sortby, $limit); while ($page = $page_iter->next()) { if ($page->isUserPage($include_empty)) $pagelist->addPage($page); } */ if (defined('DEBUG') && DEBUG and $debug) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); } else { return $pagelist; } }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (strstr($sortby, 'mtime')) { trigger_error(_("sortby=mtime not supported with MostPopular"), E_USER_WARNING); $sortby = ''; } $columns = $info ? explode(",", $info) : array(); array_unshift($columns, 'hits'); if (!$request->getArg('count')) { //$args['count'] = $dbi->numPages(false,$exclude); $allpages = $dbi->mostPopular(0, $sortby); $args['count'] = $allpages->count(); } else { $args['count'] = $request->getArg('count'); } //$dbi->touch(); $pages = $dbi->mostPopular($limit, $sortby); $pagelist = new PageList($columns, $exclude, $args); while ($page = $pages->next()) { $hits = $page->get('hits'); // don't show pages with no hits if most popular pages // wanted if ($hits == 0 && $limit > 0) { break; } $pagelist->addPage($page); } $pages->free(); if (!$noheader) { if ($limit > 0) { $pagelist->setCaption(_("The %d most popular pages of this wiki:")); } else { if ($limit < 0) { $pagelist->setCaption(_("The %d least popular pages of this wiki:")); } else { $pagelist->setCaption(_("Visited pages on this wiki, ordered by popularity:")); } } } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); // There's probably a more efficient way to do this (eg a // tailored SQL query via the backend, but this does the job $allpages_iter = $dbi->getAllPages($include_empty); $pages = array(); while ($page = $allpages_iter->next()) { $links_iter = $page->getBackLinks(); // Test for absence of backlinks. If a page is linked to // only by itself, it is still an orphan $parent = $links_iter->next(); if (!$parent or $parent->getName() == $page->getName() and !$links_iter->next()) { $pages[] = $page; } } $args['count'] = count($pages); $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption(_("Orphaned Pages in this wiki (%d total):")); } // deleted pages show up as version 0. if ($include_empty) { $pagelist->_addColumn('version'); } list($offset, $pagesize) = $pagelist->limit($args['limit']); if (!$pagesize) { $pagelist->addPageList($pages); } else { for ($i = $offset; $i < $offset + $pagesize - 1; $i++) { if ($i >= $args['count']) { break; } $pagelist->addPage($pages[$i]); } } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) { return ''; } $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']); $pages = $dbi->titleSearch($query, $args['sortby'], $args['limit'], $args['exclude']); $pagelist = new PageList($args['info'], $args['exclude'], $args); while ($page = $pages->next()) { $pagelist->addPage($page); $last_name = $page->getName(); } if ($args['format'] == 'livesearch') { $request->discardOutput(); $request->buffer_output(false); echo '<div class="LSRes">'; echo $pagelist->asXml(); echo '</div>'; if (empty($WikiTheme->DUMP_MODE)) { unset($GLOBALS['ErrorManager']->_postponed_errors); $request->finish(); } } // Provide an unknown WikiWord link to allow for page creation // when a search returns no results if (!$args['noheader']) { $s = $args['s']; if (!$pagelist->getTotal() and !$query->_regex) { $s = WikiLink($args['s'], 'auto'); } $pagelist->setCaption(fmt("Title search results for '%s'", $s)); } if ($args['auto_redirect'] && $pagelist->getTotal() == 1) { return HTML($request->redirect(WikiURL($last_name, false, 'absurl'), false), $pagelist); } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if ($args['basepage']) { $pagename = $args['basepage']; } else { $pagename = $request->getArg('pagename'); } // FIXME: explodePageList from stdlib doesn't seem to work as // expected when there are no subpages. (see also // UnfoldSubPages plugin) $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*'); if (!$subpages) { return $this->error(_("The current page has no subpages defined.")); } extract($args); $content = HTML(); $subpages = array_reverse($subpages); if ($maxpages) { $subpages = array_slice($subpages, 0, $maxpages); } $descrip = fmt("SubPages of %s:", WikiLink($pagename, 'auto')); if ($info) { $info = explode(",", $info); if (in_array('count', $info)) { $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center'); } } $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption($descrip); } foreach ($subpages as $page) { // A page cannot include itself. Avoid doublettes. static $included_pages = array(); if (in_array($page, $included_pages)) { $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $page))); continue; } array_push($included_pages, $page); //if ($relative) { // TODO: add relative subpage name display to PageList class //} $pagelist->addPage($page); array_pop($included_pages); } $content->pushContent($pagelist); return $content; }
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; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); // XXX: fix to reflect multi-user ratings? $caption = _("Displaying %d ratings:"); $active_user = $request->getUser(); $active_userid = $active_user->_userid; // check for request to display a category's ratings if (isset($category) && is_string($category) && strlen($category)) { $pageids = array(); $category_page = $dbi->getPage($category); $iter = $category_page->getLinks(); while ($item = $iter->next()) { array_push($pageids, $item->getName()); } // XXX: is there a way to retrieve the preferred plural // representation of a category name? // XXX: should the category text be a link? can it be one easily? $caption = sprintf(_("Showing all %ss (%%d):"), $category); } elseif (!isset($pageids) || !is_array($pageids)) { // XXX: need support for sorted ratings // bug: pages excluded from the PageList via the "exclude" argument // count toward the limit! $pageids = array(); $active_user_ratings_user =& RatingsUserFactory::getUser($active_user->getId()); $current_user_ratings = $active_user_ratings_user->get_ratings(); if ($userPage) { //we're on a user's homepage, get *their* ratings $this_page_user =& RatingsUserFactory::getUser($userPage); $caption = _("Here are {$userPage}" . "'s %d page ratings:"); $ratings = $this_page_user->get_ratings(); } else { $caption = _("Here are your %d page ratings:"); $ratings = $current_user_ratings; } $i = 0; foreach ($ratings as $pagename => $page_ratings) { // limit is currently only honored for "own" ratings if ($limit > 0 && $i >= $limit) { break; } if (isset($page_ratings[$dimension])) { array_push($pageids, $pagename); $i++; } } // $caption = _("Here are your %d page ratings:"); //make $ratings the user's ratings again if it had been treated as the current page // name's ratings $ratings = $current_user_ratings; } // if userids is null or empty, fill it with just the active user if (!isset($userids) || !is_array($userids) || !count($userids)) { // TKL: moved getBuddies call inside if statement because it was // causing the userids[] parameter to be ignored if (is_string($active_userid) && strlen($active_userid) && $active_user->isSignedIn() && !$userPage) { if (isset($category_page)) { $userids = getBuddies($active_userid, $dbi, $category_page->getName()); } else { $userids = getBuddies($active_userid, $dbi); } } elseif ($userPage) { //we're on a user page, show that user's ratings as the only column $userids = array(); array_push($userids, $userPage); } else { $userids = array(); // XXX: this wipes out the category caption... // $caption = _("You must be logged in to view ratings."); } } // find out which users we should show ratings for // users allowed in the prediction calculation $allowed_users = array(); // users actually allowed to be shown to the user $allowed_users_toshow = array(); foreach ($userids as $userid) { $user =& RatingsUserFactory::getUser($userid); if ($user->allow_view_ratings($active_user)) { array_push($allowed_users_toshow, $user); } // all users should be allowed in calculation array_push($allowed_users, $user); // This line ensures $user is not a reference type after this loop // If it is a reference type, that can produce very unexpected behavior! unset($user); } // if no buddies, use allusers in prediction calculation if (count($userids) == 0 || $userPage) { $allowed_users = array(); //$people_iter = $dbi->get_users_rated(); $people_dbi = RatingsDb::getTheRatingsDb(); $people_iter = $people_dbi->sql_get_users_rated(); while ($people_array = $people_iter->next()) { $userid = $people_array['pagename']; $user =& RatingsUserFactory::getUser($userid); array_push($allowed_users, $user); } } $columns = $info ? explode(",", $info) : array(); // build our table... $pagelist = new PageList($columns, $exclude, array('dimension' => $dimension, 'users' => $allowed_users_toshow)); // augment columns //$preds = new _PageList_Column_prediction('prediction', _("Pred"), 'right', $dimension, $allowed_users); $preds = array('_PageList_column_prediction', 'custom:prediction', _("Pred"), 'right', ' ', $allowed_users); $pagelist->addColumnObject($preds); //$widget = new _PageList_Column_ratingwidget('ratingwidget', _("Rate"), 'left', $dimension); $widget = array('_PageList_column_ratingwidget', 'custom:ratingwidget', _("Rate"), 'center'); $pagelist->addColumnObject($widget); $noRatingUsers = array(); if (!$nobuds) { foreach ($allowed_users_toshow as $idx => $user) { // For proper caching behavior, get a ref, don't user $user $u =& $allowed_users_toshow[$idx]; //$col = new _PageList_Column_ratingvalue('ratingvalue', $u->getId(), 'right', $dimension, $u); $col = array('_PageList_Column_ratingvalue', 'custom:ratingvalue', $u->getId(), 'right', ' ', $u); $pagelist->addColumnObject($col); unset($u); } } // add rows -- each row represents an item (page) foreach ($pageids as $pagename) { // addPage can deal with cases where it is passed a string $pagelist->addPage($pagename); } if (!$noheader) { $pagelist->setCaption(_($caption)); } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $this->_supported_operators = array(':=', '<', '<=', '>', '>=', '!=', '==', '=~'); $args = $this->getArgs($argstr, $request); $posted = $request->getArg('semsearch'); $request->setArg('semsearch', false); if ($request->isPost() and isset($posted['help'])) { $request->redirect(WikiURL(_("Help/SemanticSearchAdvancedPlugin"), array('redirectfrom' => $basepage), true)); } $allrelations = $dbi->listRelations(); $form = $this->showForm($dbi, $request, $args, $allrelations); if (isset($this->_norelations_warning)) { $form->pushContent(HTML::div(array('class' => 'warning'), _("Warning:") . $this->_norelations_warning)); } extract($args); // For convenience, peace and harmony we allow GET requests also. if (!$args['s']) { // check for good GET request return $form; } // nobody called us, so just display our form // In reality we have to iterate over all found pages. // To makes things shorter extract the next AND required expr and // iterate only over this, then recurse into the next AND expr. // => Split into an AND and OR expression tree. $parsed_relations = $this->detectRelationsAndAttributes($args['s']); $regex = ''; if ($parsed_relations) { $regex = preg_grep("/[\\*\\?]/", $parsed_relations); } else { $this->error("Invalid query: No relations or attributes in the query {$s} found"); } $pagelist = new PageList($args['info'], $args['exclude'], $args); if (!$noheader) { $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("Semantic %s Search Result for \"%s\" in pages \"%s\"", '', $s, $page))); } if (!$regex and $missing = array_diff($parsed_relations, $allrelations)) { return $pagelist; } $relquery = new TextSearchQuery(join(" ", $parsed_relations)); if (!$relquery->match(join(" ", $allrelations))) { return $pagelist; } $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']); // if we have only numeric or text ops we can optimize. //$parsed_attr_ops = $this->detectAttrOps($args['s']); //TODO: writeme $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']); $links = $dbi->linkSearch($pagequery, $linkquery, 'relation', $relquery); $pagelist->_links = array(); while ($link = $links->next()) { $pagelist->addPage($link['pagename']); $pagelist->_links[] = $link; } $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('relation', _("Relation"), $pagelist)); $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('link', _("Link"), $pagelist)); return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $args = $this->getArgs($argstr, $request); if (empty($args['page'])) { $args['page'] = "*"; } $form = $this->showForm($dbi, $request, $args); extract($args); if (empty($s)) { return $form; } $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']); $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']); $links = $dbi->linkSearch($pagequery, $linkquery, $direction == 'in' ? 'linkfrom' : 'linkto'); $pagelist = new PageList($args['info'], $args['exclude'], $args); $pagelist->_links = array(); while ($link = $links->next()) { $pagelist->addPage($link['pagename']); $pagelist->_links[] = $link; } $pagelist->addColumnObject(new _PageList_Column_LinkSearch_link('link', _("Link"), $pagelist)); if (!$noheader) { // We put the form into the caption just to be able to return one pagelist object, // and to still have the convenience form at the top. we could workaround this by // putting the form as WikiFormRich into the actionpage. but thid doesnt look as // nice as this here. $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("LinkSearch result for \"%s\" in pages \"%s\", direction %s", $s, $page, $direction))); } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; $this->_supported_operators = array(':=', '<', '<=', '>', '>=', '!=', '==', '=~'); $this->_text_operators = array(':=', '==', '=~', '!='); $args = $this->getArgs($argstr, $request); if (empty($args['page'])) { $args['page'] = "*"; } if (!isset($args['s'])) { // it might be (integer) 0 $args['s'] = "*"; } $posted = $request->getArg("semsearch"); $form = $this->showForm($dbi, $request, $args); if (isset($this->_norelations_warning)) { $form->pushContent(HTML::div(array('class' => 'warning'), _("Warning:"), HTML::br(), _("No relations nor attributes in the whole wikidb defined!"), "\n", fmt("See %s", WikiLink(_("Help:SemanticRelations"))))); } extract($args); // for convenience and harmony we allow GET requests also. if (!$request->isPost()) { if ($relation or $attribute) { // check for good GET request } else { return $form; } // nobody called us, so just display our supadupa form } $pagequery = $this->regex_query($page, $args['case_exact'], $args['regex']); // we might want to check for semsearch['relations'] and semsearch['attributes'] also if (empty($relation) and empty($attribute)) { // so we just clicked without selecting any relation. // hmm. check which button we clicked, before we do the massive alltogether search. if (isset($posted['relations']) and $posted['relations']) { $relation = '*'; } elseif (isset($posted['attributes']) and $posted['attributes']) { $attribute = '*'; // here we have to check for invalid text operators. ignore it then if (!in_array($attr_op, $this->_text_operators)) { $attribute = ''; } } } $searchtype = "Text"; if (!empty($relation)) { $querydesc = $relation . "::" . $s; $linkquery = $this->regex_query($s, $args['case_exact'], $args['regex']); $relquery = $this->regex_query($relation, $args['case_exact'], $args['regex']); $links = $dbi->linkSearch($pagequery, $linkquery, 'relation', $relquery); $pagelist = new PageList($info, $exclude, $args); $pagelist->_links = array(); while ($link = $links->next()) { $pagelist->addPage($link['pagename']); $pagelist->_links[] = $link; } // default (=empty info) wants all three. but we want to be able to override this. // $pagelist->_columns_seen is the exploded info if (!$info or $info and isset($pagelist->_columns_seen['relation'])) { $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('relation', _("Relation"), $pagelist)); } if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['linkto'])) { $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('linkto', _("Link"), $pagelist)); } } // can we merge two different pagelist? if (!empty($attribute)) { $relquery = $this->regex_query($attribute, $args['case_exact'], $args['regex']); if (!in_array($attr_op, $this->_supported_operators)) { return HTML($form, $this->error(fmt("Illegal operator: %s", HTML::tt($attr_op)))); } $s_base = preg_replace("/,/", "", $s); $units = new Units(); if (!is_numeric($s_base)) { $s_base = $units->basevalue($s_base); $is_numeric = is_numeric($s_base); } else { $is_numeric = true; } // check which type to search with: // at first check if forced text matcher if ($attr_op == '=~') { if ($s == '*') { $s = '.*'; } // help the poor user. we need pcre syntax. $linkquery = new TextSearchQuery("{$s}", $args['case_exact'], 'pcre'); $querydesc = "{$attribute} {$attr_op} {$s}"; } elseif ($is_numeric) { // do comparison with numbers /* We want to search for multiple attributes also. linkSearch can do this. * But we have to construct the query somehow. (that's why we try the AND OR dhtml) * population < 1 million AND area > 50 km2 * Here we check only for one attribute per page. * See SemanticSearchAdvanced for the full expression. */ // it might not be the best idea to use '*' as variable to expand. hmm. if ($attribute == '*') { $attribute = '_star_'; } $searchtype = "Numeric"; $query = $attribute . " " . $attr_op . " " . $s_base; $linkquery = new SemanticAttributeSearchQuery($query, $attribute, $units->baseunit($s)); if ($attribute == '_star_') { $attribute = '*'; } $querydesc = $attribute . " " . $attr_op . " " . $s; // no number or unit: check other text matchers or '*' MATCH_ALL } elseif (in_array($attr_op, $this->_text_operators)) { if ($attr_op == '=~') { if ($s == '*') { $s = '.*'; } // help the poor user. we need pcre syntax. $linkquery = new TextSearchQuery("{$s}", $args['case_exact'], 'pcre'); } else { $linkquery = $this->regex_query($s, $args['case_exact'], $args['regex']); } $querydesc = "{$attribute} {$attr_op} {$s}"; // should we fail or skip when the user clicks on Relations? } elseif (isset($posted['relations']) and $posted['relations']) { $linkquery = false; // skip } else { $querydesc = $attribute . " " . $attr_op . " " . $s; return HTML($form, $this->error(fmt("Only text operators can be used with strings: %s", HTML::tt($querydesc)))); } if ($linkquery) { $links = $dbi->linkSearch($pagequery, $linkquery, 'attribute', $relquery); if (empty($relation)) { $pagelist = new PageList($args['info'], $args['exclude'], $args); $pagelist->_links = array(); } while ($link = $links->next()) { $pagelist->addPage($link['pagename']); $pagelist->_links[] = $link; } // default (=empty info) wants all three. but we want to override this. if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['attribute'])) { $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('attribute', _("Attribute"), $pagelist)); } if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['value'])) { $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('value', _("Value"), $pagelist)); } } } if (!isset($pagelist)) { $querydesc = _("<empty>"); $pagelist = new PageList(); } if (!$noheader) { // We put the form into the caption just to be able to return one pagelist object, // and to still have the convenience form at the top. we could workaround this by // putting the form as WikiFormRich into the actionpage. but thid doesnt look as // nice as this here. $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("Semantic %s Search Result for \"%s\" in pages \"%s\"", $searchtype, $querydesc, $page))); } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $this->args = $this->getArgs($argstr, $request); extract($this->args); $this->request =& $request; if (!$from_lang) { $from_lang = $request->getPref('lang'); } if (!$from_lang) { $from_lang = $GLOBALS['LANG']; } $this->lang = $from_lang; if (empty($languages)) { $available_languages = listAvailableLanguages(); if ($from_lang == 'en') { // "en" is always the first. array_shift($available_languages); } // put from_lang to the very end. if (in_array($from_lang, $available_languages)) { $languages = $available_languages; } else { $languages = array_merge($available_languages, array($from_lang)); } } elseif (strstr($languages, ',')) { $languages = explode(',', $languages); } else { $languages = array($languages); } if (in_array('zh', $languages) or in_array('ja', $languages)) { // If the current charset != utf-8 the text will not be displayed correctly. // But here we cannot change the header anymore. So we can decide to ignore them, // or display them with all the errors. //FIXME: do iconv the ob if ($GLOBALS['charset'] != 'utf-8' and !defined('NEED_ICONV_TO')) { define('NEED_ICONV_TO', 'utf-8'); //either the extension or external //$GLOBALS['charset'] = 'utf-8'; } } $to_lang = $languages[0]; if (!empty($string) and count($languages) == 1) { return $this->translate($string, $to_lang, $from_lang); } if (!empty($page)) { $pagename = $page; if ($dbi->isWikiPage($pagename)) { $url = ''; // google can only translate from english and french if (in_array($from_lang, array('en', 'fr'))) { $url = "http://translate.google.com/translate"; $url .= "?langpair=" . urlencode($from_lang . "|" . $to_lang); $url .= "&u=" . urlencode(WikiURL($pagename, false, true)); } // redirect or transclude? if ($url) { return $request->redirect($url); } return HTML(fmt("TODO: Google can only translate from english and french. Find a translation service for %s to language %s", WikiURL($pagename, false, true), $to_lang)); } else { return $this->error(fmt("%s is empty", $pagename)); } } $pagelist = new PageList('', $exclude, $this->args); $pagelist->_columns[0]->_heading = "{$from_lang}"; foreach ($languages as $lang) { if ($lang == $from_lang) { continue; } $field = "custom:{$lang}"; $pagelist->addColumnObject(new _PageList_Column_customlang($field, $from_lang, $this)); } if (!empty($string)) { $pagelist->addPage($string); return $pagelist; } switch ($what) { case 'allpages': $pagelist->addPages($dbi->getAllPages($include_empty, $sortby, $limit, $exclude)); break; case 'pages': // not all pages, only the pgsrc pages if (!is_array($exclude)) { $exclude = $pagelist->explodePageList($exclude, false, $sortby, $limit, $exclude); } $path = FindLocalizedFile(WIKI_PGSRC); $pgsrc = new fileSet($path); foreach ($pgsrc->getFiles($exclude, $sortby, $limit) as $pagename) { $pagename = urldecode($pagename); if (substr($pagename, -1, 1) == '~') { continue; } if (in_array($pagename, $exclude)) { continue; } // exclude page. if ($match != '*' and !glob_match($match, $pagename)) { continue; } $page_handle = $dbi->getPage($pagename); $pagelist->addPage($page_handle); } break; case 'wikiwords': if (!isset($this->_locales[$from_lang])) { $this->init_locale($from_lang); } $locale =& $this->_locales[$from_lang]; if (is_array($locale)) { $count = 0; foreach ($locale as $from => $to) { if ($match != '*' and !glob_match($match, $from)) { continue; } if (isWikiWord($from)) { $count++; $pagelist->addPage($from); if ($limit and $count > $limit) { break; } } } } break; // all Button texts, which need a localized .png // where to get them from? templates/*.tmpl: Button() // and WikiLink(?,'button') // navbar links, actionpages, and admin requests // all Button texts, which need a localized .png // where to get them from? templates/*.tmpl: Button() // and WikiLink(?,'button') // navbar links, actionpages, and admin requests case 'buttons': $buttons = $GLOBALS['AllActionPages']; $fileset = new FileSet(FindFile("themes/MacOSX/buttons/en"), "*.png"); foreach ($fileset->getFiles() as $file) { $b = urldecode(substr($file, 0, -4)); if (!in_array($b, $buttons)) { $buttons[] = $b; } } $count = 0; foreach ($buttons as $button) { $pagelist->addPage($button); if ($limit and ++$count > $limit) { break; } } break; } return $pagelist; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if (empty($page) and $page != '0') { return ''; } // exclude is now already expanded in WikiPlugin::getArgs() if (empty($exclude)) { $exclude = array(); } if (!$include_self) { $exclude[] = $page; } if ($info) { $info = explode(",", $info); if (in_array('count', $info)) { $args['types']['count'] = new _PageList_Column_BackLinks_count('count', _("#"), 'center'); } } if (!empty($limit)) { $args['limit'] = $limit; } $args['dosort'] = !empty($args['sortby']); // override DB sort (??) $pagelist = new PageList($info, $exclude, $args); // support logical AND: page1,page2 $pages = explodePageList($page); $count = count($pages); if (count($pages) > 1) { // AND: the intersection of all these pages $bl = array(); foreach ($pages as $p) { $dp = $dbi->getPage($p); $bi = $dp->getBackLinks(false, $sortby, 0, $exclude); while ($b = $bi->next()) { $name = $b->getName(); if (isset($bl[$name])) { $bl[$name]++; } else { $bl[$name] = 1; } } } foreach ($bl as $b => $v) { if ($v == $count) { $pagelist->addPage($b); } } } else { $p = $dbi->getPage($page); $pagelist->addPages($p->getBackLinks(false, $sortby, 0, $exclude)); } $total = $pagelist->getTotal(); // Localization note: In English, the differences between the // various phrases spit out here may seem subtle or negligible // enough to tempt you to combine/normalize some of these // strings together, but the grammar employed most by other // languages does not always end up with so subtle a // distinction as it does with English in this case. :) if (!$noheader) { if ($page == $request->getArg('pagename') and !$dbi->isWikiPage($page)) { // BackLinks plugin is more than likely being called // upon for an empty page on said page, while either // 'browse'ing, 'create'ing or 'edit'ing. // // Don't bother displaying a WikiLink 'unknown', just // the Un~WikiLink~ified (plain) name of the uncreated // page currently being viewed. $pagelink = $page; if ($pagelist->isEmpty()) { return HTML::p(fmt("No other page links to %s yet.", $pagelink)); } if ($total == 1) { $pagelist->setCaption(fmt("One page would link to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages would link to %s:", $total, $pagelink)); } } else { if ($count) { $tmp_pages = $pages; $p = array_shift($tmp_pages); $pagelink = HTML(WikiLink($p, 'auto')); foreach ($tmp_pages as $p) { $pagelink->pushContent(" ", _("AND"), " ", WikiLink($p, 'auto')); } } else { // BackLinks plugin is being displayed on a normal page. $pagelink = WikiLink($page, 'auto'); } if ($pagelist->isEmpty()) { return HTML::p(fmt("No page links to %s.", $pagelink)); } //trigger_error("DEBUG: " . $pagelist->getTotal()); if ($total == 1) { $pagelist->setCaption(fmt("One page links to %s:", $pagelink)); } else { $pagelist->setCaption(fmt("%s pages link to %s:", $limit > 0 ? $total : _("Those"), $pagelink)); } } } if (!empty($args['linkmore']) and $dbi->isWikiPage($args['linkmore']) and $limit > 0 and $total > $limit) { $pagelist->addCaption(WikiLink($args['linkmore'], "auto", _("More..."))); } return $pagelist; }
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 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 ''; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (!empty($args['exclude_from'])) { $args['exclude_from'] = is_string($args['exclude_from']) ? explodePageList($args['exclude_from']) : $args['exclude_from']; } // <! plugin-list !> extract($args); if ($page == _("WantedPages")) { $page = ""; } // There's probably a more memory-efficient way to do this (eg // a tailored SQL query via the backend, but this gets the job // done. // TODO: Move this to backend/dumb/WantedPagesIter.php if (!$page) { $GLOBALS['WikiTheme']->addPageListColumn(array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left'))); } $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args); // search button? $pagelist->_wpagelist = array(); if (!$page) { list($offset, $maxcount) = $pagelist->limit($limit); $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit); while ($row = $wanted_iter->next()) { $wanted = $row['pagename']; $wantedfrom = $row['wantedfrom']; // ignore duplicates: if (empty($pagelist->_wpagelist[$wanted])) { $pagelist->addPage($wanted); } $pagelist->_wpagelist[$wanted][] = $wantedfrom; } $wanted_iter->free(); // update limit, but it's still a hack. $pagelist->_options['limit'] = "{$offset}," . min($pagelist->getTotal(), $maxcount); } elseif ($dbi->isWikiPage($page)) { //only get WantedPages links for one page $page_handle = $dbi->getPage($page); $links = $page_handle->getPageLinks(true); // include_empty while ($link_handle = $links->next()) { if (!$dbi->isWikiPage($linkname = $link_handle->getName())) { $pagelist->addPage($linkname); //if (!array_key_exists($linkname, $this->_wpagelist)) $pagelist->_wpagelist[$linkname][] = 1; } } } /* if ($sortby) { ksort($this->_wpagelist); arsort($this->_wpagelist); }*/ if (!$noheader) { if ($page) { $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page)); } else { $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:"))); } } // reference obviously doesn't work, so force an update to add _wpagelist to parentobj if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted') { $pagelist->_columns[1]->parentobj =& $pagelist; } return $pagelist; }