Joeytje50 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358572 )

Change subject: Add more Object-oriented class properties/variables
......................................................................

Add more Object-oriented class properties/variables

Moved a couple more variables to be class variables, to reduce function
headers and to improve readability (this way, you know where to look
when you see, for instance, $this->tif).

Change-Id: I4c9cb64bf0628331d29856dd23099a27eb0b8044
---
M includes/PF_FormPrinter.php
1 file changed, 153 insertions(+), 175 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms 
refs/changes/72/358572/1

diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php
index 8041675..e35cab3 100644
--- a/includes/PF_FormPrinter.php
+++ b/includes/PF_FormPrinter.php
@@ -23,9 +23,14 @@
 
        private $form_is_disabled; // bool
        private $source_matches_form; // bool
-       private $preloaded_free_text= null; // store preloaded free text
+       private $preloaded_free_text = null; // store preloaded free text
        private $free_text_was_included; // bool
        private $wiki_page; // wiki page object, used all throughout this class
+       private $tif; // TemplateInForm object used throughout class
+       private $template; // pageform-template used in this pageform
+       private $existing_page_content; // the current page content to add to
+       private $section; // the section being processed
+       private $placeholderFields; // array for placeholder fields
 
        public function __construct() {
                global $wgPageFormsDisableOutsideServices;
@@ -288,18 +293,18 @@
                return '@insertHTML_' . $str . '@';
        }
 
