How do you create a new MediaWiki article with preloaded text based on HTML form input?

770 views Asked by At

I'm creating a private wiki using MediaWiki and have a Special page with HTML added to create a sort of template entry page. When the user submits the input I would like to create a new WikiPage filled out with the input text in a similar format to my template. I have been playing around with Semantic Forms and it does a great job of allowing template/form actions but its still not quite perfect. The wiki requires only two main page templates so I want to just create them myself and make it an incredibly simple user interface for others. Can I do this with only HTML and PHP or do I need some helper JavaScript? How do I save the data from the forms and programmatically generate a new WikiPage with it in PHP? I've done the new WikiPage(...) and tried new Article(...) but I assume I still need to interact with the database.

3

There are 3 answers

0
Tgr On

edit.php can create an article for you and the source code is short and easy to understand.

0
Sophivorus On

Minimal code:

$title = Title::newFromText( 'Desired page title goes here' );
if ( !is_null( $title ) && !$title->isKnown() && $title->canExist() ){
    $page = new WikiPage( $title );
    $content = ContentHandler::makeContent( 'Page content goes here', $title );
    $page->doEditContent( $content, 'Edit summary goes here' );
}
0
Sumit On

You'll need to do new WikiPage() and then doEditContent, you could try looking at this simple code in an extension https://github.com/mkroetzsch/AutoCreatePage/blob/master/AutoCreatePage.php#L123 which automaticaly creates pages, if not created. Documented here https://www.mediawiki.org/wiki/Extension:AutoCreatePage