MWX/MakePage: Difference between revisions
(some actual documentation) |
(proper method of getting form-target URL) |
||
Line 16: | Line 16: | ||
* add instructions for invoking modloader | * add instructions for invoking modloader | ||
To invoke the necessary Ferreteria libraries, include modloader and the following two lines before including SMP:<php> | To invoke the necessary Ferreteria libraries, include modloader and the following two lines before including SMP: | ||
clsLibrary::Load_byName('ferreteria.mw.1'); | <php>clsLibrary::Load_byName('ferreteria.mw.1'); | ||
clsLibrary::Load_byName('ferreteria.db.1');</php> | clsLibrary::Load_byName('ferreteria.db.1');</php> | ||
To get the target URL for your form ("action="), you can use the following code: | |||
<php>$mwoMakePage = Title::newFromText('Special:MakePage'); | |||
$urlMakePage = $mwoMakePage->getLocalURL();</php> | |||
==Example Sites== | ==Example Sites== | ||
* I use it on Issuepedia for [[issuepedia:Issuepedia:Link Filing|filing links]]: | * I use it on Issuepedia for [[issuepedia:Issuepedia:Link Filing|filing links]]: | ||
Line 27: | Line 32: | ||
** MakePage uses [[htwiki:project:Forms/handling/blog/post|this template]] to render the form's output as a page. | ** MakePage uses [[htwiki:project:Forms/handling/blog/post|this template]] to render the form's output as a page. | ||
==How it works== | ==How it works== | ||
SMP receives the input of any form POSTed to it | SMP receives the input of any form POSTed to it and takes the following actions: | ||
# A title is generated according to the value received in !TITLETPLT. Special variables (see below) may be used in this string. | # A title is generated according to the value received in !TITLETPLT. Special variables (see below) may be used in this string. | ||
# The template specified by !TPLTPAGE (and !TPLTSTART and !TPLTSTOP) is read, and variables are replaced by POSTed values. | # The template specified by !TPLTPAGE (and !TPLTSTART and !TPLTSTOP) is read, and variables are replaced by POSTed values. |
Revision as of 00:03, 13 September 2015
Special:MakePage (SMP) is a MediaWiki SpecialPage for creating new wiki pages based on the contents of a form plus other environmental conditions such as the username of the submitter and when the form was submitted. It can be used for creating a simple blog, for example.
- source: GitHub
- 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:
- 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.
- a template page that defines how the form data should be formatted in the resulting page
To do:
- post modloader.php on GitHub.
- add instructions for invoking modloader
To invoke the necessary Ferreteria libraries, include modloader and the following two lines before including SMP: <php>clsLibrary::Load_byName('ferreteria.mw.1'); clsLibrary::Load_byName('ferreteria.db.1');</php>
To get the target URL for your form ("action="), you can use the following code: <php>$mwoMakePage = Title::newFromText('Special:MakePage'); $urlMakePage = $mwoMakePage->getLocalURL();</php>
Example Sites
- I use it on Issuepedia for filing links:
- The entry form is built using w3tpl tags.
- MakePage uses this template to render the form's output as a page.
- I use it on the HypertWiki for blogging:
- The entry form is built using w3tpl tags.
- MakePage uses this template to render the form's output as a page.
How it works
SMP receives the input of any form POSTed to it and takes the following actions:
- A title is generated according to the value received in !TITLETPLT. Special variables (see below) may be used in this string.
- The template specified by !TPLTPAGE (and !TPLTSTART and !TPLTSTOP) is read, and variables are replaced by POSTed values.
- 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
- !TIMEFMT is the format to use for the !TIMESTAMP special variable
- !TIMESTAMP is the date/time at which the form was submitted, formatted as a string according to !TIMEFMT. (This is useful for time-stamping blog entries.)
- !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
- !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).
Inlinks
- /archive: old version of code