Skip to content

Commit

Permalink
Merge pull request #82 from bencroskery/master
Browse files Browse the repository at this point in the history
1.0.7
  • Loading branch information
bencroskery authored Jan 8, 2017
2 parents 3e3ef13 + bbfb132 commit a310982
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 214 deletions.
3 changes: 1 addition & 2 deletions backup/moodle2/backup_socialwiki_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
class backup_socialwiki_activity_structure_step extends backup_activity_structure_step
{

protected function define_structure()
{
protected function define_structure() {
// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');

Expand Down
14 changes: 7 additions & 7 deletions editors/wikieditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct($elementname = null, $elementlabel = null, $attribut
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_socialwikieditor($elementName = null, $elementLabel = null, $attributes = null) {
public function MoodleQuickForm_socialwikieditor($elementname = null, $elementlabel = null, $attributes = null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $attributes);
self::__construct($elementname, $elementlabel, $attributes);
}

public function setwikiformat($wikiformat) {
Expand All @@ -78,7 +78,7 @@ private function printwikieditor($textarea) {
}

private function getbuttons() {
global $PAGE, $OUTPUT, $CFG;
global $PAGE, $OUTPUT;

$PAGE->requires->js(new moodle_url('/mod/socialwiki/editors/wikieditor.js'));
$editor = $this->wikiformat;
Expand Down Expand Up @@ -155,14 +155,14 @@ private function getbuttons() {
return $html;
}

private function makeitem($title, $start_tag, $end_tag) {
private function makeitem($title, $starttag, $endtag) {
return html_writer::tag('li', html_writer::tag('a', $title,
array('href' => '#', 'start_tag' => $start_tag, 'end_tag' => $end_tag)));
array('href' => '#', 'start_tag' => $starttag, 'end_tag' => $endtag)));
}

private function makebutton($src, $title, $start_tag, $end_tag, $sample_text = true) {
private function makebutton($src, $title, $starttag, $endtag, $sampletext = true) {
return html_writer::tag('button', $this->imageicon($src), array('title' => get_string($title, 'socialwiki'),
'sample' => $sample_text, 'start_tag' => $start_tag, 'end_tag' => $end_tag));
'sample' => $sampletext, 'start_tag' => $starttag, 'end_tag' => $endtag));
}

private function imageicon($src) {
Expand Down
2 changes: 0 additions & 2 deletions filesedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,5 @@
}

echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
125 changes: 26 additions & 99 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function socialwiki_add_instance($wiki) {

$wikiid = $DB->insert_record('socialwiki', $wiki);

$record = new StdClass();
$record = new stdClass();
$record->wikiid = $wikiid;
$record->groupid = 0;
$record->userid = 0;
Expand Down Expand Up @@ -132,6 +132,11 @@ function socialwiki_delete_instance($id) {
return $result;
}

/**
* Reset the socialwiki user data.
* @param stdClass $data The plugin user data.
* @return array|bool The status after reset.
*/
function socialwiki_reset_userdata($data) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/socialwiki/pagelib.php');
Expand Down Expand Up @@ -179,6 +184,10 @@ function socialwiki_reset_userdata($data) {
return $status;
}

/**
* Add extra elements to the reset form.
* @param MoodleQuickForm $mform
*/
function socialwiki_reset_course_form_definition(&$mform) {
$mform->addElement('header', 'socialwikiheader', get_string('modulenameplural', 'socialwiki'));
$mform->addElement('advcheckbox', 'reset_socialwiki_tags', get_string('removeallwikitags', 'socialwiki'));
Expand Down Expand Up @@ -249,85 +258,6 @@ function socialwiki_supports($feature) {
}
}

/**
* Given a course and a time, this module should find recent activity
* that has occurred in wiki activities and print it out.
* Return true if there was output, or false is there was none.
*
* @uses CONTEXT_MODULE
* @uses VISIBLEGROUPS
* @param stdClass $course
* @param bool $viewfullnames capability
* @param int $timestart
* @return bool
* */
function socialwiki_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $DB, $OUTPUT;

$sql = "SELECT p.*, w.id as wikiid, sw.groupid
FROM {socialwiki_pages} p
JOIN {socialwiki_subwikis} sw ON sw.id = p.subwikiid
JOIN {socialwiki} w ON w.id = sw.wikiid
WHERE p.timecreated > ? AND w.course = ?
ORDER BY p.timecreated ASC";
if (!$pages = $DB->get_records_sql($sql, array($timestart, $course->id))) {
return false;
}

$modinfo = get_fast_modinfo($course);
$wikis = array();

foreach ($pages as $page) {
if (!isset($modinfo->instances['socialwiki'][$page->wikiid])) {
// Not visible.
continue;
}
$cm = $modinfo->instances['socialwiki'][$page->wikiid];
if (!$cm->uservisible) {
continue;
}
$context = context_module::instance($cm->id);

if (!has_capability('mod/socialwiki:viewpage', $context)) {
continue;
}

$groupmode = groups_get_activity_groupmode($cm, $course);

if ($groupmode) {
if ($groupmode == SEPARATEGROUPS && !has_capability('mod/socialwiki:managewiki', $context)) {
// Separate mode.
if (isguestuser()) {
// Shortcut.
continue;
}

if (is_null($modinfo->groups)) {
$modinfo->groups = groups_get_user_groups($course->id); // Load all my groups and cache it in modinfo.
}

if (!in_array($page->groupid, $modinfo->groups[0])) {
continue;
}
}
}
$wikis[] = $page;
}
unset($pages);

if (!$wikis) {
return false;
}
echo $OUTPUT->heading(get_string("updatedwikipages", 'socialwiki') . ':', 3);
foreach ($wikis as $wiki) {
$cm = $modinfo->instances['socialwiki'][$wiki->wikiid];
$link = $CFG->wwwroot . '/mod/socialwiki/view.php?pageid=' . $wiki->id;
print_recent_activity_note($wiki->timecreated, $wiki, $cm->name, $link, false, $viewfullnames);
}

return true; // True if anything was printed, otherwise false.
}

/**
* Function to be run periodically according to the moodle cron
* This function searches for things that need to be done, such
Expand Down Expand Up @@ -383,7 +313,7 @@ function socialwiki_pluginfile($course, $cm, $context, $filearea, $args, $forced
require_once($CFG->dirroot . "/mod/socialwiki/locallib.php");

if ($filearea == 'attachments') {
$swid = (int) array_shift($args);
$swid = (int)array_shift($args);

if (!$subwiki = socialwiki_get_subwiki($swid)) {
return false;
Expand All @@ -409,22 +339,18 @@ function socialwiki_pluginfile($course, $cm, $context, $filearea, $args, $forced
function socialwiki_search_form($cm, $search = "") {
global $CFG;

$output = '<div class="socialwikisearch">';
$output .= '<form method="post" action="' . $CFG->wwwroot . '/mod/socialwiki/search.php" style="display:inline">';
$output .= '<fieldset class="invisiblefieldset">';
$output .= '<legend class="accesshide">' . get_string('search', 'socialwiki') . '</legend>';
$output .= '<label class="accesshide" for="search_socialwiki">' . get_string("searchterms", "socialwiki") . '</label>';
$output .= '<input id="search_socialwiki" name="searchstring" type="text" size="18" value="';
$output .= s($search, true) . '" alt="search" />';
$output .= '<input name="courseid" type="hidden" value="' . $cm->course . '" />';
$output .= '<input name="id" type="hidden" value="' . $cm->id . '" />';
$output .= '<input name="search_social_content" type="hidden" value="1" />';
$output .= '<input value="' . get_string('search', 'socialwiki') . '" type="submit" />';
$output .= '</fieldset>';
$output .= '</form>';
$output .= '</div>';

return $output;
return '
<div class="socialwikisearch">
<form method="get" action="' . $CFG->wwwroot . '/mod/socialwiki/search.php" style="display:inline">
<fieldset class="invisiblefieldset">
<legend class="accesshide">' . get_string('search', 'socialwiki') . '</legend>
<label class="accesshide" for="search_socialwiki">' . get_string("searchterms", "socialwiki") . '</label>
<input id="search_socialwiki" name="searchstring" type="text" size="18" value="' . s($search, true) . '" alt="search" />
<input name="id" type="hidden" value="' . $cm->id . '" />
<input value="' . get_string('search', 'socialwiki') . '" type="submit" />
</fieldset>
</form>
</div>';
}

/**
Expand Down Expand Up @@ -530,13 +456,14 @@ function socialwiki_comment_validate($commentparam) {
* @param string $pagetype Current page type.
* @param stdClass $parentcontext Block's parent context.
* @param stdClass $currentcontext Current context of block.
* @return array
*/
function socialwiki_page_type_list($pagetype, $parentcontext, $currentcontext) {
$modulepagetype = array(
$modulepagetype = [
'mod-socialwiki-*' => get_string('page-mod-socialwiki-x', 'socialwiki'),
'mod-socialwiki-view' => get_string('page-mod-socialwiki-view', 'socialwiki'),
'mod-socialwiki-comments' => get_string('page-mod-socialwiki-comments', 'socialwiki'),
'mod-socialwiki-versions' => get_string('page-mod-socialwiki-versions', 'socialwiki')
);
];
return $modulepagetype;
}
7 changes: 5 additions & 2 deletions pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,11 @@ protected function print_edit($content = null, $notify = true) {
$params['fileitemid'] = $this->subwiki->id;
$params['component'] = 'mod_socialwiki';
$params['filearea'] = 'attachments';
echo "<a href='{$CFG->wwwroot}/mod/socialwiki/filesedit.php?subwiki={$this->subwiki->id}&pageid={$this->page->id}'>"
. get_string('uploadtitle', 'socialwiki') . '</a>';

if (has_capability('mod/socialwiki:managefiles', $this->modcontext)) {
echo "<a href='{$CFG->wwwroot}/mod/socialwiki/filesedit.php?subwiki={$this->subwiki->id}&pageid={$this->page->id}'>"
. get_string('uploadtitle', 'socialwiki') . '</a>';
}
}
$form = new mod_socialwiki_edit_form($url, $params);
$form->set_data($data);
Expand Down
8 changes: 5 additions & 3 deletions parser/markups/wikimarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,19 @@ protected function process_toc() {
}

private function process_toc_level($next, $current) {
$tags = '';
if ($next > $current) {
for ($t = 0; $t < $next - $current; $t++) {
return '<ol>';
$tags .= '<ol>';
}
} else if ($next < $current) {
for ($t = 0; $t < $current - $next; $t++) {
return '</ol></li>';
$tags .= '</ol></li>';
}
} else {
return '</li>';
$tags .= '</li>';
}
return $tags;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions peer.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ private function set_follow_sim($uid, $swid) {
global $DB;
$sql = 'SELECT COUNT(usertoid) AS total, COUNT(DISTINCT usertoid) AS different
FROM {socialwiki_follows}
WHERE (userfromid=? OR userfromid=?) AND subwikiid=?';
$data = $DB->get_record_sql($sql, array($this->id, $uid, $swid));
if ($data->total > 0) {
WHERE ((userfromid=? AND usertoid<>?) OR (userfromid=? AND usertoid<>?)) AND subwikiid=?';
$data = $DB->get_record_sql($sql, array($this->id, $uid, $uid, $this->id , $swid));

if ($data->total > 0) {
// Get the similarity between follows and divide by the number of unique likes.
$this->followsim = ($data->total - $data->different) / $data->different;
}
Expand Down
14 changes: 10 additions & 4 deletions tests/behat/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ Feature: Edit page
| Social Wiki name | Test Socialwiki |
And I follow "Test Socialwiki"
And I follow "Pages"
And I press "id_submitbutton"
And I press "Make a new Page"

# Create a page
And I set the field "New page title" to "<format> Page"
And I set the field "<format> format" to "1"
And I press "Create page"

# Use toolbar buttons
Then ".socialwikieditor-toolbar" "css_element" should be visible
When I click on "Bold text" "button"
Expand All @@ -49,6 +52,8 @@ Feature: Edit page
And I click on "styleprops" "button"
And I click on "Pre-formatted" "link"
And I press "Save"

# Check HTML
Then I should see "Bold textItalic textInternal linkhttp://External URL"
And ".wikipage img" "css_element" should exist
And I should see "Level 1 Header" in the ".wikipage .text_to_html h3" "css_element"
Expand All @@ -61,11 +66,11 @@ Feature: Edit page

Examples:
| format | content | bold | italic |
| Creole | **Bold text**//Italic text//[[Internal link]]http://External URL{{Image\|Alt}} | ** | //I |
| NWiki | ''Bold text'''''Italic text'''[[Internal link]]http://External URL[[image:Image\|alt]] | '' | ''' |
| Creole | **Bold text**//Italic text//[[Internal link]]http://External URL{{Image\|Alt}} | ** | //I |

Scenario Outline: Forced format + Nojs
And I add a "Social Wiki" to section "1" and I fill the form with:
When I add a "Social Wiki" to section "1" and I fill the form with:
| Social Wiki name | Force Format Socialwiki |
| Default format | <format> |
| Force format | 1 |
Expand All @@ -77,7 +82,8 @@ Feature: Edit page
And I press "Create page"
And I set the field "<format> format" to "<input> [[<format> format]]."
And I press "Save"
Then I should see "Forcing" in the ".wikipage strong" "css_element"
Then I should see "Forcing the use of the <format> format" in the ".wikipage" "css_element"
And I should see "Forcing" in the ".wikipage strong" "css_element"
And I should see "use of" in the ".wikipage em" "css_element"

Examples:
Expand Down
Loading

0 comments on commit a310982

Please sign in to comment.