MWX/MakePage: Difference between revisions

From Woozle Writes Code
< MWX
Jump to navigation Jump to search
(some updates)
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''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.
[[category:MediaWiki extension]]
{{DEFAULTSORT:MakePage}}
==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''': [https://gitlab.com/woozalia/Special-MakePage Git repository]
* '''source''': [https://gitlab.com/woozalia/Special-MakePage Git repository]
Line 6: Line 9:
==How to use it==
==How to use it==
Basic usage, then, involves creating two things:
Basic usage, then, involves creating two things:
# an HTML form which includes certain fields that SMP needs, and which submits its contents to SMP
:'''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.
:* 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.
:* 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.
:* 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
:'''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 use it in a MediaWiki installation, save the extension in MediaWiki's <code>extensions</code> folder and include this in <code>LocalSettings.php</code>:
To use it in a MediaWiki installation, save the extension in MediaWiki's <code>extensions</code> folder and include this in <code>LocalSettings.php</code>:
Line 20: Line 19:


(I think the necessary libraries are now required automatically, but you do need to install {{l/ferreteria}} and require <code>ferreteria/start.php</code>.)
(I think the necessary libraries are now required automatically, but you do need to install {{l/ferreteria}} and require <code>ferreteria/start.php</code>.)
To get the target URL ("action={{arg|target URL}}") to use when designing a form, you can use the following code:
<syntaxhighlight lang=php>$mwoMakePage = Title::newFromText('Special:MakePage');
$urlMakePage = $mwoMakePage->getLocalURL();</syntaxhighlight>


==Example Sites==
==Example Sites==
Line 40: Line 35:
#* 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==
MakePage will look for the following variables in the POST data:
* '''!TIMEFMT''' is the format MakePage will use for setting 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. 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
* '''!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
* '''!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.
** 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 rather than coming from form data. So "!" means variables whose value (set by form data) has special significance, while "?" indicates variables that are set by MakePage.
==Pages==
 
* [[/history]]
==Inlinks==
* [[/archive]]: old version of code

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