2 //This function provides automatic linking to
3 //wiki pages when its page title is found inside every Moodle text
4 //It's based in the glosssary filter by Williams Castillo
5 //Modifications by mchurch. Enjoy! :-)
7 require_once($CFG->dirroot
.'/mod/wiki/lib.php');
9 function wiki_filter($courseid, $text) {
16 if (!empty($nothingtodo)) { // We've been here in this page already
20 if (empty($courseid)) {
24 /// Create a list of all the wikis to search for. It may be cached already.
26 if (empty($wikipagelist)) {
28 /// Get all wikis for this course.
29 if (!$wikis = wiki_get_course_wikis($courseid)) {
34 $wikipagelist = array();
36 /// Walk through each wiki, and get entries.
37 foreach ($wikis as $wiki) {
38 if ($wiki_entries = wiki_get_entries($wiki)) {
40 /// Walk through each entry and get the pages.
41 foreach ($wiki_entries as $wiki_entry) {
42 if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id
, 'pagename, version DESC')) {
43 /// Walk through each page and filter.
44 $wikientries = array();
45 foreach ($wiki_pages as $wiki_page) {
46 if (!in_array($wiki_page->pagename
, $wikientries)) {
47 $startlink = '<a class="wiki autolink" title="Wiki" href="'
48 .$CFG->wwwroot
.'/mod/wiki/view.php?wid='.$wiki->id
49 .'&userid='.$wiki_entry->userid
50 .'&groupid='.$wiki_entry->groupid
51 .'&page='.$wiki_page->pagename
.'">';
52 $wikipagelist[] = new filterobject($wiki_page->pagename
, $startlink, '</a>', false, true);
53 $wikientries[] = $wiki_page->pagename
;
62 return filter_phrases($text, $wikipagelist);