From 4c6ddfd55e76ce3f216db95e433eb5bd815bc139 Mon Sep 17 00:00:00 2001 From: Neil Kandalgaonkar Date: Wed, 15 Dec 2010 01:17:28 +0000 Subject: [PATCH] refactored HTMLForm show() into three methods, in case you want to process a form in some way separate from showing it. --- includes/HTMLForm.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 0fddfe4617..0d1a77f08b 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -184,23 +184,26 @@ class HTMLForm { } /** - * The here's-one-I-made-earlier option: do the submission if - * posted, or display the form with or without funky valiation - * errors - * @return Bool or Status whether submission was successful. + * Prepare form for submission */ - function show() { + function prepareForm() { # Check if we have the info we need if ( ! $this->mTitle ) { throw new MWException( "You must call setTitle() on an HTMLForm" ); } + // FIXME shouldn't this be closer to displayForm() ? self::addJS(); # Load data from the request. $this->loadData(); + } - # Try a submission + /** + * Try submitting, with edit token check first + * @return Status|boolean + */ + function tryAuthorizedSubmit() { global $wgUser, $wgRequest; $editToken = $wgRequest->getVal( 'wpEditToken' ); @@ -208,12 +211,23 @@ class HTMLForm { if ( $wgUser->matchEditToken( $editToken ) ) { $result = $this->trySubmit(); } + return $result; + } + /** + * The here's-one-I-made-earlier option: do the submission if + * posted, or display the form with or without funky valiation + * errors + * @return Bool or Status whether submission was successful. + */ + function show() { + $this->prepareForm(); + + $result = $this->tryAuthorizedSubmit(); if ( $result === true || ( $result instanceof Status && $result->isGood() ) ){ return $result; } - # Display form. $this->displayForm( $result ); return false; } @@ -528,7 +542,6 @@ class HTMLForm { $this->mSubmitTooltip = $name; } - /** * Set the id for the submit button. * @param $t String. FIXME: Integrity is *not* validated -- 2.20.1