Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 402] [Versions 310 and 403]

This contains functions and classes that will be used by scripts in wiki module

Author: Jordi Piguillem
Author: Marc Alier
Author: David Jimenez
Author: Josep Arus
Author: Daniel Serrano
Author: Kenneth Riba
Copyright: 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
Copyright: 2009 Universitat Politecnica de Catalunya http://www.upc.edu
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1857 lines (62 kb)
Included or required: 1 time
Referenced: 15 times
Includes or requires: 0 files

Defines 69 functions

  wiki_get_wiki()
  wiki_get_subwikis()
  wiki_get_subwiki_by_group()
  wiki_get_subwiki()
  wiki_add_subwiki()
  wiki_get_wiki_from_pageid()
  wiki_get_page()
  wiki_get_current_version()
  wiki_get_last_version()
  wiki_get_section_page()
  wiki_get_page_by_title()
  wiki_get_version()
  wiki_get_first_page()
  wiki_save_section()
  wiki_save_page()
  wiki_refresh_cachedcontent()
  wiki_restore_page()
  wiki_refresh_page_links()
  wiki_create_page()
  wiki_make_cache_expire()
  wiki_get_wiki_page_version()
  wiki_get_wiki_page_versions()
  wiki_count_wiki_page_versions()
  wiki_get_linked_to_pages()
  wiki_get_linked_from_pages()
  wiki_get_contributions()
  wiki_get_missing_or_empty_pages()
  wiki_get_page_list()
  wiki_get_orphaned_pages()
  wiki_search_title()
  wiki_search_content()
  wiki_search_all()
  wiki_get_user_info()
  wiki_increment_pageviews()
  wiki_get_formats()
  wiki_parse_content()
  wiki_parser_link()
  wiki_parser_table()
  wiki_parser_real_path()
  wiki_parser_get_token()
  wiki_user_can_view()
  wiki_user_can_edit()
  wiki_is_page_section_locked()
  wiki_set_lock()
  wiki_delete_locks()
  wiki_delete_old_locks()
  wiki_delete_links()
  wiki_delete_synonym()
  wiki_delete_pages()
  wiki_delete_page_versions()
  wiki_get_comment()
  wiki_get_comments()
  wiki_add_comment()
  wiki_delete_comment()
  wiki_delete_comments_wiki()
  wiki_add_progress()
  wiki_get_wiki_page_id()
  wiki_print_page_content()
  wiki_trim_string()
  wiki_print_edit_form_default_fields()
  wiki_print_upload_table()
  wiki_build_tree()
  wiki_get_linked_pages()
  wiki_get_updated_pages_by_subwiki()
  wiki_can_create_pages()
  wiki_get_possible_subwiki_by_group()
  wiki_get_visible_subwikis()
  wiki_get_subwiki_by_group_and_user_with_validation()
  mod_wiki_get_tagged_pages()

Functions that are not part of a class:

wiki_get_wiki($wikiid)   X-Ref
Get a wiki instance

param: int $wikiid the instance id of wiki

wiki_get_subwikis($wikiid)   X-Ref
Get sub wiki instances with same wiki id

param: int $wikiid

wiki_get_subwiki_by_group($wikiid, $groupid, $userid = 0)   X-Ref
Get a sub wiki instance by wiki id and group id

param: int $wikiid
param: int $groupid
return: object

wiki_get_subwiki($subwikiid)   X-Ref
Get a sub wiki instace by instance id

param: int $subwikiid
return: object

wiki_add_subwiki($wikiid, $groupid, $userid = 0)   X-Ref
Add a new sub wiki instance

param: int $wikiid
param: int $groupid
return: int $insertid

wiki_get_wiki_from_pageid($pageid)   X-Ref
Get a wiki instance by pageid

param: int $pageid
return: object

wiki_get_page($pageid)   X-Ref
Get a wiki page by pageid

param: int $pageid
return: object

