|
|
@ -15,12 +15,21 @@ error_reporting(0); |
|
|
|
# what is the color hashing used in RevertedPIM for this group, color A, B or C? |
|
|
|
# what is the color hashing used in RevertedPIM for this group, color A, B or C? |
|
|
|
# might require JS |
|
|
|
# might require JS |
|
|
|
# keyword or URL in pages |
|
|
|
# keyword or URL in pages |
|
|
|
|
|
|
|
# definition of word and vice versa |
|
|
|
|
|
|
|
# limited to pages with definitions (e.g. some languages) |
|
|
|
|
|
|
|
# list lines with "* word = definition" |
|
|
|
|
|
|
|
# split word and definition |
|
|
|
|
|
|
|
# pick one and display the other with alternatives |
|
|
|
# implemented |
|
|
|
# implemented |
|
|
|
# which of those page corresponds the updates visualization V, A, B or C? (type=historyvisualization) |
|
|
|
# which of those page corresponds the updates visualization V, A, B or C? (type=historyvisualization) |
|
|
|
# is page A linked to page B? (type=pagelink) |
|
|
|
# is page A linked to page B? (type=pagelink) |
|
|
|
# consider a difficulty parameter |
|
|
|
# consider a difficulty parameter |
|
|
|
# should be linked to the counter |
|
|
|
# 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) |
|
|
|
# e.g. increasing the number of possibilities (at least 1 out of 5 pages instead of at least 1 out of 3) |
|
|
|
|
|
|
|
# XXX |
|
|
|
|
|
|
|
# picking a random page seems to fail from time to time |
|
|
|
|
|
|
|
# some (very few) indices are not used, resulting in picked an empty string |
|
|
|
|
|
|
|
# http://php.net/manual/en/function.array-rand.php seems to fix it |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$RecipeInfo['Exercises']['Version'] = '2011-12-08'; |
|
|
|
$RecipeInfo['Exercises']['Version'] = '2011-12-08'; |
|
|
@ -43,6 +52,17 @@ function Exercises($pagename, $auth){ |
|
|
|
|
|
|
|
|
|
|
|
$result = ""; |
|
|
|
$result = ""; |
|
|
|
$verbatimresult = ""; |
|
|
|
$verbatimresult = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$n=3; |
|
|
|
|
|
|
|
// n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty |
|
|
|
|
|
|
|
// it used to determine the number of false answers |
|
|
|
|
|
|
|
// it can be overwritten per each exercise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$counterparam = ""; |
|
|
|
|
|
|
|
if ( $counter > 0) { |
|
|
|
|
|
|
|
$counterparam = "counter=$counter&"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch ($type){ |
|
|
|
switch ($type){ |
|
|
|
case "pagelink": |
|
|
|
case "pagelink": |
|
|
|
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... |
|
|
|
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... |
|
|
@ -58,8 +78,6 @@ function Exercises($pagename, $auth){ |
|
|
|
$sourcepage = $pages[rand(0,count($pages)-1)]; |
|
|
|
$sourcepage = $pages[rand(0,count($pages)-1)]; |
|
|
|
|
|
|
|
|
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT); |
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT); |
|
|
|
//$text = $content["text"]; |
|
|
|
|
|
|
|
// to use later on for expression exercises |
|
|
|
|
|
|
|
$links = $content["targets"]; |
|
|
|
$links = $content["targets"]; |
|
|
|
$links_array = explode(",",$links); |
|
|
|
$links_array = explode(",",$links); |
|
|
|
|
|
|
|
|
|
|
@ -73,8 +91,6 @@ function Exercises($pagename, $auth){ |
|
|
|
unset($pages[array_search($answers[0],$pages)]); |
|
|
|
unset($pages[array_search($answers[0],$pages)]); |
|
|
|
|
|
|
|
|
|
|
|
//randomly pick n-1 others pages which may not be amongst the list of linked page |
|
|
|
//randomly pick n-1 others pages which may not be amongst the list of linked page |
|
|
|
// n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty |
|
|
|
|
|
|
|
$n=3; |
|
|
|
|
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
$answers[] = $pages[rand(0,count($pages)-1)]; |
|
|
|
$answers[] = $pages[rand(0,count($pages)-1)]; |
|
|
|
unset($pages[array_search($answers[$i],$pages)]); |
|
|
|
unset($pages[array_search($answers[$i],$pages)]); |
|
|
@ -83,11 +99,6 @@ function Exercises($pagename, $auth){ |
|
|
|
//display |
|
|
|
//display |
|
|
|
$result .="Is page [[$sourcepage]] linked to "; |
|
|
|
$result .="Is page [[$sourcepage]] linked to "; |
|
|
|
|
|
|
|
|
|
|
|
$counterparam = ""; |
|
|
|
|
|
|
|
if ( $counter > 0) { |
|
|
|
|
|
|
|
$counterparam = "counter=$counter&"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// there should now be at least 1 needle in the haystack, the first one |
|
|
|
// there should now be at least 1 needle in the haystack, the first one |
|
|
|
// note that there might be more but this is not a problem as long as the question is stated clearly. |
|
|
|
// note that there might be more but this is not a problem as long as the question is stated clearly. |
|
|
|
shuffle($answers); |
|
|
|
shuffle($answers); |
|
|
@ -134,8 +145,6 @@ function Exercises($pagename, $auth){ |
|
|
|
unset($pages[array_search($answers[0],$pages)]); |
|
|
|
unset($pages[array_search($answers[0],$pages)]); |
|
|
|
|
|
|
|
|
|
|
|
//randomly pick n-1 others pages which may not be amongst the list of linked page |
|
|
|
//randomly pick n-1 others pages which may not be amongst the list of linked page |
|
|
|
// n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty |
|
|
|
|
|
|
|
$n=3; |
|
|
|
|
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
$answers[] = $pages[rand(0,count($pages)-1)]; |
|
|
|
$answers[] = $pages[rand(0,count($pages)-1)]; |
|
|
|
unset($pages[array_search($answers[$i],$pages)]); |
|
|
|
unset($pages[array_search($answers[$i],$pages)]); |
|
|
@ -146,11 +155,6 @@ function Exercises($pagename, $auth){ |
|
|
|
$verbatimresult = $historyvisualization; |
|
|
|
$verbatimresult = $historyvisualization; |
|
|
|
$result .="Which of those page corresponds the updates visualization:"; |
|
|
|
$result .="Which of those page corresponds the updates visualization:"; |
|
|
|
|
|
|
|
|
|
|
|
$counterparam = ""; |
|
|
|
|
|
|
|
if ( $counter > 0) { |
|
|
|
|
|
|
|
$counterparam = "counter=$counter&"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// there should now be at least 1 needle in the haystack, the first one |
|
|
|
// there should now be at least 1 needle in the haystack, the first one |
|
|
|
// note that there might be more but this is not a problem as long as the question is stated clearly. |
|
|
|
// note that there might be more but this is not a problem as long as the question is stated clearly. |
|
|
|
shuffle($answers); |
|
|
|
shuffle($answers); |
|
|
@ -163,10 +167,10 @@ function Exercises($pagename, $auth){ |
|
|
|
if ($group != "AllPages") { |
|
|
|
if ($group != "AllPages") { |
|
|
|
list($currentgroup,$currentpage) = explode(".",$answers[$i]); |
|
|
|
list($currentgroup,$currentpage) = explode(".",$answers[$i]); |
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$currentpage."]], "; |
|
|
|
."type=$type&source=$sourcepage&answer=".md5($answers[$i])."|".$currentpage."]], "; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
$result .="[[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
."type=$type&source=$sourcepage&answer=".$answers[$i]."|".$answers[$i]."]], "; |
|
|
|
."type=$type&source=$sourcepage&answer=".md5($answers[$i])."|".$answers[$i]."]], "; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -175,8 +179,82 @@ function Exercises($pagename, $auth){ |
|
|
|
// XXX checking of the result is not yet done, might have to hide (e.g. via hash) the answer and the source |
|
|
|
// XXX checking of the result is not yet done, might have to hide (e.g. via hash) the answer and the source |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "pagehasexpression": |
|
|
|
case "pagehasexpression": |
|
|
|
// explode content by line "%0a" or word " " |
|
|
|
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... |
|
|
|
$result .= "Does the page 'PAGE' has expression 'EXPRESSIONA', 'EXPRESSIONB' or 'EXPRESSIONC?"; |
|
|
|
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)]; |
|
|
|
|
|
|
|
$sourcepage = $pages[array_rand($pages)]; |
|
|
|
|
|
|
|
unset($pages[array_search($sourcepage,$pages)]); |
|
|
|
|
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT); |
|
|
|
|
|
|
|
$text = $content["text"]; |
|
|
|
|
|
|
|
$lines = explode("\n",$text); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $links = $content["targets"]; |
|
|
|
|
|
|
|
// $links_array = explode(",",$links); |
|
|
|
|
|
|
|
// could be use for increase difficulty, e.g. pick content from related pages |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//$answers = array(); |
|
|
|
|
|
|
|
//consider pilling up potential in $answers[] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$minlinelength = 20; |
|
|
|
|
|
|
|
// this could also be consider a difficulty, the shorter the harder |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//$answers[]["source"] = $sourcepage; |
|
|
|
|
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
|
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
|
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
|
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
|
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//$answers[]["line"] = $pickedline; |
|
|
|
|
|
|
|
$actualanswer = $pickedline; |
|
|
|
|
|
|
|
$answers[] = $pickedline; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//randomly pick n-1 others pages which may not be amongst the list of linked page |
|
|
|
|
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
|
|
|
|
$otherpage = $pages[rand(0,count($pages)-1)]; |
|
|
|
|
|
|
|
$otherpage = $pages[array_rand($pages)]; |
|
|
|
|
|
|
|
unset($pages[array_search($otherpage,$pages)]); |
|
|
|
|
|
|
|
$content = ReadPage($otherpage,READPAGE_CURRENT); |
|
|
|
|
|
|
|
$text = $content["text"]; |
|
|
|
|
|
|
|
$lines = explode("\n",$text); |
|
|
|
|
|
|
|
//$answers[]["source"] = $otherpage; |
|
|
|
|
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
|
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
|
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
|
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
|
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//$answers[]["line"] = $pickedline; |
|
|
|
|
|
|
|
$answers[] = $pickedline; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//display |
|
|
|
|
|
|
|
$result .= "Does the page [[$sourcepage]] has expression "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// there should now be at least 1 needle in the haystack, the first one |
|
|
|
|
|
|
|
// note that there might be more but this is not a problem as long as the question is stated clearly. |
|
|
|
|
|
|
|
shuffle($answers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ($i=0;$i<$n;$i++) { |
|
|
|
|
|
|
|
if ($answers[$i]==$actualanswer) |
|
|
|
|
|
|
|
$hashedanswer = md5($sourcepage); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
$hashedanswer = md5($answers[$i]); |
|
|
|
|
|
|
|
$result .="\n* [[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
|
|
|
|
."type=$type&source=$sourcepage&answer=$hashedanswer|$i]] [@".$answers[$i]."@] "; |
|
|
|
|
|
|
|
//should be better parsed! |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$result .="\n\nClick on the answer."; |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case "expressioninpage": |
|
|
|
case "expressioninpage": |
|
|
|
// explode content by line "%0a" or word " " |
|
|
|
// explode content by line "%0a" or word " " |
|
|
@ -247,7 +325,7 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "historyvisualization": |
|
|
|
case "historyvisualization": |
|
|
|
if ( $sourcepage == $answer ) { |
|
|
|
if ( md5($sourcepage) === $answer ) { |
|
|
|
$result .="Excellent! [[$sourcepage]] indeed has that history of editions."; |
|
|
|
$result .="Excellent! [[$sourcepage]] indeed has that history of editions."; |
|
|
|
if ( $counter > 0) { |
|
|
|
if ( $counter > 0) { |
|
|
|
$counter++; |
|
|
|
$counter++; |
|
|
@ -257,6 +335,23 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$result .="No, it was the visualization of [[$sourcepage]] history of editions."; |
|
|
|
$result .="No, it was the visualization of [[$sourcepage]] history of editions."; |
|
|
|
|
|
|
|
// display it again |
|
|
|
|
|
|
|
if ($counter > 0) $result .="\nIt means you are losing your $counter points."; |
|
|
|
|
|
|
|
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case "pagehasexpression": |
|
|
|
|
|
|
|
if ( md5($sourcepage) === $answer ) { |
|
|
|
|
|
|
|
$result .="Excellent! [[$sourcepage]] indeed has that expression."; |
|
|
|
|
|
|
|
if ( $counter > 0) { |
|
|
|
|
|
|
|
$counter++; |
|
|
|
|
|
|
|
$result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=$counter|solve yet another one]]. "; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=1|solve yet another one]]. "; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$result .="No, it was the expressoin of [[$sourcepage]]."; |
|
|
|
|
|
|
|
// display it again |
|
|
|
if ($counter > 0) $result .="\nIt means you are losing your $counter points."; |
|
|
|
if ($counter > 0) $result .="\nIt means you are losing your $counter points."; |
|
|
|
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; |
|
|
|
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; |
|
|
|
} |
|
|
|
} |
|
|
|