jenkins-bot has submitted this change and it was merged.
Change subject: fix bug (handling of alternate forms with no default form)
......................................................................
fix bug (handling of alternate forms with no default form)
When only "alternate forms", and not a "default form", were specified for a
property in order to generate red links, too many error messages where
displayed.
Basically the reporting level was not accounted for and the fix consists of
only reporting warnings and errors (i.e. no notices and no debug messages).
In addition alternate forms where not taken into account when looking for the
form to use.
Now the following logic is used to find a form:
* Try for a form explicitly set as a URL parameter
* Try for an alternate form explicitly set as a URL parameter
* Try for a default form for the given target page
* Try for a default alternate form for the given target page
* Throw an error
Change-Id: Ibcfdee695d4498cfcbaf28bdc1a7d78dc88bbee7
---
M includes/SF_AutoeditAPI.php
M specials/SF_FormEdit.php
2 files changed, 44 insertions(+), 20 deletions(-)
Approvals:
Yaron Koren: Checked; Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/SF_AutoeditAPI.php b/includes/SF_AutoeditAPI.php
index ab09538..77a3dc0 100644
--- a/includes/SF_AutoeditAPI.php
+++ b/includes/SF_AutoeditAPI.php
@@ -115,7 +115,7 @@
try {
$this->doAction();
} catch ( MWException $e ) {
- $this->logMessage( $e->getMessage() );
+ $this->logMessage( $e->getMessage(), $e->getCode() );
}
$this->finalizeResults();
@@ -236,34 +236,55 @@
*/
protected function getFormTitle() {
- // if no form was specified, try finding the default form for
the target page.
+ // if no form was explicitly specified, try for explicitly set
alternate forms
if ( $this->mOptions[ 'form' ] === '' ) {
$this->logMessage( 'No form specified. Will try to find
the default form for the target page.', self::DEBUG );
- // if no form and no target page was specified, give up
- if ( $this->mOptions[ 'target' ] === '' ) {
- throw new MWException( wfMessage(
'sf_autoedit_notargetspecified' )->parse() );
+ $formNames = array();
+
+ // try explicitly set alternative forms
+ if ( array_key_exists( 'alt_form', $this->mOptions ) ) {
+
+ $formNames = (array)$this->mOptions[ 'alt_form'
]; // cast to array to make sure we get an array, even if only a string was sent
+
}
- $targetTitle = Title::newFromText( $this->mOptions[
'target' ] );
-
- // if the specified target title is invalid, give up
- if ( !$targetTitle instanceof Title ) {
- throw new MWException( wfMessage(
'sf_autoedit_invalidtargetspecified', $this->mOptions[ 'target' ] )->parse() );
- }
-
- $formNames = SFFormLinker::getDefaultFormsForPage(
$targetTitle );
-
- // if no form can be found, give up
+ // if no alternate forms were explicitly set, try
finding a default form for the target page
if ( count( $formNames ) === 0 ) {
- throw new MWException( wfMessage(
'sf_autoedit_noformfound' )->parse() );
+
+ // if no form and and no alt forms and no
target page was specified, give up
+ if ( $this->mOptions[ 'target' ] === '' ) {
+ throw new MWException( wfMessage(
'sf_autoedit_notargetspecified' )->parse() );
+ }
+
+ $targetTitle = Title::newFromText(
$this->mOptions[ 'target' ] );
+
+ // if the specified target title is invalid,
give up
+ if ( !$targetTitle instanceof Title ) {
+ throw new MWException( wfMessage(
'sf_autoedit_invalidtargetspecified', $this->mOptions[ 'target' ] )->parse() );
+ }
+
+ $formNames =
SFFormLinker::getDefaultFormsForPage( $targetTitle );
+
+ // if no default form can be found, try
alternate forms
+ if ( count( $formNames ) === 0 ) {
+
+ $formNames =
SFFormLinker::getFormsThatPagePointsTo( $targetTitle->getText(),
$targetTitle->getNamespace(), SFFormLinker::ALTERNATE_FORM );
+
+ // if still no form can be found, give
up
+ if ( count( $formNames ) === 0 ) {
+ throw new MWException(
wfMessage( 'sf_autoedit_noformfound' )->parse() );
+ }
+
+ }
+
}
- // if more than one form was found, issue a warning and
use the first form
- // FIXME: If we have more than one form, should we stop?
+ // if more than one form was found, issue a notice and
give up
+ // this happens if no default form but several
alternate forms are defined
if ( count( $formNames ) > 1 ) {
- $this->logMessage( wfMessage(
'sf_autoedit_toomanyformsfound' )->parse(), self::WARNING );
+ throw new MWException( wfMessage(
'sf_autoedit_toomanyformsfound' )->parse(), self::DEBUG );
}
$this->mOptions[ 'form' ] = $formNames[ 0 ];
diff --git a/specials/SF_FormEdit.php b/specials/SF_FormEdit.php
index 9d7affa..85c9558 100644
--- a/specials/SF_FormEdit.php
+++ b/specials/SF_FormEdit.php
@@ -109,7 +109,10 @@
if ( array_key_exists( 'errors', $resultData ) ) {
foreach ($resultData['errors'] as $error) {
- $text .= Html::rawElement( 'p', array(
'class' => 'error' ), $error['message'] ) . "\n";
+ // FIXME: This should probably not be
hard-coded to WARNING but put into a setting
+ if ( $error[ 'level' ] <=
SFAutoeditAPI::WARNING ) {
+ $text .= Html::rawElement( 'p',
array( 'class' => 'error' ), $error[ 'message' ] ) . "\n";
+ }
}
}
}
--
To view, visit https://gerrit.wikimedia.org/r/93861
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibcfdee695d4498cfcbaf28bdc1a7d78dc88bbee7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits