r31797 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31796‎ | r31797 | r31798 >
Date:16:44, 11 March 2008
Author:yaron
Status:old
Tags:
Comment:
Added support for automatic creation of page title, through new
$page_name_formula and $generated_page_name variables
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -98,7 +98,7 @@
9999 $this->mInputTypeHooks[$input_type] = array($function_name, $default_args);
100100 }
101101
102 - function formHTML($form_def, $form_submitted, $source_is_page, $existing_page_content = null, $page_title = null) {
 102+ function formHTML($form_def, $form_submitted, $source_is_page, $existing_page_content = null, $page_title = null, $page_name_formula = null) {
103103 global $wgRequest, $wgUser, $wgParser;
104104 global $sfgTabIndex; // used to represent the current tab index in the form
105105 global $sfgFieldNum; // used for setting various HTML IDs
@@ -109,6 +109,7 @@
110110 $sfgFieldNum = 1;
111111 $source_page_matches_this_form = false;
112112 $form_page_title = NULL;
 113+ $generated_page_name = $page_name_formula;
113114 // $form_is_partial is true if:
114115 // (a) 'partial' == 1 in the arguments
115116 // (b) 'partial form' is found in the form definition
@@ -138,7 +139,12 @@
139140 // disable all form elements if user doesn't have edit permission -
140141 // two different checks are needed, because editing permissions can be
141142 // set in different ways
142 - $this->mPageTitle = Title::newFromText($page_title);
 143+ // HACK - sometimes we don't know the page name in advance, but we still
 144+ // need to set a title here for testing permissions
 145+ if ($page_title == '')
 146+ $this->mPageTitle = Title::newFromText("Semantic Forms permissions test");
 147+ else
 148+ $this->mPageTitle = Title::newFromText($page_title);
143149 if ($wgUser->isAllowed('edit') && $this->mPageTitle->userCanEdit()) {
144150 $form_is_disabled = false;
145151 $form_text = "";
@@ -624,6 +630,14 @@
625631 $input_name = $query_template_name . '[num][' . $field_name . ']';
626632 else
627633 $input_name = $query_template_name . '[' . $field_name . ']';
 634+
 635+ // if we're creating the page name from a formula based on
 636+ // form values, see if the current input is part of that formula,
 637+ // and if so, substitute in the actual value
 638+ if ($form_submitted && $generated_page_name != '') {
 639+ $true_input_name = str_replace('_', ' ', $input_name);
 640+ $generated_page_name = str_ireplace("<$true_input_name>", $cur_value, $generated_page_name);
 641+ }
628642 // disable this field if either the whole form is disabled, or
629643 // it's a restricted field and user doesn't have sysop privileges
630644 $is_disabled = ($form_is_disabled ||
@@ -1275,7 +1289,7 @@
12761290 if($wgRequest->getCheck('partial'))
12771291 $data_text = $existing_page_content;
12781292 $javascript_text .= $fields_javascript_text;
1279 - return array($form_text, $javascript_text, $data_text, $form_page_title);
 1293+ return array($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name);
12801294 }
12811295
12821296 function formFieldHTML($form_field, $cur_value) {

Status & tagging log