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

Change subject: Step one: Split up some variables to support OOP
......................................................................

Step one: Split up some variables to support OOP

Made as many variables as sensible a class property, so that the chances
of me overlooking a variable that's used in multiple places, but can't
be accessed by different functions (when I split up the formHTML
function), which could cause unexpected behaviour

Change-Id: I3a224e3b53d6d397745bb797ca4f60586b4c43cd
---
M includes/PF_FormPrinter.php
1 file changed, 283 insertions(+), 253 deletions(-)


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

diff --git a/includes/PF_FormPrinter.php b/includes/PF_FormPrinter.php
index cbdf276..d9b6ff4 100644
--- a/includes/PF_FormPrinter.php
+++ b/includes/PF_FormPrinter.php
@@ -21,6 +21,31 @@
        public $standardInputsIncluded;
        public $mPageTitle;
 
+       // variables used throughout this class
+       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 $form_text; // the contents of the entire form
+       private $new_text;
+
+       // more specific variables used more rarely, but still useful to have 
here
+       private $preloaded_free_text = null;
+       private $placeholderFields; // array
+       private $form_is_disabled; // bool
+       private $source_matches_form; // bool
+       private $free_text_was_included; // bool
+       private $free_text;
+       private $tag_components;
+       private $template_name;
+       private $source_is_page;
+       private $partial_form_submitted;
+       private $source_page_matches_this_form;
+       private $form_submitted;
+       private $is_query;
+       private $form_is_partial;
+
        public function __construct() {
                global $wgPageFormsDisableOutsideServices;
                // Initialize variables.
@@ -282,18 +307,18 @@
                return '@insertHTML_' . $str . '@';
        }
 
