/**
 * internal setup function. It just bring the possibility to callback functions from get param.
 */
function wiki_setup_content()
{
    //this function contains all the instructions to configurate the module
    global $dfformaddtitle, $dfformoldcontent, $CFG;
    $dfform = wiki_param('dfform');
    //this is a little tricky for the editor: javascript can't refer
    //dfform[content] but it can refer dfformcontent.
    if ($dfformcontent = wiki_param('dfformcontent')) {
        $dfform['content'] = $dfformcontent;
    }
    if (isset($dfformaddtitle)) {
        $dfform['addtitle'] = $dfformaddtitle;
    }
    if (isset($dfformoldcontent)) {
        $dfform['oldcontent'] = $dfformoldcontent;
    }
    wiki_param('dfform', $dfform);
    $dfsetup = wiki_param('dfsetup');
    $dfsetupf = wiki_param('dfsetupf');
    if (is_numeric($dfsetup) && isset($dfsetupf[$dfsetup])) {
        $main_function = $dfsetupf[$dfsetup];
    } else {
        $main_function = 'wiki_main_setup';
    }
    if (!function_exists($main_function)) {
        require_once $CFG->dirroot . '/blocks/wiki_ead/lib.php';
        require_once $CFG->dirroot . '/blocks/wiki_search/lib.php';
    }
    $main_function();
}
/**
 * This file contains block_wiki_new_page functions.
 * @deprecated version - 23/08/2007
 * @author DFWiki LABS
 * @author Marc Alier i Forment
 * @author David Castro, Ferran Recio, Jordi Piguillem, UPC, 
 * and members of DFWikiteam listed at http://morfeo.upc.edu/crom
 * @version  $Id: lib.php,v 1.6 2007/08/23 12:24:00 tusefomal Exp $
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package Wiki_Blocks
 */
function wiki_block_new_page()
{
    $name = optional_param('dfformname', NULL, PARAM_FILE);
    if (isset($name)) {
        wiki_param('page', $name);
    }
    wiki_main_setup();
}
 /**
  * Constructor of the class.
  *
  * @param   int     $wikiid
  * @param   string  $name
  * @param   int     $version
  * @param   int     $groupid
  * @param   int     $ownerid
  */
 function wiki_pageid($wikiid = null, $name = null, $version = null, $groupid = null, $ownerid = null)
 {
     global $WS;
     if (isset($wikiid)) {
         $this->wikiid = $wikiid;
         $this->name = $name;
         $this->version = $version;
         $this->groupid = $groupid;
         $this->ownerid = $ownerid;
     } else {
         $wiki = wiki_param('dfwiki');
         $this->wikiid = $wiki->id;
         $this->name = $WS->page;
         $this->version = null;
         $this->groupid = $WS->groupmember->groupid;
         $this->ownerid = 0;
         if ($WS->cm->groupmode == 0 or $wiki->studentmode != 0) {
             $this->ownerid = $WS->member->id;
         }
     }
 }
function wiki_ead_cleanpage()
{
    global $dfwiki_ead_stat;
    $cleanpage = optional_param('cleanpage', NULL, PARAM_FILE);
    $dfwiki = wiki_param('dfwiki');
    if (wiki_can_change()) {
        if (wiki_page_exists(false, $cleanpage, false)) {
            $cleanconfirm = optional_param('dfformcleanconfirm', NULL, PARAM_ALPHA);
            if (isset($cleanconfirm)) {
                $cleanvers = optional_param('dfformcleanvers', NULL, PARAM_INT);
                if (delete_records_select('wiki_pages', 'dfwiki=' . $dfwiki->id . ' and pagename=\'' . addslashes($cleanpage) . '\' and version < ' . $cleanvers)) {
                    $dfwiki_ead_stat = 'cleanok';
                } else {
                    $dfwiki_ead_stat = 'cleanerror';
                }
            } else {
                //show confirm form
                $dfwiki_ead_stat = 'cleanconfirm';
            }
        } else {
            //this page can't be eliminated
            $dfwiki_ead_stat = 'cleanerror';
        }
    }
    wiki_param('dfcontent', 9);
    wiki_main_setup();
}
<?php

