*/ class WikiPlugin_UserRatings extends WikiPlugin { function getName () { return _("UserRatings"); } function getDescription () { return _("List the user's ratings."); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 1.5 $"); } function getDefaultArguments() { return array('dimension' => '0', // array of userids to display ratings for; null/empty for // active user only 'userids' => null, // array of pageids to display ratings for; null for all // of current active user's ratings 'pageids' => null, // a category to display ratings for; null for no category; // has higher precedence than pageids 'category' => null, 'pagename' => '[pagename]', // hackish 'exclude' => '', 'limit' => 0, // limit of <=0 is show-all 'noheader' => 0, // rating columns are added later 'info' => 'pagename,ratingwidget'); // getting a bit crowded with the buddies... // 'info' => 'hits,pagename,author,ratingwidget'); } // info arg allows multiple columns // info=mtime,hits,summary,version,author,locked,minor // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges function run($dbi, $argstr, $request) { 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 = "Showing all ${category}s (%d):"; } // if null is passed as the pageids argument and no category was passed, // show active user's ratings 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(); $ratings = $active_user->get_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:"; } // 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)) { $userids = getBuddies($active_userid, $dbi); } 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 $allowed_users = array(); foreach($userids as $userid) { if($userid != $active_userid) { $user = new WikiUser($request, $userid, WIKIAUTH_USER); if($user->allow_view_ratings($active_user)) { array_push($allowed_users, $user); } } else { array_push($allowed_users, $active_user); } } $columns = $info ? explode(",", $info) : array(); // augment columns foreach($allowed_users as $user) { // can specify a custom heading by sending a colon-delimited pair array_push($columns, sprintf("ratingvalue:%s", $user->getId())); } // build our table... $pagelist = new PageList($columns, $exclude, array('dimension' => $dimension, 'users' => $allowed_users)); // 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; } }; // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>