-       function multipleTemplateStartHTML( $tif ) {
+       function multipleTemplateStartHTML() {
                $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;
@@ -303,8 +328,8 @@
         * Creates the HTML for the inner table for every instance of a
         * multiple-instance template in the form.
         */
-       function multipleTemplateInstanceTableHTML( $form_is_disabled, 
$mainText ) {
-               if ( $form_is_disabled ) {
+       function multipleTemplateInstanceTableHTML( $mainText ) {
+               if ( $this->form_is_disabled ) {
                        $addAboveButton = $removeButton = '';
                } else {
                        $addAboveButton = Html::element( 'a', array( 'class' => 
"addAboveButton", 'title' => wfMessage( 'pf_formedit_addanotherabove' )->text() 
) );
@@ -329,22 +354,22 @@
         * Creates the HTML for a single instance of a multiple-instance
         * template.
         */
-       function multipleTemplateInstanceHTML( $template_in_form, 
$form_is_disabled, &$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]', 
"[{$template_in_form->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',
@@ -354,7 +379,7 @@
                                // wikis before PF 2.0.9.
                                'class' => "multipleTemplateInstance 
multipleTemplate"
                        ),
-                       $this->multipleTemplateInstanceTableHTML( 
$form_is_disabled, $section )
+                       $this->multipleTemplateInstanceTableHTML( 
$this->section )
                ) . "\n";
 
                return $text;
@@ -364,7 +389,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, $form_is_disabled, 
$section ) {
+       function multipleTemplateEndHTML() {
                global $wgPageFormsTabIndex;
 
                $text = "\t\t" . Html::rawElement( 'div',
@@ -372,14 +397,14 @@
                                'class' => "multipleTemplateStarter",
                                'style' => "display: none",
                        ),
-                       $this->multipleTemplateInstanceTableHTML( 
$form_is_disabled, $section )
+                       $this->multipleTemplateInstanceTableHTML( 
$this->section )
                ) . "\n";
 
                $attributes = array(
                        'tabindex' => $wgPageFormsTabIndex,
                        'class' => 'multipleTemplateAdder',
                );
-               if ( $form_is_disabled ) {
+               if ( $this->form_is_disabled ) {
                        $attributes['disabled'] = true;
                }
                $button = Html::input( null, Sanitizer::decodeCharReferences( 
$template_in_form->getAddButtonText() ), 'button', $attributes );
@@ -393,10 +418,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 {
@@ -404,7 +429,7 @@
                }
 
                $html = '';
-               foreach ( $tif->getFields() as $formField ) {
+               foreach ( $this->tif->getFields() as $formField ) {
                        $fieldName = $formField->template_field->getFieldName();
                        if ( $gridValues == null ) {
                                $curValue = null;
@@ -447,14 +472,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();
@@ -482,22 +507,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;
        }
@@ -668,21 +693,26 @@
                global $wgPageFormsTabIndex; // used to represent the current 
tab index in the form
                global $wgPageFormsFieldNum; // used for setting various HTML 
IDs
 
+               $this->existing_page_content = $existing_page_content;
+               $this->source_is_page = $source_is_page;
+               $this->form_submitted = $form_submitted;
+               $this->is_query = $this->is_query;
+
                // Initialize some variables.
-               $wiki_page = new PFWikiPage();
+               $this->wiki_page = new PFWikiPage();
                $wgPageFormsTabIndex = 0;
                $wgPageFormsFieldNum = 0;
-               $source_page_matches_this_form = false;
+               $this->source_page_matches_this_form = false;
                $form_page_title = null;
                $generated_page_name = $page_name_formula;
-               // $form_is_partial is true if:
+               // $this->form_is_partial is true if:
                // (a) 'partial' == 1 in the arguments
                // (b) 'partial form' is found in the form definition
                // in the latter case, it may remain false until close to the 
end of
                // the parsing, so we have to assume that it will become a 
possibility
-               $form_is_partial = false;
-               $partial_form_submitted = $wgRequest->getCheck( 'partial' );
-               $new_text = "";
+               $this->form_is_partial = false;
+               $this->partial_form_submitted = $wgRequest->getCheck( 'partial' 
);
+               $this->new_text = "";
 
                // If we have existing content and we're not in an active 
replacement
                // situation, preserve the original content. We do this because 
we want
@@ -692,15 +722,15 @@
                // minimize the html traffic and would allow us to do a 
concurrent
                // update check. For now, we pass it through a hidden text 
field.
 
-               if ( ! $partial_form_submitted ) {
-                       $original_page_content = $existing_page_content;
+               if ( ! $this->partial_form_submitted ) {
+                       $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;
+                               $this->form_is_partial = true;
                        }
                }
 
@@ -714,7 +744,7 @@
                        // just use the name of the actual page we're on.
                        global $wgTitle;
                        $this->mPageTitle = $wgTitle;
-               } elseif ( $is_query ) {
+               } elseif ( $this->is_query ) {
                        // We're in Special:RunQuery - just use that as the
                        // title.
                        global $wgTitle;
@@ -729,7 +759,7 @@
                global $wgOut;
                // Show previous set of deletions for this page, if it's been
                // deleted before.
-               if ( ! $form_submitted &&
+               if ( ! $this->form_submitted &&
                        ( $this->mPageTitle && !$this->mPageTitle->exists() &&
                        is_null( $page_name_formula ) )
                ) {
@@ -740,7 +770,7 @@
                // "$wgEmailConfirmToEdit = true;". Instead, we'll just get the
                // permission errors from the start, and use those to determine
                // whether the page is editable.
-               if ( !$is_query ) {
+               if ( !$this->is_query ) {
                        // $userCanEditPage = ( $wgUser->isAllowed( 'edit' ) && 
$this->mPageTitle->userCan( 'edit' ) );
                        $permissionErrors = 
$this->mPageTitle->getUserPermissionsErrors( 'edit', $wgUser );
                        // The handling of $wgReadOnly and $wgReadOnlyFile
@@ -751,22 +781,22 @@
                        $userCanEditPage = count( $permissionErrors ) == 0;
                        Hooks::run( 'PageForms::UserCanEditPage', array( 
$this->mPageTitle, &$userCanEditPage ) );
                }
-               $form_text = "";
-               if ( $is_query || $userCanEditPage ) {
-                       $form_is_disabled = false;
+               $this->form_text = "";
+               if ( $this->is_query || $userCanEditPage ) {
+                       $this->form_is_disabled = false;
                        // Show "Your IP address will be recorded" warning if
                        // user is anonymous, and it's not a query.
-                       if ( $wgUser->isAnon() && ! $is_query ) {
+                       if ( $wgUser->isAnon() && ! $this->is_query ) {
                                // Based on code in MediaWiki's EditPage.php.
                                $anonEditWarning = wfMessage( 'anoneditwarning',
                                        // Log-in link
                                        
'{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}',
                                        // Sign-up link
                                        
'{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}' )->parse();
-                               $form_text .= Html::rawElement( 'div', array( 
'id' => 'mw-anon-edit-warning', 'class' => 'warningbox' ), $anonEditWarning );
+                               $this->form_text .= Html::rawElement( 'div', 
array( 'id' => 'mw-anon-edit-warning', 'class' => 'warningbox' ), 
$anonEditWarning );
                        }
                } else {
-                       $form_is_disabled = true;
+                       $this->form_is_disabled = true;
                        $wgOut->setPageTitle( wfMessage( 'badaccess' )->text() 
);
                        $wgOut->addWikiText( 
$wgOut->formatPermissionsErrorMessage( $permissionErrors, 'edit' ) );
                        $wgOut->addHTML( "\n<hr />\n" );
@@ -790,20 +820,20 @@
                $form_def_sections = array();
                $start_position = 0;
                $section_start = 0;
-               $free_text_was_included = false;
-               $preloaded_free_text = null;
+               $this->free_text_was_included = false;
+               $this->preloaded_free_text = null;
                // @HACK - replace the 'free text' standard input with a
                // field declaration to get it to be handled as a field.
                $form_def = str_replace( 'standard input|free text', 
'field|#freetext#', $form_def );
                while ( $brackets_loc = strpos( $form_def, "{{{", 
$start_position ) ) {
                        $brackets_end_loc = strpos( $form_def, "}}}", 
$brackets_loc );
                        $bracketed_string = substr( $form_def, $brackets_loc + 
3, $brackets_end_loc - ( $brackets_loc + 3 ) );
-                       $tag_components = PFUtils::getFormTagComponents( 
$bracketed_string );
-                       $tag_title = trim( $tag_components[0] );
+                       $this->tag_components = PFUtils::getFormTagComponents( 
$bracketed_string );
+                       $tag_title = trim( $this->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;
@@ -814,71 +844,71 @@
                // existing article as well, finding template and field
                // declarations and replacing them with form elements, either
                // blank or pre-populated, as appropriate.
-               $template_name = null;
-               $template = null;
-               $tif = null;
+               $this->template_name = 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 ) );
-                               $tag_components = 
PFUtils::getFormTagComponents( $bracketed_string );
-                               $tag_title = trim( $tag_components[0] );
+                       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 ) );
+                               $this->tag_components = 
PFUtils::getFormTagComponents( $bracketed_string );
+                               $tag_title = trim( $this->tag_components[0] );
                                // 
=====================================================
                                // for template processing
                                // 
=====================================================
                                if ( $tag_title == 'for template' ) {
-                                       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 );
+                                       $this->template_name = str_replace( 
'_', ' ', $this->tag_components[1] );
+                                       $is_new_template = ( 
$this->template_name != $previous_template_name );
                                        if ( $is_new_template ) {
-                                               $template = 
PFTemplate::newFromName( $template_name );
-                                               $tif = 
PFTemplateInForm::newFromFormTag( $tag_components );
+                                               $this->template = 
PFTemplate::newFromName( $this->template_name );
+                                               $this->tif = 
PFTemplateInForm::newFromFormTag( $this->tag_components );
                                        }
                                        // 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 );
                                        // If we are editing a page, and this
                                        // template can be found more than
                                        // once in that page, and multiple
                                        // values are allowed, repeat this
                                        // section.
-                                       if ( $source_is_page || 
$partial_form_submitted ) {
-                                               $tif->setPageRelatedInfo( 
$existing_page_content );
+                                       if ( $this->source_is_page || 
$this->partial_form_submitted ) {
+                                               $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 && $this->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
                                                        // page was created 
with this form - note
                                                        // that, so we don't 
send the user a warning.
-                                                       
$source_page_matches_this_form = true;
+                                                       
$this->source_page_matches_this_form = true;
                                                }
                                        }
 
@@ -887,27 +917,27 @@
                                        // 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( 
$this->form_submitted, $this->source_is_page );
 
-                                       if ( !$tif->allInstancesPrinted() ) {
-                                               $wiki_page->addTemplate( $tif );
+                                       if ( !$this->tif->allInstancesPrinted() 
) {
+                                               $this->wiki_page->addTemplate( 
$this->tif );
                                        }
 
                                // 
=====================================================
                                // end template processing
                                // 
=====================================================
                                } elseif ( $tag_title == 'end template' ) {
-                                       if ( $source_is_page ) {
+                                       if ( $this->source_is_page ) {
                                                // Add any unhandled template 
fields
                                                // in the page as hidden 
variables.
-                                               $form_text .= 
PFFormUtils::unhandledFieldsHTML( $tif );
+                                               $this->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
                                // 
=====================================================
@@ -916,40 +946,40 @@
                                        // 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,
                                        // because PFFormField isn't equipped
                                        // to deal with the #freetext# hack,
                                        // among others.
-                                       $field_name = trim( $tag_components[1] 
);
-                                       $form_field = 
PFFormField::newFromFormFieldTag( $tag_components, $template, $tif, 
$form_is_disabled );
+                                       $field_name = trim( 
$this->tag_components[1] );
+                                       $form_field = 
PFFormField::newFromFormFieldTag( $this->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(), 
$this->form_submitted, $this->source_is_page, $this->tif->allInstancesPrinted() 
);
                                        if ( $form_field->holdsTemplate() ) {
-                                               $placeholderFields[] = 
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 ( $this->source_is_page && ( 
$this->tif->getFullTextInPage() != '' && !$this->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
@@ -957,7 +987,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.
@@ -969,12 +999,12 @@
                                        // Handle the free text field.
                                        if ( $field_name == '#freetext#' ) {
                                                // If there was no preloading, 
this will just be blank.
-                                               $preloaded_free_text = 
$cur_value;
+                                               $this->preloaded_free_text = 
$cur_value;
                                                // Add placeholders for the 
free text in both the form and
                                                // the page, using <free_text> 
tags - once all the free text
                                                // is known (at the end), it 
will get substituted in.
                                                if ( $form_field->isHidden() ) {
-                                                       $new_text = 
Html::hidden( 'pf_free_text', '!free_text!' );
+                                                       $this->new_text = 
Html::hidden( 'pf_free_text', '!free_text!' );
                                                } else {
                                                        $wgPageFormsTabIndex++;
                                                        $wgPageFormsFieldNum++;
@@ -983,14 +1013,14 @@
                                                        } else {
                                                                $default_value 
= $cur_value;
                                                        }
-                                                       $freeTextInput = new 
PFTextAreaInput( $input_number = null, $default_value, 'pf_free_text', ( 
$form_is_disabled || $form_field->isRestricted() ), $form_field->getFieldArgs() 
);
+                                                       $freeTextInput = new 
PFTextAreaInput( $input_number = null, $default_value, 'pf_free_text', ( 
$this->form_is_disabled || $form_field->isRestricted() ), 
$form_field->getFieldArgs() );
                                                        
$freeTextInput->addJavaScript();
-                                                       $new_text = 
$freeTextInput->getHtmlText();
+                                                       $this->new_text = 
$freeTextInput->getHtmlText();
                                                        if ( 
$form_field->hasFieldArg( 'edittools' ) ) {
                                                                // borrowed 
from EditPage::showEditTools()
                                                                $edittools_text 
= $wgParser->recursiveTagParse( wfMessage( 'edittools', array( 'content' ) 
)->text() );
 
-                                                               $new_text .= 
<<<END
+                                                               $this->new_text 
.= <<<END
                <div class="mw-editTools">
                $edittools_text
                </div>
@@ -998,12 +1028,12 @@
 END;
                                                        }
                                                }
-                                               $free_text_was_included = true;
-                                               
$wiki_page->addFreeTextSection();
+                                               $this->free_text_was_included = 
true;
+                                               
$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, $this->new_text, $brackets_loc, 
$brackets_end_loc + 3 - $brackets_loc );
                                        } else {
                                                if ( is_array( $cur_value ) ) {
                                                        // @TODO - is this code 
ever called?
@@ -1039,7 +1069,7 @@
                                                // If we're creating the page 
name from a formula based on
                                                // form values, see if the 
current input is part of that formula,
                                                // and if so, substitute in the 
actual value.
-                                               if ( $form_submitted && 
$generated_page_name !== '' ) {
+                                               if ( $this->form_submitted && 
$generated_page_name !== '' ) {
                                                        // This line appears to 
be unnecessary.
                                                        // $generated_page_name 
= str_replace('.', '_', $generated_page_name);
                                                        $generated_page_name = 
str_replace( ' ', '_', $generated_page_name );
@@ -1053,7 +1083,7 @@
                                                // Call hooks - unfortunately 
this has to be split into two
                                                // separate calls, because of 
the different variable names in
                                                // each case.
-                                               if ( $form_submitted ) {
+                                               if ( $this->form_submitted ) {
                                                        Hooks::run( 
'PageForms::CreateFormField', array( &$form_field, &$cur_value_in_template, 
true ) );
                                                } else {
                                                        if ( !empty( $cur_value 
) &&
@@ -1117,22 +1147,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() );
+                                               $this->new_text = 
$this->formFieldHTML( $form_field, $cur_value );
+                                               $this->new_text .= 
$form_field->additionalHTMLForInput( $cur_value, $field_name, 
$this->tif->getTemplateName() );
 
-                                               if ( $new_text ) {
-                                                       
$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 );
+                                               if ( $this->new_text ) {
+                                                       
$this->wiki_page->addTemplateParam( $this->template_name, 
$this->tif->getInstanceNum(), $field_name, $cur_value_in_template );
+                                                       $this->section = 
substr_replace( $this->section, $this->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' ) {
@@ -1143,8 +1173,8 @@
                                                }
                                        }
 
-                                       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 );
                                        }
 
                                // 
=====================================================
@@ -1152,22 +1182,22 @@
                                // 
=====================================================
                                } elseif ( $tag_title == 'standard input' ) {
                                        // handle all the possible values
-                                       $input_name = $tag_components[1];
+                                       $input_name = $this->tag_components[1];
                                        $input_label = null;
                                        $attr = array();
 
                                        // 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 );
+                                       if ( ( $this->is_query && $input_name 
!= 'run query' ) || ( !$this->is_query && $input_name == 'run query' ) ) {
+                                               $this->new_text = "";
+                                               $this->section = 
substr_replace( $this->section, $this->new_text, $brackets_loc, 
$brackets_end_loc + 3 - $brackets_loc );
                                                continue;
                                        }
                                        // set a flag so that the standard 
'form bottom' won't get displayed
                                        $this->standardInputsIncluded = true;
                                        // cycle through the other components
                                        $is_checked = false;
-                                       for ( $i = 2; $i < count( 
$tag_components ); $i++ ) {
-                                               $component = 
$tag_components[$i];
+                                       for ( $i = 2; $i < count( 
$this->tag_components ); $i++ ) {
+                                               $component = 
$this->tag_components[$i];
                                                $sub_components = array_map( 
'trim', explode( '=', $component ) );
                                                if ( count( $sub_components ) 
== 1 ) {
                                                        if ( $sub_components[0] 
== 'checked' ) {
@@ -1189,27 +1219,27 @@
                                        }
                                        if ( $input_name == 'summary' ) {
                                                $value = $wgRequest->getVal( 
'wpSummary' );
-                                               $new_text = 
PFFormUtils::summaryInputHTML( $form_is_disabled, $input_label, $attr, $value );
+                                               $this->new_text = 
PFFormUtils::summaryInputHTML( $this->form_is_disabled, $input_label, $attr, 
$value );
                                        } elseif ( $input_name == 'minor edit' 
) {
                                                $is_checked = 
$wgRequest->getCheck( 'wpMinoredit' );
-                                               $new_text = 
PFFormUtils::minorEditInputHTML( $form_submitted, $form_is_disabled, 
$is_checked, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::minorEditInputHTML( $this->form_submitted, 
$this->form_is_disabled, $is_checked, $input_label, $attr );
                                        } elseif ( $input_name == 'watch' ) {
                                                $is_checked = 
$wgRequest->getCheck( 'wpWatchthis' );
-                                               $new_text = 
PFFormUtils::watchInputHTML( $form_submitted, $form_is_disabled, $is_checked, 
$input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::watchInputHTML( $this->form_submitted, $this->form_is_disabled, 
$is_checked, $input_label, $attr );
                                        } elseif ( $input_name == 'save' ) {
-                                               $new_text = 
PFFormUtils::saveButtonHTML( $form_is_disabled, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::saveButtonHTML( $this->form_is_disabled, $input_label, $attr );
                                        } elseif ( $input_name == 'save and 
continue' ) {
-                                               $new_text = 
PFFormUtils::saveAndContinueButtonHTML( $form_is_disabled, $input_label, $attr 
);
+                                               $this->new_text = 
PFFormUtils::saveAndContinueButtonHTML( $this->form_is_disabled, $input_label, 
$attr );
                                        } elseif ( $input_name == 'preview' ) {
-                                               $new_text = 
PFFormUtils::showPreviewButtonHTML( $form_is_disabled, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::showPreviewButtonHTML( $this->form_is_disabled, $input_label, 
$attr );
                                        } elseif ( $input_name == 'changes' ) {
-                                               $new_text = 
PFFormUtils::showChangesButtonHTML( $form_is_disabled, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::showChangesButtonHTML( $this->form_is_disabled, $input_label, 
$attr );
                                        } elseif ( $input_name == 'cancel' ) {
-                                               $new_text = 
PFFormUtils::cancelLinkHTML( $form_is_disabled, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::cancelLinkHTML( $this->form_is_disabled, $input_label, $attr );
                                        } elseif ( $input_name == 'run query' ) 
{
-                                               $new_text = 
PFFormUtils::runQueryButtonHTML( $form_is_disabled, $input_label, $attr );
+                                               $this->new_text = 
PFFormUtils::runQueryButtonHTML( $this->form_is_disabled, $input_label, $attr );
                                        }
-                                       $section = substr_replace( $section, 
$new_text, $brackets_loc, $brackets_end_loc + 3 - $brackets_loc );
+                                       $this->section = substr_replace( 
$this->section, $this->new_text, $brackets_loc, $brackets_end_loc + 3 - 
$brackets_loc );
                                // 
=====================================================
                                // for section processing
                                // 
=====================================================
@@ -1217,19 +1247,19 @@
                                        $wgPageFormsFieldNum++;
                                        $wgPageFormsTabIndex++;
 
-                                       $section_name = trim( 
$tag_components[1] );
-                                       $page_section_in_form = 
PFPageSection::newFromFormTag( $tag_components );
+                                       $section_name = trim( 
$this->tag_components[1] );
+                                       $page_section_in_form = 
PFPageSection::newFromFormTag( $this->tag_components );
                                        $section_text = null;
 
                                        // 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 ( $this->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(), '=' );
@@ -1241,45 +1271,45 @@
                                                        '[ ]*?' .
                                                        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 ) );
-                                                       
$tag_components_next_section = PFUtils::getFormTagComponents( 
$bracketed_string_next_section );
-                                                       $tag_title_next_section 
= trim( $tag_components_next_section[0] );
+                                                       $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 ) );
+                                                       
$this->tag_components_next_section = PFUtils::getFormTagComponents( 
$bracketed_string_next_section );
+                                                       $tag_title_next_section 
= trim( $this->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}[ ]*?' . $this->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 );
                                                }
                                        }
 
                                        // If input is from the form.
-                                       if ( ( ! $source_is_page ) && 
$wgRequest ) {
+                                       if ( ( ! $this->source_is_page ) && 
$wgRequest ) {
                                                $text_per_section = 
$wgRequest->getArray( '_section' );
                                                $section_text = 
$text_per_section[trim( $section_name )];
-                                               $wiki_page->addSection( 
$section_name, $page_section_in_form->getSectionLevel(), $section_text );
+                                               $this->wiki_page->addSection( 
$section_name, $page_section_in_form->getSectionLevel(), $section_text );
                                        }
 
                                        $section_text = trim( $section_text );
@@ -1295,45 +1325,45 @@
                                        if ( $page_section_in_form->isHidden() 
) {
                                                $form_section_text = 
Html::hidden( $input_name, $section_text );
                                        } else {
-                                               $sectionInput = new 
PFTextAreaInput( $input_number = null, $section_text, $input_name, ( 
$form_is_disabled || $page_section_in_form->isRestricted() ), $other_args );
+                                               $sectionInput = new 
PFTextAreaInput( $input_number = null, $section_text, $input_name, ( 
$this->form_is_disabled || $page_section_in_form->isRestricted() ), $other_args 
);
                                                $sectionInput->addJavaScript();
                                                $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 );
                                // 
=====================================================
                                // page info processing
                                // 
=====================================================
                                } elseif ( $tag_title == 'info' ) {
                                        // TODO: Generate an error message if 
this is included more than once
-                                       foreach ( array_slice( $tag_components, 
1 ) as $component ) {
+                                       foreach ( array_slice( 
$this->tag_components, 1 ) as $component ) {
                                                $sub_components = array_map( 
'trim', explode( '=', $component, 2 ) );
                                                // Tag names are 
case-insensitive
                                                $tag = strtolower( 
$sub_components[0] );
                                                if ( $tag == 'create title' || 
$tag == 'add title' ) {
                                                        // Handle this only if
                                                        // we're adding a page.
-                                                       if ( !$is_query && 
!$this->mPageTitle->exists() ) {
+                                                       if ( !$this->is_query 
&& !$this->mPageTitle->exists() ) {
                                                                
$form_page_title = $sub_components[1];
                                                        }
                                                } elseif ( $tag == 'edit title' 
) {
                                                        // Handle this only if
                                                        // we're editing a page.
-                                                       if ( !$is_query && 
$this->mPageTitle->exists() ) {
+                                                       if ( !$this->is_query 
&& $this->mPageTitle->exists() ) {
                                                                
$form_page_title = $sub_components[1];
                                                        }
                                                } elseif ( $tag == 'query 
title' ) {
                                                        // Handle this only if
                                                        // we're in 'RunQuery'.
-                                                       if ( $is_query ) {
+                                                       if ( $this->is_query ) {
                                                                
$form_page_title = $sub_components[1];
                                                        }
                                                } elseif ( $tag == 'partial 
form' ) {
-                                                       $form_is_partial = true;
+                                                       $this->form_is_partial 
= true;
                                                        // replacement pages 
may have minimal matches...
-                                                       
$source_page_matches_this_form = true;
+                                                       
$this->source_page_matches_this_form = true;
                                                } elseif ( $tag == 'includeonly 
free text' || $tag == 'onlyinclude free text' ) {
-                                                       
$wiki_page->makeFreeTextOnlyInclude();
+                                                       
$this->wiki_page->makeFreeTextOnlyInclude();
                                                } elseif ( $tag == 'query form 
at top' ) {
                                                        // TODO - this should 
be made a field of
                                                        // some non-static 
class that actually
@@ -1343,74 +1373,74 @@
                                                        
$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 = 
$wiki_page->createTemplateCallsForTemplateName( $tif->getTemplateName() );
+                       if ( $this->tif && ( !$this->tif->allowsMultiple() || 
$this->tif->allInstancesPrinted() ) ) {
+                               $template_text = 
$this->wiki_page->createTemplateCallsForTemplateName( 
$this->tif->getTemplateName() );
                                // Escape the '$' characters for the 
preg_replace() call.
                                $template_text = str_replace( '$', '\$', 
$template_text );
 
                                // 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', '}�',
+                               } elseif ( $this->partial_form_submitted ) {
+                                       $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() ) {
-                                       $form_text .= $fieldsetStartHTML;
-                               } elseif ( $tif->allowsMultiple() && 
$tif->getInstanceNum() == 0 ) {
+                       if ( $this->tif && $this->tif->getLabel() != null ) {
+                               $fieldsetStartHTML = "<fieldset>\n" . 
Html::element( 'legend', null, $this->tif->getLabel() ) . "\n";
+                               if ( !$this->tif->allowsMultiple() ) {
+                                       $this->form_text .= $fieldsetStartHTML;
+                               } 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();
                                        }
-                                       if ( ! $tif->allInstancesPrinted() ) {
-                                               $multipleTemplateHTML .= 
$this->multipleTemplateInstanceHTML( $tif, $form_is_disabled, $section );
+                                       if ( ! 
$this->tif->allInstancesPrinted() ) {
+                                               $multipleTemplateHTML .= 
$this->multipleTemplateInstanceHTML();
                                        } else {
-                                               $multipleTemplateHTML .= 
$this->multipleTemplateEndHTML( $tif, $form_is_disabled, $section );
+                                               $multipleTemplateHTML .= 
$this->multipleTemplateEndHTML();
                                        }
                                }
-                               $placeholder = $tif->getPlaceholder();
+                               $placeholder = $this->tif->getPlaceholder();
                                if ( $placeholder == null ) {
                                        // The normal process.
-                                       $form_text .= $multipleTemplateHTML;
+                                       $this->form_text .= 
$multipleTemplateHTML;
                                } else {
                                        // The template text won't be appended
                                        // at the end of the template like for
@@ -1428,130 +1458,130 @@
                                        // placeholder tag, but also add another
                                        // placeholder tag, to keep track of it.
                                        $multipleTemplateHTML .= 
self::makePlaceholderInFormHTML( $placeholder );
-                                       $form_text = str_replace( 
self::makePlaceholderInFormHTML( $placeholder ), $multipleTemplateHTML, 
$form_text );
+                                       $this->form_text = str_replace( 
self::makePlaceholderInFormHTML( $placeholder ), $multipleTemplateHTML, 
$this->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' ) {
+                               $this->form_text .= $this->tableHTML( 0 );
+                       } elseif ( $this->tif && !$this->tif->allowsMultiple() 
&& $this->tif->getLabel() != null ) {
+                               $this->form_text .= $this->section . 
"\n</fieldset>";
                        } else {
-                               $form_text .= $section;
+                               $this->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 );
+                       $this->form_text = str_replace( 
self::makePlaceholderInFormHTML( $stringToReplace ), '', $this->form_text );
                }
 
                // If it wasn't included in the form definition, add the
                // 'free text' input as a hidden field at the bottom.
-               if ( ! $free_text_was_included ) {
-                       $form_text .= Html::hidden( 'pf_free_text', 
'!free_text!' );
+               if ( ! $this->free_text_was_included ) {
+                       $this->form_text .= Html::hidden( 'pf_free_text', 
'!free_text!' );
                }
                // Get free text, and add to page data, as well as retroactively
                // inserting it into the form.
 
-               // If $form_is_partial is true then either:
+               // If $this->form_is_partial is true then either:
                // (a) we're processing a replacement (param 'partial' == 1)
                // (b) we're sending out something to be replaced (param 
'partial' is missing)
-               if ( $form_is_partial ) {
-                       if ( !$partial_form_submitted ) {
-                               $free_text = $original_page_content;
+               if ( $this->form_is_partial ) {
+                       if ( !$this->partial_form_submitted ) {
+                               $this->free_text = $original_page_content;
                        } else {
-                               $free_text = null;
-                               $existing_page_content = preg_replace( array( 
'/�\{/m', '/\}�/m' ),
+                               $this->free_text = null;
+                               $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 ) {
+                       $this->form_text .= Html::hidden( 'partial', 1 );
+               } elseif ( $this->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 );
+                       $this->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' );
-                       if ( ! $free_text_was_included ) {
-                               $wiki_page->addFreeTextSection();
+                       $this->free_text = $wgRequest->getVal( 'pf_free_text' );
+                       if ( ! $this->free_text_was_included ) {
+                               $this->wiki_page->addFreeTextSection();
                        }
-               } elseif ( $preloaded_free_text != null ) {
-                       $free_text = $preloaded_free_text;
+               } elseif ( $this->preloaded_free_text != null ) {
+                       $this->free_text = $this->preloaded_free_text;
                } else {
-                       $free_text = null;
+                       $this->free_text = null;
                }
 
-               if ( $wiki_page->freeTextOnlyInclude() ) {
-                       $free_text = str_replace( "<onlyinclude>", '', 
$free_text );
-                       $free_text = str_replace( "</onlyinclude>", '', 
$free_text );
-                       $free_text = trim( $free_text );
+               if ( $this->wiki_page->freeTextOnlyInclude() ) {
+                       $this->free_text = str_replace( "<onlyinclude>", '', 
$this->free_text );
+                       $this->free_text = str_replace( "</onlyinclude>", '', 
$this->free_text );
+                       $this->free_text = trim( $this->free_text );
                }
 
                $page_text = '';
 
                Hooks::run( 'PageForms::BeforeFreeTextSubst',
-                       array( &$free_text, $existing_page_content, &$page_text 
) );
+                       array( &$this->free_text, $this->existing_page_content, 
&$page_text ) );
 
                // Now that we have the free text, we can create the full page
                // text.
                // The page text needs to be created whether or not the form
                // was submitted, in case this is called from #formredlink.
-               $wiki_page->setFreeText( $free_text );
-               $page_text = $wiki_page->createPageText();
+               $this->wiki_page->setFreeText( $this->free_text );
+               $page_text = $this->wiki_page->createPageText();
 
                // Also substitute the free text into the form.
-               $escaped_free_text = Sanitizer::safeEncodeAttribute( $free_text 
);
-               $form_text = str_replace( '!free_text!', $escaped_free_text, 
$form_text );
+               $escaped_free_text = Sanitizer::safeEncodeAttribute( 
$this->free_text );
+               $this->form_text = str_replace( '!free_text!', 
$escaped_free_text, $this->form_text );
 
                // 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 
!== ''
-                       && !$source_page_matches_this_form ) {
-                       $form_text = "\t" . '<div class="warningbox">' .
+               if ( !$this->is_query && is_null( $page_name_formula ) &&
+                       $this->mPageTitle->exists() && 
$this->existing_page_content !== ''
+                       && !$this->source_page_matches_this_form ) {
+                       $this->form_text = "\t" . '<div class="warningbox">' .
                                wfMessage( 'pf_formedit_formwarning', 
$page_name )->parse() .
-                               "</div>\n<br clear=\"both\" />\n" . $form_text;
+                               "</div>\n<br clear=\"both\" />\n" . 
$this->form_text;
                }
 
                // Add form bottom, if no custom "standard inputs" have been 
defined.
                if ( !$this->standardInputsIncluded ) {
-                       if ( $is_query ) {
-                               $form_text .= PFFormUtils::queryFormBottom( 
$form_is_disabled );
+                       if ( $this->is_query ) {
+                               $this->form_text .= 
PFFormUtils::queryFormBottom( $this->form_is_disabled );
                        } else {
-                               $form_text .= PFFormUtils::formBottom( 
$form_submitted, $form_is_disabled );
+                               $this->form_text .= PFFormUtils::formBottom( 
$this->form_submitted, $this->form_is_disabled );
                        }
                }
 
-               if ( !$is_query ) {
-                       $form_text .= Html::hidden( 'wpStarttime', 
wfTimestampNow() );
+               if ( !$this->is_query ) {
+                       $this->form_text .= Html::hidden( 'wpStarttime', 
wfTimestampNow() );
                        $article = new Article( $this->mPageTitle, 0 );
-                       $form_text .= Html::hidden( 'wpEdittime', 
$article->getTimestamp() );
+                       $this->form_text .= Html::hidden( 'wpEdittime', 
$article->getTimestamp() );
 
-                       $form_text .= Html::hidden( 'wpEditToken', 
$wgUser->getEditToken() );
+                       $this->form_text .= Html::hidden( 'wpEditToken', 
$wgUser->getEditToken() );
                }
 
-               $form_text .= "\t</form>\n";
-               $wgParser->replaceLinkHolders( $form_text );
-               Hooks::run( 'PageForms::RenderingEnd', array( &$form_text ) );
+               $this->form_text .= "\t</form>\n";
+               $wgParser->replaceLinkHolders( $this->form_text );
+               Hooks::run( 'PageForms::RenderingEnd', array( &$this->form_text 
) );
 
                // Send the autocomplete values to the browser, along with the
                // mappings of which values should apply to which fields.
                // If doing a replace, the page text is actually the modified
                // original page.
-               if ( $partial_form_submitted ) {
-                       $page_text = $existing_page_content;
+               if ( $this->partial_form_submitted ) {
+                       $page_text = $this->existing_page_content;
                }
 
                if ( !$is_embedded ) {
@@ -1562,7 +1592,7 @@
 
 //             $wgParser = $oldParser;
 
-               return array( $form_text, $page_text, $form_page_title, 
$generated_page_name );
+               return array( $this->form_text, $page_text, $form_page_title, 
$generated_page_name );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a224e3b53d6d397745bb797ca4f60586b4c43cd
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