require_once $CFG->dirroot . '/mod/wiki/part/search/lib.php';
//include part tabs
//$tabme = new wikitab ('prova','$baseurl/part/prova/index.php?$pageselector','prova_tab',true);
//wiki_add_tab($tabme);
$dfform = wiki_param('dfform');
if (optional_param('dfsearch') || isset($dfform['field']) && trim($dfform['field']) != '') {
    wiki_add_callback('dfsetup', 'wiki_part_search_load');
}
function wiki_footer()
{
    global $COURSE, $CFG;
    ///document	ending
    $PAGE = wiki_page_info('PAGE');
    $pageblocks = wiki_page_info('pageblocks');
    $editing = $PAGE->user_is_editing();
    wiki_table_end();
    /// The right column
    //if there are not blocks on the right part then don't enter in this condition
    if (!empty($pageblocks[BLOCK_POS_RIGHT])) {
        //to work out the default widths need to check all blocks
        $preferred_width_right = optional_param('preferred_width_right', blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), PARAM_INT);
        //preferred_width_right sizes
        //should be between BLOCK_x_MAX_WIDTH and BLOCK_x_MIN_WIDTH.
        $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
        $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
    }
    //if there are blocks on the right part, then they are placed
    if (!empty($pageblocks[BLOCK_POS_RIGHT])) {
        //checks if there are blocks to place on the right-hand side
        if (!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing)) {
            $prop = new stdClass();
            $prop->id = "right-column";
            $prop->class = "blockcourse";
            wiki_change_column($prop);
            $prop = new stdClass();
            $prop->width = $preferred_width_right . 'px';
            wiki_table_start($prop);
            blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
            wiki_table_end();
            $prop = new stdClass();
        }
    }
    wiki_table_end();
    // select the teacher
    $cm = wiki_param('cm');
    $dfwiki = wiki_param('dfwiki');
    wiki_print_teacher_selection($cm, $dfwiki);
    wiki_div_end();
    // content wrapper end
    /// Finish the page
    print_footer($COURSE);
}
function wiki_can_change($deprecated = false)
{
    $cm = wiki_param('cm');
    $dfwiki = wiki_param('dfwiki');
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (has_capability('mod/wiki:editanywiki', $context) or !$cm->groupmode and has_capability('mod/wiki:editawiki', $context)) {
        return true;
    } else {
        return false;
    }
}
/**
 * return a moment callbacks list
 * @param String $breakname: identifier of the breakname
 * @return Array of Strings
 */
function wiki_get_callbacks($breakname)
{
    $callbacks = wiki_param('wiki_callback');
    $res = array();
    if (!is_array($callbacks)) {
        return $res;
    }
    if (!isset($callbacks[$breakname])) {
        return $res;
    }
    return $callbacks[$breakname];
}
/*if ($id) {
        $cm = wiki_param ('cm',get_coursemodule_from_id('wiki',$id));
        if (!$cm) {
            error("Course Module ID was incorrect");
        }
        if (! $course = get_record("course", "id", $WS->cm->course)) {
            error("Course is misconfigured");
        }
    } else {
        $dfwiki = wiki_param ('dfwiki',get_record('wiki', "id", $a));
        if (!$dfwiki) {
            error("Course module is incorrect");
        }
        if (! $course = get_record("course", "id", $WS->dfwiki->course)) {
            error("Course is misconfigured");
		}
    }*/
//$WS->set_info($id);
///wiki_param (null,null,'set_info');
/*$cm = wiki_param('cm');
	if (!$course = get_record("course", "id", $cm->course)) {
		error("Course is misconfigured");
	}*/
