Skip to content

Commit

Permalink
Plagiarism API MDL-13680 add plagiarism support for user submitted fi…
Browse files Browse the repository at this point in the history
…les - currently only added to single and advanced Assignment types - other modules to come in future.
  • Loading branch information
danmarsden committed Sep 20, 2010
1 parent e71e340 commit bce5952
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 2 deletions.
12 changes: 11 additions & 1 deletion admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,17 @@
}
}
}

if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
$ADMIN->add('modules', new admin_category('plagiarism', get_string('plagiarism', 'plagiarism')));
$temp = new admin_settingpage('plagiarismsettings', get_string('plagiarismsettings', 'plagiarism'));
$temp->add(new admin_setting_manageplagiarism());
$ADMIN->add('plagiarism', $temp);
foreach (get_plugin_list('plagiarism') as $plugin => $plugindir) {
if (file_exists($plugindir.'/settings.php')) {
$ADMIN->add('plagiarism', new admin_externalpage('plagiarism'.$plugin, get_string($plugin, 'plagiarism_'.$plugin), "$CFG->wwwroot/plagiarism/$plugin/settings.php", 'moodle/site:config'));
}
}
}
$ADMIN->add('reports', new admin_externalpage('comments', get_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
/// Now add reports

Expand Down
2 changes: 2 additions & 0 deletions admin/settings/subsystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
$optionalsubsystems->add(new admin_setting_configcheckbox('enableavailability',
get_string('enableavailability','condition'),
get_string('configenableavailability','condition'), 0));

$optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', get_string('enableplagiarism','plagiarism'), get_string('configenableplagiarism','plagiarism'), 0));
}
2 changes: 2 additions & 0 deletions course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/completionlib.php');
require_once($CFG->libdir.'/conditionlib.php');
require_once($CFG->libdir.'/plagiarismlib.php');

$add = optional_param('add', '', PARAM_ALPHA); // module name
$update = optional_param('update', 0, PARAM_INT);
Expand Down Expand Up @@ -560,6 +561,7 @@

rebuild_course_cache($course->id);
grade_regrade_final_grades($course->id);
plagiarism_save_form_elements($fromform); //save plagiarism settings

if (isset($fromform->submitbutton)) {
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
Expand Down
9 changes: 9 additions & 0 deletions lang/en/plagiarism.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
$string['availableplugins'] = 'Available plugins';
$string['configplagiarismplugins'] = 'Please choose the plagiarism plugin you would like to configure';
$string['enableplagiarism'] ='Enable plagiarism plugins';
$string['configenableplagiarism'] = 'This will allow administrators to configure plagiarism plugins (if installed)';
$string['manageplagiarism'] = 'Manage plagiarism plugins';
$string['nopluginsinstalled'] = 'No plagiarism plugins are installed.';
$string['plagiarism'] = 'Plagiarism prevention';
$string['plagiarismsettings'] = 'Plagiarism settings';
86 changes: 86 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6552,6 +6552,92 @@ public function output_html($data, $query='') {
return highlight($query, $return);
}
}
/**
* Special class for plagiarism administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageplagiarism extends admin_setting {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
$this->nosave = true;
parent::__construct('plagiarismui', get_string('plagiarismsettings', 'plagiarism'), '', '');
}

/**
* Always returns true
*
* @return true
*/
public function get_setting() {
return true;
}

/**
* Always returns true
*
* @return true
*/
public function get_defaultsetting() {
return true;
}

/**
* Always returns '' and doesn't write anything
*
* @return string Always returns ''
*/
public function write_setting($data) {
// do not write any setting
return '';
}

/**
* Return XHTML to display control
*
* @param mixed $data Unused
* @param string $query
* @return string highlight
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;

// display strings
$txt = get_strings(array('settings', 'name'));

$plagiarismplugins = get_plugin_list('plagiarism');
if (empty($plagiarismplugins)) {
return get_string('nopluginsinstalled', 'plagiarism');
}

$return = $OUTPUT->heading(get_string('availableplugins', 'plagiarism'), 3, 'main');
$return .= $OUTPUT->box_start('generalbox authsui');

$table = new html_table();
$table->head = array($txt->name, $txt->settings);
$table->align = array('left', 'center');
$table->data = array();
$table->attributes['class'] = 'manageplagiarismtable generaltable';

// iterate through auth plugins and add to the display table
$authcount = count($plagiarismplugins);
foreach ($plagiarismplugins as $plugin => $dir) {
if (file_exists($dir.'/settings.php')) {
$displayname = "<span>".get_string($plugin, 'plagiarism_'.$plugin)."</span>";
// settings link
$settings = "<a href=\"$CFG->wwwroot/plagiarism/$plugin/settings.php\">{$txt->settings}</a>";
// add a row to the table
$table->data[] =array($displayname, $settings);
}
}
$return .= html_writer::table($table);
$return .= get_string('configplagiarismplugins', 'plagiarism');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
}

/**
* Special class for overview of external services
Expand Down
4 changes: 4 additions & 0 deletions lib/cronlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ function cron_run() {
}
mtrace('Finished blocks');

//now do plagiarism checks
require_once($CFG->libdir.'/plagiarismlib.php');
plagiarism_cron();

mtrace("Starting quiz reports");
if ($reports = $DB->get_records_select('quiz_report', "cron > 0 AND ((? - lastcron) > cron)", array($timenow))) {
foreach ($reports as $report) {
Expand Down
2 changes: 2 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6917,6 +6917,7 @@ function get_core_subsystems() {
'notes' => 'notes',
'pagetype' => NULL,
'pix' => NULL,
'plagiarism' => 'plagiarism',
'portfolio' => 'portfolio',
'publish' => 'course/publish',
'question' => 'question',
Expand Down Expand Up @@ -6973,6 +6974,7 @@ function get_plugin_types($fullpaths=true) {
'portfolio' => 'portfolio',
'qtype' => 'question/type',
'qformat' => 'question/format',
'plagiarism' => 'plagiarism',
'theme' => 'theme'); // this is a bit hacky, themes may be in dataroot too

$mods = get_plugin_list('mod');
Expand Down
170 changes: 170 additions & 0 deletions lib/plagiarismlib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* plagiarismlib.php - Contains core Plagiarism related functions.
*
* @since 2.0
* @package moodlecore
* @subpackage plagiarism
* @copyright 2010 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

///// GENERIC PLAGIARISM FUNCTIONS ////////////////////////////////////////////////////

if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}

/**
* displays the similarity score and provides a link to the full report if allowed.
*
* @param object $linkarray contains all relevant information for the plugin to generate a link
* @return string - url to allow login/viewing of a similarity report
*/
function plagiarism_get_links($linkarray) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
$output = '';
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$output .= $plagiarismplugin->get_links($linkarray);
}
return $output;
}

