Difference between revisions of "MediaWiki/extension/Special/MakePage"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(proper method of getting form-target URL)
(→‎Special variables: !TIMESTAMP -> ?TIMESTAMP)
Line 39: Line 39:
 
#* 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.)
 
#* 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==
 
==Special variables==
* '''!TIMEFMT''' is the format to use for the !TIMESTAMP special variable
+
* '''!TIMEFMT''' is the format MakePage will use for setting 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.)
+
* '''?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.
 
* '''!TITLETPLT''' is the template for generating the title of the page to be created
 
* '''!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
 
* '''!TPLTPAGE''' is the title of the page from on the creation template may be found
Line 46: Line 47:
 
** 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.
 
** 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).
 
* '''!TPLTSTOP''' defines where in the template page to stop reading the actual template (see !TPLTSTART).
 +
 +
Note: I changed "!TIMESTAMP" to "?TIMESTAMP" to indicate the fact that it's set in code, not by form data. So "!" means variables whose value (set by form data) has special significance, while "?" indicates variables that are set by MakePage.
  
 
==Inlinks==
 
==Inlinks==
 
* [[/archive]]: old version of code
 
* [[/archive]]: old version of code

Revision as of 12:28, 16 March 2016

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:

  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 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

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

  • !TIMEFMT is the format MakePage will use for setting the ?TIMESTAMP special variable
  • ?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.
  • !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).

Note: I changed "!TIMESTAMP" to "?TIMESTAMP" to indicate the fact that it's set in code, not by form data. So "!" means variables whose value (set by form data) has special significance, while "?" indicates variables that are set by MakePage.

Inlinks