Skip to content

Commit

Permalink
"MDL-21146, adding file license support to repository api, first commit"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Mar 29, 2010
1 parent 58ee836 commit 1dce626
Show file tree
Hide file tree
Showing 34 changed files with 705 additions and 86 deletions.
57 changes: 57 additions & 0 deletions admin/licenses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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/>.

/**
* Allows admin to configure licenses.
*/

require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/licenselib.php');

require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));

$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managelicenses";

$action = optional_param('action', '', PARAM_ACTION);
$license = optional_param('license', '', PARAM_SAFEDIR);

////////////////////////////////////////////////////////////////////////////////
// process actions

if (!confirm_sesskey()) {
redirect($returnurl);
}

$return = true;
switch ($action) {
case 'disable':
license_manager::disable($license);
break;

case 'enable':
license_manager::enable($license);
break;

default:
break;
}

if ($return) {
redirect ($returnurl);
}
7 changes: 7 additions & 0 deletions admin/settings/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
$options[$i] = $i;
}
$temp->add(new admin_setting_configselect('maxcategorydepth', get_string('configsitemaxcategorydepth','admin'), get_string('configsitemaxcategorydepthhelp','admin'), 0, $options));
require_once($CFG->libdir . '/licenselib.php');
$licenses = array();
$array = license_manager::get();
foreach ($array as $key=>$value) {
$licenses[$value->shortname] = $value->fullname;
}
$temp->add(new admin_setting_configselect('sitedefaultlicense', get_string('configsitedefaultlicense','admin'), get_string('configsitedefaultlicensehelp','admin'), 'allrightsreserved', $licenses));

$temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
Expand Down
5 changes: 5 additions & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
$ADMIN->add('editorsettings', $editor_setting);
}
}
/// License types
$ADMIN->add('modules', new admin_category('licensesettings', get_string('license')));
$temp = new admin_settingpage('managelicenses', get_string('license'));
$temp->add(new admin_setting_managelicenses());
$ADMIN->add('licensesettings', $temp);

/// Filter plugins
$ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters')));
Expand Down
2 changes: 1 addition & 1 deletion files/files_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @package moodlecore
* @subpackage file
* @copyright 1999 onwards Dongsheng Cai <[email protected]>
* @copyright 2010 Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand Down
4 changes: 4 additions & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@
$string['configlookahead'] = 'Days to look ahead';
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
$string['configmaxbytes'] = 'This specifies a maximum size that uploaded files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody. In turn, maxbytes limits the range of sizes that can be chosen at course level or module level. If \'Server Limit\' is chosen, the server maximum allowed by the server will be used.';
$string['configsitedefaultlicense'] = 'Default site license';
$string['configsitedefaultlicensehelp'] = 'Default license will be used to publish content on this site';
$string['configsitemaxcategorydepth'] = 'Maximum Category Depth';
$string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories shown';
$string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc. Usually 30 minutes is a good value.';
Expand Down Expand Up @@ -574,6 +576,7 @@
$string['latexpreamble'] = 'LaTeX preamble';
$string['latexsettings'] = 'LaTeX renderer Settings';
$string['latinexcelexport'] = 'Excel encoding';
$string['licensesettings'] = 'License settings';
$string['localetext'] = 'Sitewide locale';
$string['localstringcustomization'] = 'Local string customization';
$string['location'] = 'Location';
Expand All @@ -588,6 +591,7 @@
$string['maintfileopenerror'] = 'Error opening maintenance files!';
$string['maintinprogress'] = 'Maintenance is in progress...';
$string['managelang'] = 'Manage';
$string['managelicenses'] = 'Manage licenses';
$string['manageqtypes'] = 'Manage question types';
$string['maintenancemode'] = 'In Maintenance Mode';
$string['maxbytes'] = 'Maximum uploaded file size';
Expand Down
3 changes: 2 additions & 1 deletion lang/en_utf8/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@
$string['latestnews'] = 'Latest News';
$string['layouttable'] = 'Layout table';
$string['leavetokeep'] = 'Leave blank to keep current password';
$string['license'] = 'GPL License';
$string['license'] = 'License';
$string['gpllicense'] = 'GPL License';
$string['liketologin'] = 'Would you like to log in now with a full user account?';
$string['list'] = 'List';
$string['listfiles'] = 'List of files in $a';
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$string['areauserprofile'] = 'Profile';
$string['attachment'] = 'Attachment';
$string['attachedfiles'] = 'Attached files';
$string['author'] = 'Author';
$string['back'] = '&laquo; Back';
$string['cacheexpire'] = 'Cache expire';
$string['cachecleared'] = 'Cached files are removed';
Expand All @@ -25,6 +26,7 @@
$string['cannotdownloaddir'] = 'Cannot download this folder';
$string['cannotinitplugin'] = 'Call plugin_init failed';
$string['choosealink'] = 'Choose a link...';
$string['chooselicense'] = 'Choose license';
$string['clicktohide'] = 'Click here to hide';
$string['clicktoshow'] = 'Click here to show';
$string['close'] = 'Close';
Expand Down
86 changes: 86 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5008,6 +5008,92 @@ public function output_html($data, $query='') {
}
}