/**
* saves/updates plagiarism settings from a modules config page - called by course/modedit.php
*
* @param object $data - form data
*/
function plagiarism_save_form_elements($data) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->save_form_elements($data);
}
}

/**
* adds the list of plagiarism settings to a form - called inside modules that have enabled plagiarism
*
* @param object $mform - Moodle form object
* @param object $context - context object
*/
function plagiarism_get_form_elements_module($mform, $context) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->get_form_elements_module($mform, $context);
}
}
/**
* updates the status of all files within a module
*
* @param object $course - full Course object
* @param object $cm - full cm object
*/
function plagiarism_update_status($course, $cm) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->update_status($course, $cm);
}
}

/**
* Function that prints the student disclosure notifying that the files will be checked for plagiarism
* @param integer $cmid - the cmid of this module
*/
function plagiarism_print_disclosure($cmid) {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->print_disclosure($cmid);
}
}
/**
* used by admin/cron.php to get similarity scores from submitted files.
*
*/
function plagiarism_cron() {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return '';
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->cron();
}
}
/**
* helper function - also loads lib file of plagiarism plugin
* @return array of available plugins
*/
function plagiarism_load_available_plugins() {
global $CFG;
if (empty($CFG->enableplagiarism)) {
return array();
}
$plagiarismplugins = get_plugin_list('plagiarism');
$availableplugins = array();
foreach($plagiarismplugins as $plugin => $dir) {
//check this plugin is enabled and a lib file exists.
if (get_config('plagiarism', $plugin."_use") && file_exists($dir."/lib.php")) {
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
if (class_exists($plagiarismclass)) {
$availableplugins[$plugin] = $dir;
}
}
}
return $availableplugins;
}
4 changes: 4 additions & 0 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function view_intro() {
echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
echo format_module_intro('assignment', $this->assignment, $this->cm->id);
echo $OUTPUT->box_end();
plagiarism_print_disclosure($this->cm->id);
}

/**
Expand Down Expand Up @@ -1096,6 +1097,7 @@ function display_submissions($message='') {
self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));

$updatepref = optional_param('updatepref', 0, PARAM_INT);
plagiarism_update_status($this->course, $this->cm);

if (isset($_POST['updatepref'])){
$perpage = optional_param('perpage', 10, PARAM_INT);
Expand Down Expand Up @@ -1873,6 +1875,8 @@ function print_user_files($userid=0, $return=false) {
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
$output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
$output .= '<br />';
}
if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php');
Expand Down
3 changes: 2 additions & 1 deletion mod/assignment/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ protected function htmllize_tree($tree, $dir) {
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
$icon = mimeinfo("icon", $filename);
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
$image = $this->output->pix_icon("f/$icon", $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$file->portfoliobutton.'</div></li>';
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}

$result .= '</ul>';
Expand Down
1 change: 1 addition & 0 deletions mod/assignment/submissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once("../../config.php");
require_once("lib.php");
require_once($CFG->libdir.'/plagiarismlib.php');

$id = optional_param('id', 0, PARAM_INT); // Course module ID
$a = optional_param('a', 0, PARAM_INT); // Assignment ID
Expand Down
2 changes: 2 additions & 0 deletions mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,8 @@ function setup_elements(&$mform) {
$mform->addHelpButton('var4', 'trackdrafts', 'assignment');
$mform->setDefault('var4', 1);

$course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
plagiarism_get_form_elements_module($mform, $course_context);
}

function portfolio_exportable() {
Expand Down
Loading

0 comments on commit bce5952

Please sign in to comment.