Commit 5e177cc7 authored by lphuberdeau's avatar lphuberdeau

[ENH] Move categlib and userlib to DI, clean-up inclusions

parent 57df92ef
......@@ -16,7 +16,10 @@ if (isset($_REQUEST['connectprefs'])) {
}
ask_ticket('admin-inc-connect');
global $userlib, $prefs, $base_url, $headerlib, $smarty;
global $prefs, $base_url;
$userlib = TikiLib::lib('user');
$headerlib = TikiLib::lib('header');
$smarty = TikiLib::lib('smarty');
$headerlib->add_jsfile('lib/jquery_tiki/tiki-connect.js');
......
......@@ -155,7 +155,7 @@ $smarty->assign('gdlib', $gdlib);
$smarty->assign('imagicklib', $imagicklib);
if ($prefs['feature_categories'] == 'y') {
include_once ('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
$catree = $categlib->getCategories(null, true, false);
$smarty->assign('catree', $catree);
}
......
......@@ -29,8 +29,11 @@ $s = new XML_RPC_Server($map);
*/
function sendStructurePage($params)
{
global $tikilib, $userlib, $commlib, $prefs;
include_once ('lib/structures/structlib.php');
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$structlib = TikiLib::lib('struct');
$site = $params->getParam(0); $site = $site->scalarval();
$user = $params->getParam(1); $user = $user->scalarval();
$pass = $params->getParam(2); $pass = $pass->scalarval();
......@@ -72,7 +75,9 @@ function sendStructurePage($params)
function sendPage($params)
{
// Get the page and store it in received_pages
global $tikilib, $userlib, $commlib, $prefs;
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$pp = $params->getParam(0);
$site = $pp->scalarval();
......@@ -116,7 +121,9 @@ function sendPage($params)
function sendArticle($params)
{
// Get the page and store it in received_pages
global $tikilib, $userlib, $commlib, $prefs;
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$pp = $params->getParam(0);
$site = $pp->scalarval();
......
......@@ -11,5 +11,11 @@
<service id="tiki.lib.service" class="ServiceLib">
<file>%kernel.root_dir%/lib/servicelib.php</file>
</service>
<service id="tiki.lib.user" class="UsersLib">
<file>%kernel.root_dir%/lib/userslib.php</file>
</service>
<service id="tiki.lib.categ" class="CategLib">
<file>%kernel.root_dir%/lib/categories/categlib.php</file>
</service>
</services>
</container>
......@@ -11,7 +11,7 @@
include_once("lib/init/initlib.php");
require_once("db/tiki-db.php");
require_once("lib/tikilib.php");
require_once("lib/categories/categlib.php");
$categlib = TikiLib::lib('categ');
require_once("lib/structures/structlib.php");
/**
......
......@@ -16,10 +16,9 @@ $tikidomain2 = "cc.tikiwiki.org";
require_once("db/tiki-db.php");
require_once("lib/tikilib.php");
require_once("lib/userslib.php");
$userlib = TikiLib::lib('user');
$tikilib = new TikiLib;
$userlib = new UsersLib;
$users = $userlib->get_group_users('CC');
......
......@@ -6,7 +6,7 @@
// $Id$
require_once('tiki-setup.php');
require_once('lib/userslib.php');
$userlib = TikiLib::lib('user');
/*
if ($tiki_p_admin != 'y') {
......@@ -19,4 +19,4 @@ if ($tiki_p_admin != 'y') {
}*/
$userlib->ldap_sync_all_users();
$userlib->ldap_sync_all_groups();
\ No newline at end of file
$userlib->ldap_sync_all_groups();
......@@ -31,8 +31,8 @@ function upgrade_999999991_decode_pages_sources_tiki($installer)
global $user_overrider_prefs, $systemConfiguration;
set_time_limit(60 * 60); // Set maximum execution time to 1 hour since this runs on all pages
include_once('tiki-setup_base.php');
include_once ('lib/categories/categlib.php'); // needed for cat_jail fn in list_pages()
include_once('lib/wiki/wikilib.php');
$categlib = TikiLib::lib('categ');
$wikilib = TikiLib::lib('wiki');
$converter = new convertToTiki9();
$converter->convertPages();
......
......@@ -940,8 +940,7 @@ if (
$install_type = 'scratch';
require_once 'lib/tikilib.php';
$tikilib = new TikiLib;
require_once 'lib/userslib.php';
$userlib = new UsersLib;
$userlib = TikiLib::lib('user');
require_once 'lib/tikidate.php';
$tikidate = new TikiDate();
}
......@@ -980,7 +979,8 @@ if ($install_step == '8') {
touch('db/'.$tikidomainslash.'lock');
}
global $userlib, $cachelib;
$userlib = TikiLib::lib('user');
$cachelib = TikiLib::lib('cache');
if (session_id()) {
session_destroy();
}
......
......@@ -53,7 +53,7 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
print_debug("Login Anonymous User=".$data->username." Already logged\n");
return true;
}
global $userlib; include_once('lib/userslib.php');
$userlib = TikiLib::lib('user');
if ($prefs['auth_method'] == 'cas') {
// Workaround : Webdav doesn't work with cas
$prefs['auth_method'] = 'ldap';
......@@ -82,7 +82,7 @@ class TikiWebdav_Auth_Default extends ezcWebdavBasicAuth implements ezcWebdavAut
$user = $_SESSION['webdav_user'] = 'Anonymous';
return true;
}
global $userlib; include_once('lib/userslib.php');
$userlib = TikiLib::lib('user');
list($isvalid, $user, $error) = $userlib->validate_user($data->username, 'tototi');
print_debug("Login Digest User=" . $data->username . " " . ($isvalid ? 'OK' : 'FAILED') . " " . print_r($data, true) . "\n");
if ($isvalid) {
......
......@@ -78,7 +78,8 @@ class AccountingLib extends LogsLib
, $bookAutoTax = 'y'
)
{
global $userlib, $user;
global $user;
$userlib = TikiLib::lib('user');
if (strlen($bookName) == 0) {
return "The book must have a name";
}
......
......@@ -1045,7 +1045,8 @@ class ArtLib extends TikiLib
)
{
global $userlib, $user, $prefs;
global $user, $prefs;
$userlib = TikiLib::lib('user');
$mid = $join = '';
$bindvars = array();
......@@ -1203,7 +1204,7 @@ class ArtLib extends TikiLib
$bindvars[] = $max_rating;
}
global $categlib; require_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
if ( $categId ) {
$jail = $categId;
} else {
......
......@@ -36,8 +36,8 @@ class BlogLib extends TikiDb_Bridge
*/
function list_blogs($offset = 0, $maxRecords = -1, $sort_mode = 'created_desc', $find = '', $ref='', $with = '')
{
global $tikilib, $categlib;
if (!$categlib) require_once 'lib/categories/categlib.php';
$tikilib = TikiLib::lib('tiki');
$categlib = TikiLib::lib('categ');
$bindvars = array();
$join = '';
$where = '';
......@@ -90,8 +90,9 @@ class BlogLib extends TikiDb_Bridge
*/
function get_blog($blogId)
{
global $tikilib, $prefs, $user, $categlib; if (!$categlib) require_once 'lib/categories/categlib.php';
global $prefs, $user;
$tikilib = TikiLib::lib('tiki');
$categlib = TikiLib::lib('categ');
$bindvars = array();
if ( $jail = $categlib->get_jail() ) {
......@@ -596,7 +597,9 @@ class BlogLib extends TikiDb_Bridge
*/
function list_blog_post_comments($approved = 'y', $maxRecords = -1)
{
global $user, $tikilib, $userlib, $tiki_p_admin, $tiki_p_blog_admin, $tiki_p_blog_post;
global $user, $tiki_p_admin, $tiki_p_blog_admin, $tiki_p_blog_post;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
// TODO: use commentslib instead of querying database directly
// Blog Recent Comments
......
......@@ -50,7 +50,7 @@ class CalendarLib extends TikiLib
$bindvars[] = '%'.$find.'%';
}
global $categlib; require_once( 'lib/categories/categlib.php' );
$categlib = TikiLib::lib('categ');
$join = '';
if ( $jail = $categlib->get_jail() ) {
......@@ -207,7 +207,7 @@ class CalendarLib extends TikiLib
$query = "delete from `tiki_calendar_locations` where `calendarId`=?";
$this->query($query, array($calendarId));
// uncategorize calendar
global $categlib; require_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
$categlib->uncategorize_object('calendar', $calendarId);
// now remove the calendar itself:
$query = "delete from `tiki_calendars` where `calendarId`=?";
......
......@@ -384,12 +384,13 @@ class CategLib extends ObjectLib
function list_category_objects($categId, $offset, $maxRecords, $sort_mode='pageName_asc', $type='', $find='', $deep=false, $and=false, $filter=null)
{
global $userlib, $prefs;
global $prefs;
$userlib = TikiLib::lib('user');
if ($prefs['feature_sefurl'] == 'y') {
include_once('tiki-sefurl.php');
}
if ($prefs['feature_trackers'] == 'y') {
global $trklib;require_once('lib/trackers/trackerlib.php');
$trklib = TikiLib::lib('trk');
}
// Build the condition to restrict which categories objects must be in to be returned.
......@@ -1155,7 +1156,8 @@ class CategLib extends ObjectLib
// Gets a list of categories that will block objects to be seen by user, recursive
function list_forbidden_categories($parentId=0, $parentAllowed='', $perm='tiki_p_view_categorized')
{
global $user, $userlib;
global $user;
$userlib = TikiLib::lib('user');
if (empty($parentAllowed)) {
global $tiki_p_view_categorized;
$parentAllowed = $tiki_p_view_categorized;
......@@ -1410,7 +1412,7 @@ class CategLib extends ObjectLib
*/
function has_edit_permission($user, $categoryId)
{
global $userlib;
$userlib = TikiLib::lib('user');
return ($userlib->user_has_permission($user, 'tiki_p_admin')
|| ($userlib->user_has_permission($user, 'tiki_p_edit') && !$userlib->object_has_one_permission($categoryId, "category"))
|| $userlib->object_has_permission($user, $categoryId, "category", "tiki_p_edit")
......@@ -1479,7 +1481,8 @@ class CategLib extends ObjectLib
// $objId: A unique identifier of an object of the given type, for example "Foo" for Wiki page Foo.
function update_object_categories($categories, $objId, $objType, $desc=NULL, $name=NULL, $href=NULL, $managedCategories = null, $override_perms = false)
{
global $prefs, $user, $userlib;
global $prefs, $user;
$userlib = TikiLib::lib('user');
if (empty($categories)) {
$forcedcat = $userlib->get_user_group_default_category($user);
......@@ -1806,4 +1809,4 @@ class CategLib extends ObjectLib
return $this->parentCategories[$categId];
}
}
$categlib = new CategLib;
......@@ -619,7 +619,9 @@ class Comments extends TikiLib
//Approve queued message -> post as new comment
function approve_queued($qId)
{
global $userlib, $tikilib, $prefs;
global $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$info = $this->queue_get($qId);
$message_id = '';
......@@ -793,7 +795,7 @@ class Comments extends TikiLib
$bind_time[] = $type;
}
global $categlib; require_once 'lib/categories/categlib.php';
$categlib = TikiLib::lib('categ');
if ($jail = $categlib->get_jail()) {
$categlib->getSqlJoin($jail, 'forum', '`a`.`object`', $join, $where, $bind_vars);
} else {
......@@ -1930,7 +1932,8 @@ class Comments extends TikiLib
$approved='y'
)
{
global $userlib, $tiki_p_admin_comments, $prefs;
global $tiki_p_admin_comments, $prefs;
$userlib = TikiLib::lib('user');
$orig_maxRecords = $maxRecords;
$orig_offset = $offset;
......@@ -2261,7 +2264,7 @@ class Comments extends TikiLib
$left = ', tc.`title` as parentTitle';
}
global $categlib; require_once 'lib/categories/categlib.php';
$categlib = TikiLib::lib('categ');
if ($jail = $categlib->get_jail()) {
$categlib->getSqlJoin($jail, '`objectType`', 'tc.`object`', $jail_join, $jail_where, $jail_bind, 'tc.`objectType`');
} else {
......
......@@ -25,13 +25,13 @@ class Perms_Reflection_Global implements Perms_Reflection_Container
function add( $group, $permission )
{
global $userlib;
$userlib = TikiLib::lib('user');
$userlib->assign_permission_to_group($permission, $group);
}
function remove( $group, $permission )
{
global $userlib;
$userlib = TikiLib::lib('user');
if ($group != 'Admins' || $permission != 'tiki_p_admin') {
$userlib->remove_permission_from_group($permission, $group);
}
......
......@@ -20,19 +20,19 @@ class Perms_Reflection_Object implements Perms_Reflection_Container
function add( $group, $permission )
{
global $userlib;
$userlib = TikiLib::lib('user');
$userlib->assign_object_permission($group, $this->object, $this->type, $permission);
}
function remove( $group, $permission )
{
global $userlib;
$userlib = TikiLib::lib('user');
$userlib->remove_object_permission($group, $this->object, $this->type, $permission);
}
function getDirectPermissions()
{
global $userlib;
$userlib = TikiLib::lib('user');
$set = new Perms_Reflection_PermissionSet;
$permissions = $userlib->get_object_permissions($this->object, $this->type);
......@@ -75,7 +75,7 @@ class Perms_Reflection_Object implements Perms_Reflection_Container
private function getCategories()
{
global $categlib; require_once 'lib/categories/categlib.php';
$categlib = TikiLib::lib('categ');
return $categlib->get_object_categories($this->type, $this->object);
}
......
......@@ -42,7 +42,7 @@ class Reports_Factory
case 'Reports_Cache':
return new Reports_Cache($db, $dt);
case 'Reports_Manager':
global $userlib;
$userlib = TikiLib::lib('user');
return new Reports_Manager(
Reports_Factory::build('Reports_Users', $dt, $tm, $tikilib),
Reports_Factory::build('Reports_Cache', $dt, $tm, $tikilib),
......
......@@ -97,7 +97,7 @@ class Reports_Send_EmailBuilder
*/
public function makeEmailBody(array $report_cache, array $report_preferences)
{
global $userlib;
$userlib = TikiLib::lib('user');
$change_array = $this->makeChangeArray($report_cache);
$body = '';
......
......@@ -62,8 +62,7 @@ class Tiki_Profile_InstallHandler_Category extends Tiki_Profile_InstallHandler
$this->replaceReferences($this->migrateparent);
$this->replaceReferences($this->items);
global $categlib;
require_once 'lib/categories/categlib.php';
$categlib = TikiLib::lib('categ');
if ($id = $categlib->exist_child_category($this->parent, $this->name)) {
$categlib->update_category($id, $this->name, $this->description, $this->parent);
} else {
......
......@@ -59,7 +59,7 @@ class Tiki_Profile_InstallHandler_User extends Tiki_Profile_InstallHandler
function _install()
{
if ($this->canInstall()) {
global $userlib; if (!$userlib) require_once 'lib/userslib.php';
$userlib = TikiLib::lib('user');
$user = $this->getData();
......
......@@ -460,7 +460,7 @@ class Tiki_Profile_Installer
private function setupGroup( $groupName, $info, $permissions, $objects, $groupMap ) // {{{
{
global $userlib;
$userlib = TikiLib::lib('user');
if ( ! $userlib->group_exists($groupName) ) {
$userlib->add_group($groupName, $info['description'], $info['home'], $info['user_tracker'], $info['group_tracker'], implode(':', $info['registration_fields']), $info['user_signup'], $info['default_category'], $info['theme'], $info['user_tracker_field'], $info['group_tracker_field']);
......
......@@ -42,7 +42,8 @@ class Tracker_Field_UserPreference extends Tracker_Field_Abstract
if (isset($requestData[$ins_id])) {
$value = $requestData[$ins_id];
} else {
global $trklib, $userlib;
$userlib = TikiLib::lib('user');
$trklib = TikiLib::lib('trk');
$value = '';
$itemId = $this->getItemId();
......
......@@ -105,7 +105,8 @@ class CreditsLib extends TikiLib
// Handle level-type credits in a different manner
// Level of used amount stored in user preferences
// Total used (flow) from credits table
global $tikilib, $userlib;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$info = $userlib->get_userid_info($userId);
$creditTypes = $this->getCreditTypes();
......@@ -242,7 +243,8 @@ class CreditsLib extends TikiLib
}
if ( $credits[$creditType]['remain'] > 0 ) {
global $tikilib, $userlib;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$info = $userlib->get_userid_info($userId);
// Expense all credits if not enough
......@@ -314,7 +316,8 @@ class CreditsLib extends TikiLib
return false;
}
global $tikilib, $userlib;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$info = $userlib->get_userid_info($userId);
$prefName = "credits_level_" . $creditType;
......
......@@ -43,6 +43,9 @@ class DbgPermissions extends DebuggerCommand
/// Execute command with given set of arguments.
function execute($params)
{
$userlib = TikiLib::lib('user');
$smarty = TikiLib::lib('smarty');
$this->set_result_type(TPL_RESULT);
$this->set_result_tpl('debug/tiki-debug_permissions.tpl');
......@@ -50,10 +53,8 @@ class DbgPermissions extends DebuggerCommand
$p = explode(' ', trim($params));
$mask = count($p) > 0 ? str_replace('$', '', trim($p[0])) : '';
// Get list of all vars
global $smarty;
$tpl_vars = $smarty->getTemplateVars();
// Get descriptions for all permissions
global $userlib;
$pd = $userlib->get_permissions();
$descriptions = array();
......
......@@ -632,7 +632,7 @@ class FileGalLib extends TikiLib
}
if ($prefs['feature_categories'] == 'y') {
global $categlib; require_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
$categlib->uncategorize_object('file', $id);
}
......@@ -1485,7 +1485,9 @@ class FileGalLib extends TikiLib
// not the best optimisation as using a library using files and not content
function zip($fileIds, &$error, $zipName='')
{
global $tiki_p_admin_file_galleries, $userlib, $tikilib, $prefs, $user;
global $tiki_p_admin_file_galleries, $prefs, $user;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$list = array();
$temp = 'temp/'.md5($tikilib->now).'/';
if (!mkdir($temp)) {
......
......@@ -69,7 +69,8 @@ class groupAlertLib extends TikiLib
*/
function Notify ( $ListUserToAlert,$URI )
{
global $tikilib,$userlib ;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
if (!is_array($ListUserToAlert)) {
return;
}
......
......@@ -1600,7 +1600,8 @@ class ImageGalsLib extends TikiLib
$cant = $this->getOne($query_cant, $bindvars);
$ret = array();
global $prefs, $userlib, $user, $tiki_p_admin;
global $prefs, $user, $tiki_p_admin;
$userlib = TikiLib::lib('user');
while ($res = $result->fetchRow()) {
$res['perms'] = $this->get_perm_object($res['galleryId'], 'image gallery', $res, false);
if ($res['perms']['tiki_p_view_image_gallery'] == 'y') {
......
......@@ -308,7 +308,7 @@ class TikiImporter_Blog extends TikiImporter
*/
function createCategories($categories)
{
global $categlib; require_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
foreach ($categories as $categ) {
if (!empty($categ['parent'])) {
......@@ -331,7 +331,7 @@ class TikiImporter_Blog extends TikiImporter
*/
function linkObjectWithCategories($objId, $type, $categories)
{
global $categlib; require_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
foreach ($categories as $categName) {
$categId = $categlib->get_category_id($categName);
......
......@@ -209,7 +209,7 @@ class TikiImporter_Wiki extends TikiImporter
$first = false;
}
if (!empty($rev['categories'])) {
global $categlib; include_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
foreach ($rev['categories'] as $cat) {
$categId = $categlib->get_category_id($cat);
if (empty($categId)) {
......
......@@ -129,7 +129,7 @@ class LogsLib extends TikiLib
}
if ($logCateg) {
global $categlib; include_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
if ($objectType == 'comment') {
preg_match('/type=([^&]*)/', $param, $matches);
$categs = $categlib->get_object_categories($matches[1], $object);
......@@ -185,7 +185,7 @@ class LogsLib extends TikiLib
}
if ($logCateg) {
global $categlib; include_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
if ($objectType == 'comment') {
preg_match('/type=([^&]*)/', $param, $matches);
$categs = $categlib->get_object_categories($matches[1], $object);
......@@ -501,7 +501,7 @@ class LogsLib extends TikiLib
}
if ($res['objectType'] == 'comment' && empty($res['categId'])) {
global $categlib; include_once('lib/categories/categlib.php');
$categlib = TikiLib::lib('categ');
preg_match('/type=([^&]*)/', $res['comment'], $matches);
$categs = $categlib->get_object_categories($matches[1], $res['object']);
$i = 0;
......
......@@ -19,7 +19,9 @@ class Messu extends TikiLib
*/
function save_sent_message($user, $from, $to, $cc, $subject, $body, $priority, $replyto_hash = '')
{
global $smarty, $userlib, $prefs;
global $prefs;
$userlib = TikiLib::lib('user');
$smarty = TikiLib::lib('smarty');
$subject = strip_tags($subject);
$body = strip_tags($body, '<a><b><img><i>');
......@@ -77,7 +79,9 @@ class Messu extends TikiLib
*/
function post_message($user, $from, $to, $cc, $subject, $body, $priority, $replyto_hash = '', $replyto_email = '', $bcc_sender = '')
{
global $smarty, $userlib, $prefs;
global $prefs;
$userlib = TikiLib::lib('user');
$smarty = TikiLib::lib('smarty');
$subject = strip_tags($subject);
$body = strip_tags($body, '<a><b><img><i>');
......
......@@ -172,7 +172,8 @@ class NlLib extends TikiLib
public function get_all_subscribers($nlId, $genUnsub)
{
global $userlib, $prefs, $user;
global $prefs, $user;
$userlib = TikiLib::lib('user');
$return = array();
$all_users = array();
$group_users = array();
......@@ -389,7 +390,10 @@ class NlLib extends TikiLib
public function newsletter_subscribe($nlId, $add, $isUser='n', $validateAddr='', $addEmail='')
{
global $smarty, $tikilib, $user, $prefs, $userlib;