/**
* Special class for license administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_managelicenses extends admin_setting {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
$this->nosave = true;
parent::__construct('licensesui', get_string('licensesettings', 'admin'), '', '');
}

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

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

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

/**
* Builds the XHTML to display the control
*
* @param string $data Unused
* @param string $query
* @return string
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
require_once($CFG->libdir . '/licenselib.php');

// display strings
$txt = get_strings(array('administration', 'settings', 'name', 'enable', 'disable', 'none'));
$licenses = license_manager::get();

$return = $OUTPUT->heading(get_string('managelicenses', 'admin'), 3, 'main', true);
$return .= $OUTPUT->box_start('generalbox editorsui');

$table = new html_table();
$table->head = array($txt->name, $txt->enable);
$table->align = array('left', 'center');
$table->width = '100%';
$table->data = array();

$url = "licenses.php?sesskey=" . sesskey();
foreach ($licenses as $key => $value) {
$displayname = html_writer::link($value->source, $value->fullname, array('target'=>'_blank'));

if ($value->enabled == 1) {
$hideshow = html_writer::link($url.'&action=disable&license='.$value->shortname,
html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/hide'), 'class'=>'icon', 'alt'=>'disable')));
} else {
$hideshow = html_writer::link($url.'&action=enable&license='.$value->shortname,
html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/show'), 'class'=>'icon', 'alt'=>'enable')));
}
$enabled = true;

$table->data[] =array($displayname, $hideshow);
}
$return .= html_writer::table($table);
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
}
/**
* Special class for filter administration.
*
Expand Down
24 changes: 20 additions & 4 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20100317" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20100325" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -2099,7 +2099,10 @@
<FIELD NAME="mimetype" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="type of file - jpeg image, open document spreadsheet" PREVIOUS="filesize" NEXT="status"/>
<FIELD NAME="status" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="number greater than 0 means something is wrong with this file (virus, missing, etc.)" PREVIOUS="mimetype" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="status" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="timecreated"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="timecreated" NEXT="source"/>
<FIELD NAME="source" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="store the reference if the file is imported from external sites" PREVIOUS="timemodified" NEXT="author"/>
<FIELD NAME="author" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="The original author of the file" PREVIOUS="source" NEXT="license"/>
<FIELD NAME="license" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="license of the file to guide reuse" PREVIOUS="author"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="contextid"/>
Expand Down Expand Up @@ -2391,7 +2394,7 @@
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
<TABLE NAME="rating" COMMENT="moodle ratings" PREVIOUS="blog_external">
<TABLE NAME="rating" COMMENT="moodle ratings" PREVIOUS="blog_external" NEXT="license">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="contextid"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="id" NEXT="itemid"/>
Expand All @@ -2406,5 +2409,18 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="license" COMMENT="store licenses used by moodle" PREVIOUS="rating">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="shortname"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="id" NEXT="fullname"/>
<FIELD NAME="fullname" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="shortname" NEXT="source"/>
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" PREVIOUS="fullname" NEXT="enabled"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="source" NEXT="version"/>
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="enabled"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
54 changes: 54 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,7 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2010031900);
}


if ($result && $oldversion < 2010032400) {
// Upgrade all of those using the standardold theme to the use the standard
// theme instead
Expand All @@ -3113,6 +3114,59 @@ function xmldb_main_upgrade($oldversion) {
$DB->execute('UPDATE {user} SET theme=? WHERE theme=?', array('standard', 'standardold'));
upgrade_main_savepoint($result, 2010032400);
}

if ($result && $oldversion < 2010032405) {

/// Define field source to be added to files
$table = new xmldb_table('files');

$field = new xmldb_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'timemodified');

/// Conditionally launch add field source
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'source');

/// Conditionally launch add field author
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

$field = new xmldb_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'author');

/// Conditionally launch add field license
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

/// Define table license to be created
$table = new xmldb_table('license');

/// Adding fields to table license
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
$table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');

/// Adding keys to table license
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

/// Conditionally launch create table for license
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
require_once($CFG->libdir . '/licenselib.php');
license_manager::install_licenses();
/// set site default license
set_config('sitedefaultlicense', 'allrightsreserved');

/// Main savepoint reached
upgrade_main_savepoint($result, 2010032405);
}

return $result;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/file/file_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ public function get_timemodified() {
return null;
}

/**
* Returns the license type of the file
* @return string license short name or null
*/
public function get_license() {
return null;
}

/**
* Returns the author name of the file
* @return string author name or null
*/
public function get_author() {
return null;
}

/**
* Returns the source of the file
* @return string a source url or null
*/
public function get_source() {
return null;
}

/**
* Create new directory, may throw exception - make sure
* params are valid.
Expand Down
Loading

0 comments on commit 1dce626

Please sign in to comment.