From be5df3df206bd49417ef0d5a68033e22de747e8b Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Sat, 6 Jun 2026 15:03:30 +0100 Subject: xref: migrate query methods to LibertyXrefType; docblocks throughout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LibertyXrefType gains five runtime statics (getDisplayGroups, getTypeMarkers, getAvailableItems, getTemplateFormats, getContentTypeMarkers) — role-filtered, content-type-scoped. LibertyContent xref query methods become one-line delegates. LibertyXrefInfo added as new class (was missing from repo). Docblocks added to LibertyContent class, LibertyXref, LibertyXrefGroup, LibertyXrefInfo, LibertyXrefType. list_xref.tpl: remove dead legacy $source path; new path only. loadXrefList() removed from LibertyContent (stock fully migrated). Co-Authored-By: Claude Sonnet 4.6 --- includes/classes/LibertyContent.php | 312 +++++++++++++++++++--------------- includes/classes/LibertyXref.php | 87 ++++++++++ includes/classes/LibertyXrefGroup.php | 54 +++++- includes/classes/LibertyXrefInfo.php | 87 ++++++++++ includes/classes/LibertyXrefType.php | 260 +++++++++++++++++++++++++++- 5 files changed, 648 insertions(+), 152 deletions(-) create mode 100644 includes/classes/LibertyXrefInfo.php (limited to 'includes') diff --git a/includes/classes/LibertyContent.php b/includes/classes/LibertyContent.php index 3798639..13d0f4d 100755 --- a/includes/classes/LibertyContent.php +++ b/includes/classes/LibertyContent.php @@ -50,8 +50,66 @@ if( !defined( 'BIT_CONTENT_DEFAULT_STATUS' ) ) { define( 'LIBERTY_SPLIT_REGEX', "!\.[3]split\.[3][\t ]*\n?!" ); /** - * Virtual base class (as much as one can have such things in PHP) for all - * derived tikiwiki classes that require database access. + * Base class for all content types managed by the liberty content engine. + * + * Every piece of user-visible content in bitweaver — wiki pages, articles, blog posts, + * contacts, stock items, movements — is backed by a row in liberty_content and + * represented by a subclass of LibertyContent. The shared row carries fields common + * to all content: title, creator/modifier user_id, timestamps, format_guid, + * content_status_id, and the raw data blob. + * + * ## Lifecycle + * + * Subclasses follow this pattern: + * - **`verify(&$pParamHash)`** — validate and normalise inbound data; build + * `$pParamHash['content_store']` ready for DB write. Call `parent::verify()` + * first, then extend with package-specific checks. + * - **`store(&$pParamHash)`** — write to liberty_content (insert or update), then + * call `parent::store()`. Opens a transaction; the subclass writes its own table + * inside the same transaction. + * - **`load()`** — load from DB into `$this->mInfo`. The subclass loads its own + * table joined to liberty_content, then calls `parent::load()` to trigger + * services and load preferences. + * - **`expunge()`** — delete the content item and all related records. The + * subclass deletes its own table rows first, then calls `parent::expunge()` which + * removes xref rows, history, hits, aliases, and the liberty_content row itself. + * + * ## Permissions + * + * Five permission strings are set as class properties and defaulted in `__construct()`: + * - `mViewContentPerm` — if empty, view is always allowed + * - `mCreateContentPerm` — required to create new content of this type + * - `mUpdateContentPerm` — required to edit existing content + * - `mExpungeContentPerm` — required to delete content + * - `mAdminContentPerm` — supersedes all other checks; grants full access + * + * Per-item permission overrides (liberty_content_permissions) can supplement or + * revoke role permissions for a specific content item independently of global roles. + * + * ## XRef System + * + * LibertyContent is the gateway into the xref system for content subclasses: + * - `loadXrefInfo()` — populate `$this->mXrefInfo` (a LibertyXrefInfo) with all + * display groups and their rows for this content item. Call this from page files + * before assigning `gXrefInfo` to Smarty. Package classes override this to + * enrich rows (e.g. resolving contact titles from xref content_ids). + * - `loadXrefTypeList()` — load sort_order=0 type markers into mInfo. + * - `storeXref(&$pParamHash)` / `stepXref(&$pParamHash)` — write xref rows. + * - `getXrefListTemplate()` / `getXrefRecordTemplate()` / `getXrefEditTemplate()` — + * resolve the correct Smarty template for a group or item. + * + * ## Content Status + * + * `liberty_content.content_status_id` is a numeric threshold: + * - >= 50 public / available + * - < 0 various hidden/private/deleted tiers (thresholds configurable via kernel_config) + * + * ## Services + * + * `invokeServices($pServiceFunction, &$param)` calls all registered service functions + * of a given type (e.g. `content_store_function`, `content_list_sql_function`). + * Services augment content behaviour — categorisation, search indexing, access + * control — without modifying this class. * * @package liberty */ @@ -85,6 +143,9 @@ class LibertyContent extends LibertyBase implements BitCacheable { */ public $mType; + /** Populated by loadXrefInfo() — LibertyXrefInfo instance for this content item */ + public ?LibertyXrefInfo $mXrefInfo = null; + /** *Permissions hash specific to the user accessing this LibertyContent object * @public @@ -2155,8 +2216,35 @@ class LibertyContent extends LibertyBase implements BitCacheable { * @param number $pContentId a valid content id * @param array $pMixed a hash of params to add to the url */ + /** + * Hook for packages to enrich a single xref row after it has been loaded. + * + * Called by edit_xref.php when displaying a single xref for editing. + * Override in a package class to add computed fields (e.g. contact title from + * an xref content_id, component pack size) directly into the row array before + * it reaches the template. + * + * @param array &$pXrefInfo the raw xref row from liberty_xref (mutate in place) + */ public function enrichXrefDisplay( array &$pXrefInfo ): void {} + /** + * Resolve the Smarty group template for an xref group. + * + * Template resolution order (first match wins): + * 1. `/templates//view_xref_