$course = wiki_param('course');
///require_login($course->id);
///wiki_setup_content();
//The format begins here
wiki_header();
// Include the actual course format
wiki_print_content($WS);
wiki_footer();
function parse_username_datetime($matches)
{
    $wikimanager = wiki_manager_get_instance();
    $page = wiki_param('pagedata');
    $author = $wikimanager->get_user_info($page->author);
    return $author->firstname . " " . $author->lastname . ", " . strftime('%x') . " - " . strftime('%X');
}
 function set_info($id = false)
 {
     global $CFG, $USER, $COURSE, $course;
     //trying to force cm id
     if ($id) {
         $this->id = $id;
     }
     if (!isset($this->a) || !$this->a) {
         $a = optional_param('a', NULL, PARAM_INT);
         wiki_param('a', $a);
     }
     if (!isset($this->id) || !$this->id) {
         $id = optional_param('id', NULL, PARAM_INT);
         wiki_param('id', $id);
     }
     //course-module
     if (isset($this->id) && $this->id) {
         if (!($this->cm = get_coursemodule_from_id('wiki', $this->id))) {
             error("Course Module ID was incorrect");
         }
     } else {
         if (!($this->cm = get_coursemodule_from_instance('wiki', $this->a))) {
             error("Course Module ID was incorrect");
         }
     }
     if (!($this->dfwiki = get_record('wiki', "id", $this->cm->instance))) {
         error("Course Module is incorrect");
     }
     if (!($this->course = get_record("course", "id", $this->cm->course))) {
         error("Course is misconfigured");
     }
     //for some reason it's necessary to use $course as a global
     $course = $this->course;
     if (!isset($this->a) || !$this->a) {
         $this->a = $this->cm->instance;
     }
     if (!isset($this->id) || !$this->id) {
         $this->id = $this->cm->id;
     }
     /*if (!isset($this->cm->id)) {
     			if (! $this->cm = get_coursemodule_from_instance('wiki',$this->dfwiki->id)) {
     	            error("Course Module ID was incorrect");
     	        }
     		} else {
     			if (! $this->cm = get_coursemodule_from_id('wiki',$this->cm->id)) {
     	            error("Course Module ID was incorrect02");
     	        }
     		}
     		//dfwiki
     		if (!isset($this->dfwiki->id)) {
     	        if (! $this->dfwiki = get_record('wiki', "id", $this->cm->instance)) {
     	            error("Course Module is incorrect");
     	        }
     		}*/
     $this->linkid = $this->cm->id;
     if (isset($this->dfcourse)) {
         $this->wikitype = '/course/view.php?id=';
         $this->linkid = $COURSE->id;
     }
     //$this->pagename = wiki_get_real_pagename ($this,$this->dfwiki->pagename);
     //load user group data
     if (isset($this->gid)) {
         $this->groupmember->groupid = $this->gid;
     } else {
         if (isset($this->dfform['selectgroup'])) {
             $this->groupmember->groupid = $this->dfform['selectgroup'];
         } else {
             if (isset($USER->groupmember)) {
                 if (!in_array($this->groupmember, $USER->groupmember)) {
                     $this->groupmember->groupid = '0';
                 }
             }
             if ($this->cm->id == '0') {
                 $this->groupmember->groupid = '0';
             }
             if ($this->cm->groupmode != '0') {
                 $group = get_records('groups_members', 'userid', $USER->id);
                 if (is_array($group)) {
                     $this->groupmember->groupid = array_shift($group)->groupid;
                 }
             }
         }
     }
     //load user data
     if ($this->uid) {
         $this->member->id = $this->uid;
     } else {
         if (isset($this->dfform['selectstudent'])) {
             $this->member->id = $this->dfform['selectstudent'];
         } else {
             $this->member->id = $USER->id;
             //for commune wiki or students in group
             if ($this->dfwiki->studentmode == '0') {
                 $this->member->id = '0';
             }
         }
     }
     //load teacher page if it's selected
     if (isset($this->dfform['selectteacher'])) {
         $this->member->id = $this->dfform['selectteacher'];
         //teacher group (by the moment without group):
         $this->groupmember->groupid = 0;
     }
     $this->wikibook = optional_param('wikibook', NULL, PARAM_CLEANHTML);
 }
 function get_content()
 {
     global $CFG, $WS;
     $wiki = wiki_param('dfwiki');
     $groupmember = wiki_param('groupmember');
     if ($this->content !== NULL) {
         return $this->content;
     }
     //Scritp WIKI_TREE
     $prop = null;
     $prop->type = 'text/javascript';
     if (isset($WS->dfcourse)) {
         $prop->src = '../mod/wiki/editor/wiki_tree.js';
     } else {
         $prop->src = 'editor/wiki_tree.js';
     }
     wiki_script('', $prop);
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     //$this->content->footer = '<br />'.helpbutton ('list_pages', get_string('block_list_pages', 'wiki'), 'wiki', true, false, '', true).get_string('block_list_pages', 'wiki');
     $this->content->items[] = '<a href="http://www.google.com">google</a>';
     $this->content->icons[] = '<img src="icon.gif" alt="">';
     //If we are out of a dfwiki activity or in a different
     //dfwiki format course and we want to create a block:
     if (empty($WS->dfwiki)) {
         $this->content->text = get_string('block_warning', 'wiki');
         return $this->content;
     }
     $ead = wiki_manager_get_instance();
     $pages = $ead->get_wiki_page_names_of_wiki($wiki, $groupmember->groupid);
     $this->orderpages($pages);
     $syns = $ead->get_wiki_synonyms();
     $this->orderpages($syns);
     $list = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="nwikileftnow">
 			<ul class="wiki_listme">';
     if (!isset($WS->pagedata->pagename)) {
         $WS->load_page_data();
     }
     if (count($pages) != 0) {
         foreach ($this->ordereds as $key => $ordered) {
             //chack if the letter is the curretn one.
             if ($key == $this->get_index($WS->pagedata->pagename)) {
                 $display = '';
                 $image_ico = $this->images['minus'];
             } else {
                 $display = 'display:none';
                 $image_ico = $this->images['plus'];
             }
             $list .= '<li class="wiki_listme">' . $image_ico . '<a href="#" class="wiki_folding">' . $key . '</a>
 					<ul class="wiki_listme" style="margin:auto auto auto 15px;' . $display . '">';
             // dfwiki-block || course-block
             $dir = "";
             if ($this->instance->pagetype == "mod-wiki-view") {
                 $dir = $CFG->wwwroot . '/mod/wiki/view.php?id=' . $WS->cm->id;
             } else {
                 $dir = $CFG->wwwroot . '/course/view.php?id=' . $WS->cm->course;
             }
             foreach ($ordered as $link) {
                 if (in_array($link, $syns)) {
                     $page_icon = $this->images['syn'];
                     $page = wiki_get_real_pagename($link);
                 } else {
                     $page_icon = $this->images['square'];
                     $page = $link;
                 }
                 $list .= '<li class="wiki_listme">' . $page_icon . '<a href="' . $dir . '&amp;page=' . urlencode($page) . '&amp;gid=' . $WS->groupmember->groupid . '&amp;uid=' . $WS->member->id . '" title="' . urlencode($link) . '">' . format_text($this->trim_string($link, 20), FORMAT_PLAIN) . '</a>' . '</li>';
             }
             $list .= '</ul></li>';
         }
     } else {
         $list .= '<li>' . get_string('nopages', 'wiki') . '</li>';
     }
     $list .= '</ul></td></tr></table>';
     $this->content->text = $list;
     $this->content->footer .= '<style>.wiki_listme { padding-right:5px; } .dir-rtl td.nwikileftnow  { text-align:right; } </style>';
     return $this->content;
 }
 /**
  * return an array with page names where user participates EXCLUDING THE DISCUSSION PAGES
  * @param int $user
  * @return array of Strings
  */
 function user_activity($user)
 {
     $dfwiki = wiki_param('dfwiki');
     $res = $this->user_activity_in_wiki($user, $dfwiki->id);
     if (!$res) {
         return array();
     }
     return $res;
 }
/**
 * this function return an array with the pagenames of search results
 */
function wiki_part_search_result($text)
{
    global $CFG, $WS;
    $res = array('pagename' => array(), 'content' => array());
    // mount search string
    $field = '%';
    $fields = explode(' ', $text);
    foreach ($fields as $f) {
        $field .= $f . '%';
    }
    $ead = wiki_manager_get_instance();
    $wiki = wiki_param('dfwiki');
    $groupmember = wiki_param('groupmember');
    $pages = $ead->get_wiki_page_names_of_wiki($wiki, $groupmember->groupid);
    foreach ($pages as $page) {
        $pageinfo = wiki_page_last_version($page);
        $contentfound = count($fields) != 0;
        $namefound = count($fields) != 0;
        foreach ($fields as $f) {
            $f = stripslashes_safe($f);
            $namefound = $namefound && stripos($pageinfo->pagename, $f) !== false;
            $contentfound = $contentfound && strpos($pageinfo->content, $f) !== false;
        }
        if ($contentfound) {
            $res['content'][] = $pageinfo->pagename;
        }
        if ($namefound) {
            $res['pagename'][] = $pageinfo->pagename;
        }
    }
    // search in synonyms
    $wikimanager = wiki_manager_get_instance();
    $synonyms = $wikimanager->get_synonyms_by_wikiid($WS->dfwiki->id);
    foreach ($synonyms as $synonym) {
        $found = count($fields) != 0;
        foreach ($fields as $f) {
            $f = stripslashes_safe($f);
            $found = $found && stripos($synonym->name, $f) !== false;
        }
        if ($found && !in_array($synonym->pageid->name, $res['pagename'])) {
            $res['pagename'][] = $synonym->pageid->name;
        }
    }
    return $res;
}
 /**
  * this function return the real name if it's a synonymous,
  * or the same pagename otherwise.
  * 
  * @param   string  $name       name of the page.
  * @param   int     $id         dfwiki instance id, current dfwiki default
  * @param   int     $onwerid
  * @param   int     $groupid
  * @return  string
  */
 function wiki_get_real_pagename($name, $id = false, $groupid = null, $ownerid = null)
 {
     //set default $id value
     //$id = ($id)? $id : $WS->dfwiki->id;
     $dfwiki = wiki_param('dfwiki');
     $id = $id ? $id : $dfwiki->id;
     $select = "syn='" . addslashes($name) . "' AND dfwiki={$id}";
     if (isset($groupid)) {
         $select .= " AND groupid={$groupid}";
     }
     if (isset($ownerid)) {
         $select .= " AND ownerid={$ownerid}";
     }
     //watch in synonymous
     if ($synonymous = get_record_select('wiki_synonymous', $select)) {
         //if there's synonymous search for the original
         return $synonymous->original;
     }
     //if isn't a synonymous it will be an original or an uncreated page.
     return $name;
 }
function wiki_convert_tree_to_html($tree, $row = 0)
{
    global $WS;
    $str = "\n" . '<ul class="tabrow' . $row . '">' . "\n";
    $first = true;
    $count = count($tree);
    foreach ($tree as $tab) {
        $count--;
        // countdown to zero
        $liclass = '';
        if ($first && $count == 0) {
            // Just one in the row
            $liclass = 'first last';
            $first = false;
        } else {
            if ($first) {
                $liclass = 'first';
                $first = false;
            } else {
                if ($count == 0) {
                    $liclass = 'last';
                }
            }
        }
        if (empty($tab->subtree) && !empty($tab->selected)) {
            $liclass .= empty($liclass) ? 'onerow' : ' onerow';
        }
        if ($tab->inactive || $tab->active || $tab->selected && !$tab->linkedwhenselected) {
            if ($tab->selected) {
                $liclass .= empty($liclass) ? 'here selected' : ' here selected';
            } else {
                if ($tab->active) {
                    $liclass .= empty($liclass) ? 'here active' : ' here active';
                }
            }
        }
        $str .= !empty($liclass) ? '<li class="' . $liclass . '">' : '<li>';
        $page = wiki_param('page');
        if (!wiki_discussion_page_exists($WS, $page) && $tab->id == 'discussion' && $tab->text == get_string('discuss', 'wiki')) {
            $estilo = ' style="color:red"';
        } else {
            $estilo = "";
        }
        if ($tab->inactive || $tab->active || $tab->selected && !$tab->linkedwhenselected) {
            $str .= '<a href="#" title="' . $tab->title . '"><span' . $estilo . '>' . $tab->text . '</span></a>';
        } else {
            $str .= '<a href="' . $tab->link . '" title="' . $tab->title . '"><span' . $estilo . '>' . $tab->text . '</span></a>';
        }
        if (!empty($tab->subtree)) {
            $str .= wiki_convert_tree_to_html($tab->subtree, $row + 1);
        } else {
            if ($tab->selected) {
                $str .= '<div class="tabrow' . ($row + 1) . ' empty">&nbsp;</div>' . "\n";
            }
        }
        $str .= '</li>' . "\n";
    }
    $str .= '</ul>' . "\n";
    return $str;
}