|
|
|
<?php if (!defined('PmWiki')) exit();
|
|
|
|
|
|
|
|
# generate exercises based on wiki content and its structure
|
|
|
|
#
|
|
|
|
# still to implement (cf http://fabien.benetou.fr/Cookbook/Cognition#DailyExercisesFeed )
|
|
|
|
# is word X from page A, B, C or D?
|
|
|
|
# does page A contains word X, Y or Z?
|
|
|
|
# what is the correct order for pages A, B and C on descending criteria i A>B>C? A>C>B? B>C>A? B>A>C? C>B>A? C>A>B?
|
|
|
|
# e.g. size, frequency update, last edition, ...
|
|
|
|
# which of those page corresponds the updates visualization V, A, B or C?
|
|
|
|
# keyword or URL in pages
|
|
|
|
# implemented
|
|
|
|
# is page A linked to page B? (type=pagelink)
|
|
|
|
# consider a difficulty parameter
|
|
|
|
# should be linked to the counter
|
|
|
|
# e.g. increasing the number of possibilities (at least 1 out of 5 pages instead of at least 1 out of 3)
|
|
|
|
|
|
|
|
|
|
|
|
$RecipeInfo['Exercises']['Version'] = '2011-12-08';
|
|
|
|
|
|
|
|
SDV($HandleActions['Exercises'], 'Exercises');
|
|
|
|
SDV($HandleAuth['Exercises'],'read');
|
|
|
|
|
|
|
|
function Exercises($pagename, $auth){
|
|
|
|
$type = $_GET["type"];
|
|
|
|
|
|
|
|
$availableexercisetypes = array("pagelink", "expressioninpage");
|
|
|
|
|
|
|
|
switch ($type){
|
|
|
|
case "pagelink":
|
|
|
|
list($group,$page) = explode(".",$pagename);
|
|
|
|
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ...
|
|
|
|
if ($group == "AllPages"){
|
|
|
|
// equivalent to getting ALL pages
|
|
|
|
$pages = ListPages();
|
|
|
|
} else {
|
|
|
|
$pages = ListPages("/$group\./e");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//randomly pick a page in the possible pages
|
|
|
|
$sourcepage = $pages[rand(0,count($pages)-1)];
|
|
|
|
|
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT);
|
|
|
|
//$text = $content["text"];
|
|
|
|
// to use later on for expression exercises
|
|
|
|
$links = $content["targets"];
|
|
|
|
$links_array = explode(",",$links);
|
|
|
|
|
|
|
|
//$answers = array();
|
|
|
|
//consider pilling up potential in $answers[]
|
|
|
|
|
|
|
|
//randomly pick a page amongst the linked pages
|
|
|
|
$pageA = $links_array[rand(0,count($links_array)-1)];
|
|
|
|
|
|
|
|
unset($pages[array_search($pageA,$links_array)]);
|
|
|
|
unset($pages[array_search($pageA,$pages)]);
|
|
|
|
//randomly pick 2 others pages which are not amongst the list of linked page
|
|
|
|
$pageB = $pages[rand(0,count($pages)-1)];
|
|
|
|
unset($pages[array_search($pageB,$pages)]);
|
|
|
|
$pageC = $pages[rand(0,count($pages)-1)];
|
|
|
|
unset($pages[array_search($pageC,$pages)]);
|
|
|
|
|
|
|
|
//display
|
|
|
|
$result .="Is page [[$sourcepage]] linked to ";
|
|
|
|
$counter = (int) $_GET["counter"];
|
|
|
|
|
|
|
|
$counterparam = "";
|
|
|
|
if ( $counter > 0) {
|
|
|
|
$counterparam = "counter=$counter&";
|
|
|
|
}
|
|
|
|
|
|
|
|
$answers = array ($pageA,$pageB,$pageC);
|
|
|
|
shuffle($answers);
|
|
|
|
for ($i=0;$i<count($answers);$i++) {
|
|
|
|
if ($answers[$i] != "") {
|
|
|
|
if ( $i == count($answers) -1 )
|
|
|
|
$result .= " or ";
|
|
|
|
//display the groupname everytime only if using AllPages
|
|
|
|
if ($group != "AllPages") {
|
|
|
|
list($currentgroup,$currentpage) = explode(".",$answers[$i]);
|
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
|
|
|
|
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], ";
|
|
|
|
} else {
|
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam
|
|
|
|
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$result .="? ";
|
|
|
|
$result .="\n\nClick on the answer.";
|
|
|
|
break;
|
|
|
|
case "expressioninpage":
|
|
|
|
// explode content by line "%0a" or word " "
|
|
|
|
$result .= "Does the expression 'EXPRESSION' come from PAGEA PAGEB or PAGEC?";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$result .= "Exercise type unknown.";
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]. ";
|
|
|
|
unset($availableexercisetypes[array_search($type,$availableexercisetypes)]);
|
|
|
|
if (count($availableexercisetypes) > 0) {
|
|
|
|
$result .= " Try other types of exercises:";
|
|
|
|
foreach ($availableexercisetypes as $e) {
|
|
|
|
$result .= " [[$pagename?action=Exercises&type=$e|$e]],";
|
|
|
|
}
|
|
|
|
$result .= ".";
|
|
|
|
}
|
|
|
|
if ( $counter > 0) {
|
|
|
|
$result .= " (note that it resets the counter)";
|
|
|
|
}
|
|
|
|
$renderedresult = MarkupToHTML($pagename, $result);
|
|
|
|
print $renderedresult;
|
|
|
|
|
|
|
|
//$text = RetrieveAuthSection($pagename,$auth);
|
|
|
|
//$content = MarkupToHTML($pagename, $text);
|
|
|
|
//print $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDV($HandleActions['ExercisesCheck'], 'ExercisesCheck');
|
|
|
|
SDV($HandleAuth['ExercisesCheck'],'read');
|
|
|
|
|
|
|
|
function ExercisesCheck($pagename, $auth){
|
|
|
|
$type = $_GET["type"];
|
|
|
|
$sourcepage = $_GET["source"];
|
|
|
|
$answer = $_GET["answer"];
|
|
|
|
$counter = (int) $_GET["counter"];
|
|
|
|
|
|
|
|
list($group,$page) = explode(".",$pagename);
|
|
|
|
if ($group == "AllPages"){
|
|
|
|
// equivalent to getting ALL pages
|
|
|
|
$pages = ListPages();
|
|
|
|
} else {
|
|
|
|
$pages = ListPages("/$group\./e");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case "pagelink":
|
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT);
|
|
|
|
$links = $content["targets"];
|
|
|
|
$links_array = explode(",",$links);
|
|
|
|
$formattedlinks = implode(", ",$links_array);
|
|
|
|
|
|
|
|
if ( in_array($answer,$links_array) ) {
|
|
|
|
$result .="Excellent! [[$sourcepage]] is indeed linked to [[$answer]]. ";
|
|
|
|
$result .="Note that $formattedlinks also are. ";
|
|
|
|
if ( $counter > 0) {
|
|
|
|
$counter++;
|
|
|
|
$result .="\n\nSee if you can [[$pagename?action=Exercises&counter=$counter|solve yet another one]]. ";
|
|
|
|
} else {
|
|
|
|
$result .="\n\nSee if you can [[$pagename?action=Exercises&counter=1|solve yet another one]]. ";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result .="No, [[$sourcepage]] is not linked to [[$answer]] ";
|
|
|
|
$result .="but $formattedlinks are. ";
|
|
|
|
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises|trying another time]]. ";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$result .= "Exercise type unknown.";
|
|
|
|
}
|
|
|
|
$result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]";
|
|
|
|
$renderedresult = MarkupToHTML($pagename, $result);
|
|
|
|
print $renderedresult;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|