From 0f27d666fc7e6d088040a4f800f8890c4bf123e4 Mon Sep 17 00:00:00 2001 From: vargenau Date: Mon, 7 Mar 2011 13:08:01 +0000 Subject: [PATCH] No tabs git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@7967 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/wikilens/Buddy.php | 144 ++++++++++++------------- lib/wikilens/CustomPrefs.php | 6 +- lib/wikilens/RatingsDb.php | 201 +++++++++++++++++------------------ lib/wikilens/RatingsUser.php | 38 ++++--- lib/wikilens/Utils.php | 9 +- 5 files changed, 192 insertions(+), 206 deletions(-) diff --git a/lib/wikilens/Buddy.php b/lib/wikilens/Buddy.php index 8652510c6..43f7bd91e 100644 --- a/lib/wikilens/Buddy.php +++ b/lib/wikilens/Buddy.php @@ -15,16 +15,8 @@ // serialized string. // If no homepage, fallback to prefs in cookie as in 1.3.3. - -/** -* -*/ require_once (dirname(__FILE__)."/Utils.php"); -/* -class Buddy extends WikiUserNew {} -*/ - function addBuddy($user, $buddy, $dbi) { $START_DELIM = _("Buddies:"); @@ -43,95 +35,95 @@ function getBuddies($fromUser, $dbi, $thePage = ""){ $buddies_array = getPageTextData($fromUser, $dbi, _("Buddies:"), $DELIM); } if (empty($buddies_array)) { - // 1. calculate buddies automatically from the 10 top raters with the most numratings (min. 5 ratings). - // of all pages (only SQL) - // or 2. from 10 random raters of this page (non-SQL) - // or 3. from all members of your group (department) if <= 20 - $rdbi = RatingsDb::getTheRatingsDb(); - $dimension = ''; + // 1. calculate buddies automatically from the 10 top raters with the most numratings (min. 5 ratings). + // of all pages (only SQL) + // or 2. from 10 random raters of this page (non-SQL) + // or 3. from all members of your group (department) if <= 20 + $rdbi = RatingsDb::getTheRatingsDb(); + $dimension = ''; if (RATING_STORAGE == 'SQL') { - //$result = $this->_sql_get_rating_result($dimension, null, null, 'numrating', "rater"); - $dbh = &$rdbi->_sqlbackend; - extract($dbh->_table_names); - $query = "SELECT raterpage, COUNT(rateepage) as numrating" - . " FROM $rating_tbl r, $page_tbl p " -// . " WHERE ratingvalue > 0 AND numrating > 5" - . " WHERE ratingvalue > 0" - . " GROUP BY raterpage" - . " ORDER BY numrating" - . " LIMIT 10"; - $result = $dbh->_dbh->query($query); - } else { - // from 10 random raters of this page (non-SQL) - ; - } + //$result = $this->_sql_get_rating_result($dimension, null, null, 'numrating', "rater"); + $dbh = &$rdbi->_sqlbackend; + extract($dbh->_table_names); + $query = "SELECT raterpage, COUNT(rateepage) as numrating" + . " FROM $rating_tbl r, $page_tbl p " +// . " WHERE ratingvalue > 0 AND numrating > 5" + . " WHERE ratingvalue > 0" + . " GROUP BY raterpage" + . " ORDER BY numrating" + . " LIMIT 10"; + $result = $dbh->_dbh->query($query); + } else { + // from 10 random raters of this page (non-SQL) + ; + } } $result = array(); if (is_array($buddies_array)) - foreach ($buddies_array as $userid) { - $result[] = new RatingsUser($userid); + foreach ($buddies_array as $userid) { + $result[] = new RatingsUser($userid); } return $result; } function CoAgreement($dbi, $page, $users, $active_userid){ - //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether - //the group agrees on the page based on their ratings - $cur_page = $page; - - $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page); - $my_ratings_single = $my_ratings_iter->next(); - $cur_rating = $my_ratings_single['ratingvalue']; - - $MIDDLE_RATING = 3; - - if($cur_rating >= $MIDDLE_RATING){ - $agreePos = 1; - } else { - $agreePos = 0; - } - foreach($users as $buddy){ - $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page); - $buddy_rating_array = $buddy_rating_iter->next(); - $buddy_rating = $buddy_rating_array['ratingvalue']; - if($buddy_rating == ""){ - $agree = 1; - }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){ - $agree = 1; - } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){ - $agree = 1; - } else { - $agree = 0; - break; - } - } - if($agree && $agreePos){ - return 1; - } else if($agree && !$agreePos){ - return -1; - } else { - return 0; - } + //Returns a "yes" 1, "no" -1, or "unsure" 0 for whether + //the group agrees on the page based on their ratings + $cur_page = $page; + + $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page); + $my_ratings_single = $my_ratings_iter->next(); + $cur_rating = $my_ratings_single['ratingvalue']; + + $MIDDLE_RATING = 3; + + if($cur_rating >= $MIDDLE_RATING){ + $agreePos = 1; + } else { + $agreePos = 0; + } + foreach($users as $buddy){ + $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page); + $buddy_rating_array = $buddy_rating_iter->next(); + $buddy_rating = $buddy_rating_array['ratingvalue']; + if($buddy_rating == ""){ + $agree = 1; + }else if($agreePos && $buddy_rating >= $MIDDLE_RATING){ + $agree = 1; + } else if(!$agreePos && $buddy_rating < $MIDDLE_RATING){ + $agree = 1; + } else { + $agree = 0; + break; + } + } + if($agree && $agreePos){ + return 1; + } else if($agree && !$agreePos){ + return -1; + } else { + return 0; + } } function MinMisery($dbi, $page, $users, $active_userid){ //Returns the minimum rating for the page //from all the users. - + $cur_page = $page; - + $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page); $my_ratings_single = $my_ratings_iter->next(); $cur_rating = $my_ratings_single['ratingvalue']; - + $min = $cur_rating; foreach($users as $buddy){ $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page); $buddy_rating_array = $buddy_rating_iter->next(); $buddy_rating = $buddy_rating_array['ratingvalue']; if($buddy_rating != "" && $buddy_rating < $min){ - $min = $buddy_rating; + $min = $buddy_rating; } } return $min; @@ -140,9 +132,9 @@ function MinMisery($dbi, $page, $users, $active_userid){ function AverageRating($dbi, $page, $users, $active_userid){ //Returns the average rating for the page //from all the users. - + $cur_page = $page; - + $my_ratings_iter = $dbi->get_rating(0, $active_userid, $page); $my_ratings_single = $my_ratings_iter->next(); $cur_rating = $my_ratings_single['ratingvalue']; @@ -157,9 +149,9 @@ function AverageRating($dbi, $page, $users, $active_userid){ $buddy_rating_iter = $dbi->get_rating(0, $buddy, $cur_page); $buddy_rating_array = $buddy_rating_iter->next(); $buddy_rating = $buddy_rating_array['ratingvalue']; - if($buddy_rating != ""){ + if($buddy_rating != ""){ $total = $total + $buddy_rating; - $count++; + $count++; } } if($count == 0){ diff --git a/lib/wikilens/CustomPrefs.php b/lib/wikilens/CustomPrefs.php index 2a21b611c..dd6803568 100644 --- a/lib/wikilens/CustomPrefs.php +++ b/lib/wikilens/CustomPrefs.php @@ -4,7 +4,7 @@ /** * Custom UserPreferences: * A list of name => _UserPreference class pairs. - * Rationale: Certain themes should be able to extend the predefined list + * Rationale: Certain themes should be able to extend the predefined list * of preferences. Display/editing is done in the theme specific userprefs.tmpl * but storage/sanification/update/... must be extended to the Get/SetPreferences methods. * @@ -29,7 +29,7 @@ extends _UserPreference var $valid_values = array ( 'itemCos', // Item-based Top-N recommendation algorithm with cosine-based similarity function - 'itemProb', // Item-based Top-N recommendation algorithm with probability-based similarity function. + 'itemProb', // Item-based Top-N recommendation algorithm with probability-based similarity function. // This algorithms tends to outperform the rest. 'userCos', // User-based Top-N recommendation algorithm with cosine-based similarity function. 'bayes'); // Naïve Bayesian Classifier @@ -45,7 +45,7 @@ class _UserPreference_recnnbr // recommendation engine key clustering, neighborh extends _UserPreference_numeric{}; $WikiTheme->customUserPreferences - (array + (array ( 'recengine' => new _UserPreference_recengine('php'), 'recalgo' => new _UserPreference_recalgo('itemProb'), diff --git a/lib/wikilens/RatingsDb.php b/lib/wikilens/RatingsDb.php index b7aa34190..d39f286a2 100644 --- a/lib/wikilens/RatingsDb.php +++ b/lib/wikilens/RatingsDb.php @@ -4,7 +4,7 @@ /* * @author: Dan Frankowski (wikilens group manager), Reini Urban (as plugin) * - * TODO: + * TODO: * - fix RATING_STORAGE = WIKIPAGE (dba, file) * - fix smart caching * - finish mysuggest.c (external engine with data from mysql) @@ -30,7 +30,7 @@ if (!defined('RATING_STORAGE')) // but this is problematic. define('RATING_STORAGE', $GLOBALS['request']->_dbi->_backend->isSQL() ? 'SQL' : 'WIKIPAGE'); //define('RATING_STORAGE','WIKIPAGE'); // not fully supported yet - + // leave undefined for internal, slow php engine. //if (!defined('RATING_EXTERNAL')) // define('RATING_EXTERNAL',PHPWIKI_DIR . 'suggest.exe'); @@ -61,38 +61,38 @@ class RatingsDb extends WikiDB { } elseif (isa($this->_backend, 'WikiDB_backend_ADODOB')) { $this->_sqlbackend = &$this->_backend; $this->dbtype = "ADODB"; - } else { - include_once("lib/WikiDB/backend/ADODB.php"); - // It is not possible to decouple a ref from the source again. (4.3.11) - // It replaced the main request backend. So we don't initialize _sqlbackend before. - //$this->_sqlbackend = clone($this->_backend); + } else { + include_once("lib/WikiDB/backend/ADODB.php"); + // It is not possible to decouple a ref from the source again. (4.3.11) + // It replaced the main request backend. So we don't initialize _sqlbackend before. + //$this->_sqlbackend = clone($this->_backend); $this->_sqlbackend = new WikiDB_backend_ADODB($GLOBALS['DBParams']); - $this->dbtype = "ADODB"; + $this->dbtype = "ADODB"; } $this->iter_class = "WikiDB_backend_".$this->dbtype."_generic_iter"; extract($this->_sqlbackend->_table_names); if (empty($rating_tbl)) { - $rating_tbl = (!empty($GLOBALS['DBParams']['prefix']) + $rating_tbl = (!empty($GLOBALS['DBParams']['prefix']) ? $GLOBALS['DBParams']['prefix'] : '') . 'rating'; $this->_sqlbackend->_table_names['rating_tbl'] = $rating_tbl; } } else { - $this->iter_class = "WikiDB_Array_PageIterator"; + $this->iter_class = "WikiDB_Array_PageIterator"; } } - + // this is a singleton. It ensures there is only 1 ratingsDB. function & getTheRatingsDb(){ static $_theRatingsDb; - + if (!isset($_theRatingsDb)){ $_theRatingsDb = new RatingsDb(); - } + } //echo "rating db is $_theRatingsDb"; return $_theRatingsDb; } - + /// ************************************************************************************* // FIXME @@ -110,7 +110,7 @@ class RatingsDb extends WikiDB { function deleteRating($userid=null, $pagename=null, $dimension=null) { if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($userid)) $userid = $this->userid; + if (is_null($userid)) $userid = $this->userid; if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { $this->sql_delete_rating($userid, $pagename, $dimension); @@ -118,13 +118,13 @@ class RatingsDb extends WikiDB { $this->metadata_set_rating($userid, $pagename, $dimension, -1); } } - + function getRating($userid=null, $pagename=null, $dimension=null) { if (RATING_STORAGE == 'SQL') { $ratings_iter = $this->sql_get_rating($dimension, $userid, $pagename); if ($rating = $ratings_iter->next() and isset($rating['ratingvalue'])) { return $rating['ratingvalue']; - } else + } else return false; } else { return $this->metadata_get_rating($userid, $pagename, $dimension); @@ -133,20 +133,19 @@ class RatingsDb extends WikiDB { function getUsersRated($dimension=null, $orderby = null) { if (is_null($dimension)) $dimension = $this->dimension; - //if (is_null($userid)) $userid = $this->userid; + //if (is_null($userid)) $userid = $this->userid; //if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { $ratings_iter = $this->sql_get_users_rated($dimension, $orderby); if ($rating = $ratings_iter->next() and isset($rating['ratingvalue'])) { return $rating['ratingvalue']; - } else + } else return false; } else { return $this->metadata_get_users_rated($dimension, $orderby); } } - - + /** * Get ratings. * @@ -184,7 +183,7 @@ class RatingsDb extends WikiDB { * If this is null (or left off), the info returned * is for the 'ratee' page (i.e., thing being rated). * - * @return DB iterator with results + * @return DB iterator with results */ function get_rating($dimension=null, $rater=null, $ratee=null, $orderby = null, $pageinfo = "ratee") { @@ -192,7 +191,7 @@ class RatingsDb extends WikiDB { $ratings_iter = $this->sql_get_rating($dimension, $rater, $pagename); if ($rating = $ratings_iter->next() and isset($rating['ratingvalue'])) { return $rating['ratingvalue']; - } else + } else return false; } else { return $this->metadata_get_rating($rater, $pagename, $dimension); @@ -205,12 +204,12 @@ class RatingsDb extends WikiDB { function get_users_rated($dimension=null, $pagename = null, $orderby = null) { if (RATING_STORAGE == 'SQL') { $ratings_iter = $this->sql_get_users_rated($dimension, $pagename, $orderby); - // iter as userid - $users = array(); - while ($rating = $ratings_iter->next()) { - $users[] = $rating['userid']; - } - return $users; + // iter as userid + $users = array(); + while ($rating = $ratings_iter->next()) { + $users[] = $rating['userid']; + } + return $users; } else { return $this->metadata_get_users_rated($dimension, $pagename, $orderby); } @@ -225,9 +224,9 @@ class RatingsDb extends WikiDB { if (RATING_STORAGE == 'SQL') { return $this->sql_get_rating($dimension, $rater, $ratee, $orderby, $pageinfo); } else { - // empty dummy iterator - $pages = array(); - return new WikiDB_Array_PageIterator($pages); + // empty dummy iterator + $pages = array(); + return new WikiDB_Array_PageIterator($pages); } } @@ -275,9 +274,9 @@ class RatingsDb extends WikiDB { $this->metadata_set_rating($userid, $pagename, $dimension, $rating); } } - + //function getUsersRated(){} - + //******************************************************************************* // TODO: // Use wikilens/RatingsUser.php for the php methods. @@ -287,22 +286,22 @@ class RatingsDb extends WikiDB { // http://www-users.cs.umn.edu/~karypis/suggest/ // until we implement a simple recommendation engine. // Note that "suggest" is only free for non-profit organizations. - // I am currently writing a binary CGI mysuggest using suggest, which loads + // I am currently writing a binary CGI mysuggest using suggest, which loads // data from mysql. function getPrediction($userid=null, $pagename=null, $dimension=null) { if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($userid)) $userid = $this->userid; + if (is_null($userid)) $userid = $this->userid; if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { $dbh = &$this->_sqlbackend; if (isset($pagename)) $page = $dbh->_get_pageid($pagename); - else + else return 0; if (isset($userid)) $user = $dbh->_get_pageid($userid); - else + else return 0; } if (defined('RATING_EXTERNAL') and RATING_EXTERNAL) { @@ -325,7 +324,7 @@ class RatingsDb extends WikiDB { */ function php_prediction($userid=null, $pagename=null, $dimension=null) { if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($userid)) $userid = $this->userid; + if (is_null($userid)) $userid = $this->userid; if (is_null($pagename)) $pagename = $this->pagename; if (empty($this->buddies)) { require_once("lib/wikilens/RatingsUser.php"); @@ -335,7 +334,7 @@ class RatingsDb extends WikiDB { } return $user->knn_uu_predict($pagename, $this->buddies, $dimension); } - + function getNumUsers($pagename=null, $dimension=null) { if (is_null($dimension)) $dimension = $this->dimension; if (is_null($pagename)) $pagename = $this->pagename; @@ -349,7 +348,7 @@ class RatingsDb extends WikiDB { $data = $page->get('rating'); if (!empty($data[$dimension])) return count($data[$dimension]); - else + else return 0; } } @@ -359,23 +358,23 @@ class RatingsDb extends WikiDB { if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { $dbi = &$this->_sqlbackend; - if (isset($pagename) || isset($dimension)) { - $where = "WHERE"; - } + if (isset($pagename) || isset($dimension)) { + $where = "WHERE"; + } if (isset($pagename)) { $raterid = $this->_sqlbackend->_get_pageid($pagename, true); $where .= " raterpage=$raterid"; } if (isset($dimension)) { - if (isset($pagename)) $where .= " AND"; + if (isset($pagename)) $where .= " AND"; $where .= " dimension=$dimension"; } //$dbh = &$this->_dbi; extract($dbi->_table_names); $query = "SELECT AVG(ratingvalue) as avg" - . " FROM $rating_tbl r, $page_tbl p " - . $where - . " GROUP BY raterpage"; + . " FROM $rating_tbl r, $page_tbl p " + . $where + . " GROUP BY raterpage"; $result = $dbi->_dbh->query($query); $iter = new $this->iter_class($this, $result); $row = $iter->next(); @@ -387,8 +386,8 @@ class RatingsDb extends WikiDB { if (!empty($data[$dimension])) // hash of userid => rating return array_sum(array_values($data[$dimension])) / count($data[$dimension]); - else - return 0; + else + return 0; } } //******************************************************************************* @@ -431,7 +430,7 @@ class RatingsDb extends WikiDB { * If this is null (or left off), the info returned * is for the 'ratee' page (i.e., thing being rated). * - * @return DB iterator with results + * @return DB iterator with results */ function sql_get_rating($dimension=null, $rater=null, $ratee=null, $orderby=null, $pageinfo = "ratee") { @@ -449,16 +448,16 @@ class RatingsDb extends WikiDB { // all users who rated this page resp if null all pages.. needed? function metadata_get_users_rated($dimension=null, $pagename=null, $orderby=null) { if (is_null($dimension)) $dimension = $this->dimension; - $users = array(); - if (!$pagename) { - // TODO: all pages? - return new WikiDB_Array_PageIterator($users); - } - $page = $this->_dbi->getPage($pagename); - $data = $page->get('rating'); - if (!empty($data[$dimension])) { - //array($userid => (float)$rating); - return new WikiDB_Array_PageIterator(array_keys($data[$dimension])); + $users = array(); + if (!$pagename) { + // TODO: all pages? + return new WikiDB_Array_PageIterator($users); + } + $page = $this->_dbi->getPage($pagename); + $data = $page->get('rating'); + if (!empty($data[$dimension])) { + //array($userid => (float)$rating); + return new WikiDB_Array_PageIterator(array_keys($data[$dimension])); } return new WikiDB_Array_PageIterator($users); } @@ -487,19 +486,19 @@ class RatingsDb extends WikiDB { } if (isset($ratee)) { if(is_array($ratee)){ - $where .= " AND ("; - for($i = 0; $i < count($ratee); $i++){ - $rateeid = $dbi->_get_pageid($ratee[$i], true); - $where .= "rateepage=$rateeid"; - if($i != (count($ratee) - 1)){ - $where .= " OR "; - } - } - $where .= ")"; - } else { - $rateeid = $dbi->_get_pageid($ratee, true); - $where .= " AND rateepage=$rateeid"; - } + $where .= " AND ("; + for($i = 0; $i < count($ratee); $i++){ + $rateeid = $dbi->_get_pageid($ratee[$i], true); + $where .= "rateepage=$rateeid"; + if($i != (count($ratee) - 1)){ + $where .= " OR "; + } + } + $where .= ")"; + } else { + $rateeid = $dbi->_get_pageid($ratee, true); + $where .= " AND rateepage=$rateeid"; + } } $orderbyStr = ""; if (isset($orderby)) { @@ -508,10 +507,10 @@ class RatingsDb extends WikiDB { if (isset($rater) or isset($ratee)) $what = '*'; // same as _get_users_rated_result() else { - $what = 'DISTINCT p.pagename'; - if ($pageinfo == 'rater') - $what = 'DISTINCT p.pagename as userid'; - } + $what = 'DISTINCT p.pagename'; + if ($pageinfo == 'rater') + $what = 'DISTINCT p.pagename as userid'; + } $query = "SELECT $what" . " FROM $rating_tbl r, $page_tbl p " @@ -582,24 +581,24 @@ class RatingsDb extends WikiDB { $insert = "INSERT INTO $rating_tbl (dimension, raterpage, rateepage, ratingvalue, rateeversion)" ." VALUES ('$dimension', $raterid, $rateeid, '$rating', '$rateeversion')"; $dbi->_dbh->query($insert); - + $dbi->unlock(); return true; } function metadata_get_rating($userid, $pagename, $dimension) { - if (!$pagename) return false; + if (!$pagename) return false; $page = $this->_dbi->getPage($pagename); $data = $page->get('rating'); if (!empty($data[$dimension][$userid])) return (float)$data[$dimension][$userid]; - else + else return false; } function metadata_set_rating($userid, $pagename, $dimension, $rating = -1) { - if (!$pagename) return false; - $page = $this->_dbi->getPage($pagename); + if (!$pagename) return false; + $page = $this->_dbi->getPage($pagename); $data = $page->get('rating'); if ($rating == -1) unset($data[$dimension][$userid]); @@ -615,7 +614,7 @@ class RatingsDb extends WikiDB { } /* -class RatingsDB_backend_PearDB +class RatingsDB_backend_PearDB extends WikiDB_backend_PearDB { function get_rating($dimension=null, $rater=null, $ratee=null, $orderby=null, $pageinfo = "ratee") { @@ -623,7 +622,7 @@ extends WikiDB_backend_PearDB { $dimension, $rater, $ratee, $orderby, $pageinfo); return new WikiDB_backend_PearDB_generic_iter($this, $result); } - + function get_users_rated($dimension=null, $orderby=null) { $result = $this->_get_users_rated_result( $dimension, $orderby); @@ -655,20 +654,20 @@ extends WikiDB_backend_PearDB { $where .= " AND raterpage=$raterid"; } if (isset($ratee)) { - if(is_array($ratee)){ - $where .= " AND ("; - for($i = 0; $i < count($ratee); $i++){ - $rateeid = $this->_get_pageid($ratee[$i], true); - $where .= "rateepage=$rateeid"; - if($i != (count($ratee) - 1)){ - $where .= " OR "; - } - } - $where .= ")"; - } else { - $rateeid = $this->_get_pageid($ratee, true); - $where .= " AND rateepage=$rateeid"; - } + if(is_array($ratee)){ + $where .= " AND ("; + for($i = 0; $i < count($ratee); $i++){ + $rateeid = $this->_get_pageid($ratee[$i], true); + $where .= "rateepage=$rateeid"; + if($i != (count($ratee) - 1)){ + $where .= " OR "; + } + } + $where .= ")"; + } else { + $rateeid = $this->_get_pageid($ratee, true); + $where .= " AND rateepage=$rateeid"; + } } $orderbyStr = ""; @@ -685,7 +684,7 @@ extends WikiDB_backend_PearDB { return $result; } - + function _get_users_rated_result($dimension=null, $orderby=null) { $dbh = &$this->_dbh; extract($this->_table_names); @@ -735,7 +734,7 @@ extends WikiDB_backend_PearDB { $this->unlock(); return true; } -} +} */ // Local Variables: diff --git a/lib/wikilens/RatingsUser.php b/lib/wikilens/RatingsUser.php index 33e57e518..a58340e5c 100644 --- a/lib/wikilens/RatingsUser.php +++ b/lib/wikilens/RatingsUser.php @@ -77,13 +77,13 @@ class RatingsUser { return $this->_rdbi; } - // XXX: may want to think about caching ratings in the PHP session + // XXX: may want to think about caching ratings in the PHP session // since a WikiUser is created for *every* access, in which case rate.php // will want to change to use this object instead of direct db access /** * Check whether $user is allowed to view this user's ratings - * + * * @return bool True if $user can view this user's ratings, false otherwise */ function allow_view_ratings($user) @@ -93,7 +93,7 @@ class RatingsUser { /** * Gets this user's ratings - * + * * @return array Assoc. array [page_name][dimension] = _UserRating object */ function get_ratings() @@ -104,13 +104,13 @@ class RatingsUser { /** * Gets this user's mean rating across a dimension - * + * * @return float Mean rating */ function mean_rating($dimension = 0) { // use memoized result if available - if (isset($this->_mean_ratings[$dimension])) + if (isset($this->_mean_ratings[$dimension])) { return $this->_mean_ratings[$dimension]; } @@ -147,8 +147,6 @@ class RatingsUser { $this->_load_ratings(); if (isset($dimension)) { - - if (isset($this->_ratings[$pagename][$dimension])) { return true; @@ -231,7 +229,7 @@ class RatingsUser { { return $this->_pearson_sims[$user->getId()][$dimension]; } - + $ratings1 = $this->get_ratings(); $mean1 = $this->mean_rating($dimension); // XXX: sanify user input? @@ -278,7 +276,7 @@ class RatingsUser { // items that the similarity was based on // prevent division-by-zero - if (sqrt($sum11) == 0 || sqrt($sum12) == 0) + if (sqrt($sum11) == 0 || sqrt($sum12) == 0) $sim = array(0, $n); else // Pearson similarity @@ -368,9 +366,9 @@ class RatingsUser { } $this->_num_ratings++; $this->_ratings[$rating['pagename']][$rating['dimension']] - = new _UserRating($this->_userid, + = new _UserRating($this->_userid, $rating['pagename'], - $rating['dimension'], + $rating['dimension'], $rating['ratingvalue']); } @@ -382,7 +380,7 @@ class RatingsUser { /** Represent a rating. */ class _UserRating { - function _UserRating ($rater, $ratee, $dimension, $rating) + function _UserRating ($rater, $ratee, $dimension, $rating) { $this->rater = (string)$rater; $this->ratee = (string)$ratee; @@ -390,42 +388,42 @@ class _UserRating $this->rating = (float)$rating; } - function get_rater() + function get_rater() { return $this->rater; } - function get_ratee() + function get_ratee() { return $this->ratee; } - function get_rating() + function get_rating() { return $this->rating; } - function get_dimension() + function get_dimension() { return $this->dimension; } - function set_rater() + function set_rater() { $this->rater = (string)$rater; } - function set_ratee() + function set_ratee() { $this->ratee = (string)$ratee; } - function set_rating() + function set_rating() { $this->rating = (float)$rating; } - function set_dimension() + function set_dimension() { $this->dimension = (int)$dimension; } diff --git a/lib/wikilens/Utils.php b/lib/wikilens/Utils.php index 9c8c3ae00..cc9ff7a9d 100644 --- a/lib/wikilens/Utils.php +++ b/lib/wikilens/Utils.php @@ -20,9 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/** - */ - function addPageTextData($user, $dbi, $new_data, $START_DELIM, $DELIM) { // This is largely lifted from the TranslateText plugin, which performs a // similar set of functions (retrieves a user's homepage, modifies it @@ -64,15 +61,15 @@ function getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM) { if (is_object($fromUser)) $fromUser = $fromUser->getId(); if ($fromUser == "") - return ""; + return ""; $userPage = $dbi->getPage($fromUser); $transformed = $userPage->getCurrentRevision(); $pageArray = $transformed->getContent(); $p = -1; for ($i = 0; $i < count($pageArray); $i++){ - if($pageArray[$i] != ""){ + if($pageArray[$i] != ""){ if(!((strpos($pageArray[$i], $START_DELIM)) === FALSE)){ - $p = $i; + $p = $i; break; } } -- 2.45.0