User:Algorithm/actionCreate
From Meta, a Wikimedia project coordination wiki
NOTE: This extension has been deprecated in favor of CreateBox. Please use that extension for new installations.
This plugin defines an action=create page for use with the Inputbox extension. Action=create allows Inputbox to check whether a page already exists and displays an error message if it does.
Additionally, this code allows Inputbox to define prefixes for the pages it creates. (I.e., submitting "Page" to an inputbox would result in the creation of "Prefix:Page".)
The code listed here should be installed into Inputbox directly, instead of into LocalSettings.php. Here is a step-by-step procedure:
- Upload the code listed here into
extensions/create.php - Add this line to inputbox.php:
include("extensions/create.php"); - At the line 227 inputbox.php contains
value="edit", replace it withvalue="create".
Modifying Inputbox to allow for prefixes is somewhat more involved. Here is a modified version with the necessary changes.
The complete code for action=create is listed below.
--Algorithm 01:10, 24 February 2006 (UTC)
<?php /* This extension defines a new action for use with the InputBox extension. After installation, modify the InputBox code so that the creation form has action=create instead of action=edit. Optionally, you may also define an extra parameter named "prefix", which will prepend itself to the text input upon submission. Author: Algorithm [http://meta.wikimedia.org/wiki/User:Algorithm] Version 0.1 2/23/06 */ $wgHooks['UnknownAction'][] = 'actionCreate'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'actionCreate', 'author' => 'Algorithm', 'url' => 'http://meta.wikimedia.org/wiki/User:Algorithm/actionCreate', ); /* Define default messages; these can be overwritten by MediaWiki: page content */ $wgCreateMessages = array('create' => "Create", 'createmessage' => "'''ERROR:''' The article you are attempting to create already exists."); function actionCreate($action, $article) { if($action != 'create') return true; global $wgRequest, $wgTitle, $wgOut; if($prefix = $wgRequest->getVal('prefix')) { $title = $wgRequest->getVal('title'); if(strpos($title, $prefix)!==0) $title = $prefix . $title; $title = Title::newFromText( $title ); if(is_null($title)) { $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); $wgOut->errorpage( 'badtitle', 'badtitletext' ); } else if($title->getArticleID() == 0) { acRedirect($title, 'edit'); } else { acRedirect($title, 'create'); } } else if( $wgRequest->getVal('section')=='new' || $article->getID() == 0 ) { acRedirect($article->getTitle(), 'edit'); } else { $text = $wgTitle->getPrefixedText(); $wgOut->setPageTitle( $text ); $wgOut->setHTMLTitle(wfMsg('pagetitle', $text.' - '.acMsg('create'))); $text = "<div align='center'>" . acMsg('createmessage') . "</div>\n<inputbox>\ntype=create\ndefault=" . $text; if($arg = $wgRequest->getVal('preload')) $text .= "\npreload=" . $arg; if($arg = $wgRequest->getVal('editintro')) $text .= "\neditintro=" . $arg; $wgOut->addWikiText( $text . "\n</inputbox>" ); } return false; } function acMsg($key) { $msg = wfMsg($key); if( $msg === "&lt;$key&gt;" ) // NOTE: Replace with wfEmptyMsg when defined { global $wgCreateMessages; return $wgCreateMessages[$key]; } return $msg; } function acRedirect($title, $action) { global $wgRequest, $wgOut; $query = "action={$action}§ion=" . $wgRequest->getVal('section') . "&preload=" . $wgRequest->getVal('preload') . "&editintro=" . $wgRequest->getVal('editintro'); $wgOut->setSquidMaxage( 1200 ); $wgOut->redirect($title->getFullURL( $query ), '301'); } ?>