A wiki in a box - this is a backup read-only mirror of the main Github repository. https://github.com/sbrl/Pepperminty-Wiki/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
7.8 KiB

  1. # Developer Documentation
  2. The core of Pepperminty Wiki exposes several global objects, classes, functions, and miscellaneous files that you can use to write your own modules. This page documents these them so that you can create your own modules more easily.
  3. ## Table of Contents
  4. - [Rest API](#rest-api)
  5. - [Module API](#module-api)
  6. - [Global Variables](#global-variables)
  7. - [Files](#files)
  8. - [`pageindex.json`](#pageindexjson)
  9. - [`idindex.json`](#idindexjson)
  10. - [`invindex.json`](#invindexjson)
  11. - [`recent-changes.json`](#recent-changesjson)
  12. - [`statsindex.json`](#statsindexjson)
  13. ## Rest API
  14. The REST api provided by Pepperminty Wiki itself is documented for bot owners and software developers alike over on GitHub pages [here](https://sbrl.github.io/Pepperminty-Wiki/docs/RestApi/).
  15. ## Module API
  16. The main PHP-based module API is documented with php documentor. The docs can be found [here](https://sbrl.github.io/Pepperminty-Wiki/docs/ModuleApi/), hosted on GitHub Pages.
  17. This documentation covers all the functions and classes available in both the Pepperminty Wiki core, and the modules stored in this repository - as well as mentioning which module they are a part of.
  18. There are one or two additional things that haven't made their way into the module api docs, which are detailed below:
  19. ### `page_renderer::register_part_preprocessor($code)`
  20. This function's use is more complicated to explain. Pepperminty Wiki renders pages with a very simple templating system. For example, in the template a page's content is denoted by `{content}`. A function registered here will be passed all the components of a page _just_ before they are dropped into the template. Note that the function you pass in here should take a *reference* to the components, as the return value of the function passed is discarded. Here's an example:
  21. ```php
  22. <?php
  23. register_module([
  24. "name" => "Content shuffler",
  25. "version" => "0.1",
  26. "author" => "Bob",
  27. "description" => "Shuffles the content of a page randomly.",
  28. "id" => "extra-content-shuffler",
  29. "code" => function() {
  30. page_renderer::register_part_preprocessor(function(&$parts) {
  31. $parts["{body}"] = str_shuffle($parts["{body}"]);
  32. });
  33. }
  34. ]);
  35. ?>
  36. ```
  37. Currently, the following parts are used in the templating process:
  38. Key | Purpose
  39. ----------------------------|------------------
  40. `{body}` | Holds the main body of the page.
  41. `{sitename}` | The name of the current installation of Pepperminty Wiki
  42. `{favicon-url}` | The url of the favicon.
  43. `{header-html}` | The extra HTML that will be added to the `<head />` tag.
  44. `{navigation-bar}` | The navigation bar's HTML.
  45. `{navigation-bar-bottom}` | The bottom navigation bar's HTML.
  46. `{admin-details-name}` | The name of the administrator.
  47. `{admin-details-email}` | The email address of the administrator.
  48. `{admins-name-list}` | The list of moderator's (user)names.
  49. `{generation-date}` | The date at which the page was generated.
  50. `{all-pages-datalist}` | The `<datalist />` tag that powers the search bar.
  51. [Take a look at the code](https://github.com/sbrl/Pepperminty-Wiki/blob/master/core.php#L394) to see the very latest list of parts.
  52. ### `add_parser($code)`
  53. This function adds a parser to Pepperminty Wiki. An example follows below, but please note that this will ~~probably~~ be changing soon so that the parser's name is attached to it when it is registered. This is so that the user can choose which of the registered parsers are used at any one time.
  54. ```php
  55. <?php
  56. register_module([
  57. "name" => "Reverse parser",
  58. "version" => "0.1",
  59. "author" => "Bob",
  60. "description" => "A parser that reverse the page's source.",
  61. "id" => "parser-reverse",
  62. "code" => function() {
  63. add_parser(function($source) {
  64. return strrev($source);
  65. });
  66. }
  67. ]);
  68. ?>
  69. ```
  70. ### Global Variables
  71. There are a number of global variables floating around that can give you a lot of information about the current request. ~~I will be tidying them up into a single `$env` object soon.~~ Most of the below have been tidied up into a single `$env` object now! Below is a table of all the variables Pepperminty Wiki has lying around:
  72. Variable | Description
  73. ------------------------|------------------------------------------
  74. `$env` | An object that contains a _bunch_ of useful information about the current request.
  75. `$env->page` | The current page name.
  76. `$env->is_logged_in` | Whether the current user is currently logged in.
  77. `$env->is_admin` | Whether the current user is an administrator.
  78. `$env->user` | The current user's name. Currently only set if the user is logged in.
  79. `$env->action` | The current action.
  80. `$settings` | The settings object from the top of the file.
  81. `$pageindex` | Contains a list of all the pages that Pepperminty Wiki currently knows about, along with information about each page. Exists to improve performance.
  82. ## Files
  83. Pepperminty Wiki maintains several files (most of which are indexes) containing various information about the current site that you can utilise. Some of them also have an 'API' of sorts that you can use to interact with them - which is documented in the [module api](#module-api) above.
  84. ### `pageindex.json`
  85. This is by _far_ the most important index. It contains an entry for each page, under which a number of interesting pieces of information are stored. It's automatically loaded into the global variable `$pageindex` too, so you don't even have to read it in. Here's an example pageindex:
  86. ```json
  87. {
  88. "Internal link": {
  89. "filename": "Internal link.md",
  90. "size": 120,
  91. "lastmodified": 1446019377,
  92. "lasteditor": "admin",
  93. "tags": [
  94. "testing",
  95. "test tag with spaces",
  96. "really really really really really really long tag"
  97. ]
  98. },
  99. "Main Page": {
  100. "filename": "Main Page.md",
  101. "size": 151,
  102. "lastmodified": 1446388276,
  103. "lasteditor": "admin",
  104. "tags": []
  105. },
  106. "Internal link\/Sub": {
  107. "filename": "Internal link\/Sub.md",
  108. "size": 35,
  109. "lastmodified": 1446370194,
  110. "lasteditor": "admin",
  111. "tags": [
  112. "test"
  113. ]
  114. },
  115. "Files\/AJ Scr.png": {
  116. "filename": "Files\/AJ Scr.png.md",
  117. "size": 29,
  118. "lastmodified": 1445501914,
  119. "lasteditor": "admin",
  120. "uploadedfile": true,
  121. "uploadedfilepath": "Files\/AJ Scr.png",
  122. "uploadedfilemime": "image\/png"
  123. }
  124. }
  125. ```
  126. Currently, Pepperminty Wiki is configured to pretty print the json in the pageindex when saving it to disk, so if you find yourself saving the pageindex please do the same.
  127. Now that alternate data storage directories are supported, the `$entry->filename` will *not* contain the `$env->storage_prefix` prefix. You will need to add this manually if you use it.
  128. ### `idindex.json`
  129. The id index converts page ids into page names and vice versa. It's loaded into the global variable `$idindex`, but you normally wouldn't need to touch that, as there's a seamless API that you can use instead, which can be found under the `ids` class.
  130. ### `invindex.json`
  131. This is the main search index. Obviously, it's only present if the `feature-search` module is loaded and active. It can be interacted with though the `search` class that the `feature-search` module exposes.
  132. ### `recent-changes.json`
  133. This is not loaded automatically, but it contains a list of recent changes that have occurred throughout the wiki. You don't have to fiddle with it directly though if you just want to add a new change, because the `feature-recent-changes` module has a fewe handy methods you can use for that purpose.
  134. ### `statsindex.json`
  135. This file is brand new as of v0.15, and contains the most recently calculated statistics about the wiki. The `feature-stats` module oversees the regeneration of this file. Consult if you need access to such statistics that might be somewhat expensive to calculate.