wiki_get_current_version($pageid)   X-Ref
Get latest version of wiki page

param: int $pageid
return: object

wiki_get_last_version($pageid)   X-Ref
Alias of wiki_get_current_version

param: int $pageid
return: object

wiki_get_section_page($page, $section)   X-Ref
Get page section

param: int $pageid
param: string $section

wiki_get_page_by_title($swid, $title)   X-Ref
Get a wiki page by page title

param: int $swid, sub wiki id
param: string $title
return: object

wiki_get_version($versionid)   X-Ref
Get a version record by record id

param: int $versionid, the version id
return: object

wiki_get_first_page($subwikid, $module = null)   X-Ref
Get first page of wiki instace

param: int $subwikiid
param: int $module, wiki instance object

wiki_save_section($wikipage, $sectiontitle, $sectioncontent, $userid)   X-Ref
No description

wiki_save_page($wikipage, $newcontent, $userid)   X-Ref
Save page content

param: object $wikipage
param: string $newcontent
param: int $userid

wiki_refresh_cachedcontent($page, $newcontent = null)   X-Ref
No description

wiki_restore_page($wikipage, $version, $context)   X-Ref
Restore a page with specified version.

param: stdClass $wikipage wiki page record
param: stdClass $version wiki page version to restore
param: context_module $context context of wiki module
return: stdClass restored page

wiki_refresh_page_links($page, $links)   X-Ref
No description

wiki_create_page($swid, $title, $format, $userid)   X-Ref
Create a new wiki page, if the page exists, return existing pageid

param: int $swid
param: string $title
param: string $format
param: int $userid

wiki_make_cache_expire($pagename)   X-Ref
No description

wiki_get_wiki_page_version($pageid, $version)   X-Ref
Get a specific version of page

param: int $pageid
param: int $version

wiki_get_wiki_page_versions($pageid, $limitfrom, $limitnum)   X-Ref
Get version list

param: int $pageid
param: int $limitfrom
param: int $limitnum

wiki_count_wiki_page_versions($pageid)   X-Ref
Count the number of page version

param: int $pageid

wiki_get_linked_to_pages($pageid)   X-Ref
Get linked from page

param: int $pageid

wiki_get_linked_from_pages($pageid)   X-Ref
Get linked from page

param: int $pageid

wiki_get_contributions($swid, $userid)   X-Ref
Get pages which user have been edited

param: int $swid
param: int $userid

wiki_get_missing_or_empty_pages($swid)   X-Ref
Get missing or empty pages in wiki

param: int $swid sub wiki id

wiki_get_page_list($swid, $sort = 'title ASC')   X-Ref
Get pages list in wiki

param: int $swid sub wiki id
param: string $sort How to sort the pages. By default, title ASC.

wiki_get_orphaned_pages($swid)   X-Ref
Return a list of orphaned wikis for one specific subwiki

param: int $swid sub wiki id

wiki_search_title($swid, $search)   X-Ref
Search wiki title

param: int $swid sub wiki id
param: string $search

wiki_search_content($swid, $search)   X-Ref
Search wiki content

param: int $swid sub wiki id
param: string $search

wiki_search_all($swid, $search)   X-Ref
Search wiki title and content

param: int $swid sub wiki id
param: string $search

wiki_get_user_info($userid)   X-Ref
Get user data


wiki_increment_pageviews($page)   X-Ref
Increase page view nubmer

param: int $page, database record

wiki_get_formats()   X-Ref
Text format supported by wiki module


