*
*
*/
require_once('lib/PageList.php');
class WikiPlugin_PopularNearby
extends WikiPlugin
{
function getName () {
return _("PopularNearby");
}
function getDescription () {
return _("List the most popular pages nearby.");
}
function getVersion() {
return preg_replace("/[Revision: $]/", '',
"\$Revision: 1.2 $");
}
function getDefaultArguments() {
return array('pagename' => '[pagename]',
'mode' => 'nearby', // or 'incoming' or 'outgoing'
'exclude' => '',
'limit' => 5,
'noheader' => 0,
);
}
function run($dbi, $argstr, &$request, $basepage) {
$args = $this->getArgs($argstr, $request);
extract($args);
$header = '';
$page = $dbi->getPage($pagename);
switch ($mode) {
case 'incoming': // not the hits, but the number of links
if (! $noheader )
$header = sprintf(_("%d best incoming links: "),$limit);
$links = $this->sortedLinks($page->getLinks("reversed"),"reversed",$limit);
break;
case 'outgoing': // not the hits, but the number of links
if (! $noheader )
$header = sprintf(_("%d best outgoing links: "),$limit);
$links = $this->sortedLinks($page->getLinks(),false,$limit);
break;
case 'nearby': // all linksfrom and linksto, sorted by hits
if (! $noheader )
$header = sprintf(_("%d most popular nearby: "),$limit);
$inlinks = $page->getLinks();
$outlinks = $page->getLinks('reversed');
$links = $this->sortedLinks(array_merge($inlinks->asArray(),
$outlinks->asArray()),
false,$limit);
break;
}
$html = HTML($header);
for ($i=0; $ipushContent($links[$i]['format'],$iget('hits');
if (!$hits) continue;
$links[] = array('hits' => $hits,
'pagename' => $page->_pagename,
'format' => HTML(WikiLink($page->_pagename),' (' . $hits . ')'));
}
} else {
while ($page = $pages->next()) {
// different score algorithm:
// the number of links to/from the page
$l = $page->getLinks(!$direction);
$score = $l->count();
if (!$score) continue;
$name = $page->_pagename;
$links[] = array('hits' => $score,
'pagename' => $name,
'format' => HTML(WikiLink($name),' (' . $score . ')'));
}
$pages->free();
}
if (count($links) > $limit)
array_splice($links, $limit);
return $this->sortByHits($links);
}
function sortByHits($links) {
if (!$links) return array();
usort($links,array('WikiPlugin_PopularNearby','cmp_hits'));
reset($links);
return $links;
}
function cmp_hits($a, $b) {
return ($a['hits'] < $b['hits']) ? 1 : ($a['hits'] == $b['hits']) ? 0 : -1;
}
};
// $Log: not supported by cvs2svn $
// Revision 1.1 2004/04/29 18:32:38 rurban
// Re-implement the classic phpwiki-1.2 feature of the
// * 5 best incoming links: xx, xx, xx, ...
// * 5 best outgoing links: xx, xx, xx, ...
// * 5 most popular nearby: xx, xx, xx, ...
//
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>