MWX/MakePage: Difference between revisions

From Woozle Writes Code
< MWX
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
[[category:MediaWiki extension]]
[[category:MediaWiki extension]]
{{DEFAULTSORT:MakePage}}
==About==
==About==
'''Special:MakePage''' (SMP) is a [[MediaWiki]] SpecialPage which can create a wiki page from a form submission, using a template to turn the form inputs into page title and content. It can also use other environmental conditions such as the username of the submitter and when the form was submitted.  
'''Special:MakePage''' (SMP) is a [[MediaWiki]] SpecialPage which can create a wiki page from a form submission, using a template to turn the form inputs into page title and content. It can also use other environmental conditions such as the username of the submitter and when the form was submitted.  

Latest revision as of 16:57, 18 April 2022


About

Special:MakePage (SMP) is a MediaWiki SpecialPage which can create a wiki page from a form submission, using a template to turn the form inputs into page title and content. It can also use other environmental conditions such as the username of the submitter and when the form was submitted.

  • source: Git repository
  • requires: Ferreteria libraries:
    • W3TPL may be useful for prototyping various views of the created pages (e.g. a listing of blog posts, with synopses)

How to use it

Basic usage, then, involves creating two things:

1. an HTML form which includes certain fields that SMP needs, and which submits its contents to SMP
  • You can create form within a MediaWiki site by any number of means, including w3tpl, but it doesn't have to be on the same site.
  • In theory, you don't even have to have an actual form; you could use code to POST form data from an application.
  • Either way, you have to be logged in as a user with the ability to create new pages wherever the form has been told to create them.
2. a template page that defines how the form data should be formatted in the resulting page

To use it in a MediaWiki installation, save the extension in MediaWiki's extensions folder and include this in LocalSettings.php:

wfLoadExtension( 'MakePage' );

(I think the necessary libraries are now required automatically, but you do need to install Ferreteria and require ferreteria/start.php.)

Example Sites

How it works

SMP receives the input of any form POSTed to it and takes the following actions:

  1. A title is generated according to the value received in !TITLETPLT. Special variables (see below) may be used in this string.
  2. The template specified by !TPLTPAGE (and !TPLTSTART and !TPLTSTOP) is read, and variables are replaced by POSTed values.
  3. MediaWiki is requested to start editing a new page (titled according to #1), and the results of #2 are submitted as the possible contents.
    • By default, the new page is not yet saved; the user needs to do this. This is to give the user a chance to review the results before saving.
    • In the future, I may add an option to create the page immediately. I may also want to give forms the ability to create pages that cannot be edited directly by their creators, but can only be edited via forms. (This may be necessary, for example, in order to allow users to create and edit pages that access protected functions in w3tpl without themselves being able to modify the code that accesses those functions, which would be a significant security hole.)

Special variables

MakePage will look for the following variables in the POST data:

  • !TIMEFMT is the format MakePage will use for setting the ?TIMESTAMP special variable
  • !TITLETPLT is the template for generating the title of the page to be created
  • !TPLTPAGE is the title of the page from on the creation template may be found
  • !TPLTTEXT is the text to use for the template

MakePage will provide a value for the following variables, if used:

  • @TIMESTAMP is the date/time at which the form was submitted, formatted as a string according to !TIMEFMT. It is set by MakePage (i.e. don't set it in the form data).
    • This is useful for time-stamping blog entries.
  • @EDITUSER is the login-name of the user submitting the form

These are being replaced by !TPLTTEXT:

  • !TPLTSTART defines where in the template page to start reading the actual template
    • This is so you can make notes before and after without having the notes included in every page generated. To do: a proper comment syntax that doesn't conflict with HTML comments.
  • !TPLTSTOP defines where in the template page to stop reading the actual template (see !TPLTSTART).

Pages