From b37eac91ccd1ce4d3aaf7bba3f0358da76425c7e Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Tue, 26 May 2009 03:57:03 +0000 Subject: [PATCH] lib MDL-19236 Added boilerplates and copyrights --- lib/searchlib.php | 49 +++++++++++++++++++++++--- lib/session-test.php | 36 +++++++++++++++---- lib/sessionlib.php | 44 ++++++++++++++++++++++-- lib/setup.php | 62 ++++++++++++++++++++++++++++----- lib/setuplib.php | 46 ++++++++++++++++++++++--- lib/simpletestlib.php | 80 +++++++++++++++++++++++++++++++++++++------ lib/soaplib.php | 28 +++++++++++++-- lib/statslib.php | 23 ++++++++++++- 8 files changed, 327 insertions(+), 41 deletions(-) diff --git a/lib/searchlib.php b/lib/searchlib.php index ceb462d5f8..de0cf18b7d 100644 --- a/lib/searchlib.php +++ b/lib/searchlib.php @@ -1,8 +1,30 @@ -. +/** + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** @see lexer.php */ require_once($CFG->libdir.'/lexer.php'); -// Constants for the various types of tokens +/** Constants for the various types of tokens */ define("TOKEN_USER","0"); define("TOKEN_META","1"); @@ -14,8 +36,13 @@ define("TOKEN_DATEFROM","6"); define("TOKEN_DATETO","7"); define("TOKEN_INSTANCE","8"); -// Class to hold token/value pairs after they're parsed. - +/** + * Class to hold token/value pairs after they're parsed. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class search_token { private $value; private $type; @@ -45,6 +72,10 @@ class search_token { * This class does the heavy lifting of lexing the search string into tokens. * Using a full-blown lexer is probably overkill for this application, but * might be useful for other tasks. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class search_lexer extends Lexer{ @@ -168,6 +199,10 @@ class search_lexer extends Lexer{ * the parsed token array. * Most functions in this class should only be called by the lexer, the * one exception being getParseArray() which returns the result. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class search_parser { private $tokens; @@ -310,6 +345,9 @@ class search_parser { * $parsetree should be a parse tree generated by a * search_lexer/search_parser combination. * Other fields are database table names to search. + * + * @global object + * @global object */ function search_generate_text_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield, $userfirstnamefield, $userlastnamefield, $timefield, $instancefield) { @@ -449,6 +487,9 @@ function search_generate_text_SQL($parsetree, $datafield, $metafield, $mainidfie * $parsetree should be a parse tree generated by a * search_lexer/search_parser combination. * Other fields are database table names to search. + * + * @global object + * @global object */ function search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield, $userfirstnamefield, $userlastnamefield, $timefield, $instancefield) { diff --git a/lib/session-test.php b/lib/session-test.php index f73da062ea..01fcd659c0 100644 --- a/lib/session-test.php +++ b/lib/session-test.php @@ -1,11 +1,35 @@ . +/** + * This is a tiny standalone diagnostic script to test that sessions + * are working correctly on a given server. + * + * Just run it from a browser. The first time you run it will + * set a new variable, and after that it will try to find it again. + * The random number is just to prevent browser caching. + * + * @todo add code that actually tests moodle sessions, the old one only tested + * PHP sessions used from installer, not the real moodle sessions + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** Include config {@see config.php} */ require '../config.php'; error('session test not reimplemented yet'); diff --git a/lib/sessionlib.php b/lib/sessionlib.php index 179964b48d..80d11d19bf 100644 --- a/lib/sessionlib.php +++ b/lib/sessionlib.php @@ -1,9 +1,30 @@ -. /** - * Factory method returning moodle_session object. - * @return moodle_session + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +/** + * Factory method returning moodle_session object. + * @return moodle_session + */ function session_get_instance() { global $CFG, $DB; @@ -35,6 +56,11 @@ function session_get_instance() { return $session; } +/** + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ interface moodle_session { /** * Terminate current session @@ -52,6 +78,10 @@ interface moodle_session { /** * Class handling all session and cookies related stuff. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class session_stub implements moodle_session { protected $justloggedout; @@ -285,6 +315,10 @@ abstract class session_stub implements moodle_session { /** * Legacy moodle sessions stored in files, not recommended any more. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class legacy_file_session extends session_stub { protected function init_session_storage() { @@ -319,6 +353,10 @@ class legacy_file_session extends session_stub { /** * Recommended moodle session storage. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class database_session extends session_stub { protected $record = null; diff --git a/lib/setup.php b/lib/setup.php index 23e5aafa81..e39e6744ab 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -1,13 +1,29 @@ . + /** * setup.php - Sets up sessions, connects to databases and so on * * Normally this is only called by the main config.php file * Normally this file does not need to be edited. - * @author Martin Dougiamas - * @version $Id$ - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package moodlecore + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** @@ -20,12 +36,14 @@ * - $CFG->libdir - Path to moodle's library folder on server's filesystem. * * @global object $CFG + * @name $CFG */ global $CFG; /** * Database connection. Used for all access to the database. * @global moodle_database $DB + * @name $DB */ global $DB; @@ -33,6 +51,7 @@ global $DB; * Moodle's wrapper round PHP's $_SESSION. * * @global object $SESSION + * @name $SESSION */ global $SESSION; @@ -54,6 +73,7 @@ global $SESSION; * - $USER->lang - The user's language choice. * * @global object $USER + * @name $USER */ global $USER; @@ -62,12 +82,14 @@ global $USER; * generating in response to the user's request. * * @global moodle_page $PAGE + * @name $PAGE */ global $PAGE; /** * The current course. An alias for $PAGE->course. * @global object $COURSE + * @name $COURSE */ global $COURSE; @@ -79,12 +101,14 @@ global $COURSE; * - $THEME->cellheading2 - Alternate cell colors. * * @global object $THEME + * @name THEME */ global $THEME; /** * Shared memory cache. * @global object $MCACHE + * @name $MCACHE */ global $MCACHE; @@ -93,19 +117,38 @@ global $MCACHE; * * Its primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false. * Its enabled only by the httpsrequired() function and used in some pages to update some URLs -*/ + * + * @global bool $HTTPSPAGEREQUIRED + * @name $HTTPSPAGEREQUIRED + */ global $HTTPSPAGEREQUIRED; -/** Full script path including all params, slash arguments, scheme and host.*/ +/** + * Full script path including all params, slash arguments, scheme and host. + * @global string $FULLME + * @name $FULLME + */ global $FULLME; -/** Script path including query string and slash arguments without host. */ +/** + * Script path including query string and slash arguments without host. + * @global string $ME + * @name $ME + */ global $ME; -/** $FULLME without slasharguments and query string.*/ +/** + * $FULLME without slasharguments and query string. + * @global string $FULLSCRIPT + * @name $FULLSCRIPT + */ global $FULLSCRIPT; -/** Relative moodle script path '/course/view.php' */ +/** + * Relative moodle script path '/course/view.php' + * @global string $SCRIPT + * @name $SCRIPT + */ global $SCRIPT; if (!isset($CFG->wwwroot)) { @@ -118,6 +161,7 @@ global $SCRIPT; if (isset($_SERVER['REMOTE_ADDR'])) { define('CLI_SCRIPT', false); } else { + /** @ignore */ define('CLI_SCRIPT', true); } } diff --git a/lib/setuplib.php b/lib/setuplib.php index 61b478be35..275aa8f08d 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -1,16 +1,46 @@ -. +/** + * These functions are required very early in the Moodle + * setup process, before any of the main libraries are + * loaded. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + /** * Simple class + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class object {}; /** * Base Moodle Exception class + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class moodle_exception extends Exception { public $errorcode; @@ -47,6 +77,10 @@ class moodle_exception extends Exception { /** * Exception indicating programming error, must be fixed by a programer. For example * a core API might throw this type of exception if a plugin calls it incorrectly. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class coding_exception extends moodle_exception { /** @@ -65,6 +99,10 @@ class coding_exception extends moodle_exception { * CONTEXT_... constant. You might throw an invalid_state_exception in the * default case, to just in case something really weird is going on, and * $context->contextlevel is invalid - rather than ignoring this possibility. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class invalid_state_exception extends moodle_exception { /** diff --git a/lib/simpletestlib.php b/lib/simpletestlib.php index 47bb9bb758..3c447ae8d5 100644 --- a/lib/simpletestlib.php +++ b/lib/simpletestlib.php @@ -1,4 +1,20 @@ -. + /** * Utility functions to make unit testing easier. * @@ -6,13 +22,18 @@ * dirty methods for getting things done in test cases. None of these * methods should be used outside test code. * + * Major Contirbutors + * - T.J.Hunt@open.ac.uk + * + * @package moodlecore + * @subpackage simpletestex * @copyright © 2006 The Open University - * @author T.J.Hunt@open.ac.uk - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @version $Id$ - * @package SimpleTestEx + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +/** + * Includes + */ require_once(dirname(__FILE__) . '/../config.php'); require_once($CFG->libdir . '/simpletestlib/simpletest.php'); require_once($CFG->libdir . '/simpletestlib/unit_tester.php'); @@ -52,6 +73,11 @@ function recurseFolders($path, $callback, $fileregexp = '/.*/', $exclude = false /** * An expectation for comparing strings ignoring whitespace. + * + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class IgnoreWhitespaceExpectation extends SimpleExpectation { var $expect; @@ -76,6 +102,11 @@ class IgnoreWhitespaceExpectation extends SimpleExpectation { /** * An Expectation that two arrays contain the same list of values. + * + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class ArraysHaveSameValuesExpectation extends SimpleExpectation { var $expect; @@ -108,6 +139,11 @@ class ArraysHaveSameValuesExpectation extends SimpleExpectation { * An Expectation that compares to objects, and ensures that for every field in the * expected object, there is a key of the same name in the actual object, with * the same value. (The actual object may have other fields to, but we ignore them.) + * + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class CheckSpecifiedFieldsExpectation extends SimpleExpectation { var $expect; @@ -160,6 +196,11 @@ class CheckSpecifiedFieldsExpectation extends SimpleExpectation { * The tear-down method for this class should automatically revert any changes * you make during test set-up using the metods defined here. That is, it will * drop tables for you automatically and revert to the real $DB and $USER->id. + * + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class UnitTestCaseUsingDatabase extends UnitTestCase { private $realdb; @@ -378,6 +419,12 @@ class UnitTestCaseUsingDatabase extends UnitTestCase { } } +/** + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class FakeDBUnitTestCase extends UnitTestCase { public $tables = array(); public $pkfile; @@ -389,7 +436,8 @@ class FakeDBUnitTestCase extends UnitTestCase { * If this file already exists, it means that a previous run of unit tests * did not complete, and has left data undeleted in the DB. This data is then * deleted and the file is retained. Otherwise it is created. - * @throws moodle_exception if CSV file cannot be created + * + * throws moodle_exception if CSV file cannot be created */ public function __construct($label = false) { global $DB, $CFG; @@ -455,8 +503,10 @@ class FakeDBUnitTestCase extends UnitTestCase { * Given a filename, opens it and parses the csv contained therein. It expects two fields per line: * 1. Table name * 2. Max id + * + * throws moodle_exception if file doesn't exist + * * @param string $filename - * @throws moodle_exception if file doesn't exist */ public function get_table_data($filename) { global $CFG; @@ -485,7 +535,7 @@ class FakeDBUnitTestCase extends UnitTestCase { /** * Method called before each test method. Replaces the real $DB with the one configured for unit tests (different prefix, $CFG->unittestprefix). * Also detects if this config setting is properly set, and if the user table exists. - * TODO Improve detection of incorrectly built DB test tables (e.g. detect version discrepancy and offer to upgrade/rebuild) + * @todo Improve detection of incorrectly built DB test tables (e.g. detect version discrepancy and offer to upgrade/rebuild) */ public function setUp() { global $DB, $CFG; @@ -602,6 +652,11 @@ class FakeDBUnitTestCase extends UnitTestCase { * Internally, it routes all calls to $DB to a real instance of the database engine (aggregated as a member variable), * except those that are defined in this proxy class. This makes it possible to add extra code to the database engine * without subclassing it. + * + * @package moodlecore + * @subpackage simpletestex + * @copyright © 2006 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class UnitTestDB { public static $DB; @@ -672,7 +727,8 @@ class UnitTestDB { /** * Overriding update_record: If we are updating a record that was NOT inserted by unit tests, * throw an exception and cancel update. - * @throws moodle_exception If trying to update a record not inserted by unit tests. + * + * throws moodle_exception If trying to update a record not inserted by unit tests. */ public function update_record($table, $dataobject, $bulk=false) { global $DB; @@ -691,7 +747,8 @@ class UnitTestDB { /** * Overriding delete_record: If we are deleting a record that was NOT inserted by unit tests, * throw an exception and cancel delete. - * @throws moodle_exception If trying to delete a record not inserted by unit tests. + * + * throws moodle_exception If trying to delete a record not inserted by unit tests. */ public function delete_records($table, array $conditions=array()) { global $DB; @@ -730,7 +787,8 @@ class UnitTestDB { /** * Overriding delete_records_select: If we are deleting a record that was NOT inserted by unit tests, * throw an exception and cancel delete. - * @throws moodle_exception If trying to delete a record not inserted by unit tests. + * + * throws moodle_exception If trying to delete a record not inserted by unit tests. */ public function delete_records_select($table, $select, array $params=null) { global $DB; diff --git a/lib/soaplib.php b/lib/soaplib.php index b5eaf962c1..7ddfd2273c 100644 --- a/lib/soaplib.php +++ b/lib/soaplib.php @@ -1,13 +1,34 @@ . + +/** + * Web services wrapper library script + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ if (check_php_version('5') && class_exists('SoapClient')) { - // Use the native PHP5 support + /** Use the native PHP5 support */ require_once($CFG->libdir . '/soap/phpsoap.php'); } else{ - // Use nuSOAP instead + /** Use nuSOAP instead */ require_once($CFG->libdir . '/soap/nusoap.php'); function make_soap_fault($faultcode, $faultstring, $faultactor='', $detail='', $faultname='', $headerfault='') { @@ -26,6 +47,7 @@ else{ } } else { + /** @ignore */ function soap_connect($wsdl, $trace=false) { return new soapclient($wsdl, 'wsdl'); } diff --git a/lib/statslib.php b/lib/statslib.php index 00de7537a8..9f00f648da 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -1,6 +1,27 @@ . + +/** + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + /** THESE CONSTANTS ARE USED FOR THE REPORTING PAGE. */ define('STATS_REPORT_LOGINS',1); // double impose logins and unqiue logins on a line graph. site course only. define('STATS_REPORT_READS',2); // double impose student reads and teacher reads on a line graph. -- 2.39.5