jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/376914 )
Change subject: Add hierarchy validation in Special:CreateClass
......................................................................
Add hierarchy validation in Special:CreateClass
Change-Id: I1a6f12e9a1650a1b5101bbe33a532984de40c233
---
M libs/PF_CreateClass.js
M specials/PF_CreateClass.php
2 files changed, 43 insertions(+), 2 deletions(-)
Approvals:
Yaron Koren: Looks good to me, approved
jenkins-bot: Verified
diff --git a/libs/PF_CreateClass.js b/libs/PF_CreateClass.js
index b9cfdb1..619a082 100644
--- a/libs/PF_CreateClass.js
+++ b/libs/PF_CreateClass.js
@@ -1,3 +1,5 @@
+/*global alert*/
+
var rowNum = mediaWiki.config.get( '$numStartingRows');
var hierarchyPlaceholder = mediaWiki.msg(
'pf_createtemplate_hierarchystructureplaceholder' );
function createClassAddRow() {
@@ -77,6 +79,42 @@
textareaElement.attr( 'validInput', 'true' );
}
+function validateHierarchyStructure() {
+ var hierarchyTextAreas =
jQuery("textarea[name*='hierarchy_structure_']");
+ for (var i = 0; i < hierarchyTextAreas.length; i++) {
+ var structure = hierarchyTextAreas[i].value.trim();
+ if (structure !== "") {
+ var nodes = structure.split(/\n/);
+ var matches = nodes[0].match(/^([*]*)[^*]*/i);
+ if (matches[1].length !== 1) {
+ alert("Error: First entry of hierarchy values
should start with exact one \'*\', the entry \"" +
+ nodes[0] + "\" has " +
matches[1].length + " \'*\'");
+ return false;
+ }
+ var level = 0;
+ for (var j = 0; j < nodes.length; j++) {
+ matches = nodes[j].match(/^([*]*)( *)(.*)/i);
+ if (matches[1].length < 1) {
+ alert("Error: Each entry of hierarchy
values should start with at least one \'*\', the entry \"" +
+ nodes[j] + "\" has 0 '*'");
+ return false;
+ }
+ if (matches[1].length - level > 1) {
+ alert("Error: Level or count of '*' in
hierarchy values should be increased only by count of 1, the entry \"" +
+ nodes[j] + "\" should have " +
( level + 1 ) + " or fewer '*'");
+ return false;
+ }
+ level = matches[1].length;
+ if (matches[3].length === 0) {
+ alert("Error: The entry of hierarchy
values cannot be empty.");
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
+
jQuery( document ).ready( function () {
jQuery( ".disableFormAndCategoryInputs" ).click( function () {
disableFormAndCategoryInputs();
@@ -98,4 +136,7 @@
removeHierarchyPlaceholder( jQuery( this ) );
}
} );
-} );
\ No newline at end of file
+ jQuery( '#createClassForm' ).submit( function () {
+ return validateHierarchyStructure();
+ } );
+} );
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index 7500c94..5a93fe0 100644
--- a/specials/PF_CreateClass.php
+++ b/specials/PF_CreateClass.php
@@ -235,7 +235,7 @@
$creation_links[] = PFUtils::linkForSpecialPage( $linkRenderer,
'CreateForm' );
$creation_links[] = PFUtils::linkForSpecialPage( $linkRenderer,
'CreateCategory' );
- $text = '<form action="" method="post">' . "\n";
+ $text = '<form id="createClassForm" action="" method="post">' .
"\n";
$text .= "\t" . Html::rawElement( 'p', null,
wfMessage( 'pf_createclass_docu' )
->rawParams( $wgLang->listToText(
$creation_links ) )
--
To view, visit https://gerrit.wikimedia.org/r/376914
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a6f12e9a1650a1b5101bbe33a532984de40c233
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <[email protected]>
Gerrit-Reviewer: Nischayn22 <[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