Yaron Koren has uploaded a new change for review. https://gerrit.wikimedia.org/r/210113
Change subject: SF now (by default) links all red-links to a "form chooser" interface ...................................................................... SF now (by default) links all red-links to a "form chooser" interface This is enabled by a new global setting, $sfgLinkAllRedLinksToForms, which by default is set to true. Change-Id: Icd6124f9d9ccdf626b8fb140339804632f16cc39 --- M SemanticForms.php M i18n/en.json M i18n/qqq.json M includes/SF_FormEditAction.php M includes/SF_FormLinker.php 5 files changed, 54 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms refs/changes/13/210113/1 diff --git a/SemanticForms.php b/SemanticForms.php index b5b53f3..b23f886 100644 --- a/SemanticForms.php +++ b/SemanticForms.php @@ -464,6 +464,12 @@ $GLOBALS['sfgFormCacheType'] = null; # ## +# Point all red links to "action=formedit", instead of "action=edit", so +# that users can choose which form to use to create each new page. +# ## +$GLOBALS['sfgLinkAllRedLinksToForms'] = true; + +# ## # When modifying red links to potentially point to a form to edit that page, # check only the properties pointing to that missing page from the page the # user is currently on, instead of from all pages in the wiki. diff --git a/i18n/en.json b/i18n/en.json index db6e6ba..5e91832 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -128,6 +128,8 @@ "sf_formstart_noform_docu": "Enter the name of a page here, and select the form to edit it with.\nIf this page already exists, you will be sent to the form for editing that page.\nOtherwise, you will be sent to the form for adding the page.", "sf_formstart_createoredit": "Create or edit", "formedit": "Edit with form", + "sf-formedit-selectform": "Select a form to create this page:", + "sf-formedit-donotuseform": "Create page without a form.", "sf_formedit_createtitle": "Create $1: $2", "sf_formedit_createtitlenotarget": "Create $1", "sf_formedit_badurl": "This is the page for editing with a form. You must specify both a form name and a target page in the URL;\nit should look like \"Special:FormEdit?form=<form name>&target=<target page>\", or \"Special:FormEdit/<form name>/<target page>\".", diff --git a/i18n/qqq.json b/i18n/qqq.json index 6c88049..6f0f8f3 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -93,6 +93,8 @@ "sf_formstart_docu": "Used as description for the HTML form. Parameters:\n* $1 - semantic form name\nSee also:\n* {{msg-mw|Sf formstart noform docu}}", "sf_formstart_noform_docu": "Used as description for the HTML form.\n\nSee also:\n* {{msg-mw|Sf formstart docu}}", "formedit": "{{doc-special|FormEdit}}", + "sf-formedit-selectform": "A header displayed above a group of choices for the user", + "sf-formedit-donotuseform": "An option displayed to users as a link.", "sf_formedit_createtitle": "Used as page title. Parameters:\n* $1 - the main part of the title of a semantic form\n* $2 - the prefixed title, with spaces for the target page\nSee also:\n* {{msg-mw|Sf formedit createtitlenotarget}}\n* {{msg-mw|Sf formedit edittitle}}\n{{Identical|Create}}", "sf_formedit_createtitlenotarget": "Used as page title. Parameters:\n* $1 - the main part of the title of a semantic form\nSee also:\n* {{msg-mw|Sf formedit edittitle}}\n* {{msg-mw|Sf formedit createtitle}}\n{{Identical|Create}}", "sf_editsource": "{{Identical|Edit source}}", diff --git a/includes/SF_FormEditAction.php b/includes/SF_FormEditAction.php index 818be75..daf688e 100644 --- a/includes/SF_FormEditAction.php +++ b/includes/SF_FormEditAction.php @@ -146,21 +146,52 @@ return self::displayTab( $obj, $links['views'] ); } + static function displayFormChooser( $output, $title ) { + $output->addModules( 'ext.semanticforms.main' ); + + $targetName = $title->getPrefixedText(); + $output->setPageTitle( wfMessage( "creating", $targetName )->text() ); + + $output->addHTML( Html::element( 'p', null, wfMessage( 'sf-formedit-selectform' )->text() ) ); + $formNames = SFUtils::getAllForms(); + $fe = SpecialPageFactory::getPage( 'FormEdit' ); + $text = ''; + foreach( $formNames as $i => $formName ) { + if ( $i > 0 ) { + $text .= " · "; + } + + // Special handling for forms whose name contains a slash. + if ( strpos( $formName, '/' ) !== false ) { + $url = $fe->getTitle()->getLocalURL( array( 'form' => $formName, 'target' => $targetName ) ); + } else { + $url = $fe->getTitle( "$formName/$targetName" )->getLocalURL(); + } + $text .= Html::element( 'a', array( 'href' => $url ), $formName ); + } + $output->addHTML( Html::rawElement( 'div', array( 'class' => 'infoMessage' ), $text ) ); + + // We need to call linkKnown(), not link(), so that SF's + // edit=>formedit hook won't be called on this link. + $noFormLink = Linker::linkKnown( $title, wfMessage( 'sf-formedit-donotuseform' )->text(), array(), array( 'action' => 'edit', 'redlink' => true ) ); + $output->addHTML( Html::rawElement( 'p', null, $noFormLink ) ); + } + /** * The function called if we're in index.php (as opposed to one of the * special pages) */ static function displayForm( $action, $article ) { - // @todo: This looks like bad code. If we can't find a form, we - // should be showing an informative error page rather than - // making it look like an edit form page does not exist. + $output = $action->getOutput(); $title = $article->getTitle(); $form_names = SFFormLinker::getDefaultFormsForPage( $title ); if ( count( $form_names ) == 0 ) { + // If no form is set, display an interface to let the + // user choose out of all the forms defined on this wiki + // (or none at all). + self::displayFormChooser( $output, $title ); return true; } - - $output = $action->getOutput(); if ( count( $form_names ) > 1 ) { $warning_text = "\t" . '<div class="warningbox">' . wfMessage( 'sf_formedit_morethanoneform' )->text() . "</div>\n"; diff --git a/includes/SF_FormLinker.php b/includes/SF_FormLinker.php index 35a5d99..4583529 100644 --- a/includes/SF_FormLinker.php +++ b/includes/SF_FormLinker.php @@ -333,7 +333,15 @@ $link = self::formEditLink( $target, $incoming_properties ); if ( !is_null( $link ) ) { $attribs['href'] = $link; + return true; } + + global $sfgLinkAllRedLinksToForms; + if ( $sfgLinkAllRedLinksToForms ) { + $attribs['href'] = $target->getLinkURL( array( 'action' => 'formedit', 'redlink' => '1' ) ); + return true; + } + return true; } -- To view, visit https://gerrit.wikimedia.org/r/210113 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icd6124f9d9ccdf626b8fb140339804632f16cc39 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SemanticForms Gerrit-Branch: master Gerrit-Owner: Yaron Koren <yaro...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits