From 76e24be96dbf0481c6f25b693add584137bad2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Ra=C3=B1a?= Date: Fri, 3 Oct 2008 19:50:30 +0200 Subject: [PATCH] [svn r16434] WIKI: orphaned pages, wanted pages, most visited pages, most changed pages --- main/wiki/index.php | 197 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 192 insertions(+), 5 deletions(-) diff --git a/main/wiki/index.php b/main/wiki/index.php index cba5be3cbd..98e21a505c 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -187,7 +187,7 @@ if ($_POST['SaveWikiNew']) } else { - $_clean['assignment']=Database::escape_string($_POST['assignment']); //Juan Carlos Raña for mode assignment + $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment if ($_clean['assignment']==1) { auto_add_page_users($_clean['assignment']); @@ -288,7 +288,7 @@ echo '
  • '; //menu more -//echo '
  • '; // by now turn off +echo '
  • '; //menu add page echo '
  • '; @@ -341,18 +341,197 @@ echo "
    "; if ($_GET['action']=='more') { - echo '
    '; + echo '
    '; echo ''.get_lang('More').'
    '; - echo '
    '; + echo '
    '; + echo ''; +} +/////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado +if ($_GET['action']=='mactiveusers') +{ + echo '
    '; + echo ''.get_lang('MostActiveUsers').'
    '; + echo '
    '; //TODO + +} + +/////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='mostchanged') +{ + echo '
    '; + echo ''.get_lang('MostChanges').'
    '; + echo '
    '; + + $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY MAX DESC, reflink LIMIT 10'; //first ten users + $allpages=api_sql_query($sql,__FILE__,__LINE__); + echo ''; + +} + +/////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='mvisited') +{ + echo '
    '; + echo ''.get_lang('MostVisitedPages').'
    '; + echo '
    '; + + $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY tsum DESC, reflink LIMIT 10'; //first ten pages + $allpages=api_sql_query($sql,__FILE__,__LINE__); + echo ''; +} + +/////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='wanted') +{ + echo '
    '; + echo ''.get_lang('WantedPages').'
    '; + echo '
    '; + $pages = array(); + $refs = array(); + $orphaned = array(); + $sort_wanted=array(); + + //get name pages + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + $pages[] = $row['reflink']; + } + + //get name refs in last pages and make a unique list + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check + $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " " + $refs = array_merge($refs, $rf); + if ($n++ > 299) + { + $refs = array_unique($refs); + $n=0; + } // (clean-up only every 300th loop). Thanks to Erfurt Wiki + } + + //sort linksto. Find linksto into reflink. If not found ->page is wanted + natcasesort($refs); + foreach($refs as $v) + { + if(!in_array($v, $pages)) + { + $wanted[] = $v; + echo $v.'
    '; //TODO: link to page and convert reflink to title + } + } } +/////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='orphaned') +{ + echo '
    '; + echo ''.get_lang('OrphanedPages').'
    '; + echo '
    '; + + $pages = array(); + $refs = array(); + $orphaned = array(); + $sort_orphaned=array(); + + //get name pages + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + $pages[] = $row['reflink']; + } + + //get name refs in last pages and make a unique list + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check + $rf = explode("\n", trim($row["linksto"])); + + $refs = array_merge($refs, $rf); + if ($n++ > 299) + { + $refs = array_unique($refs); + $n=0; + } // (clean-up only every 300th loop). Thanks to Erfurt Wiki + } + + //search each name of list linksto into list reflink + foreach($pages as $v) + { + if(!in_array($v, $refs)) + { + $orphaned[] = $v; + } + } + + //change reflink by title + foreach($orphaned as $vshow) + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" GROUP BY reflink'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + echo ''; + } + + //sort titles //TODO: check to delete this line + //natcasesort($sort_orphaned);//TODO: check to delete this line + //foreach($sort_orphaned as $vshow_so)//TODO: check to delete this line + //{ + //echo $vshow_so.'
    '; //TODO: link to page //TODO: check to delete this line + //}//TODO: check to delete this line + +} /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado @@ -1883,6 +2062,14 @@ function display_wiki_entry() $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version + //update visits + if($row['id']) + { + $sql='UPDATE '.$tbl_wiki.' SET hits=(hits+1) WHERE id='.$row['id'].''; + api_sql_query($sql,__FILE__,__LINE__); + } + + // if both are empty and we are displaying the index page then we display the default text. if ($row['content']=='' AND $row['title']=='' AND $page='index') {