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; $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) { 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) { $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; }