getNumLinks(); $theIter = $page_handle->getBackLinks(); $total = 0; while($curr = $theIter->next()){ $total++; } return $total; } }; class _PageList_Column_coagreement extends _PageList_Column_custom { function _PageList_Column_coagreement ($params) { $this->_pagelist =& $params[3]; $this->_PageList_Column($params[0], $params[1], $params[2]); $this->_selectedBuddies = $this->_pagelist->getOption('selectedBuddies'); } function _getValue ($page_handle, &$revision_handle) { global $request; $pagename = $page_handle->getName(); $active_user = $request->getUser(); $active_userId = $active_user->getId(); $dbi = $request->getDbh(); $p = CoAgreement($dbi, $pagename, $this->_selectedBuddies, $active_userId); if($p == 1){ $p = "yes"; } elseif($p == 0){ $p = "unsure"; } elseif($p == -1){ $p = "no"; } else { $p = "error"; } //FIXME: $WikiTheme->getImageURL() return HTML::img(array('src' => "../images/" . $p . ".gif")); } } class _PageList_Column_minmisery extends _PageList_Column_custom { function _PageList_Column_minmisery ($params) { $this->_pagelist =& $params[3]; $this->_PageList_Column($params[0], $params[1], $params[2]); $this->_selectedBuddies = $this->_pagelist->getOption('selectedBuddies'); } function _getValue ($page_handle, &$revision_handle) { global $request; $pagename = $page_handle->getName(); $active_user = $request->getUser(); $active_userId = $active_user->getId(); $dbi = $request->getDbh(); $p = MinMisery($dbi, $pagename, $this->_selectedBuddies, $active_userId); $imgFix = floor($p * 2) / 2; //FIXME: $WikiTheme->getImageURL() return HTML::img(array('src' => "../images/" . $imgFix . ".png")); } } class _PageList_Column_averagerating extends _PageList_Column_custom { function init ($field, $default_heading, $align, &$pagelist) { $this->_PageList_Column($field, $default_heading, $align); $this->_selectedBuddies = $pagelist->getOption('selectedBuddies'); } function _getValue ($page_handle, &$revision_handle) { global $request; $pagename = $page_handle->getName(); $active_user = $request->getUser(); $active_userId = $active_user->getId(); $dbi = $request->getDbh(); $p = round(AverageRating($dbi, $pagename, $this->_selectedBuddies, $active_userId), 2); $imgFix = floor($p * 2) / 2; $html = HTML(); //FIXME: $WikiTheme->getImageURL() $html->pushContent(HTML::img(array('src' => "../images/" . $imgFix . ".png"))); $html->pushContent($p); return $html; } }; /** * Show the value of a rating as a digit (or "-" if no value), given the * user who is the rater. */ class _PageList_Column_ratingvalue extends _PageList_Column { var $_user; var $_dimension; function _PageList_Column_ratingvalue ($params) { $this->_pagelist =& $params[3]; $this->_user =& $params[4];//$this->_pagelist->getOption('user'); assert(!empty($this->_user)); $this->_PageList_Column($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension'); } function format ($pagelist, $page_handle, &$revision_handle) { $rating = $this->_getValue($page_handle, $revision_handle); $mean = $this->_user->mean_rating($this->_dimension); $td = HTML::td($this->_tdattr); $div = HTML::div(); if($rating != '-' && abs($rating - $mean) >= 0.75) $div->setAttr('style', 'color: #' . ($rating > $mean ? '009900' : 'ff3333')); $div->pushContent($rating); $td->pushContent($div); return $td; } function _getValue ($page_handle, &$revision_handle) { $pagename = $page_handle->getName(); $tu = & $this->_user; $rating = $tu->get_rating($pagename, $this->_dimension); // a dash (or *something*) arguably looks better than a big blank space return ($rating ? $rating : "-"); } function hasNoRatings($pages) { $total = 0; $use = & $this->_user; foreach ($pages as $page) { if ($use->get_rating($page, $this->_dimension)) { $total++; } } if ($total == 0) { return true; } return false; } }; /** * Ratings widget for the logged-in user and the given page */ class _PageList_Column_ratingwidget extends _PageList_Column_custom { function _PageList_Column_ratingwidget ($params) { $this->_pagelist =& $params[3]; $this->_PageList_Column($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension'); } function format ($pagelist, $page_handle, &$revision_handle) { $widget = WikiPlugin_RateIt::RatingWidgetHtml($page_handle->getName(), "", "pagerat", $this->_dimension, "small"); $td = HTML::td($widget); $td->setAttr('nowrap', 'nowrap'); return $td; } function _getValue ($page_handle, &$revision_handle) { global $request; $pagename = $page_handle->getName(); $active_user = $request->getUser(); $active_userid = $active_user->_userid; $tu = & RatingsUserFactory::getUser($active_userid); return $tu->get_rating($pagename, $this->_dimension); } }; class _PageList_Column_prediction extends _PageList_Column { var $_active_ratings_user; var $_users; function _PageList_Column_prediction ($params) { global $request; $active_user = $request->getUser(); // This needs to be a reference so things aren't recomputed for this user $this->_active_ratings_user =& RatingsUserFactory::getUser($active_user->getId()); $this->_pagelist =& $params[3]; $this->_PageList_Column($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension');; $this->_users = $this->_pagelist->getOption('users'); } function format ($pagelist, $page_handle, &$revision_handle) { $pred = $this->_getValue($page_handle, $revision_handle); $mean = $this->_active_ratings_user->mean_rating($this->_dimension); $td = HTML::td($this->_tdattr); $div = HTML::div(); if($pred > 0 && abs($pred - $mean) >= 0.75) $div->setAttr('style', 'color: #' . ($pred > $mean ? '009900' : 'ff3333')); $div->pushContent($pred); $td->pushContent($div); return $td; } function _getValue ($page_handle, &$revision_handle) { $pagename = $page_handle->getName(); $html = HTML(); $pred = $this->_active_ratings_user->knn_uu_predict($pagename, $this->_users, $this->_dimension); return sprintf("%.1f", min(5, max(0, $pred))); } }; class _PageList_Column_top3recs extends _PageList_Column_custom { var $_active_ratings_user; var $_users; function _PageList_Column_top3recs ($params) { global $request; $active_user = $request->getUser(); // No, I don't know exactly why, but this needs to be a reference for // the memoization in pearson_similarity and mean_rating to work $this->_active_ratings_user =& new RatingsUser($active_user->getId()); $this->_PageList_Column($params[0], $params[1], $params[2]); if (!empty($params[3])) { $this->_pagelist =& $params[3]; $this->_dimension = $this->_pagelist->getOption('dimension'); $this->_users = $this->_pagelist->getOption('users'); } } function _getValue ($page_handle, &$revision_handle) { $ratings = $this->_active_ratings_user->get_ratings(); $iter = $page_handle->getLinks(); $recs = array(); while($current = $iter->next()) { //filter out already rated if (!$this->_active_ratings_user->get_rating($current->getName(), $this->_dimension)) { $recs[$current->getName()] = $this->_active_ratings_user->knn_uu_predict($current->getName(), $this->_users, $this->_dimension); } } arsort($recs); $counter = 0; if (count($recs) >= 3){ $numToShow = 3; } else { // if <3 just show as many as there are $numToShow = count($recs); } $html = HTML(); while ((list($key, $val) = each($recs)) && $counter < $numToShow) { if ($val < 3){ break; } if ($counter > 0){ $html->pushContent(" , "); } $html->pushContent(WikiLink($key)); $counter++; } if (count($recs) == 0 || $counter == 0){ $html->pushContent(_("None")); } //return $top3list; return $html; } }; // register custom PageList type global $WikiTheme; $WikiTheme->addPageListColumn (array ( 'numbacklinks' => array('_PageList_Column_numbacklinks','custom:numbacklinks', _("# things"), false), 'rating' => array('_PageList_Column_ratingwidget','custom:rating', _("Rate"), false), 'coagreement' => array('_PageList_Column_coagreement','custom:coagreement', _("Go?"), 'center'), 'minmisery' => array('_PageList_Column_minmisery','custom:minmisery', _("MinMisery"), 'center'), 'averagerating' => array('_PageList_Column_averagerating','custom:averagerating', _("Avg. Rating"), 'left'), 'top3recs' => array('_PageList_Column_top3recs','custom:top3recs', _("Top Recommendations"), 'left'), )); // $Log: not supported by cvs2svn $ // Revision 1.3 2004/06/21 17:01:41 rurban // fix typo and rating method call // // Revision 1.2 2004/06/21 16:22:32 rurban // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps, // fixed dumping buttons locally (images/buttons/), // support pages arg for dumphtml, // optional directory arg for dumpserial + dumphtml, // fix a AllPages warning, // show dump warnings/errors on DEBUG, // don't warn just ignore on wikilens pagelist columns, if not loaded. // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?) // // Revision 1.1 2004/06/18 14:42:17 rurban // added wikilens libs (not yet merged good enough, some work for DanFr) // // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>