wiki_parse_content($markup, $pagecontent, $options = array()   X-Ref
Parses a string with the wiki markup language in $markup.

author: Josep Arús Pous
return: Array or false when something wrong has happened.

wiki_parser_link($link, $options = null)   X-Ref
This function is the parser callback to parse wiki links.

It returns the necesary information to print a link.

NOTE: Empty pages and non-existent pages must be print in red color.

!!!!!! IMPORTANT !!!!!!
It is critical that you call format_string on the content before it is used.

param: string|page_wiki $link name of a page
param: array $options
return: array Array('content' => string, 'url' => string, 'new' => bool, 'link_info' => array)

wiki_parser_table($table)   X-Ref
Returns the table fully parsed (HTML)

author: Josep Arús Pous
return: HTML for the table $table

wiki_parser_real_path($url, $context, $component, $filearea, $swid)   X-Ref
Returns an absolute path link, unless there is no such link.

param: string $url Link's URL or filename
param: stdClass $context filearea params
param: string $component The component the file is associated with
param: string $filearea The filearea the file is stored in
param: int $swid Sub wiki id
return: string URL for files full path

wiki_parser_get_token($markup, $name)   X-Ref
Returns the token used by a wiki language to represent a given tag or "object" (bold -> **)

author: Josep Arús Pous
return: A string when it has only one token at the beginning (f. ex. lists). An array composed by 2 strings when it has 2 tokens, one at the beginning and one at the end (f. ex. italics). Returns false otherwise.

wiki_user_can_view($subwiki, $wiki = null)   X-Ref
Checks if current user can view a subwiki

param: stdClass $subwiki usually record from {wiki_subwikis}. Must contain fields 'wikiid', 'groupid', 'userid'.
param: stdClass $wiki optional wiki object if known
return: bool

wiki_user_can_edit($subwiki)   X-Ref
Checks if current user can edit a subwiki

param: $subwiki

wiki_is_page_section_locked($pageid, $userid, $section = null)   X-Ref
Checks if a page-section is locked.

return: true if the combination of section and page is locked, FALSE otherwise.

wiki_set_lock($pageid, $userid, $section = null, $insert = false)   X-Ref
Inserts or updates a wiki_locks record.


wiki_delete_locks($pageid, $userid = null, $section = null, $delete_from_db = true, $delete_section_and_page = false)   X-Ref
Deletes wiki_locks that are not in use. (F.Ex. after submitting the changes). If no userid is present, it deletes ALL the wiki_locks of a specific page.

param: int $pageid page id.
param: int $userid id of user for which lock is deleted.
param: string $section section to be deleted.
param: bool $delete_from_db deleted from db.
param: bool $delete_section_and_page delete section and page version.

wiki_delete_old_locks()   X-Ref
Deletes wiki_locks that expired 1 hour ago.


wiki_delete_links($linkid = null, $topageid = null, $frompageid = null, $subwikiid = null)   X-Ref
Deletes wiki_links. It can be sepecific link or links attached in subwiki

param: int $linkid id of the link to be deleted
param: int $topageid links to the specific page
param: int $frompageid links from specific page
param: int $subwikiid links to subwiki

wiki_delete_synonym($subwikiid, $pageid = null)   X-Ref
Delete wiki synonyms related to subwikiid or page

param: int $subwikiid id of sunbwiki
param: int $pageid id of page

wiki_delete_pages($context, $pageids = null, $subwikiid = null)   X-Ref
Delete pages and all related data

param: mixed $context context in which page needs to be deleted.
param: mixed $pageids id's of pages to be deleted
param: int $subwikiid id of the subwiki for which all pages should be deleted

wiki_delete_page_versions($deleteversions, $context = null)   X-Ref
Delete specificed versions of a page or versions created by users
if version is 0 then it will remove all versions of the page

param: array $deleteversions delete versions for a page
param: context_module $context module context

wiki_get_comment($commentid)   X-Ref
No description

wiki_get_comments($contextid, $pageid)   X-Ref
Returns all comments by context and pageid

param: int $contextid Current context id
param: int $pageid Current pageid

wiki_add_comment($context, $pageid, $content, $editor)   X-Ref
Add comments ro database

param: object $context. Current context
param: int $pageid. Current pageid
param: string $content. Content of the comment
param: string editor. Version of editor we are using.

wiki_delete_comment($idcomment, $context, $pageid)   X-Ref
Delete comments from database

param: $idcomment. Id of comment which will be deleted
param: $context. Current context
param: $pageid. Current pageid

wiki_delete_comments_wiki()   X-Ref
Delete al comments from wiki


wiki_add_progress($pageid, $oldversionid, $versionid, $progress)   X-Ref
No description

wiki_get_wiki_page_id($pageid, $id)   X-Ref
No description

wiki_print_page_content($page, $context, $subwikiid)   X-Ref
No description

wiki_trim_string($text, $limit = 25)   X-Ref
This function trims any given text and returns it with some dots at the end

param: string $text
param: string $limit
return: string

wiki_print_edit_form_default_fields($format, $pageid, $version = -1, $upload = false, $deleteuploads = array()   X-Ref
Prints default edit form fields and buttons

param: string $format Edit form format (html, creole...)
param: integer $version Version number. A negative number means no versioning.

wiki_print_upload_table($context, $filearea, $fileitemid, $deleteuploads = array()   X-Ref
Prints a table with the files attached to a wiki page

param: object $context
param: string $filearea
param: int $fileitemid
param: array deleteuploads

wiki_build_tree($page, $node, &$keys)   X-Ref
Generate wiki's page tree

param: page_wiki $page. A wiki page object
param: navigation_node $node. Starting navigation_node
param: array $keys. An array to store keys
return: an array with all tree nodes

wiki_get_linked_pages($pageid)   X-Ref
Get linked pages from page

param: int $pageid

wiki_get_updated_pages_by_subwiki($swid)   X-Ref
Get updated pages from wiki

param: int $pageid

wiki_can_create_pages($context, $user = null)   X-Ref
Check if the user can create pages in a certain wiki.

param: context $context Wiki's context.
param: integer|stdClass $user A user id or object. By default (null) checks the permissions of the current user.
return: bool True if user can create pages, false otherwise.

wiki_get_possible_subwiki_by_group($wikiid, $groupid, $userid = 0)   X-Ref
Get a sub wiki instance by wiki id, group id and user id.
If the wiki doesn't exist in DB it will return an isntance with id -1.

param: int $wikiid  Wiki ID.
param: int $groupid Group ID.
param: int $userid  User ID.
return: object      Subwiki instance.

wiki_get_visible_subwikis($wiki, $cm = null, $context = null)   X-Ref
Get all the possible subwikis visible to the user in a wiki.
It will return all the subwikis that can be created in a wiki, even if they don't exist in DB yet.

param: stdClass $wiki          Wiki to get the subwikis from.
param: cm_info|stdClass $cm    Optional. The course module object.
param: context_module $context Optional. Context of wiki module.
return: array                   List of subwikis.

wiki_get_subwiki_by_group_and_user_with_validation($wiki, $groupid, $userid)   X-Ref
Utility function for getting a subwiki by group and user, validating that the user can view it.
If the subwiki doesn't exists in DB yet it'll have id -1.

param: stdClass $wiki The wiki.
param: int $groupid Group ID. 0 means the subwiki doesn't use groups.
param: int $userid User ID. 0 means the subwiki doesn't use users.
return: stdClass Subwiki. If it doesn't exists in DB yet it'll have id -1. If the user can't view the

mod_wiki_get_tagged_pages($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0)   X-Ref
Returns wiki pages tagged with a specified tag.

This is a callback used by the tag area mod_wiki/wiki_pages to search for wiki pages
tagged with a specific tag.

param: core_tag_tag $tag
param: bool $exclusivemode if set to true it means that no other entities tagged with this tag
param: int $fromctx context id where the link was displayed, may be used by callbacks
param: int $ctx context id where to search for records
param: bool $rec search in subcontexts as well
param: int $page 0-based number of page being displayed
return: \core_tag\output\tagindex