From: <var...@us...> - 2022-03-24 13:48:03
|
Revision: 11013 http://sourceforge.net/p/phpwiki/code/11013 Author: vargenau Date: 2022-03-24 13:48:01 +0000 (Thu, 24 Mar 2022) Log Message: ----------- run php-cs-fixer Modified Paths: -------------- trunk/lib/wikilens/Buddy.php trunk/lib/wikilens/CustomPrefs.php trunk/lib/wikilens/PageListColumns.php trunk/lib/wikilens/RatingsDb.php trunk/lib/wikilens/RatingsUser.php trunk/lib/wikilens/Utils.php Modified: trunk/lib/wikilens/Buddy.php =================================================================== --- trunk/lib/wikilens/Buddy.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/Buddy.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -36,7 +36,7 @@ // serialized string. // If no homepage, fallback to prefs in cookie as in 1.3.3. -require_once (dirname(__FILE__) . "/Utils.php"); +require_once(dirname(__FILE__) . "/Utils.php"); function addBuddy($user, $buddy, $dbi) { @@ -78,13 +78,13 @@ } else { // from 10 random raters of this page (non-SQL) } - } $result = array(); - if (is_array($buddies_array)) + if (is_array($buddies_array)) { foreach ($buddies_array as $userid) { $result[] = new RatingsUser($userid); } + } return $result; } Modified: trunk/lib/wikilens/CustomPrefs.php =================================================================== --- trunk/lib/wikilens/CustomPrefs.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/CustomPrefs.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -38,10 +38,13 @@ public $valid_values = array('php', 'mysuggest', 'mymovielens', 'mycluto'); public $default_value = 'php'; - function sanify($value) + public function sanify($value) { - if (!in_array($value, $this->valid_values)) return $this->default_value; - else return $value; + if (!in_array($value, $this->valid_values)) { + return $this->default_value; + } else { + return $value; + } } } @@ -48,8 +51,7 @@ class _UserPreference_recalgo // recommendation engine algorithm extends _UserPreference { - public $valid_values = array - ( + public $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. // This algorithms tends to outperform the rest. @@ -57,10 +59,13 @@ 'bayes'); // Naïve Bayesian Classifier public $default_value = 'itemProb'; - function sanify($value) + public function sanify($value) { - if (!in_array($value, $this->valid_values)) return $this->default_value; - else return $value; + if (!in_array($value, $this->valid_values)) { + return $this->default_value; + } else { + return $value; + } } } @@ -69,9 +74,7 @@ { } -$WikiTheme->customUserPreferences -(array -( +$WikiTheme->customUserPreferences(array( 'recengine' => new _UserPreference_recengine('php'), 'recalgo' => new _UserPreference_recalgo('itemProb'), //recnnbr: typically 15-30 for item-based, 40-80 for user-based algos Modified: trunk/lib/wikilens/PageListColumns.php =================================================================== --- trunk/lib/wikilens/PageListColumns.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/PageListColumns.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -46,13 +46,13 @@ */ class _PageList_Column_numbacklinks extends _PageList_Column_custom { - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { $theIter = $page_handle->getBackLinks(); return $theIter->count(); } - function _getSortableValue($page_handle, $revision_handle) + public function _getSortableValue($page_handle, $revision_handle) { return $this->_getValue($page_handle, $revision_handle); } @@ -60,7 +60,7 @@ class _PageList_Column_coagreement extends _PageList_Column_custom { - function __construct($params) + public function __construct($params) { $this->_pagelist =& $params[3]; _PageList_Column::__construct($params[0], $params[1], $params[2]); @@ -67,7 +67,7 @@ $this->_selectedBuddies = $this->_pagelist->getOption('selectedBuddies'); } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { global $request; @@ -93,7 +93,7 @@ class _PageList_Column_minmisery extends _PageList_Column_custom { - function __construct($params) + public function __construct($params) { $this->_pagelist =& $params[3]; _PageList_Column::__construct($params[0], $params[1], $params[2]); @@ -100,7 +100,7 @@ $this->_selectedBuddies = $this->_pagelist->getOption('selectedBuddies'); } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { global $request, $WikiTheme; @@ -117,7 +117,7 @@ class _PageList_Column_averagerating extends _PageList_Column_custom { - function __construct($params) + public function __construct($params) { $this->_pagelist =& $params[3]; _PageList_Column::__construct($params[0], $params[1], $params[2]); @@ -124,7 +124,7 @@ $this->_selectedBuddies = $this->_pagelist->getOption('selectedBuddies'); } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { global $request, $WikiTheme; @@ -153,7 +153,7 @@ public $_user; public $_dimension; - function __construct($params) + public function __construct($params) { $this->_pagelist =& $params[3]; $this->_user =& $params[4]; //$this->_pagelist->getOption('user'); @@ -164,10 +164,12 @@ } parent::__construct($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension'); - if (!$this->_dimension) $this->_dimension = 0; + if (!$this->_dimension) { + $this->_dimension = 0; + } } - function format($pagelist, $page_handle, $revision_handle) + public function format($pagelist, $page_handle, $revision_handle) { /** * @var WikiRequest $request @@ -174,8 +176,9 @@ */ global $request; - if (empty($this->_user)) + if (empty($this->_user)) { $this->_user =& RatingsUserFactory::getUser($request->_user->_userid); + } assert(!empty($this->_user)); $rating = $this->_getValue($page_handle, $revision_handle); $mean = $this->_user->mean_rating($this->_dimension); @@ -182,8 +185,9 @@ $td = HTML::td($this->_tdattr); $div = HTML::div(); - if ($rating != '-' && abs($rating - $mean) >= 0.75) + if ($rating != '-' && abs($rating - $mean) >= 0.75) { $div->setAttr('style', 'color: #' . ($rating > $mean ? '009900' : 'ff3333')); + } $div->pushContent($rating); $td->pushContent($div); @@ -191,7 +195,7 @@ return $td; } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { $pagename = $page_handle->getName(); @@ -202,7 +206,7 @@ return ($rating ? $rating : "-"); } - function hasNoRatings($pages) + public function hasNoRatings($pages) { $total = 0; $use = & $this->_user; @@ -215,10 +219,9 @@ return true; } return false; - } - function _getSortableValue($page_handle, $revision_handle) + public function _getSortableValue($page_handle, $revision_handle) { return $this->_getValue($page_handle, $revision_handle); } @@ -230,23 +233,35 @@ */ class _PageList_Column_ratingwidget extends _PageList_Column_custom { - function __construct($params) + public function __construct($params) { $this->_pagelist =& $params[3]; _PageList_Column::__construct($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension'); - if (!$this->_dimension) $this->_dimension = 0; + if (!$this->_dimension) { + $this->_dimension = 0; + } } - function format($pagelist, $page_handle, $revision_handle) + public function format($pagelist, $page_handle, $revision_handle) { $plugin = new WikiPlugin_RateIt(); if (defined('FUSIONFORGE') && FUSIONFORGE) { - $widget = $plugin->RatingWidgetHtml($page_handle->getName(), "", - "BStar", $this->_dimension, "small"); + $widget = $plugin->RatingWidgetHtml( + $page_handle->getName(), + "", + "BStar", + $this->_dimension, + "small" + ); } else { - $widget = $plugin->RatingWidgetHtml($page_handle->getName(), "", - "Star", $this->_dimension, "small"); + $widget = $plugin->RatingWidgetHtml( + $page_handle->getName(), + "", + "Star", + $this->_dimension, + "small" + ); } $td = HTML::td($widget); $td->setAttr('nowrap', 'nowrap'); @@ -253,7 +268,7 @@ return $td; } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { global $request; @@ -271,7 +286,7 @@ } } - function _getSortableValue($page_handle, $revision_handle) + public function _getSortableValue($page_handle, $revision_handle) { return $this->_getValue($page_handle, $revision_handle); } @@ -282,7 +297,7 @@ public $_active_ratings_user; public $_users; - function __construct($params) + public function __construct($params) { global $request; $active_user = $request->getUser(); @@ -292,11 +307,13 @@ $this->_pagelist =& $params[3]; parent::__construct($params[0], $params[1], $params[2]); $this->_dimension = $this->_pagelist->getOption('dimension'); - if (!$this->_dimension) $this->_dimension = 0; + if (!$this->_dimension) { + $this->_dimension = 0; + } $this->_users = $this->_pagelist->getOption('users'); } - function format($pagelist, $page_handle, $revision_handle) + public function format($pagelist, $page_handle, $revision_handle) { $pred = $this->_getValue($page_handle, $revision_handle); $mean = $this->_active_ratings_user->mean_rating($this->_dimension); @@ -303,8 +320,9 @@ $td = HTML::td($this->_tdattr); $div = HTML::div(); - if ($pred > 0 && abs($pred - $mean) >= 0.75) + if ($pred > 0 && abs($pred - $mean) >= 0.75) { $div->setAttr('style', 'color: #' . ($pred > $mean ? '009900' : 'ff3333')); + } $div->pushContent($pred); $td->pushContent($div); @@ -312,7 +330,7 @@ return $td; } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { $pagename = $page_handle->getName(); @@ -320,7 +338,7 @@ return sprintf("%.1f", min(5, max(0, $pred))); } - function _getSortableValue($page_handle, $revision_handle) + public function _getSortableValue($page_handle, $revision_handle) { return $this->_getValue($page_handle, $revision_handle); } @@ -328,11 +346,10 @@ class _PageList_Column_top3recs extends _PageList_Column_custom { - public $_active_ratings_user; public $_users; - function __construct($params) + public function __construct($params) { global $request; $active_user = $request->getUser(); @@ -349,12 +366,14 @@ if (!empty($params[3])) { $this->_pagelist =& $params[3]; $this->_dimension = $this->_pagelist->getOption('dimension'); - if (!$this->_dimension) $this->_dimension = 0; + if (!$this->_dimension) { + $this->_dimension = 0; + } $this->_users = $this->_pagelist->getOption('users'); } } - function _getValue($page_handle, $revision_handle) + public function _getValue($page_handle, $revision_handle) { $ratings = $this->_active_ratings_user->get_ratings(); $iter = $page_handle->getLinks(); @@ -363,8 +382,11 @@ //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); + $this->_active_ratings_user->knn_uu_predict( + $current->getName(), + $this->_users, + $this->_dimension + ); } } arsort($recs); @@ -397,9 +419,7 @@ // register custom PageList type global $WikiTheme; -$WikiTheme->addPageListColumn -(array -( +$WikiTheme->addPageListColumn(array( 'numbacklinks' => array('_PageList_Column_numbacklinks', 'custom:numbacklinks', _("# things"), 'center'), Modified: trunk/lib/wikilens/RatingsDb.php =================================================================== --- trunk/lib/wikilens/RatingsDb.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/RatingsDb.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -53,8 +53,9 @@ // For other than SQL backends. dba ratings are allowed but deprecated. // We will probably drop this hack. -if (!defined('RATING_STORAGE')) +if (!defined('RATING_STORAGE')) { define('RATING_STORAGE', $request->_dbi->_backend->isSQL() ? 'SQL' : 'WIKIPAGE'); +} //define('RATING_STORAGE','WIKIPAGE'); // not fully supported yet // leave undefined for internal, slow php engine. @@ -62,20 +63,23 @@ // define('RATING_EXTERNAL',PHPWIKI_DIR . 'suggest.exe'); // Dimensions -if (!defined('EXPLICIT_RATINGS_DIMENSION')) +if (!defined('EXPLICIT_RATINGS_DIMENSION')) { define('EXPLICIT_RATINGS_DIMENSION', 0); -if (!defined('LIST_ITEMS_DIMENSION')) +} +if (!defined('LIST_ITEMS_DIMENSION')) { define('LIST_ITEMS_DIMENSION', 1); -if (!defined('LIST_OWNER_DIMENSION')) +} +if (!defined('LIST_OWNER_DIMENSION')) { define('LIST_OWNER_DIMENSION', 2); -if (!defined('LIST_TYPE_DIMENSION')) +} +if (!defined('LIST_TYPE_DIMENSION')) { define('LIST_TYPE_DIMENSION', 3); +} //TODO: split class into SQL and metadata backends class RatingsDb extends WikiDB { - - function __construct() + public function __construct() { global $request; $this->_dbi = &$request->_dbi; @@ -103,7 +107,7 @@ } // this is a singleton. It ensures there is only 1 ratingsDB. - static function & getTheRatingsDb() + public static function & getTheRatingsDb() { static $_theRatingsDb; @@ -115,10 +119,10 @@ } -/// ************************************************************************************* -// FIXME -// from Reini Urban's RateIt plugin - function addRating($rating, $userid, $pagename, $dimension) + /// ************************************************************************************* + // FIXME + // from Reini Urban's RateIt plugin + public function addRating($rating, $userid, $pagename, $dimension) { if (RATING_STORAGE == 'SQL') { $page = $this->_dbi->getPage($pagename); @@ -130,11 +134,17 @@ } } - function deleteRating($userid = null, $pagename = null, $dimension = null) + public 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($pagename)) $pagename = $this->pagename; + if (is_null($dimension)) { + $dimension = $this->dimension; + } + 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); } else { @@ -142,22 +152,25 @@ } } - function getRating($userid = null, $pagename = null, $dimension = null) + public 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); } } - function getUsersRated($dimension = null, $orderby = null) + public function getUsersRated($dimension = null, $orderby = null) { - if (is_null($dimension)) $dimension = $this->dimension; + if (is_null($dimension)) { + $dimension = $this->dimension; + } //if (is_null($userid)) $userid = $this->userid; //if (is_null($pagename)) $pagename = $this->pagename; if (RATING_STORAGE == 'SQL') { @@ -164,8 +177,9 @@ $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); } @@ -210,15 +224,21 @@ * * @return DB iterator with results */ - function get_rating($dimension = null, $rater = null, $ratee = null, - $orderby = null, $pageinfo = "ratee") + public function get_rating( + $dimension = null, + $rater = null, + $ratee = null, + $orderby = null, + $pageinfo = "ratee" + ) { if (RATING_STORAGE == 'SQL') { $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); } @@ -227,7 +247,7 @@ /* UR: What is this for? NOT USED! Maybe the list of users (ratees) who rated on this page. */ - function get_users_rated($dimension = null, $pagename = null, $orderby = null) + public function get_users_rated($dimension = null, $pagename = null, $orderby = null) { if (RATING_STORAGE == 'SQL') { $ratings_iter = $this->sql_get_users_rated($dimension, $pagename, $orderby); @@ -246,8 +266,13 @@ * Like get_rating(), but return a WikiDB_PageIterator * FIXME! */ - function get_rating_page($dimension = null, $rater = null, $ratee = null, - $orderby = null, $pageinfo = "ratee") + public function get_rating_page( + $dimension = null, + $rater = null, + $ratee = null, + $orderby = null, + $pageinfo = "ratee" + ) { if (RATING_STORAGE == 'SQL') { return $this->sql_get_rating($dimension, $rater, $ratee, $orderby, $pageinfo); @@ -303,7 +328,7 @@ //function getUsersRated(){} -//******************************************************************************* + //******************************************************************************* // TODO: // Use wikilens/RatingsUser.php for the php methods. // @@ -314,29 +339,38 @@ // Note that "suggest" is only free for non-profit organizations. // I am currently writing a binary CGI mysuggest using suggest, which loads // data from mysql. - function getPrediction($userid = null, $pagename = null, $dimension = null) + public 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($pagename)) $pagename = $this->pagename; + if (is_null($dimension)) { + $dimension = $this->dimension; + } + if (is_null($userid)) { + $userid = $this->userid; + } + if (is_null($pagename)) { + $pagename = $this->pagename; + } if (RATING_STORAGE == 'SQL') { $dbh = &$this->_sqlbackend; - if (isset($pagename)) + if (isset($pagename)) { $page = $dbh->_get_pageid($pagename); - else + } else { return 0; - if (isset($userid)) + } + if (isset($userid)) { $user = $dbh->_get_pageid($userid); - else + } else { return 0; + } } if (defined('RATING_EXTERNAL') and RATING_EXTERNAL) { // how call mysuggest.exe? as CGI or natively //$rating = HTML::raw("<!--#include virtual=".RATING_ENGINE." -->"); $args = "-u$user -p$page -malpha"; // --top 10 - if (isset($dimension)) + if (isset($dimension)) { $args .= " -d$dimension"; + } $rating = passthru(RATING_EXTERNAL . " $args"); } else { $rating = $this->php_prediction($userid, $pagename, $dimension); @@ -349,7 +383,7 @@ * Only the SUGGEST_EstimateAlpha part * Take wikilens/RatingsUser.php for the php methods. */ - function php_prediction($userid = null, $pagename = null, $dimension = null) + public function php_prediction($userid = null, $pagename = null, $dimension = null) { /** * @var WikiRequest $request @@ -356,9 +390,15 @@ */ global $request; - if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($userid)) $userid = $this->userid; - if (is_null($pagename)) $pagename = $this->pagename; + if (is_null($dimension)) { + $dimension = $this->dimension; + } + if (is_null($userid)) { + $userid = $this->userid; + } + if (is_null($pagename)) { + $pagename = $this->pagename; + } if (empty($this->buddies)) { require_once 'lib/wikilens/RatingsUser.php'; require_once 'lib/wikilens/Buddy.php'; @@ -368,29 +408,45 @@ return $user->knn_uu_predict($pagename, $this->buddies, $dimension); } - function getNumUsers($pagename = null, $dimension = null) + public function getNumUsers($pagename = null, $dimension = null) { - if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($pagename)) $pagename = $this->pagename; + if (is_null($dimension)) { + $dimension = $this->dimension; + } + if (is_null($pagename)) { + $pagename = $this->pagename; + } if (RATING_STORAGE == 'SQL') { - $ratings_iter = $this->sql_get_rating($dimension, null, $pagename, - null, "ratee"); + $ratings_iter = $this->sql_get_rating( + $dimension, + null, + $pagename, + null, + "ratee" + ); return $ratings_iter->count(); } else { - if (!$pagename) return 0; + if (!$pagename) { + return 0; + } $page = $this->_dbi->getPage($pagename); $data = $page->get('rating'); - if (!empty($data[$dimension])) + if (!empty($data[$dimension])) { return count($data[$dimension]); - else + } else { return 0; + } } } - function getAvg($pagename = null, $dimension = null) + public function getAvg($pagename = null, $dimension = null) { - if (is_null($dimension)) $dimension = $this->dimension; - if (is_null($pagename)) $pagename = $this->pagename; + if (is_null($dimension)) { + $dimension = $this->dimension; + } + if (is_null($pagename)) { + $pagename = $this->pagename; + } if (RATING_STORAGE == 'SQL') { $dbi = &$this->_sqlbackend; if (isset($pagename) || isset($dimension)) { @@ -406,7 +462,9 @@ } } if (isset($dimension)) { - if (isset($pagename)) $where .= " AND"; + if (isset($pagename)) { + $where .= " AND"; + } $where .= " dimension=$dimension"; } extract($dbi->_table_names); @@ -420,19 +478,21 @@ $row = $iter->next(); return is_array($row) ? $row['avg'] : 0; } else { - if (!$pagename) + if (!$pagename) { return 0; + } $page = $this->_dbi->getPage($pagename); $data = $page->get('rating'); - if (!empty($data[$dimension])) + if (!empty($data[$dimension])) { // hash of userid => rating return array_sum(array_values($data[$dimension])) / count($data[$dimension]); - else + } else { return 0; + } } } -//******************************************************************************* + //******************************************************************************* /** * Get ratings. @@ -474,25 +534,36 @@ * * @return DB iterator with results */ - function sql_get_rating($dimension = null, $rater = null, $ratee = null, - $orderby = null, $pageinfo = "ratee") + public function sql_get_rating( + $dimension = null, + $rater = null, + $ratee = null, + $orderby = null, + $pageinfo = "ratee" + ) { - if (is_null($dimension)) $dimension = $this->dimension; + if (is_null($dimension)) { + $dimension = $this->dimension; + } $result = $this->_sql_get_rating_result($dimension, $rater, $ratee, $orderby, $pageinfo); return new $this->iter_class($this, $result); } - function sql_get_users_rated($dimension = null, $pagename = null, $orderby = null) + public function sql_get_users_rated($dimension = null, $pagename = null, $orderby = null) { - if (is_null($dimension)) $dimension = $this->dimension; + if (is_null($dimension)) { + $dimension = $this->dimension; + } $result = $this->_sql_get_rating_result($dimension, null, $pagename, $orderby, "rater"); return new $this->iter_class($this, $result); } // all users who rated this page resp if null all pages.. needed? - function metadata_get_users_rated($dimension = null, $pagename = null, $orderby = null) + public function metadata_get_users_rated($dimension = null, $pagename = null, $orderby = null) { - if (is_null($dimension)) $dimension = $this->dimension; + if (is_null($dimension)) { + $dimension = $this->dimension; + } $users = array(); if (!$pagename) { // TODO: all pages? @@ -510,15 +581,22 @@ /** * @return result ressource, suitable to the iterator */ - private function _sql_get_rating_result($dimension = null, $rater = null, $ratee = null, - $orderby = null, $pageinfo = "ratee") + private function _sql_get_rating_result( + $dimension = null, + $rater = null, + $ratee = null, + $orderby = null, + $pageinfo = "ratee" + ) { // pageinfo must be 'rater' or 'ratee' - if (($pageinfo != "ratee") && ($pageinfo != "rater")) + if (($pageinfo != "ratee") && ($pageinfo != "rater")) { return; + } $dbi = &$this->_sqlbackend; - if (is_null($dbi)) + if (is_null($dbi)) { return; + } //$dbh = &$this->_dbi; extract($dbi->_table_names); $where = "WHERE r." . $pageinfo . "page = p.id"; @@ -549,12 +627,15 @@ if (isset($orderby)) { $orderbyStr = " ORDER BY " . $orderby; } - if (isset($rater) or isset($ratee)) $what = '*'; + if (isset($rater) or isset($ratee)) { + $what = '*'; + } // same as _get_users_rated_result() else { $what = 'DISTINCT p.pagename'; - if ($pageinfo == 'rater') + if ($pageinfo == 'rater') { $what = 'DISTINCT p.pagename as userid'; + } } $query = "SELECT $what" @@ -609,8 +690,9 @@ { $dbi = &$this->_sqlbackend; extract($dbi->_table_names); - if (empty($rating_tbl)) + if (empty($rating_tbl)) { $rating_tbl = $this->_dbi->getParam('prefix') . 'rating'; + } $dbi->lock(); $raterid = $dbi->_get_pageid($rater, true); @@ -628,31 +710,36 @@ return true; } - function metadata_get_rating($userid, $pagename, $dimension) + public 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])) + if (!empty($data[$dimension][$userid])) { return (float)$data[$dimension][$userid]; - else + } else { return false; + } } - function metadata_set_rating($userid, $pagename, $dimension, $rating = -1) + public function metadata_set_rating($userid, $pagename, $dimension, $rating = -1) { - if (!$pagename) return; + if (!$pagename) { + return; + } $page = $this->_dbi->getPage($pagename); $data = $page->get('rating'); - if ($rating == -1) + if ($rating == -1) { unset($data[$dimension][$userid]); - else { - if (empty($data[$dimension])) + } else { + if (empty($data[$dimension])) { $data[$dimension] = array($userid => (float)$rating); - else + } else { $data[$dimension][$userid] = (float)$rating; + } } $page->set('rating', $data); } - } Modified: trunk/lib/wikilens/RatingsUser.php =================================================================== --- trunk/lib/wikilens/RatingsUser.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/RatingsUser.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -31,7 +31,7 @@ class RatingsUserFactory { - static function & getUser($userid) + public static function & getUser($userid) { //print "getUser($userid) "; global $_ratingsUserCache; @@ -60,7 +60,7 @@ public $_mean_ratings; public $_pearson_sims; - function __construct($userid) + public function __construct($userid) { $this->_userid = $userid; $this->_ratings_loaded = false; @@ -70,18 +70,19 @@ $this->_pearson_sims = array(); } - function getId() + public function getId() { return $this->_userid; } - function & _get_rating_dbi() + public function & _get_rating_dbi() { // This is a hack, because otherwise this object doesn't know about a // DBI at all. Perhaps all this ratings stuff should live somewhere // else that's less of a base class. - if (isset($this->_rdbi)) + if (isset($this->_rdbi)) { return $this->_rdbi; + } $this->_rdbi = RatingsDb::getTheRatingsDb(); return $this->_rdbi; } @@ -95,7 +96,7 @@ * * @return bool True if $user can view this user's ratings, false otherwise */ - function allow_view_ratings($user) + public function allow_view_ratings($user) { return true; } @@ -105,7 +106,7 @@ * * @return array Assoc. array [page_name][dimension] = _UserRating object */ - function get_ratings() + public function get_ratings() { $this->_load_ratings(); return $this->_ratings; @@ -116,7 +117,7 @@ * * @return float Mean rating */ - function mean_rating($dimension = 0) + public function mean_rating($dimension = 0) { // use memoized result if available if (isset($this->_mean_ratings[$dimension])) { @@ -147,7 +148,7 @@ // ephemeral and doesn't particularly care about the ratings count or any // other features that these methods might provide down the road) - function has_rated($pagename, $dimension = null) + public function has_rated($pagename, $dimension = null) { // XXX: does this really want to do a full ratings load? (scalability?) $this->_load_ratings(); @@ -163,12 +164,12 @@ return false; } - function get_rating($pagename, $dimension = 0) + public function get_rating($pagename, $dimension = 0) { // XXX: does this really want to do a full ratings load? (scalability?) - if (RATING_STORAGE == 'SQL') + if (RATING_STORAGE == 'SQL') { $this->_load_ratings(); - else { + } else { $rdbi = $this->_get_rating_dbi(); return $rdbi->metadata_get_rating($this->getId(), $pagename, $dimension); } @@ -179,7 +180,7 @@ return false; } - function set_rating($pagename, $dimension, $rating) + public function set_rating($pagename, $dimension, $rating) { // XXX: does this really want to do a full ratings load? (scalability?) $this->_load_ratings(); @@ -199,7 +200,7 @@ } } - function unset_rating($pagename, $dimension) + public function unset_rating($pagename, $dimension) { // XXX: does this really want to do a full ratings load? (scalability?) $this->_load_ratings(); @@ -215,7 +216,7 @@ } } - function pearson_similarity($user, $dimension = 0) + public function pearson_similarity($user, $dimension = 0) { // use memoized result if available if (isset($this->_pearson_sims[$user->getId()][$dimension])) { @@ -264,11 +265,12 @@ // 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 + } else { // Pearson similarity $sim = array($sum12 / (sqrt($sum11) * sqrt($sum22)), $n); + } // print "sim is " . $sim[0] . "<BR><BR>"; @@ -277,7 +279,7 @@ return $this->_pearson_sims[$user->getId()][$dimension] = $sim; } - function knn_uu_predict($pagename, &$neighbors, $dimension = 0) + public function knn_uu_predict($pagename, &$neighbors, $dimension = 0) { /* print "<PRE>"; @@ -298,8 +300,9 @@ $nbor =& $neighbors[$i]; // ignore self-neighbor - if ($this->getId() == $nbor->getId()) + if ($this->getId() == $nbor->getId()) { continue; + } if ($nbor->has_rated($pagename, $dimension)) { list($sim, $n_items) = $this->pearson_similarity($nbor); @@ -307,8 +310,9 @@ // XXX: no filtering done... small-world = too few neighbors if (1 || ($sim > 0 && abs($sim) >= 0.1)) { // n/50 sig weighting - if ($n_items < 50) + if ($n_items < 50) { $sim *= $n_items / 50; + } /* print "neighbor is " . $nbor->getId() . "<BR>"; print "weighted sim is " . $sim . "<BR>"; @@ -330,7 +334,7 @@ return ($total_sim == 0 ? 0 : ($total / $total_sim + $my_mean)); } - function _load_ratings($force = false) + public function _load_ratings($force = false) { if (!$this->_ratings_loaded || $force) { // print "load " . $this->getId() . "<BR>"; @@ -352,10 +356,12 @@ } $this->_num_ratings++; $this->_ratings[$rating['pagename']][$rating['dimension']] - = new _UserRating($this->_userid, - $rating['pagename'], - $rating['dimension'], - $rating['ratingvalue']); + = new _UserRating( + $this->_userid, + $rating['pagename'], + $rating['dimension'], + $rating['ratingvalue'] + ); } $this->_ratings_loaded = true; @@ -366,7 +372,7 @@ /** Represent a rating. */ class _UserRating { - function __construct($rater, $ratee, $dimension, $rating) + public function __construct($rater, $ratee, $dimension, $rating) { $this->rater = (string)$rater; $this->ratee = (string)$ratee; @@ -374,42 +380,42 @@ $this->rating = (float)$rating; } - function get_rater() + public function get_rater() { return $this->rater; } - function get_ratee() + public function get_ratee() { return $this->ratee; } - function get_rating() + public function get_rating() { return $this->rating; } - function get_dimension() + public function get_dimension() { return $this->dimension; } - function set_rater() + public function set_rater() { $this->rater = (string)$rater; } - function set_ratee() + public function set_ratee() { $this->ratee = (string)$ratee; } - function set_rating() + public function set_rating() { $this->rating = (float)$rating; } - function set_dimension() + public function set_dimension() { $this->dimension = (int)$dimension; } Modified: trunk/lib/wikilens/Utils.php =================================================================== --- trunk/lib/wikilens/Utils.php 2022-03-24 13:44:55 UTC (rev 11012) +++ trunk/lib/wikilens/Utils.php 2022-03-24 13:48:01 UTC (rev 11013) @@ -43,8 +43,11 @@ // add new data to the appropriate line if (preg_match('/^' . preg_quote($START_DELIM, '/') . '/', $text)) { // need multiline modifier to match EOL correctly - $text = preg_replace('/(^' . preg_quote($START_DELIM, '/') . '.*)$/m', - '$1' . $DELIM . $new_data, $text); + $text = preg_replace( + '/(^' . preg_quote($START_DELIM, '/') . '.*)$/m', + '$1' . $DELIM . $new_data, + $text + ); } else { // handle case where the line does not yet exist $text .= "\n" . $START_DELIM . $new_data . "\n"; @@ -56,16 +59,20 @@ function getMembers($groupName, $dbi, $START_DELIM = false, $DELIM = ",") { - if (!$START_DELIM) $START_DELIM = _("Members:"); + if (!$START_DELIM) { + $START_DELIM = _("Members:"); + } return getPageTextData($groupName, $dbi, $START_DELIM, $DELIM); } function getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM) { - if (is_object($fromUser)) + if (is_object($fromUser)) { $fromUser = $fromUser->getId(); - if ($fromUser == "") + } + if ($fromUser == "") { return ""; + } $userPage = $dbi->getPage($fromUser); $transformed = $userPage->getCurrentRevision(); $pageArray = $transformed->getContent(); @@ -72,7 +79,7 @@ $p = -1; for ($i = 0; $i < count($pageArray); $i++) { if ($pageArray[$i] != "") { - if (!((strpos($pageArray[$i], $START_DELIM)) === FALSE)) { + if (!((strpos($pageArray[$i], $START_DELIM)) === false)) { $p = $i; break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |