From: skaldrom Date: Fri, 3 Sep 2004 21:02:27 +0000 (+0000) Subject: Fix for Bug #1603 - Shortening URLs in Wiki pages X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=087fef3ed47a1d49c7289c146ad48715232d7368;p=moodle.git Fix for Bug #1603 - Shortening URLs in Wiki pages - Renamed wikipage in page (URL and variable) - When groupid or userid is 0, it is not shown anymore (I hope I have changed all places) --- diff --git a/mod/wiki/admin.php b/mod/wiki/admin.php index cd7026f260..e5d615fa6e 100644 --- a/mod/wiki/admin.php +++ b/mod/wiki/admin.php @@ -11,11 +11,11 @@ optional_variable($id); // Course Module ID, or - optional_variable($wikipage); // Pagename + optional_variable($page, false); // Pagename optional_variable($confirm, ""); optional_variable($action,""); // Admin Action - optional_variable($userid); // User wiki. - optional_variable($groupid); // Group wiki. + optional_variable($userid, 0); // User wiki. + optional_variable($groupid, 0); // Group wiki. if ($id) { if (! $cm = get_record("course_modules", "id", $id)) { @@ -44,9 +44,9 @@ /// Build the ewsiki script constant $ewbase = 'view.php?id='.$id; - if (isset($userid)) $ewbase .= '&userid='.$userid; - if (isset($groupid)) $ewbase .= '&groupid='.$groupid; - $ewscript = $ewbase.'&wikipage='; + if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid; + if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid; + $ewscript = $ewbase.'&page='; define("EWIKI_SCRIPT", $ewscript); if($wiki->ewikiacceptbinary) { define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size()); @@ -148,7 +148,7 @@ break; } add_to_log($course->id, "wiki", $action, "admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id", $wiki->name.($addloginfo?": ".$addloginfo:"")); - $link="admin.php?action=$action&userid=$userid&groupid=$groupid&id=$id&wikipage=$wikipage"; + $link="admin.php?action=$action".($userid?"&userid=".$userid:"").($groupid?"&groupid=".$groupid:"")."&id=$id&page=$page"; switch($action) { case "removepages": if($form->proceed) { @@ -219,7 +219,7 @@ } /// Actions which need a confirmation. If confirmed, do the action - $redirect="view.php?userid=$userid&groupid=$groupid&id=$id&wikipage=$wikipage"; + $redirect="view.php?".($groupid?"&groupid=".$groupid:"").($userid?"&userid=".$userid:"")."&id=$id&page=$page"; if($confirm && !$err) { switch($action) { case "removepages": @@ -317,7 +317,7 @@ /// Administrative Links echo ''; - wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $wikipage, $wiki->htmlmode!=2, $course); + wiki_print_administration_actions($wiki, $cm->id, $userid, $groupid, $page, $wiki->htmlmode!=2, $course); echo ''; # if($wiki->htmlmode!=2) { diff --git a/mod/wiki/filter.php b/mod/wiki/filter.php index 80da61b726..7d7fd26493 100755 --- a/mod/wiki/filter.php +++ b/mod/wiki/filter.php @@ -1 +1 @@ -dirroot.'/mod/wiki/lib.php'); function wiki_filter($courseid, $text) { global $CFG; if (empty($courseid)) { if ($site = get_site()) { $courseid = $site->id; } } if (!($course = get_record('course', 'id', $courseid))) { return $text; } // Get all wikis for this course. $wikis = wiki_get_course_wikis($courseid); if (empty($wikis)) { return $text; } // Walk through each wiki, and get entries. foreach ($wikis as $wiki) { if ($wiki_entries = wiki_get_entries($wiki)) { // Walk through each entry and get the pages. foreach ($wiki_entries as $wiki_entry) { if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) { // Walk through each page and filter. foreach ($wiki_pages as $wiki_page) { $startlink = ''; $text = wiki_link_names($text, $wiki_page->pagename, $startlink, ''); } } } } } return $text; } function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "") { $list_of_words_cp = strip_tags($name); $list_of_words_cp = trim($list_of_words_cp,'|'); $list_of_words_cp = trim($list_of_words_cp); $list_of_words_cp = preg_quote($list_of_words_cp,'/'); $invalidprefixs = "([a-zA-Z0-9])"; $invalidsufixs = "([a-zA-Z0-9])"; //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs $words = array(); $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is'; preg_match_all($regexp,$text,$list_of_words); foreach (array_unique($list_of_words[0]) as $key=>$value) { $words['<*'.$key.'*>'] = $value; } if (!empty($words)) { $text = str_replace($words,array_keys($words),$text); } //Now avoid searching inside the tag $excludes = array(); preg_match_all('/(.+?)<\/nolink>/is',$text,$list_of_excludes); foreach (array_unique($list_of_excludes[0]) as $key=>$value) { $excludes['<+'.$key.'+>'] = $value; } if (!empty($excludes)) { $text = str_replace($excludes,array_keys($excludes),$text); } //Now avoid searching inside links $links = array(); preg_match_all('/(.+?)<\/A>/is',$text,$list_of_links); foreach (array_unique($list_of_links[0]) as $key=>$value) { $links['<@'.$key.'@>'] = $value; } if (!empty($links)) { $text = str_replace($links,array_keys($links),$text); } //Now avoid searching inside every tag $final = array(); preg_match_all('/<(.+?)>/is',$text,$list_of_tags); foreach (array_unique($list_of_tags[0]) as $key=>$value) { $final['<|'.$key.'|>'] = $value; } if (!empty($final)) { $text = str_replace($final,array_keys($final),$text); } $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text); //Now rebuild excluded areas if (!empty($final)) { $text = str_replace(array_keys($final),$final,$text); } if (!empty($links)) { $text = str_replace(array_keys($links),$links,$text); } if (!empty($excludes)) { $text = str_replace(array_keys($excludes),$excludes,$text); } if (!empty($words)) { $text = str_replace(array_keys($words),$words,$text); } return $text; } ?> \ No newline at end of file +dirroot.'/mod/wiki/lib.php'); function wiki_filter($courseid, $text) { global $CFG; if (empty($courseid)) { if ($site = get_site()) { $courseid = $site->id; } } if (!($course = get_record('course', 'id', $courseid))) { return $text; } // Get all wikis for this course. $wikis = wiki_get_course_wikis($courseid); if (empty($wikis)) { return $text; } // Walk through each wiki, and get entries. foreach ($wikis as $wiki) { if ($wiki_entries = wiki_get_entries($wiki)) { // Walk through each entry and get the pages. foreach ($wiki_entries as $wiki_entry) { if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) { // Walk through each page and filter. foreach ($wiki_pages as $wiki_page) { $startlink = ''; $text = wiki_link_names($text, $wiki_page->pagename, $startlink, ''); } } } } } return $text; } function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "") { $list_of_words_cp = strip_tags($name); $list_of_words_cp = trim($list_of_words_cp,'|'); $list_of_words_cp = trim($list_of_words_cp); $list_of_words_cp = preg_quote($list_of_words_cp,'/'); $invalidprefixs = "([a-zA-Z0-9])"; $invalidsufixs = "([a-zA-Z0-9])"; //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs $words = array(); $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is'; preg_match_all($regexp,$text,$list_of_words); foreach (array_unique($list_of_words[0]) as $key=>$value) { $words['<*'.$key.'*>'] = $value; } if (!empty($words)) { $text = str_replace($words,array_keys($words),$text); } //Now avoid searching inside the tag $excludes = array(); preg_match_all('/(.+?)<\/nolink>/is',$text,$list_of_excludes); foreach (array_unique($list_of_excludes[0]) as $key=>$value) { $excludes['<+'.$key.'+>'] = $value; } if (!empty($excludes)) { $text = str_replace($excludes,array_keys($excludes),$text); } //Now avoid searching inside links $links = array(); preg_match_all('/(.+?)<\/A>/is',$text,$list_of_links); foreach (array_unique($list_of_links[0]) as $key=>$value) { $links['<@'.$key.'@>'] = $value; } if (!empty($links)) { $text = str_replace($links,array_keys($links),$text); } //Now avoid searching inside every tag $final = array(); preg_match_all('/<(.+?)>/is',$text,$list_of_tags); foreach (array_unique($list_of_tags[0]) as $key=>$value) { $final['<|'.$key.'|>'] = $value; } if (!empty($final)) { $text = str_replace($final,array_keys($final),$text); } $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text); //Now rebuild excluded areas if (!empty($final)) { $text = str_replace(array_keys($final),$final,$text); } if (!empty($links)) { $text = str_replace(array_keys($links),$links,$text); } if (!empty($excludes)) { $text = str_replace(array_keys($excludes),$excludes,$text); } if (!empty($words)) { $text = str_replace(array_keys($words),$words,$text); } return $text; } ?> \ No newline at end of file diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index c8db5620d6..c496c33d4a 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -433,7 +433,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $pagename = $defpagename; } - $key = $ME.'?id='.$id.'&userid='.$student->id.'&wikipage='.$pagename; + $key = $ME.'?id='.$id.'&userid='.$student->id.'&page='.$pagename; $wikis[$key] = fullname($student).':'.$pagename; } } @@ -451,7 +451,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $pagename = $defpagename; } - $key = $ME.'?id='.$id.'&userid='.$student->id.'&wikipage='.$pagename; + $key = $ME.'?id='.$id.'&userid='.$student->id.'&page='.$pagename; $wikis[$key] = fullname($student).':'.$pagename; } } @@ -468,7 +468,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { else { $pagename = $defpagename; } - $key = $ME.'?id='.$id.'&userid='.$student->id.'&wikipage='.$pagename; + $key = $ME.'?id='.$id.'&userid='.$student->id.'&page='.$pagename; $wikis[$key] = fullname($student).':'.$pagename; } } @@ -480,7 +480,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $wiki_entries = get_records_sql($sql); $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); foreach ($wiki_entries as $wiki_entry) { - $key = $ME.'?id='.$id.'&userid='.$wiki_entry->userid.'&wikipage='.$wiki_entry->pagename; + $key = $ME.'?id='.$id.'&userid='.$wiki_entry->userid.'&page='.$wiki_entry->pagename; $wikis[$key] = fullname($wiki_entry).':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -512,7 +512,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); foreach ($wiki_entries as $wiki_entry) { if (($viewall === true) or ismember($viewall, $wiki_entry->userid)) { - $key = $ME.'?id='.$id.'&userid='.$wiki_entry->userid.'&wikipage='.$wiki_entry->pagename; + $key = $ME.'?id='.$id.'&userid='.$wiki_entry->userid.'&page='.$wiki_entry->pagename; $wikis[$key] = fullname($wiki_entry).':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -543,7 +543,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $pagename = $defpagename; } - $key = $ME.'?id='.$id.'&groupid='.$group->id.'&wikipage='.$pagename; + $key = $ME.'?id='.$id.($group->id?"&groupid=".$group->id:"").'&page='.$pagename; $wikis[$key] = $group->name.':'.$pagename; } } @@ -557,7 +557,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $wiki_entries = get_records_sql($sql); $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); foreach ($wiki_entries as $wiki_entry) { - $key = $ME.'?id='.$id.'&groupid='.$wiki_entry->groupid.'&wikipage='.$wiki_entry->pagename; + $key = $ME.'?id='.$id.($wiki_entry->groupid?"&groupid=".$wiki_entry->groupid:"").'&page='.$wiki_entry->pagename; $wikis[$key] = $wiki_entry->gname.':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -583,7 +583,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $pagename = $defpagename; } - $key = $ME.'?id='.$id.'&groupid='.$group->id.'&wikipage='.$pagename; + $key = $ME.'?id='.$id.($group->id?"&groupid=".$group->id:"").'&page='.$pagename; $wikis[$key] = $group->name.':'.$pagename; } } @@ -597,7 +597,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $wiki_entries = get_records_sql($sql); $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); foreach ($wiki_entries as $wiki_entry) { - $key = $ME.'?id='.$id.'&groupid='.$wiki_entry->groupid.'&wikipage='.$wiki_entry->pagename; + $key = $ME.'?id='.$id.($wiki_entry->groupid?"&groupid=".$wiki_entry->groupid:"").'&page='.$wiki_entry->pagename; $wikis[$key] = $wiki_entry->gname.':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -626,7 +626,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); foreach ($wiki_entries as $wiki_entry) { if (($viewall === true) or $viewall == $wiki_entry->groupid) { - $key = $ME.'?id='.$id.'&groupid='.$wiki_entry->groupid.'&wikipage='.$wiki_entry->pagename; + $key = $ME.'?id='.$id.($wiki_entry->groupid?"&groupid=".$wiki_entry->groupid:"").'&page='.$wiki_entry->pagename; $wikis[$key] = $wiki_entry->gname.':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -924,7 +924,7 @@ function wiki_print_search_form($cmid, $search="", $userid, $groupid, $return=fa $output = $output.($userid?"":""); $output .= "".' '; $output .= ""; - $output .= ""; + $output .= ""; $output .= ""; if ($return) { @@ -934,7 +934,7 @@ function wiki_print_search_form($cmid, $search="", $userid, $groupid, $return=fa } function wiki_print_wikilinks_block($cmid, $binary=false, $return=false) { -/// Prints a lin-list of special wiki-pages +/// Prints a link-list of special wiki-pages global $CFG, $ewiki_title; $links=array(); @@ -954,41 +954,41 @@ function wiki_print_wikilinks_block($cmid, $binary=false, $return=false) { popup_form(EWIKI_SCRIPT, $links, "wikilinks", "", get_string("choosewikilinks", "wiki"), "", "", $return); } -function wiki_print_page_actions($cmid, $specialpages, $wikipage, $action, $binary=false, $canedit=true) { +function wiki_print_page_actions($cmid, $specialpages, $page, $action, $binary=false, $canedit=true) { /// Displays actions which can be performed on the page $page=array(); // Edit this Page if (in_array($action, array("edit", "links", "info", "attachments"))) { - $page["view/$wikipage"]=get_string("viewpage","wiki"); + $page["view/$page"]=get_string("viewpage","wiki"); } - if ($canedit && !in_array($wikipage, $specialpages) && $action != "edit") { - $page["edit/$wikipage"]=get_string("editthispage","wiki"); + if ($canedit && !in_array($page, $specialpages) && $action != "edit") { + $page["edit/$page"]=get_string("editthispage","wiki"); } if ($action != "links") { - $page["links/$wikipage"]=get_string("backlinks","wiki"); + $page["links/$page"]=get_string("backlinks","wiki"); } - if ($canedit && !in_array($wikipage, $specialpages) && $action!="info") { - $page["info/$wikipage"]=get_string("pageinfo","wiki"); + if ($canedit && !in_array($page, $specialpages) && $action!="info") { + $page["info/$page"]=get_string("pageinfo","wiki"); } - if($canedit && $binary && !in_array($wikipage, $specialpages) && $action != "attachments") { - $page["attachments/$wikipage"]=get_string("attachments","wiki"); + if($canedit && $binary && !in_array($page, $specialpages) && $action != "attachments") { + $page["attachments/$page"]=get_string("attachments","wiki"); } popup_form(EWIKI_SCRIPT, $page, "wikiactions", "", get_string("action", "wiki"), "", "", false); } -function wiki_print_administration_actions($wiki, $cmid, $userid, $groupid, $wikipage, $noeditor, $course) { +function wiki_print_administration_actions($wiki, $cmid, $userid, $groupid, $page, $noeditor, $course) { /// Displays actions which can be performed on the page global $ME; /// Create the URL $ewscript = 'admin.php?id='.$cmid; - if (isset($userid)) $ewscript .= '&userid='.$userid; - if (isset($groupid)) $ewscript .= '&groupid='.$groupid; - if (isset($wikipage)) $ewscript .= '&wikipage='.$wikipage; + if (isset($userid) && $userid!=0) $ewscript .= '&userid='.$userid; + if (isset($groupid) && $groupid!=0) $ewscript .= '&groupid='.$groupid; + if (isset($page)) $ewscript .= '&page='.$page; $ewscript.="&action="; diff --git a/mod/wiki/view.php b/mod/wiki/view.php index 8f10e07719..8b7fd87ca0 100644 --- a/mod/wiki/view.php +++ b/mod/wiki/view.php @@ -11,13 +11,13 @@ optional_variable($ewiki_action,""); // Action on Wiki-Page optional_variable($id); // Course Module ID, or optional_variable($wid); // Wiki ID - optional_variable($wikipage, false); // Wiki Page Name + optional_variable($page, false); // Wiki Page Name optional_variable($q,""); // Search Context - optional_variable($userid); // User wiki. - optional_variable($groupid); // Group wiki. + optional_variable($userid, 0); // User wiki. + optional_variable($groupid, 0); // Group wiki. optional_variable($canceledit,""); // Editing has been cancelled if($canceledit) { - @$wikipage=$ewiki_id; + @$page=$ewiki_id; } if ($id) { @@ -71,9 +71,9 @@ define("EWIKI_PAGE_INDEX",$wiki_entry->pagename); /// If the page has a ' in it, it may have slashes added to it. Remove them if it does. - $wikipage = ($wikipage === false) ? stripslashes(EWIKI_PAGE_INDEX) : stripslashes($wikipage); + $page = ($page === false) ? stripslashes(EWIKI_PAGE_INDEX) : stripslashes($page); -/// ### Prevent ewiki getting id as PageID... +/// # Prevent ewiki getting id as PageID... unset($_REQUEST["id"]); unset($_GET["id"]); unset($_POST["id"]); @@ -97,9 +97,9 @@ /// Build the ewsiki script constant /// ewbase will also be needed by EWIKI_SCRIPT_BINARY $ewbase = $ME.'?id='.$moodleID; - if (isset($userid)) $ewbase .= '&userid='.$userid; - if (isset($groupid)) $ewbase .= '&groupid='.$groupid; - $ewscript = $ewbase.'&wikipage='; + if (isset($userid) && $userid!=0) $ewbase .= '&userid='.$userid; + if (isset($groupid) && $groupid!=0) $ewbase .= '&groupid='.$groupid; + $ewscript = $ewbase.'&page='; define("EWIKI_SCRIPT", $ewscript); define("EWIKI_SCRIPT_URL", $ewscript); @@ -193,7 +193,7 @@ global $ewiki_author, $USER; $ewiki_author=fullname($USER); - $content=ewiki_page($wikipage); + $content=ewiki_page($page); $content2=''; ### RESTORE ID from Moodle @@ -207,13 +207,13 @@ } - # Group wiki, ...: No wikipage and no ewiki_title + # Group wiki, ...: No page and no ewiki_title if(!isset($ewiki_title)) { $ewiki_title=""; } /// Moodle Log - add_to_log($course->id, "wiki", $ewiki_action, "view.php?id=$cm->id&groupid=$groupid&userid=$userid&wikipage=$wikipage", $wiki->name." ".$ewiki_title); + add_to_log($course->id, "wiki", $ewiki_action, "view.php?id=$cm->id&groupid=$groupid&userid=$userid&page=$page", $wiki->name." ".$ewiki_title); /// Print the page header @@ -309,9 +309,9 @@ } foreach ($tabs as $tab) { $tabname = get_string("tab$tab", 'wiki'); - if ($ewiki_action != "$tab" && !in_array($wikipage, $specialpages)) { + if ($ewiki_action != "$tab" && !in_array($page, $specialpages)) { echo ''; - echo ''.$tabname.''; + echo ''.$tabname.''; echo ''; } else { echo ''.$tabname.''; @@ -325,9 +325,9 @@ /// Don't filter any pages containing wiki actions (except view). A wiki page containing /// actions will have the form [action]/[pagename]. If the '/' isn't there, or the action /// is 'view', filter it. Also, if the page doesn't exist, it will default to 'edit'. - $actions = explode('/', $wikipage); + $actions = explode('/', $page); if ($ewiki_action == "edit" || ($actions !== false && count($actions) > 1 && $actions[0] != 'view') || - (count($actions) == 1 && !record_exists('wiki_pages', 'pagename', $wikipage, 'wiki', $wiki_entry->id))) { + (count($actions) == 1 && !record_exists('wiki_pages', 'pagename', $page, 'wiki', $wiki_entry->id))) { print $content; } else {