-       function multipleTemplateStartHTML( $tif ) {
+       function multipleTemplateStartHTML( $this->tif ) {
                $text = '';
                // If placeholder is set, it means we want to insert a
                // multiple template form's HTML into the main form's HTML.
                // So, the HTML will be stored in $text.
                $text .= "\t" . '<div class="multipleTemplateWrapper">' . "\n";
                $text .= "\t" . '<div class="multipleTemplateList"';
-               if ( !is_null( $tif->getMinInstancesAllowed() ) ) {
-                       $text .= " 
minimumInstances=\"{$tif->getMinInstancesAllowed()}\"";
+               if ( !is_null( $this->tif->getMinInstancesAllowed() ) ) {
+                       $text .= " 
minimumInstances=\"{$this->tif->getMinInstancesAllowed()}\"";
                }
-               if ( !is_null( $tif->getMaxInstancesAllowed() ) ) {
-                       $text .= " 
maximumInstances=\"{$tif->getMaxInstancesAllowed()}\"";
+               if ( !is_null( $this->tif->getMaxInstancesAllowed() ) ) {
+                       $text .= " 
maximumInstances=\"{$this->tif->getMaxInstancesAllowed()}\"";
                }
                $text .= ">\n";
                return $text;
@@ -335,22 +340,22 @@
         * Creates the HTML for a single instance of a multiple-instance
         * template.
         */
-       function multipleTemplateInstanceHTML( $template_in_form, &$section ) {
+       function multipleTemplateInstanceHTML() {
                // Add the character "a" onto the instance number of this input
                // in the form, to differentiate the inputs the form starts out
                // with from any inputs added by the Javascript.
-               $section = str_replace( '[num]', 
"[{$template_in_form->getInstanceNum()}a]", $section );
+               $this->section = str_replace( '[num]', 
"[{$this->tif->getInstanceNum()}a]", $this->section );
                // @TODO - this replacement should be
                // case- and spacing-insensitive.
                // Also, keeping the "id=" attribute should not be
                // necessary; but currently it is, for "show on select".
-               $section = preg_replace_callback(
+               $this->section = preg_replace_callback(
                        '/ id="(.*?)"/',
                        function ( $matches ) {
                                $id = htmlspecialchars( $matches[1], ENT_QUOTES 
);
                                return " id=\"$id\" data-origID=\"$id\" ";
                        },
-                       $section
+                       $this->section
                );
 
                $text = "\t\t" . Html::rawElement( 'div',
@@ -360,7 +365,7 @@
                                // wikis before PF 2.0.9.
                                'class' => "multipleTemplateInstance 
multipleTemplate"
                        ),
-                       $this->multipleTemplateInstanceTableHTML( $section )
+                       $this->multipleTemplateInstanceTableHTML( 
$this->section )
                ) . "\n";
 
                return $text;
@@ -370,7 +375,7 @@
         * Creates the end of the HTML for a multiple-instance template -
         * including the sections necessary for adding additional instances.
         */
-       function multipleTemplateEndHTML( $template_in_form, $section ) {
+       function multipleTemplateEndHTML() {
                global $wgPageFormsTabIndex;
 
                $text = "\t\t" . Html::rawElement( 'div',
@@ -378,7 +383,7 @@
                                'class' => "multipleTemplateStarter",
                                'style' => "display: none",
                        ),
-                       $this->multipleTemplateInstanceTableHTML( $section )
+                       $this->multipleTemplateInstanceTableHTML( 
$this->section )
                ) . "\n";
 
                $attributes = array(
@@ -388,7 +393,7 @@
                if ( $this->form_is_disabled ) {
                        $attributes['disabled'] = true;
                }
-               $button = Html::input( null, Sanitizer::decodeCharReferences( 
$template_in_form->getAddButtonText() ), 'button', $attributes );
+               $button = Html::input( null, Sanitizer::decodeCharReferences( 
$this->tif->getAddButtonText() ), 'button', $attributes );
                $text .= <<<END
        </div><!-- multipleTemplateList -->
                <p>$button</p>
@@ -399,10 +404,10 @@
                return $text;
        }
 
-       function tableHTML( $tif, $instanceNum ) {
+       function tableHTML( $instanceNum ) {
                global $wgPageFormsFieldNum;
 
-               $allGridValues = $tif->getGridValues();
+               $allGridValues = $this->tif->getGridValues();
                if ( array_key_exists( $instanceNum, $allGridValues ) ) {
                        $gridValues = $allGridValues[$instanceNum];
                } else {
@@ -410,7 +415,7 @@
                }
 
                $html = '';
-               foreach ( $tif->getFields() as $formField ) {
+               foreach ( $this->tif->getFields() as $formField ) {
                        $fieldName = $formField->template_field->getFieldName();
                        if ( $gridValues == null ) {
                                $curValue = null;
@@ -453,14 +458,14 @@
                return $html;
        }
 
-       function spreadsheetHTML( $tif ) {
+       function spreadsheetHTML() {
                global $wgOut, $wgPageFormsGridValues, $wgPageFormsGridParams;
                global $wgPageFormsScriptPath;
 
                $wgOut->addModules( 'ext.pageforms.jsgrid' );
 
                $gridParams = array();
-               foreach ( $tif->getFields() as $formField ) {
+               foreach ( $this->tif->getFields() as $formField ) {
                        $templateField = $formField->template_field;
 
                        $inputType = $formField->getInputType();
@@ -488,22 +493,22 @@
                        $gridParams[] = $gridParamValues;
                }
 
-               $templateName = $tif->getTemplateName();
+               $templateName = $this->tif->getTemplateName();
                $templateDivID = str_replace( ' ', '', $templateName ) . "Grid";
                $templateDivAttrs = array(
                        'class' => 'pfJSGrid',
                        'id' => $templateDivID,
                        'data-template-name' => $templateName
                );
-               if ( $tif->getHeight() != null ) {
-                       $templateDivAttrs['height'] = $tif->getHeight();
+               if ( $this->tif->getHeight() != null ) {
+                       $templateDivAttrs['height'] = $this->tif->getHeight();
                }
 
                $loadingImage = Html::element( 'img', array( 'src' => 
"$wgPageFormsScriptPath/skins/loading.gif" ) );
                $text = Html::rawElement( 'div', $templateDivAttrs, 
$loadingImage );
 
                $wgPageFormsGridParams[$templateName] = $gridParams;
-               $wgPageFormsGridValues[$templateName] = $tif->getGridValues();
+               $wgPageFormsGridValues[$templateName] = 
$this->tif->getGridValues();
 
                return $text;
        }
@@ -650,21 +655,21 @@
        }
 
        // Function to handle {{{for template}}} tags
-       private function tagForTemplate(&$tif, &$template, 
&$existing_page_content, $tag_components, $template_name, $source_is_page) {
+       private function tagForTemplate($tag_components, $template_name, 
$source_is_page) {
                // first, obtain if the form is partially submitted again:
                global $wgRequest;
                $partial_form_submitted = $wgRequest->getCheck( 'partial' );
 
-               if ( $tif ) {
-                       $previous_template_name = $tif->getTemplateName();
+               if ( $this->tif ) {
+                       $previous_template_name = $this->tif->getTemplateName();
                } else {
                        $previous_template_name = '';
                }
                $template_name = str_replace( '_', ' ', $tag_components[1] );
                $is_new_template = ( $template_name != $previous_template_name 
);
                if ( $is_new_template ) {
-                       $template = PFTemplate::newFromName( $template_name );
-                       $tif = PFTemplateInForm::newFromFormTag( 
$tag_components );
+                       $this->template = PFTemplate::newFromName( 
$template_name );
+                       $this->tif = PFTemplateInForm::newFromFormTag( 
$tag_components );
                }
                // If we are editing a page, and this
                // template can be found more than
@@ -672,25 +677,25 @@
                // values are allowed, repeat this
                // section.
                if ( $source_is_page || $partial_form_submitted ) {
-                       $tif->setPageRelatedInfo( $existing_page_content );
+                       $this->tif->setPageRelatedInfo( 
$this->existing_page_content );
                        // Get the first instance of
                        // this template on the page
                        // being edited, even if there
                        // are more.
-                       if ( $tif->pageCallsThisTemplate() ) {
-                               $tif->setFieldValuesFromPage( 
$existing_page_content );
-                               $existing_template_text = 
$tif->getFullTextInPage();
+                       if ( $this->tif->pageCallsThisTemplate() ) {
+                               $this->tif->setFieldValuesFromPage( 
$this->existing_page_content );
+                               $existing_template_text = 
$this->tif->getFullTextInPage();
                                // Now remove this template from the text being 
edited.
                                // If this is a partial form, establish a new 
insertion point.
-                               if ( $existing_page_content && 
$partial_form_submitted ) {
+                               if ( $this->existing_page_content && 
$partial_form_submitted ) {
                                        // If something already exists, set the 
new insertion point
                                        // to its position; otherwise just let 
it lie.
-                                       if ( strpos( $existing_page_content, 
$existing_template_text ) !== false ) {
-                                               $existing_page_content = 
str_replace( "\n" . '{{{insertionpoint}}}', '', $existing_page_content );
-                                               $existing_page_content = 
str_replace( $existing_template_text, '{{{insertionpoint}}}', 
$existing_page_content );
+                                       if ( strpos( 
$this->existing_page_content, $existing_template_text ) !== false ) {
+                                               $this->existing_page_content = 
str_replace( "\n" . '{{{insertionpoint}}}', '', $this->existing_page_content );
+                                               $this->existing_page_content = 
str_replace( $existing_template_text, '{{{insertionpoint}}}', 
$this->existing_page_content );
                                        }
                                } else {
-                                       $existing_page_content = 
$this->strReplaceFirst( $existing_template_text, '', $existing_page_content );
+                                       $this->existing_page_content = 
$this->strReplaceFirst( $existing_template_text, '', 
$this->existing_page_content );
                                }
                                // If we've found a match in the source
                                // page, there's a good chance that this
@@ -702,29 +707,16 @@
        }
 
        // Function to handle {{{field}}} tags
-       // @return the value to add to the $placeholderFields array
-       private function tagField(
-               &$tif,
-               &$template,
-               &$existing_page_content,
-               &$section,
-               $tag_components,
-               $template_name,
-               $source_is_page,
-               $form_submitted,
-               $brackets_loc,
-               $brackets_end_loc
-       ) {
+       private function tagField($tag_components, $template_name, 
$source_is_page, $form_submitted, $brackets_loc, $brackets_end_loc) {
                global $wgPageFormsTabIndex; // used to represent the current 
tab index in the form
                global $wgPageFormsFieldNum; // used for setting various HTML 
IDs
-               $placeholdFieldText = null;
 
                // If the template is null, that (hopefully)
                // means we're handling the free text field.
                // Make the template a dummy variable.
-               if ( $tif == null ) {
-                       $template = new PFTemplate( null, array() );
-                       $tif = new PFTemplateInForm();
+               if ( $this->tif == null ) {
+                       $this->template = new PFTemplate( null, array() );
+                       $this->tif = new PFTemplateInForm();
                }
                // We get the field name both here
                // and in the PFFormField constructor,
@@ -732,30 +724,30 @@
                // to deal with the #freetext# hack,
                // among others.
                $field_name = trim( $tag_components[1] );
-               $form_field = PFFormField::newFromFormFieldTag( 
$tag_components, $template, $tif, $this->form_is_disabled );
+               $form_field = PFFormField::newFromFormFieldTag( 
$tag_components, $this->template, $this->tif, $this->form_is_disabled );
                // For special displays, add in the
                // form fields, so we know the data
                // structure.
-               if ( ( $tif->getDisplay() == 'table' && ( 
!$tif->allowsMultiple() || $tif->getInstanceNum() == 0 ) ) ||
-                       ( $tif->getDisplay() == 'spreadsheet' && 
$tif->allowsMultiple() && $tif->getInstanceNum() == 0 ) ) {
-                       $tif->addField( $form_field );
+               if ( ( $this->tif->getDisplay() == 'table' && ( 
!$this->tif->allowsMultiple() || $this->tif->getInstanceNum() == 0 ) ) ||
+                       ( $this->tif->getDisplay() == 'spreadsheet' && 
$this->tif->allowsMultiple() && $this->tif->getInstanceNum() == 0 ) ) {
+                       $this->tif->addField( $form_field );
                }
-               $cur_value = $form_field->getCurrentValue( 
$tif->getValuesFromSubmit(), $form_submitted, $source_is_page, 
$tif->allInstancesPrinted() );
+               $cur_value = $form_field->getCurrentValue( 
$this->tif->getValuesFromSubmit(), $form_submitted, $source_is_page, 
$this->tif->allInstancesPrinted() );
                if ( $form_field->holdsTemplate() ) {
-                       $placeholdFieldText = self::placeholderFormat( 
$tif->getTemplateName(), $field_name );
+                       $this->placeholderFields[] = self::placeholderFormat( 
$this->tif->getTemplateName(), $field_name );
                }
 
                // If the user is editing a page, and that page contains a call 
to
                // the template being processed, get the current field's value
                // from the template call
-               if ( $source_is_page && ( $tif->getFullTextInPage() != '' && 
!$form_submitted ) ) {
-                       if ( $tif->hasValueFromPageForField( $field_name ) ) {
+               if ( $source_is_page && ( $this->tif->getFullTextInPage() != '' 
&& !$form_submitted ) ) {
+                       if ( $this->tif->hasValueFromPageForField( $field_name 
) ) {
                                // Get value, and remove it,
                                // so that at the end we
                                // can have a list of all
                                // the fields that weren't
                                // handled by the form.
-                               $cur_value = 
$tif->getAndRemoveValueFromPageForField( $field_name );
+                               $cur_value = 
$this->tif->getAndRemoveValueFromPageForField( $field_name );
 
                                // If the field is a placeholder, the contents 
of this template
                                // parameter should be treated as elements 
parsed by an another
@@ -763,7 +755,7 @@
                                // By putting that at the very end of the 
parsed string, we'll
                                // have it processed as a regular multiple 
template form.
                                if ( $form_field->holdsTemplate() ) {
-                                       $existing_page_content .= $cur_value;
+                                       $this->existing_page_content .= 
$cur_value;
                                }
                        } elseif ( isset( $cur_value ) && !empty( $cur_value ) 
) {
                                // Do nothing.
@@ -808,8 +800,8 @@
                        $this->wiki_page->addFreeTextSection();
                }
 
-               if ( $tif->getTemplateName() === '' || $field_name == 
'#freetext#' ) {
-                       $section = substr_replace( $section, $new_text, 
$brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+               if ( $this->tif->getTemplateName() === '' || $field_name == 
'#freetext#' ) {
+                       $this->section = substr_replace( $this->section, 
$new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
                } else {
                        if ( is_array( $cur_value ) ) {
                                // @TODO - is this code ever called?
@@ -923,22 +915,22 @@
                        // (Ideally it wouldn't get
                        // set at all, but that seems a
                        // little harder.)
-                       if ( $tif->allInstancesPrinted() && 
$form_field->getDefaultValue() == null ) {
+                       if ( $this->tif->allInstancesPrinted() && 
$form_field->getDefaultValue() == null ) {
                                $cur_value = null;
                        }
 
                        $new_text = $this->formFieldHTML( $form_field, 
$cur_value );
-                       $new_text .= $form_field->additionalHTMLForInput( 
$cur_value, $field_name, $tif->getTemplateName() );
+                       $new_text .= $form_field->additionalHTMLForInput( 
$cur_value, $field_name, $this->tif->getTemplateName() );
 
                        if ( $new_text ) {
-                               $this->wiki_page->addTemplateParam( 
$template_name, $tif->getInstanceNum(), $field_name, $cur_value_in_template );
-                               $section = substr_replace( $section, $new_text, 
$brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                               $this->wiki_page->addTemplateParam( 
$template_name, $this->tif->getInstanceNum(), $field_name, 
$cur_value_in_template );
+                               $this->section = substr_replace( 
$this->section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc 
);
                        } else {
                                $start_position = $brackets_end_loc;
                        }
                }
 
-               if ( $tif->allowsMultiple() && !$tif->allInstancesPrinted() ) {
+               if ( $this->tif->allowsMultiple() && 
!$this->tif->allInstancesPrinted() ) {
                        $wordForYes = PFUtils::getWordForYesOrNo( true );
                        if ( $form_field->getInputType() == 'checkbox' ) {
                                if ( strtolower( $cur_value ) == strtolower( 
$wordForYes ) || strtolower( $cur_value ) == 'yes' || $cur_value == '1' ) {
@@ -949,14 +941,13 @@
                        }
                }
 
-               if ( $tif->getDisplay() != null && ( !$tif->allowsMultiple() || 
!$tif->allInstancesPrinted() ) ) {
-                       $tif->addGridValue( $field_name, $cur_value );
+               if ( $this->tif->getDisplay() != null && ( 
!$this->tif->allowsMultiple() || !$this->tif->allInstancesPrinted() ) ) {
+                       $this->tif->addGridValue( $field_name, $cur_value );
                }
-               return $placeholdFieldText;
        }
 
        // function to handle the {{{section}}} tag
-       private function tagSection(&$section, &$existing_page_content, 
$tag_components, $source_is_page, $brackets_loc, $brackets_end_loc) {
+       private function tagSection($tag_components, $source_is_page, 
$brackets_loc, $brackets_end_loc) {
                global $wgRequest;
                $section_name = trim( $tag_components[1] );
                $page_section_in_form = PFPageSection::newFromFormTag( 
$tag_components );
@@ -965,12 +956,12 @@
                // Split the existing page contents into the textareas in the 
form.
                $default_value = "";
                $section_start_loc = 0;
-               if ( $source_is_page && $existing_page_content !== null ) {
+               if ( $source_is_page && $this->existing_page_content !== null ) 
{
                        // For the last section of the page, there is no 
trailing newline in
-                       // $existing_page_content, but the code below expects 
it. This code
+                       // $this->existing_page_content, but the code below 
expects it. This code
                        // ensures that there is always trailing newline. T72202
-                       if ( substr( $existing_page_content, -1 ) !== "\n" ) {
-                               $existing_page_content .= "\n";
+                       if ( substr( $this->existing_page_content, -1 ) !== 
"\n" ) {
+                               $this->existing_page_content .= "\n";
                        }
 
                        $equalsSigns = str_pad( '', 
$page_section_in_form->getSectionLevel(), '=' );
@@ -982,37 +973,37 @@
                                '[ ]*?' .
                                preg_quote( $equalsSigns, '/' ) .
                                '$/m';
-                       if ( preg_match( $searchStr, $existing_page_content, 
$matches, PREG_OFFSET_CAPTURE ) ) {
+                       if ( preg_match( $searchStr, 
$this->existing_page_content, $matches, PREG_OFFSET_CAPTURE ) ) {
                                $section_start_loc = $matches[0][1];
                                $header_text = $matches[0][0];
-                               $existing_page_content = str_replace( 
$header_text, '', $existing_page_content );
+                               $this->existing_page_content = str_replace( 
$header_text, '', $this->existing_page_content );
                        } else {
                                $section_start_loc = 0;
                        }
                        $section_end_loc = -1;
 
                        // get the position of the next template or section 
defined in the form
-                       $next_section_start_loc = strpos( $section, '{{{', 
$brackets_end_loc );
+                       $next_section_start_loc = strpos( $this->section, 
'{{{', $brackets_end_loc );
                        if ( $next_section_start_loc == false ) {
-                               $section_end_loc = strpos( 
$existing_page_content, '{{', $section_start_loc );
+                               $section_end_loc = strpos( 
$this->existing_page_content, '{{', $section_start_loc );
                        } else {
-                               $next_section_end_loc = strpos( $section, 
'}}}', $next_section_start_loc );
-                               $bracketed_string_next_section = substr( 
$section, $next_section_start_loc + 3, $next_section_end_loc - ( 
$next_section_start_loc + 3 ) );
+                               $next_section_end_loc = strpos( $this->section, 
'}}}', $next_section_start_loc );
+                               $bracketed_string_next_section = substr( 
$this->section, $next_section_start_loc + 3, $next_section_end_loc - ( 
$next_section_start_loc + 3 ) );
                                $tag_components_next_section = 
PFUtils::getFormTagComponents( $bracketed_string_next_section );
                                $tag_title_next_section = trim( 
$tag_components_next_section[0] );
                                if ( $tag_title_next_section == 'section' ) {
-                                       if ( preg_match( '/(^={1,6}[ ]*?' . 
$tag_components_next_section[1] . '[ ]*?={1,6}\s*?$)/m', 
$existing_page_content, $matches, PREG_OFFSET_CAPTURE ) ) {
+                                       if ( preg_match( '/(^={1,6}[ ]*?' . 
$tag_components_next_section[1] . '[ ]*?={1,6}\s*?$)/m', 
$this->existing_page_content, $matches, PREG_OFFSET_CAPTURE ) ) {
                                                $section_end_loc = 
$matches[0][1];
                                        }
                                }
                        }
 
                        if ( $section_end_loc === -1 ) {
-                               $section_text = $existing_page_content;
-                               $existing_page_content = '';
+                               $section_text = $this->existing_page_content;
+                               $this->existing_page_content = '';
                        } else {
-                               $section_text = substr( $existing_page_content, 
$section_start_loc, $section_end_loc - $section_start_loc );
-                               $existing_page_content = substr( 
$existing_page_content, $section_end_loc );
+                               $section_text = substr( 
$this->existing_page_content, $section_start_loc, $section_end_loc - 
$section_start_loc );
+                               $this->existing_page_content = substr( 
$this->existing_page_content, $section_end_loc );
                        }
                }
 
@@ -1041,7 +1032,7 @@
                        $form_section_text = $sectionInput->getHtmlText();
                }
 
-               $section = substr_replace( $section, $form_section_text, 
$brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+               $this->section = substr_replace( $this->section, 
$form_section_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
        }
 
        // Separate function to handle form tags
@@ -1050,7 +1041,7 @@
                $form_def,
                $form_submitted,
                $form_id,
-               $existing_page_content,
+               $this->existing_page_content,
                $form_text,
                $is_query,
                $source_is_page
@@ -1080,8 +1071,8 @@
                        $tag_title = trim( $tag_components[0] );
                        if ( $tag_title == 'for template' || $tag_title == 'end 
template' ) {
                                // Create a section for everything up to here
-                               $section = substr( $form_def, $section_start, 
$brackets_loc - $section_start );
-                               $form_def_sections[] = $section;
+                               $this->section = substr( $form_def, 
$section_start, $brackets_loc - $section_start );
+                               $form_def_sections[] = $this->section;
                                $section_start = $brackets_loc;
                        }
                        $start_position = $brackets_loc + 1;
@@ -1093,20 +1084,20 @@
                // declarations and replacing them with form elements, either
                // blank or pre-populated, as appropriate.
                $template_name = null;
-               $template = null;
-               $tif = null;
+               $this->template = null;
+               $this->tif = null;
                // This array will keep track of all the replaced @<name>@ 
strings
-               $placeholderFields = array();
+               $this->placeholderFields = array();
 
                for ( $section_num = 0; $section_num < count( 
$form_def_sections ); $section_num++ ) {
                        $start_position = 0;
                        // the append is there to ensure that the original
                        // array doesn't get modified; is it necessary?
-                       $section = " " . $form_def_sections[$section_num];
+                       $this->section = " " . $form_def_sections[$section_num];
 
-                       while ( $brackets_loc = strpos( $section, '{{{', 
$start_position ) ) {
-                               $brackets_end_loc = strpos( $section, "}}}", 
$brackets_loc );
-                               $bracketed_string = substr( $section, 
$brackets_loc + 3, $brackets_end_loc - ( $brackets_loc + 3 ) );
+                       while ( $brackets_loc = strpos( $this->section, '{{{', 
$start_position ) ) {
+                               $brackets_end_loc = strpos( $this->section, 
"}}}", $brackets_loc );
+                               $bracketed_string = substr( $this->section, 
$brackets_loc + 3, $brackets_end_loc - ( $brackets_loc + 3 ) );
                                $tag_components = 
PFUtils::getFormTagComponents( $bracketed_string );
                                $tag_title = trim( $tag_components[0] );
                                // 
=====================================================
@@ -1114,22 +1105,22 @@
                                // 
=====================================================
                                if ( $tag_title == 'for template' ) {
                                        // Remove template tag.
-                                       $section = substr_replace( $section, 
'', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $this->section = substr_replace( 
$this->section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
 
                                        // Delegate main handling of this 
template to tag-handler function
-                                       $this->tagForTemplate($tif, $template, 
$existing_page_content, $tag_components, $template_name, $source_is_page, 
$partial_form_submitted);
+                                       $this->tagForTemplate($tag_components, 
$template_name, $source_is_page, $partial_form_submitted);
 
                                        // We get values from the request,
                                        // regardless of whether the the source
                                        // is the page or a form submit, because
                                        // even if the source is a page, values
                                        // can still come from a query string.
-                                       $tif->setFieldValuesFromSubmit();
+                                       $this->tif->setFieldValuesFromSubmit();
 
-                                       $tif->checkIfAllInstancesPrinted( 
$form_submitted, $source_is_page );
+                                       $this->tif->checkIfAllInstancesPrinted( 
$form_submitted, $source_is_page );
 
-                                       if ( !$tif->allInstancesPrinted() ) {
-                                               $this->wiki_page->addTemplate( 
$tif );
+                                       if ( !$this->tif->allInstancesPrinted() 
) {
+                                               $this->wiki_page->addTemplate( 
$this->tif );
                                        }
 
                                // 
=====================================================
@@ -1139,31 +1130,18 @@
                                        if ( $source_is_page ) {
                                                // Add any unhandled template 
fields
                                                // in the page as hidden 
variables.
-                                               $form_text .= 
PFFormUtils::unhandledFieldsHTML( $tif );
+                                               $form_text .= 
PFFormUtils::unhandledFieldsHTML( $this->tif );
                                        }
-                                       // Remove this tag from the $section 
variable.
-                                       $section = substr_replace( $section, 
'', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
-                                       $template = null;
-                                       $tif = null;
+                                       // Remove this tag from the 
$this->section variable.
+                                       $this->section = substr_replace( 
$this->section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $this->template = null;
+                                       $this->tif = null;
                                // 
=====================================================
                                // field processing
                                // 
=====================================================
                                } elseif ( $tag_title == 'field' ) {
                                        // Delegate handling of this tag to 
tag-handler function, to keep this function more organised
-                                       $placeholdFieldText = $this->tagField(
-                                               $tif,
-                                               $template,
-                                               $existing_page_content,
-                                               $section,
-                                               $tag_components,
-                                               $template_name,
-                                               $source_is_page,
-                                               $form_submitted,
-                                               $brackets_loc,
-                                               $brackets_end_loc
-                                       );
-                                       if ($placeholdFieldText != null)
-                                               $placeholderFields[] = 
$placeholdFieldText;
+                                       $this->tagField($tag_components, 
$template_name, $source_is_page, $form_submitted, $brackets_loc, 
$brackets_end_loc);
 
                                // 
=====================================================
                                // standard input processing
@@ -1177,7 +1155,7 @@
                                        // if it's a query, ignore all standard 
inputs except run query
                                        if ( ( $is_query && $input_name != 'run 
query' ) || ( !$is_query && $input_name == 'run query' ) ) {
                                                $new_text = "";
-                                               $section = substr_replace( 
$section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                               $this->section = 
substr_replace( $this->section, $new_text, $brackets_loc, $brackets_end_loc + 3 
- $brackets_loc );
                                                continue;
                                        }
                                        // set a flag so that the standard 
'form bottom' won't get displayed
@@ -1237,7 +1215,7 @@
                                                        $new_text = 
PFFormUtils::runQueryButtonHTML( $this->form_is_disabled, $input_label, $attr );
                                                        break;
                                        }
-                                       $section = substr_replace( $section, 
$new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $this->section = substr_replace( 
$this->section, $new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc 
);
                                // 
=====================================================
                                // for section processing
                                // 
=====================================================
@@ -1245,7 +1223,7 @@
                                        $wgPageFormsFieldNum++;
                                        $wgPageFormsTabIndex++;
 
-                                       $this->tagSection($section, 
$existing_page_content, $tag_components, $source_is_page, $brackets_loc, 
$brackets_end_loc);
+                                       $this->tagSection($tag_components, 
$source_is_page, $brackets_loc, $brackets_end_loc);
                                // 
=====================================================
                                // page info processing
                                // 
=====================================================
@@ -1288,68 +1266,68 @@
                                                        
$wgPageFormsRunQueryFormAtTop = true;
                                                }
                                        }
-                                       $section = substr_replace( $section, 
'', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $this->section = substr_replace( 
$this->section, '', $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
                                // 
=====================================================
                                // default outer level processing
                                // 
=====================================================
                                } else { // Tag is not one of the allowed 
values -
                                        // ignore it, other than to HTML-escape 
it.
-                                       $form_section_text = htmlspecialchars( 
substr( $section, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc ) );
-                                       $section = substr_replace( $section, 
$form_section_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $form_section_text = htmlspecialchars( 
substr( $this->section, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc ) 
);
+                                       $this->section = substr_replace( 
$this->section, $form_section_text, $brackets_loc, $brackets_end_loc + 3 - 
$brackets_loc );
                                        $start_position = $brackets_end_loc;
                                } // end if
                        } // end while
 
-                       if ( $tif && ( !$tif->allowsMultiple() || 
$tif->allInstancesPrinted() ) ) {
-                               $template_text = 
$this->wiki_page->createTemplateCallsForTemplateName( $tif->getTemplateName() );
+                       if ( $this->tif && ( !$this->tif->allowsMultiple() || 
$this->tif->allInstancesPrinted() ) ) {
+                               $template_text = 
$this->wiki_page->createTemplateCallsForTemplateName( 
$this->tif->getTemplateName() );
                                // If there is a placeholder in the text, we
                                // know that we are doing a replace.
-                               if ( $existing_page_content && strpos( 
$existing_page_content, '{{{insertionpoint}}}', 0 ) !== false ) {
-                                       $existing_page_content = preg_replace( 
'/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
+                               if ( $this->existing_page_content && strpos( 
$this->existing_page_content, '{{{insertionpoint}}}', 0 ) !== false ) {
+                                       $this->existing_page_content = 
preg_replace( '/\{\{\{insertionpoint\}\}\}(\r?\n?)/',
                                                preg_replace( '/\}\}/m', '}�',
                                                        preg_replace( 
'/\{\{/m', '�{', $template_text ) ) .
                                                "{{{insertionpoint}}}",
-                                               $existing_page_content );
+                                               $this->existing_page_content );
                                // Otherwise, if it's a partial form, we have 
to add the new
                                // text somewhere.
                                } elseif ( $partial_form_submitted ) {
-                                       $existing_page_content = preg_replace( 
'/\}\}/m', '}�',
+                                       $this->existing_page_content = 
preg_replace( '/\}\}/m', '}�',
                                                preg_replace( '/\{\{/m', '�{', 
$template_text ) ) .
-                                                       "{{{insertionpoint}}}" 
. $existing_page_content;
+                                                       "{{{insertionpoint}}}" 
. $this->existing_page_content;
                                }
                        }
 
                        $multipleTemplateHTML = '';
-                       if ( $tif && $tif->getLabel() != null ) {
-                               $fieldsetStartHTML = "<fieldset>\n" . 
Html::element( 'legend', null, $tif->getLabel() ) . "\n";
-                               if ( !$tif->allowsMultiple() ) {
+                       if ( $this->tif && $this->tif->getLabel() != null ) {
+                               $fieldsetStartHTML = "<fieldset>\n" . 
Html::element( 'legend', null, $this->tif->getLabel() ) . "\n";
+                               if ( !$this->tif->allowsMultiple() ) {
                                        $form_text .= $fieldsetStartHTML;
-                               } elseif ( $tif->allowsMultiple() && 
$tif->getInstanceNum() == 0 ) {
+                               } elseif ( $this->tif->allowsMultiple() && 
$this->tif->getInstanceNum() == 0 ) {
                                        $multipleTemplateHTML .= 
$fieldsetStartHTML;
                                }
                        }
-                       if ( $tif && $tif->allowsMultiple() ) {
-                               if ( $tif->getDisplay() == 'spreadsheet' ) {
-                                       if ( $tif->allInstancesPrinted() ) {
-                                               $multipleTemplateHTML .= 
$this->spreadsheetHTML( $tif );
+                       if ( $this->tif && $this->tif->allowsMultiple() ) {
+                               if ( $this->tif->getDisplay() == 'spreadsheet' 
) {
+                                       if ( $this->tif->allInstancesPrinted() 
) {
+                                               $multipleTemplateHTML .= 
$this->spreadsheetHTML();
                                                // For spreadsheets, this needs
                                                // to be specially inserted.
                                                $multipleTemplateHTML .= 
"</fieldset>\n";
                                        }
                                } else {
-                                       if ( $tif->getDisplay() == 'table' ) {
-                                               $section = $this->tableHTML( 
$tif, $tif->getInstanceNum() );
+                                       if ( $this->tif->getDisplay() == 
'table' ) {
+                                               $this->section = 
$this->tableHTML( $this->tif->getInstanceNum() );
                                        }
-                                       if ( $tif->getInstanceNum() == 0 ) {
-                                               $multipleTemplateHTML .= 
$this->multipleTemplateStartHTML( $tif );
+                                       if ( $this->tif->getInstanceNum() == 0 
) {
+                                               $multipleTemplateHTML .= 
$this->multipleTemplateStartHTML( $this->tif );
                                        }
-                                       if ( ! $tif->allInstancesPrinted() ) {
-                                               $multipleTemplateHTML .= 
$this->multipleTemplateInstanceHTML( $tif, $section );
+                                       if ( ! 
$this->tif->allInstancesPrinted() ) {
+                                               $multipleTemplateHTML .= 
$this->multipleTemplateInstanceHTML();
                                        } else {
-                                               $multipleTemplateHTML .= 
$this->multipleTemplateEndHTML( $tif, $section );
+                                               $multipleTemplateHTML .= 
$this->multipleTemplateEndHTML();
                                        }
                                }
-                               $placeholder = $tif->getPlaceholder();
+                               $placeholder = $this->tif->getPlaceholder();
                                if ( $placeholder == null ) {
                                        // The normal process.
                                        $form_text .= $multipleTemplateHTML;
@@ -1372,24 +1350,24 @@
                                        $multipleTemplateHTML .= 
self::makePlaceholderInFormHTML( $placeholder );
                                        $form_text = str_replace( 
self::makePlaceholderInFormHTML( $placeholder ), $multipleTemplateHTML, 
$form_text );
                                }
-                               if ( ! $tif->allInstancesPrinted() ) {
+                               if ( ! $this->tif->allInstancesPrinted() ) {
                                        // This will cause the section to be
                                        // re-parsed on the next go.
                                        $section_num--;
-                                       $tif->incrementInstanceNum();
+                                       $this->tif->incrementInstanceNum();
                                }
-                       } elseif ( $tif && $tif->getDisplay() == 'table' ) {
-                               $form_text .= $this->tableHTML( $tif, 0 );
-                       } elseif ( $tif && !$tif->allowsMultiple() && 
$tif->getLabel() != null ) {
-                               $form_text .= $section . "\n</fieldset>";
+                       } elseif ( $this->tif && $this->tif->getDisplay() == 
'table' ) {
+                               $form_text .= $this->tableHTML( 0 );
+                       } elseif ( $this->tif && !$this->tif->allowsMultiple() 
&& $this->tif->getLabel() != null ) {
+                               $form_text .= $this->section . "\n</fieldset>";
                        } else {
-                               $form_text .= $section;
+                               $form_text .= $this->section;
                        }
                } // end for
                // Cleanup - everything has been browsed.
                // Remove all the remaining placeholder
                // tags in the HTML and wiki-text.
-               foreach ( $placeholderFields as $stringToReplace ) {
+               foreach ( $this->placeholderFields as $stringToReplace ) {
                        // Remove the @<insertHTML>@ tags from the generated
                        // HTML form.
                        $form_text = str_replace( 
self::makePlaceholderInFormHTML( $stringToReplace ), '', $form_text );
@@ -1423,7 +1401,7 @@
                $form_submitted,
                $source_is_page,
                $form_id = null,
-               $existing_page_content = null,
+               $this->existing_page_content = null,
                $page_name = null,
                $page_name_formula = null,
                $is_query = false,
@@ -1458,12 +1436,12 @@
                // update check. For now, we pass it through a hidden text 
field.
 
                if ( ! $partial_form_submitted ) {
-                       $original_page_content = $existing_page_content;
+                       $original_page_content = $this->existing_page_content;
                } else {
                        $original_page_content = null;
                        if ( $wgRequest->getCheck( 'pf_free_text' ) ) {
-                               if ( !isset( $existing_page_content ) || 
$existing_page_content == '' ) {
-                                       $existing_page_content = 
$wgRequest->getVal( 'pf_free_text' );
+                               if ( !isset( $this->existing_page_content ) || 
$this->existing_page_content == '' ) {
+                                       $this->existing_page_content = 
$wgRequest->getVal( 'pf_free_text' );
                                }
                                $form_is_partial = true;
                        }
@@ -1554,7 +1532,7 @@
                        $form_def,
                        $form_submitted,
                        $form_id,
-                       $existing_page_content,
+                       $this->existing_page_content,
                        $form_text,
                        $is_query,
                        $source_is_page
@@ -1568,17 +1546,17 @@
                                $free_text = $original_page_content;
                        } else {
                                $free_text = null;
-                               $existing_page_content = preg_replace( array( 
'/�\{/m', '/\}�/m' ),
+                               $this->existing_page_content = preg_replace( 
array( '/�\{/m', '/\}�/m' ),
                                        array( '{{', '}}' ),
-                                       $existing_page_content );
-                               $existing_page_content = str_replace( 
'{{{insertionpoint}}}', '', $existing_page_content );
+                                       $this->existing_page_content );
+                               $this->existing_page_content = str_replace( 
'{{{insertionpoint}}}', '', $this->existing_page_content );
                        }
                        $form_text .= Html::hidden( 'partial', 1 );
                } elseif ( $source_is_page ) {
                        // If the page is the source, free_text will just be
                        // whatever in the page hasn't already been inserted
                        // into the form.
-                       $free_text = trim( $existing_page_content );
+                       $free_text = trim( $this->existing_page_content );
                // or get it from a form submission
                } elseif ( $wgRequest->getCheck( 'pf_free_text' ) ) {
                        $free_text = $wgRequest->getVal( 'pf_free_text' );
@@ -1600,7 +1578,7 @@
                $page_text = '';
 
                Hooks::run( 'PageForms::BeforeFreeTextSubst',
-                       array( &$free_text, $existing_page_content, &$page_text 
) );
+                       array( &$free_text, $this->existing_page_content, 
&$page_text ) );
 
                // Now that we have the free text, we can create the full page
                // text.
@@ -1616,7 +1594,7 @@
                // Add a warning in, if we're editing an existing page and that
                // page appears to not have been created with this form.
                if ( !$is_query && is_null( $page_name_formula ) &&
-                       $this->mPageTitle->exists() && $existing_page_content 
!== ''
+                       $this->mPageTitle->exists() && 
$this->existing_page_content !== ''
                        && !$this->source_matches_form ) {
                        $form_text = "\t" . '<div class="warningbox">' .
                                wfMessage( 'pf_formedit_formwarning', 
$page_name )->parse() .
@@ -1649,7 +1627,7 @@
                // If doing a replace, the page text is actually the modified
                // original page.
                if ( $partial_form_submitted ) {
-                       $page_text = $existing_page_content;
+                       $page_text = $this->existing_page_content;
                }
 
                if ( !$is_embedded ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/358572
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c9cb64bf0628331d29856dd23099a27eb0b8044
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Joeytje50 <joeytj...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to