[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix error in WITHIN query, due to change 374400

2017-09-20 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/379298 )

Change subject: Fix error in WITHIN query, due to change 374400
..

Fix error in WITHIN query, due to change 374400

Change-Id: I7d5bd5ab6f82e8f4a48ab626d19d7fb7e0ae7758
---
M CargoSQLQuery.php
1 file changed, 3 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/98/379298/1

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 88e89a0..daf08ff 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -1187,8 +1187,10 @@
$newWhere = " " . $fieldName . " IN " . 
$subquery;
}
 
+   $fullExpression = null;
if ( $completeMatch ) {
-   $this->substVirtualFieldName( $this->mWhereStr, 
$completeSearchPattern, $newWhere, $fieldReplaced);
+   $this->substVirtualFieldName( $this->mWhereStr, 
$completeSearchPattern, $newWhere, $fieldReplaced,
+   $fullExpression );
$this->mWhereStr = preg_replace( 
$completeSearchPattern, $newWhere, $this->mWhereStr );
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d5bd5ab6f82e8f4a48ab626d19d7fb7e0ae7758
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Adding placeholder emulation for hierarchy structure textarea

2017-09-15 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378277 )

Change subject: Adding placeholder emulation for hierarchy structure textarea
..

Adding placeholder emulation for hierarchy structure textarea

Change-Id: Ic8f39fff95fb5cd86ea4b29c405a7bb768daf243
---
M PageForms.php
M libs/PF_CreateClass.js
M specials/PF_CreateClass.php
3 files changed, 34 insertions(+), 3 deletions(-)


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

diff --git a/PageForms.php b/PageForms.php
index 9d12d22..8cef744 100644
--- a/PageForms.php
+++ b/PageForms.php
@@ -456,6 +456,9 @@
'scripts' => array(
'libs/PF_CreateClass.js',
),
+   'messages' => array(
+   'pf_createtemplate_hierarchystructureplaceholder',
+   ),
),
'ext.pageforms.PF_CreateForm' => $wgPageFormsResourceTemplate + array(
'scripts' => array(
diff --git a/libs/PF_CreateClass.js b/libs/PF_CreateClass.js
index 89fa021..9df0ca7 100644
--- a/libs/PF_CreateClass.js
+++ b/libs/PF_CreateClass.js
@@ -1,4 +1,5 @@
 var rowNum = mediaWiki.config.get( '$numStartingRows');
+var hierarchyPlaceholder = '*replace\n**placeholder\n***using\n*i18n'; 
//mediaWiki.msg( 'pf_createtemplate_hierarchystructureplaceholder' );
 function createClassAddRow() {
rowNum++;
var newRow = jQuery('#starterRow').clone().css('display', '');
@@ -42,10 +43,27 @@
if (containerElement.find( "input[name*='is_hierarchy_']" 
).prop('checked')) {
containerElement.find( "input[name*='allowed_values_']" 
).hide('medium');
containerElement.find( "textarea[name*='hierarchy_structure_']" 
).show('medium');
+   if (containerElement.find( 
"textarea[name*='hierarchy_structure_']" ).val() === "") {
+   setHierarchyPlaceholder( containerElement.find( 
"textarea[name*='hierarchy_structure_']" ) );
+   }
} else {
containerElement.find( "textarea[name*='hierarchy_structure_']" 
).hide('medium');
containerElement.find( "input[name*='allowed_values_']" 
).show('medium');
}
+}
+
+function setHierarchyPlaceholder( textareaElement ) {
+   if (textareaElement.val() === "") {
+   textareaElement.val( hierarchyPlaceholder );
+   textareaElement.css( 'color', 'gray' );
+   textareaElement.attr( 'validInput', 'false' );
+   }
+}
+
+function removeHierarchyPlaceholder( textareaElement ) {
+   textareaElement.val( '' );
+   textareaElement.css( 'color', 'black' );
+   textareaElement.attr( 'validInput', 'true' );
 }
 
 jQuery( document ).ready( function () {
@@ -61,4 +79,15 @@
jQuery( "input[name*='is_hierarchy_']" ).click( function () {
toggleHierarchyInput(jQuery( this ).closest( "tr" ));
} );
-} );
+   jQuery( "input[name*='is_hierarchy_']" ).click( function () {
+   toggleHierarchyInput(jQuery( this ).closest( "tr" ));
+   } );
+   jQuery( "textarea[name*='hierarchy_structure_']" ).blur( function () {
+   setHierarchyPlaceholder( jQuery( this ) );
+   } );
+   jQuery( "textarea[name*='hierarchy_structure_']" ).click( function () {
+   if (jQuery( this ).attr( 'validInput' ) === undefined || 
jQuery( this ).attr( 'validInput' ) !== 'true') {
+   removeHierarchyPlaceholder( jQuery( this ) );
+   }
+   } );
+} );
\ No newline at end of file
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index f52d308..93d9132 100644
--- a/specials/PF_CreateClass.php
+++ b/specials/PF_CreateClass.php
@@ -384,9 +384,8 @@

 END;
if ( defined( 'CARGO_VERSION' ) ) {
-   $hierarchyStructurePlaceholder = wfMessage( 
'pf_createtemplate_hierarchystructureplaceholder' )->escaped();
$text .= <<
+   
 END;
}
$text .= <

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Add hierarchy validation in Special:CreateClass

2017-09-09 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
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, 40 insertions(+), 1 deletion(-)


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

diff --git a/libs/PF_CreateClass.js b/libs/PF_CreateClass.js
index 89fa021..fb01a9f 100644
--- a/libs/PF_CreateClass.js
+++ b/libs/PF_CreateClass.js
@@ -48,6 +48,42 @@
}
 }
 
+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 atleast one \'*\', the entry \"" +
+   nodes[j] + "\" has " + 
matches[1].length + " '*'");
+   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 less '*'");
+   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();
@@ -61,4 +97,7 @@
jQuery( "input[name*='is_hierarchy_']" ).click( function () {
toggleHierarchyInput(jQuery( this ).closest( "tr" ));
} );
+   jQuery( '#createClassForm' ).submit( function () {
+   return validateHierarchyStructure();
+   } );
 } );
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index f52d308..0ae7485 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 = '' . "\n";
+   $text = '' . 
"\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: newchange
Gerrit-Change-Id: I1a6f12e9a1650a1b5101bbe33a532984de40c233
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Remove duplicate pages from WITHIN filter results in drilldown

2017-09-01 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375490 )

Change subject: Remove duplicate pages from WITHIN filter results in drilldown
..

Remove duplicate pages from WITHIN filter results in drilldown

Change-Id: Ia135feb7797039710aa2e809290ba62e7d07b3e7
---
M drilldown/CargoAppliedFilter.php
M drilldown/CargoFilter.php
2 files changed, 15 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/90/375490/1

diff --git a/drilldown/CargoAppliedFilter.php b/drilldown/CargoAppliedFilter.php
index 1849506..29525f5 100644
--- a/drilldown/CargoAppliedFilter.php
+++ b/drilldown/CargoAppliedFilter.php
@@ -112,11 +112,22 @@
$matches = array();
if ( preg_match( "/^~within (.+)/", $fv->text, 
$matches ) ) {
$value = $matches[1];
-   $hierarchyTableName = 
$this->filter->tableName . '__' . $this->filter->name . '__hierarchy';
+   $fieldName = $this->filter->name;
+   $fieldTableName = 
$this->filter->tableName . '__' . $fieldName;
+   $hierarchyTableName = $fieldTableName . 
'__hierarchy';
+   $fieldTableName = $cdb->tableName( 
$fieldTableName );
$hierarchyTableName = $cdb->tableName( 
$hierarchyTableName );
+
$leftCond = " $hierarchyTableName._left 
>= ( SELECT _left FROM " . $hierarchyTableName . " WHERE _value = 
'{$cdb->strencode( $value )}' ) ";
$rightCond = " 
$hierarchyTableName._right <= ( SELECT _right FROM " . $hierarchyTableName . " 
WHERE _value = '{$cdb->strencode( $value )}' ) ";
-   $sql .= "( (" . $leftCond . ") AND (" . 
$rightCond . ") )";
+   if ( 
$this->filter->fieldDescription->mIsList ) {
+   $sql .= $cdb->tableName( 
$this->filter->tableName ) .  "._ID IN
+   (SELECT 
$fieldTableName._rowID FROM $fieldTableName WHERE $fieldTableName._value IN
+   (SELECT 
$hierarchyTableName._value FROM $hierarchyTableName WHERE ($leftCond) AND 
($rightCond)))";
+   } else {
+   $sql .= $cdb->tableName( 
$this->filter->tableName ) . ".$fieldName IN
+   (SELECT 
$hierarchyTableName._value FROM $hierarchyTableName WHERE ($leftCond) AND 
($rightCond))";
+   }
}
} elseif ( $fv->is_none ) {
$checkNullOrEmptySql = ( $cdb->getType() == 
'postgres' ? '' : "$value_field = '' OR ") .
@@ -157,23 +168,13 @@
$tableNames = array();
$conds = array();
$joinConds = array();
-   $fieldTableName = $mainTableName;
-   $fieldName = $this->filter->name;
 
$conds[] = $this->checkSQL();
 
-   if ( $this->filter->fieldDescription->mIsList ) {
+   if ( $this->filter->fieldDescription->mIsList && 
!$this->filter->fieldDescription->mIsHierarchy ) {
$fieldTableName = $mainTableName . '__' . 
$this->filter->name;
-   $fieldName = '_value';
$tableNames[] = $fieldTableName;
$joinConds[$fieldTableName] = 
CargoUtils::joinOfMainAndFieldTable( $cdb, $mainTableName, $fieldTableName );
-   }
-
-   if ( $this->filter->fieldDescription->mIsHierarchy ) {
-   $hierarchyTableName = $this->filter->tableName . '__' . 
$this->filter->name . '__hierarchy';
-   $tableNames[] = $hierarchyTableName;
-   $joinConds[$hierarchyTableName] = 
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb,
-   $fieldTableName, $fieldName, 
$hierarchyTableName );
}
 
return array( $tableNames, $conds, $joinConds );
diff --git a/drilldown/CargoFilter.php b/drilldown/CargoFilter.php
index 760dc89..2bb1124 100644
--- a/drilldown/CargoFilter.php
+++ b/drilldown/CargoFilter.php
@@ -113,19 +113,10 @@
 
foreach ( $appliedFilters as $af ) {
$conds[] = $af->checkSQL();
-   $fieldTableName = $this->tableName;
-   $columnName = $af->filter->name;
-   if ( $af->filter->fieldDescription->mIsList ) {
+   if 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix duplicate page entries in case of WITHIN filter for hier...

2017-09-01 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/375487 )

Change subject: Fix duplicate page entries in case of WITHIN filter for 
hierarchy fields holding a list of values
..

Fix duplicate page entries in case of WITHIN filter for hierarchy fields 
holding a list of values

Change-Id: I36408fdb4f97becba9ef630668ffe29375adfe6d
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 7 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/87/375487/1

diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 1887990..2304aaf 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -1283,6 +1283,7 @@
$tableNames = array( $this->tableName );
$conds = array();
$joinConds = array();
+   $queryOptions = array();
 
if ( $this->fullTextSearchTerm != null ) {
list( $curTableNames, $curConds, $curJoinConds ) =
@@ -1297,6 +1298,11 @@
$tableNames = array_merge( $tableNames, $curTableNames 
);
$conds = array_merge( $conds, $curConds );
$joinConds = array_merge( $joinConds, $curJoinConds );
+   if ( $af->filter->fieldDescription->mIsHierarchy && 
$af->filter->fieldDescription->mIsList ) {
+   $hierarchyFieldTable = $this->tableName . "__" 
. $af->filter->name;
+   $queryOptions = array_merge( $queryOptions, 
array( "GROUP BY" =>
+   CargoUtils::escapedFieldName( $cdb, 
$hierarchyFieldTable, '_rowID' ) ) );
+   }
}
 
$aliasedFieldNames = array(
@@ -1333,7 +1339,7 @@
'fields' => $aliasedFieldNames,
'conds' => $conds,
'join_conds' => $joinConds,
-   'options' => array()
+   'options' => $queryOptions
);
 
return $queryInfo;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I36408fdb4f97becba9ef630668ffe29375adfe6d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Make hierarchy filters compatible for multiple filters

2017-08-28 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374388 )

Change subject: Make hierarchy filters compatible for multiple filters
..

Make hierarchy filters compatible for multiple filters

Change-Id: If1d11489ae678c72a8fb3aa2285aea2312e6125e
---
M drilldown/CargoDrilldownHierarchy.php
M drilldown/CargoSpecialDrilldown.php
2 files changed, 18 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/88/374388/1

diff --git a/drilldown/CargoDrilldownHierarchy.php 
b/drilldown/CargoDrilldownHierarchy.php
index c91a02a..9a3f4f2 100644
--- a/drilldown/CargoDrilldownHierarchy.php
+++ b/drilldown/CargoDrilldownHierarchy.php
@@ -14,37 +14,38 @@
$cdb = CargoUtils::getDB();
list( $tableNames, $conds, $joinConds ) = $f->getQueryParts( 
$fullTextSearchTerm, $appliedFilters );
if ( $f->fieldDescription->mIsList ) {
-   $countArg = "_rowID";
$fieldTableName = $f->tableName . '__' . $f->name;
+   $countColumnName = $cdb->tableName( $fieldTableName ) . 
"._rowID";
if ( !in_array( $fieldTableName, $tableNames ) ) {
$tableNames[] = $fieldTableName;
}
-   $fieldName = '_value';
+   $fieldColumnName = '_value';
if ( !array_key_exists( $fieldTableName, $joinConds ) ) 
{
$joinConds[$fieldTableName] = 
CargoUtils::joinOfMainAndFieldTable( $cdb, $f->tableName, $fieldTableName );
}
} else {
-   $countArg = "_ID";
-   $fieldName = $f->name;
+   $fieldColumnName = $f->name;
$fieldTableName = $f->tableName;
+   $countColumnName = $cdb->tableName( $fieldTableName ) . 
"._ID";
}
 
-   $countClause = "COUNT(DISTINCT($countArg)) AS total";
+   $countClause = "COUNT(DISTINCT($countColumnName)) AS total";
 
$hierarchyTableName = $f->tableName . '__' . $f->name . 
'__hierarchy';
+   $cargoHierarchyTableName = $cdb->tableName( $hierarchyTableName 
);
if ( !in_array( $hierarchyTableName, $tableNames ) ) {
$tableNames[] = $hierarchyTableName;
}
 
if ( !array_key_exists( $hierarchyTableName, $joinConds ) ) {
$joinConds[$hierarchyTableName] = 
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb,
-   $fieldTableName, $fieldName, 
$hierarchyTableName );
+   $fieldTableName, $fieldColumnName, 
$hierarchyTableName );
}
$withinTreeHierarchyConds = array();
$exactRootHierarchyConds = array();
-   $withinTreeHierarchyConds[] = "_left >= $node->mLeft";
-   $withinTreeHierarchyConds[] = "_right <= $node->mRight";
-   $exactRootHierarchyConds[] = "_left = $node->mLeft";
+   $withinTreeHierarchyConds[] = "$cargoHierarchyTableName._left 
>= $node->mLeft";
+   $withinTreeHierarchyConds[] = "$cargoHierarchyTableName._right 
<= $node->mRight";
+   $exactRootHierarchyConds[] = "$cargoHierarchyTableName._left = 
$node->mLeft";
// within hierarchy tree value count
$res = $cdb->select( $tableNames, array( $countClause ), 
array_merge( $conds, $withinTreeHierarchyConds ),
null, null, $joinConds );
diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 1887990..4137ebe 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -491,7 +491,13 @@
 
function printAppliedFilterLineForHierarchy( $af ) {
$applied_filters = $this->applied_filters;
-   $cur_url = $this->makeBrowseURL( $this->tableName, 
$this->fullTextSearchTerm, array() );
+   $applied_filters_no_hierarchy = array();
+   foreach( $applied_filters as $key => $af2 ) {
+   if ( !$af2->filter->fieldDescription->mIsHierarchy ) {
+   $applied_filters_no_hierarchy[] = $af2;
+   }
+   }
+   $cur_url = $this->makeBrowseURL( $this->tableName, 
$this->fullTextSearchTerm, $applied_filters_no_hierarchy );
$cur_url .= ( strpos( $cur_url, '?' ) ) ? '&' : '?';
// Drilldown for hierarchy is designed for literal 'drilldown'
// Therefore it has single filter value applied at anytime
@@ -581,7 +587,7 @@
if ( count( $node->mChildren ) > 0 && 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Allow any number of spaces after * in hierarchy structure

2017-08-28 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/374205 )

Change subject: Allow any number of spaces after * in hierarchy structure
..

Allow any number of spaces after * in hierarchy structure

Change-Id: Ibe261b5cc47108cdf7d095856802e545de09e6d1
---
M CargoFieldDescription.php
M CargoUtils.php
2 files changed, 1 insertion(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/05/374205/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 5d261e7..5eb0626 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -80,7 +80,7 @@
$hierarchyNodesArray = explode( "\n", 
$allowedValuesParam );
foreach ( $hierarchyNodesArray as $node 
) {
// Remove prefix of multiple "*"
-   $allowedValuesArray[] = 
preg_replace( '/^[*]* ?/', '', $node );
+   $allowedValuesArray[] = 
preg_replace( '/^[*]* */', '', $node );
}
} else {
// Replace the comma/delimiter
diff --git a/CargoUtils.php b/CargoUtils.php
index a793dd1..08d6ba2 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -968,9 +968,6 @@
if ( strlen( $matches[3] ) == 0 ) {
throw new MWException( "Error: The entry of 
hierarchy values cannot be empty." );
}
-   if ( strlen( $matches[2] ) > 1 ) {
-   throw new MWException( "Error: Single or no 
space should follow after '*'. \"" . $node . "\" needs correction." );
-   }
}
}
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe261b5cc47108cdf7d095856802e545de09e6d1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix redundant results for within drilldown filter

2017-08-25 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373947 )

Change subject: Fix redundant results for within drilldown filter
..

Fix redundant results for within drilldown filter

Change-Id: I71bbd91947c1bc674e9d5411542a34bdae0907f5
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/47/373947/1

diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 414c940..787a397 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -1294,7 +1294,7 @@
}
 
$aliasedFieldNames = array(
-   'title' => CargoUtils::escapedFieldName( $cdb, 
$this->tableName, '_pageName' ),
+   'title' => "DISTINCT(" . CargoUtils::escapedFieldName( 
$cdb, $this->tableName, '_pageName' ) . ")",
'value' => CargoUtils::escapedFieldName( $cdb, 
$this->tableName, '_pageName' ),
'namespace' => CargoUtils::escapedFieldName( $cdb, 
$this->tableName, '_pageNamespace' ),
'ID' => CargoUtils::escapedFieldName( $cdb, 
$this->tableName, '_pageID' )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I71bbd91947c1bc674e9d5411542a34bdae0907f5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Make hierarchy additional parameter order insensitive

2017-08-24 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373600 )

Change subject: Make hierarchy additional parameter order insensitive
..

Make hierarchy additional parameter order insensitive

Change-Id: I0e54dc07804523f3ffc8c58f8a7674a7dfe884a8
---
M CargoFieldDescription.php
1 file changed, 40 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/00/373600/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index acf356c..ee58916 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -42,6 +42,7 @@
// There may be additional parameters, in/ parentheses.
$matches = array();
$foundMatch2 = preg_match( '/([^(]*)\s*\((.*)\)/s', 
$fieldDescriptionStr, $matches );
+   $allowedValuesParam = "";
if ( $foundMatch2 ) {
$fieldDescriptionStr = trim( $matches[1] );
$extraParamsString = $matches[2];
@@ -58,41 +59,7 @@
$paramKey = trim( $extraParamParts[0] );
$paramValue = trim( $extraParamParts[1] 
);
if ( $paramKey == 'allowed values' ) {
-   // Replace the comma/delimiter
-   // substitution with a character
-   // that has no chance of being
-   // included in the values list -
-   // namely, the ASCII beep.
-
-   // The delimiter can't be a
-   // semicolon, because that's
-   // already used to separate
-   // "extra parameters", so just
-   // hardcode it to a semicolon.
-   $allowedValuesArray = array();
-   if( 
$fieldDescription->mIsHierarchy == true ) {
-   // $paramValue contains 
"*" hierarchy structure
-   
CargoUtils::validateHierarchyStructure( trim( $paramValue ) );
-   
$fieldDescription->mHierarchyStructure = trim( $paramValue );
-   // now make the allowed 
values param similar to the syntax
-   // used by other fields
-   $hierarchyNodesArray = 
explode( "\n", $paramValue );
-   foreach ( 
$hierarchyNodesArray as $node ) {
-   // Remove 
prefix of multiple "*"
-   
$allowedValuesArray[] = preg_replace( '/^[*]* ?/', '', $node );
-   }
-   } else {
-   $delimiter = ',';
-   $allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
-   $allowedValuesTempArray 
= explode( $delimiter, $allowedValuesStr );
-   foreach ( 
$allowedValuesTempArray as $i => $value ) {
-   if ( $value == 
'' ) continue;
-   // Replace beep 
back with delimiter, trim.
-   $value = 
str_replace( "\a", $delimiter, trim( $value ) );
-   
$allowedValuesArray[] = $value;
-   }
-   }
-   
$fieldDescription->mAllowedValues = $allowedValuesArray;
+$allowedValuesParam = $paramValue;
} elseif ( $paramKey == 'size' ) {
$fieldDescription->mSize = 
$paramValue;
} else {
@@ -100,6 +67,44 @@
}
}
}
+   if ( $allowedValuesParam !== "" ) {
+$allowedValuesArray 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix error in CargoDeleteTable.php due to fieldHelperTables

2017-08-21 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372885 )

Change subject: Fix error in CargoDeleteTable.php due to fieldHelperTables
..

Fix error in CargoDeleteTable.php due to fieldHelperTables

Change-Id: I487e39ac4b615024a4dedf8f8e47c64e8855d6ee
---
M specials/CargoDeleteTable.php
1 file changed, 5 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/85/372885/1

diff --git a/specials/CargoDeleteTable.php b/specials/CargoDeleteTable.php
index 1aff877..22965e3 100644
--- a/specials/CargoDeleteTable.php
+++ b/specials/CargoDeleteTable.php
@@ -31,15 +31,17 @@
 * Also, records need to be removed from the cargo_tables and
 * cargo_pages tables.
 */
-   public static function deleteTable( $mainTable, $fieldTables, 
$fieldHelperTables = array() ) {
+   public static function deleteTable( $mainTable, $fieldTables, 
$fieldHelperTables ) {
$cdb = CargoUtils::getDB();
try {
$cdb->dropTable( $mainTable );
foreach ( $fieldTables as $fieldTable ) {
$cdb->dropTable( $fieldTable );
}
-   foreach ( $fieldHelperTables as $fieldHelperTable ) {
-   $cdb->dropTable( $fieldHelperTable );
+   if ( is_array( $fieldHelperTables ) ) {
+   foreach ( $fieldHelperTables as 
$fieldHelperTable ) {
+   $cdb->dropTable( $fieldHelperTable );
+   }
}
} catch ( Exception $e ) {
throw new MWException( "Caught exception ($e) while 
trying to drop Cargo table. "

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I487e39ac4b615024a4dedf8f8e47c64e8855d6ee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Perform literal "drilldown" in the applied filter line for h...

2017-08-18 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372563 )

Change subject: Perform literal "drilldown" in the applied filter line for 
hierarchy field in case of within filter.
..

Perform literal "drilldown" in the applied filter line for hierarchy field in 
case of within filter.

Change-Id: I4eff3f1660538cb75930123543940192e62b24ba
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 41 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/63/372563/1

diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index f7ff850..8df5003 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -413,6 +413,9 @@
 * at least one value set
 */
function printAppliedFilterLine( $af ) {
+   if ( $af->filter->fieldDescription->mIsHierarchy ) {
+   return $this->printAppliedFilterLineForHierarchy( $af );
+   }
$results_line = "";
$current_filter_values = array();
foreach ( $this->applied_filters as $af2 ) {
@@ -486,6 +489,36 @@
return $this->printFilterLine( $af->filter->name, true, true, 
$results_line );
}
 
+   function printAppliedFilterLineForHierarchy( $af ) {
+   $applied_filters = $this->applied_filters;
+   $cur_url = $this->makeBrowseURL( $this->tableName, 
$this->fullTextSearchTerm, array() );
+   $cur_url .= ( strpos( $cur_url, '?' ) ) ? '&' : '?';
+   // Drilldown for hierarchy is designed for literal 'drilldown' 
and focuses on single filter value in case of 'within'
+   if ( count($af->values) > 0 ) {
+   $filter_value = $af->values[0]->text;
+   $matches = array();
+   if ( preg_match( "/^~within (.+)/", $filter_value, 
$matches ) ) {
+   $filter_value = $matches[1];
+   }
+   }
+   $drilldownHierarchyRoot = 
CargoDrilldownHierarchy::newFromWikiText( 
$af->filter->fieldDescription->mHierarchyStructure );
+   $stack = new SplStack();
+   // preorder traversal of the tree
+   $stack->push( $drilldownHierarchyRoot );
+   while ( !$stack->isEmpty() ) {
+   $node = $stack->pop();
+   if ( $node->mRootValue === $filter_value ) {
+   $drilldownHierarchyRoot = $node;
+   break;
+   }
+   for( $i = count( $node->mChildren ) - 1; $i >= 0; $i-- 
) {
+   $stack->push( $node->mChildren[$i] );
+   }
+   }
+   $results_line = $this->printFilterValuesForHierarchy( $cur_url, 
$af->filter, null, $applied_filters, $drilldownHierarchyRoot );
+   return $this->printFilterLine( $af->filter->name, true, true, 
$results_line );
+   }
+
function printUnappliedFilterValues( $cur_url, $f, $filter_values ) {
$results_line = "";
// now print the values
@@ -502,16 +535,20 @@
}
 
function printUnappliedFilterValuesForHierarchy( $cur_url, $f, 
$fullTextSearchTerm, $applied_filters ) {
-   $results_line = "";
// construct the tree of CargoDrilldownHierarchy
-   $drilldownHierarchyTreeRoot = 
CargoDrilldownHierarchy::newFromWikiText( 
$f->fieldDescription->mHierarchyStructure );
+   $drilldownHierarchyRoot = 
CargoDrilldownHierarchy::newFromWikiText( 
$f->fieldDescription->mHierarchyStructure );
+   return $this->printFilterValuesForHierarchy( $cur_url, $f, 
$fullTextSearchTerm, $applied_filters, $drilldownHierarchyRoot );
+   }
+
+   function printFilterValuesForHierarchy( $cur_url, $f, 
$fullTextSearchTerm, $applied_filters, $drilldownHierarchyRoot ) {
// compute counts
-   $filter_values = 
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( 
$drilldownHierarchyTreeRoot,
+   $filter_values = 
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( 
$drilldownHierarchyRoot,
$f, $fullTextSearchTerm, $applied_filters );
+   $results_line = "";
$num_printed_values = 0;
$stack = new SplStack();
// preorder traversal of the tree
-   $stack->push( $drilldownHierarchyTreeRoot );
+   $stack->push( $drilldownHierarchyRoot );
while ( !$stack->isEmpty() ) {
$node = $stack->pop();
if ( $node != ")" ) {

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

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix: Within filter not being applied with other filters

2017-08-18 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372526 )

Change subject: Fix: Within filter not being applied with other filters
..

Fix: Within filter not being applied with other filters

Change-Id: Icc5573dc9c5ce5bea4b139382e5de78b35175a51
---
M drilldown/CargoAppliedFilter.php
M drilldown/CargoSpecialDrilldown.php
2 files changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/26/372526/1

diff --git a/drilldown/CargoAppliedFilter.php b/drilldown/CargoAppliedFilter.php
index 0af3cd5..1849506 100644
--- a/drilldown/CargoAppliedFilter.php
+++ b/drilldown/CargoAppliedFilter.php
@@ -117,7 +117,6 @@
$leftCond = " $hierarchyTableName._left 
>= ( SELECT _left FROM " . $hierarchyTableName . " WHERE _value = 
'{$cdb->strencode( $value )}' ) ";
$rightCond = " 
$hierarchyTableName._right <= ( SELECT _right FROM " . $hierarchyTableName . " 
WHERE _value = '{$cdb->strencode( $value )}' ) ";
$sql .= "( (" . $leftCond . ") AND (" . 
$rightCond . ") )";
-   $fv->text = wfMessage( 
'cargo-drilldown-hierarchy-within', $value )->parse();
}
} elseif ( $fv->is_none ) {
$checkNullOrEmptySql = ( $cdb->getType() == 
'postgres' ? '' : "$value_field = '' OR ") .
diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index b89561a..f7ff850 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -399,6 +399,10 @@
} else {
return $this->msg( 'htmlform-no' )->text();
}
+   } elseif ( $filter->fieldDescription->mIsHierarchy && 
preg_match( "/^~within (.+)/", $value ) ) {
+   $matches = array();
+   preg_match( "/^~within (.+)/", $value, $matches );
+   return wfMessage( 'cargo-drilldown-hierarchy-within', 
$matches[1] )->parse();
} else {
return $value;
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icc5573dc9c5ce5bea4b139382e5de78b35175a51
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Add feature to collapse deeper levels of hierarchy to show m...

2017-08-17 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372232 )

Change subject: Add feature to collapse deeper levels of hierarchy to show 
maximum of  nodes
..

Add feature to collapse deeper levels of hierarchy to show maximum of  nodes

Change-Id: Iabed8a2d18d3a34cc07f43ecfdcbaf9569272d1e
---
M drilldown/CargoDrilldownHierarchy.php
M drilldown/CargoSpecialDrilldown.php
2 files changed, 55 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/32/372232/1

diff --git a/drilldown/CargoDrilldownHierarchy.php 
b/drilldown/CargoDrilldownHierarchy.php
index 07f889b..9b384d0 100644
--- a/drilldown/CargoDrilldownHierarchy.php
+++ b/drilldown/CargoDrilldownHierarchy.php
@@ -64,9 +64,9 @@
$stack->push( $node );
while ( !$stack->isEmpty() ) {
$node = $stack->pop();
+   CargoDrilldownHierarchy::computeNodeCountByFilter( 
$node, $f, $fullTextSearchTerm, $appliedFilters );
if ( $node->mLeft !== 1 ) {
// check if its not __pseudo_root__ node, then 
only add count
-   
CargoDrilldownHierarchy::computeNodeCountByFilter( $node, $f, 
$fullTextSearchTerm, $appliedFilters );
$filter_values[$node->mRootValue] = 
$node->mWithinTreeMatchCount;
}
if ( count( $node->mChildren ) > 0 ) {
@@ -80,4 +80,43 @@
}
return $filter_values;
}
+
+   /*
+   * Finds maximum permissible depth for listing nodes in Drilldown such 
that total nodes appearing on the Filter line
+   * is less than or equal to $wgCargoMaxHierarchyDrilldownValues
+   */
+   static function findMaxDrilldownDepth( $node ) {
+   global $wgCargoMaxHierarchyDrilldownValues;
+   if ( !isset( $wgCargoMaxHierarchyDrilldownValues ) ) {
+   return PHP_INT_MAX;
+   }
+   $maxDepth = 0;
+   $nodeCount = 0;
+   $queue = new SplQueue();
+   $queue->enqueue( $node );
+   $queue->enqueue( null );
+   while ( !$queue->isEmpty() ) {
+   $node = $queue->dequeue();
+   if ( $node == null ) {
+   if ( !$queue->isEmpty() ) {
+   if ( $flag != 0 ) {
+   $maxDepth++;
+   }
+   $queue->enqueue( null );
+   }
+   } else {
+   foreach ( $node->mChildren as $child ) {
+   if ( $child->mWithinTreeMatchCount > 0 
) {
+   if ( $nodeCount >= 
$wgCargoMaxHierarchyDrilldownValues ) {
+   break(2);
+   }
+   $queue->enqueue( $child );
+   $nodeCount++;
+   $flag = 1;
+   }
+   }
+   }
+   }
+   return max(1, $maxDepth);
+   }
 }
\ No newline at end of file
diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index b89561a..775620a 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -504,6 +504,8 @@
// compute counts
$filter_values = 
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( 
$drilldownHierarchyTreeRoot,
$f, $fullTextSearchTerm, $applied_filters );
+   $maxDepth = CargoDrilldownHierarchy::findMaxDrilldownDepth( 
$drilldownHierarchyTreeRoot );
+   $depth = 0;
$num_printed_values = 0;
$stack = new SplStack();
// preorder traversal of the tree
@@ -511,7 +513,7 @@
while ( !$stack->isEmpty() ) {
$node = $stack->pop();
if ( $node != ")" ) {
-   if ( $node->mLeft !== 1 ) {
+   if ( $node->mLeft !== 1 && 
$node->mWithinTreeMatchCount > 0 ) {
// check if its not __pseudo_root__ 
node, then only print
if ( $num_printed_values++ > 0 ) {
$results_line .= " ยท ";
@@ -523,24 +525,26 @@
$results_line .= 
$this->printFilterValueLink( $f, 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Add validation for hierarchy input

2017-08-15 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/372082 )

Change subject: Add validation for hierarchy input
..

Add validation for hierarchy input

Change-Id: I24fe67be0469dd628ddfd3d68960285bf1b6fe4d
---
M CargoFieldDescription.php
M CargoUtils.php
2 files changed, 33 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/82/372082/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 6c78859..9fff7d0 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -71,6 +71,7 @@
// hardcode it to a semicolon.
if( 
$fieldDescription->mIsHierarchy == true ) {
// $paramValue contains 
"*" hierarchy structure
+   
CargoUtils::validateHierarchyStructure( trim( $paramValue ) );

$fieldDescription->mHierarchyStructure = trim( $paramValue );
// now make the allowed 
values param similar to the syntax
// used by other fields
@@ -78,7 +79,7 @@
$allowedValuesArray = 
array();
foreach ( 
$hierarchyNodesArray as $node ) {
// Remove 
prefix of multiple "*"
-   
$allowedValuesArray[] = preg_replace( '/^[*]*/', '', $node );
+   
$allowedValuesArray[] = preg_replace( '/^[*]* ?/', '', $node );
}
} else {
$delimiter = ',';
diff --git a/CargoUtils.php b/CargoUtils.php
index a1686be..c72ce24 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -942,4 +942,35 @@
}
}
 
+   public static function validateHierarchyStructure( $hierarchyStructure 
) {
+   $hierarchyNodesArray = explode( "\n", $hierarchyStructure );
+   $matches = array();
+   preg_match( '/^([*]*)[^*]*/i', $hierarchyNodesArray[0], 
$matches );
+   if ( strlen( $matches[1] ) != 1 ) {
+   throw new MWException( "Error: First entry of hierarchy 
values should start with exact one '*', the entry \"" .
+   $hierarchyNodesArray[0] . "\" has " . strlen( 
$matches[1] ) . " '*'" );
+   }
+   $level = 0;
+   foreach( $hierarchyNodesArray as $node ) {
+   if ( !preg_match( '/^([*]*)( *)(.*)/i', $node, $matches 
) ) {
+   throw new MWException( "Error: The \"" . $node 
. "\" entry of hierarchy values does not follow syntax. " .
+   "The entry should be of the form : * 
entry" );
+   }
+   if ( strlen( $matches[1] ) < 1 ) {
+   throw new MWException( "Error: Each entry of 
hierarchy values should start with atleast one '*', the entry \"" .
+   $node . "\" has " . strlen( $matches[1] 
) . " '*'" );
+   }
+   if ( strlen( $matches[1] ) - $level > 1 ) {
+   throw new MWException( "Error: Level or count 
of '*' in hierarchy values should be increased only by count of 1, the entry 
\"" .
+   $node . "\" should have " . ( $level + 
1 ) . " or less '*'" );
+   }
+   $level = strlen( $matches[1] );
+   if ( strlen( $matches[3] ) == 0 ) {
+   throw new MWException( "Error: The entry of 
hierarchy values cannot be empty." );
+   }
+   if ( strlen( $matches[2] ) > 1 ) {
+   throw new MWException( "Error: Single or no 
space should follow after '*'. \"" . $node . "\" needs correction." );
+   }
+   }
+   }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24fe67be0469dd628ddfd3d68960285bf1b6fe4d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org

[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Add hierarchy field creation in Special:CreateClass

2017-08-11 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371583 )

Change subject: Add hierarchy field creation in Special:CreateClass
..

Add hierarchy field creation in Special:CreateClass

Change-Id: I8eea2ff62b6382b29323d5b39e0dbdbb2a5fde95
---
M libs/PF_CreateClass.js
M specials/PF_CreateClass.php
2 files changed, 33 insertions(+), 3 deletions(-)


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

diff --git a/libs/PF_CreateClass.js b/libs/PF_CreateClass.js
index 44e5fe7..be1428b 100644
--- a/libs/PF_CreateClass.js
+++ b/libs/PF_CreateClass.js
@@ -27,9 +27,24 @@
if (jQuery('#use_cargo').prop('checked')) {
jQuery('#cargo_table_input').show('medium');
$('td:nth-child(4),th:nth-child(3)').show('medium');
+   $('.hierarchy_structure_input').show('medium');
} else {
jQuery('#cargo_table_input').hide('medium');
$('td:nth-child(4),th:nth-child(3)').hide('medium');
+   $('.hierarchy_structure_input').hide('medium');
+   $("textarea[name*='hierarchy_structure_']").hide('medium');
+   $("input[name*='allowed_values_']").show('medium');
+   $('.isHierarchy').prop('checked', false);
+   }
+}
+
+function toggleHierarchyInput(containerElement) {
+   if (containerElement.find( "input[name*='is_hierarchy_']" 
).prop('checked')) {
+   containerElement.find( "input[name*='allowed_values_']" 
).hide('medium');
+   containerElement.find( "textarea[name*='hierarchy_structure_']" 
).show('medium');
+   } else {
+   containerElement.find( "textarea[name*='hierarchy_structure_']" 
).hide('medium');
+   containerElement.find( "input[name*='allowed_values_']" 
).show('medium');
}
 }
 
@@ -43,4 +58,7 @@
jQuery( ".createClassAddRow" ).click( function () {
createClassAddRow();
} );
+   jQuery( ".isHierarchy" ).click( function () {
+   toggleHierarchyInput(jQuery( this ).closest( "td" ));
+   } );
 } );
diff --git a/specials/PF_CreateClass.php b/specials/PF_CreateClass.php
index 65130a9..e3e6f6c 100644
--- a/specials/PF_CreateClass.php
+++ b/specials/PF_CreateClass.php
@@ -59,6 +59,7 @@
$property_type = $req->getVal( "property_type_$i" );
$allowed_values = $req->getVal( "allowed_values_$i" );
$is_list = $req->getCheck( "is_list_$i" );
+   $is_hierarchy = $req->getCheck( "is_hierarchy_$i" );
// Create an PFTemplateField object based on these
// values, and add it to the $fields array.
$field = PFTemplateField::create( $field_name, 
$field_name, $property_name, $is_list );
@@ -67,7 +68,11 @@
// Hopefully it's safe to use a Cargo
// utility method here.
$possibleValues = CargoUtils::smartSplit( ',', 
$allowed_values );
-   $field->setPossibleValues( $possibleValues );
+   if ( $is_hierarchy ) {
+   $field->setHierarchyStructure( 
$req->getVal( 'hierarchy_structure_' . $i ) );
+   } else {
+   $field->setPossibleValues( 
$possibleValues );
+   }
if ( $use_cargo ) {
$field->setFieldType( $property_type );
$field->setPossibleValues( 
$possibleValues );
@@ -362,10 +367,17 @@
}
$text .= "\t\t\t\t" . Html::rawElement( 
'select', array( 'name' => "property_type_$n" ), $typeDropdownBody ) . "\n";
}
+   $isHierarchyLabel = wfMessage( 
'pf_createtemplate_fieldishierarchy' )->escaped();
+   $hierarchyStructurePlaceholder = wfMessage( 
'pf_createtemplate_hierarchystructureplaceholder' )->escaped();
$text .= <<
-   
-
+   
+   
+   
+   
+   
+   $isHierarchyLabel
+   
 END;
}
$text .= <

___
MediaWiki-commits 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix: No comma escaping for hierarchy structure input

2017-08-11 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371574 )

Change subject: Fix: No comma escaping for hierarchy structure input
..

Fix: No comma escaping for hierarchy structure input

Change-Id: Ifbaaade0706ad5a6a008502ade782fcc6db58b50
---
M CargoFieldDescription.php
1 file changed, 9 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/74/371574/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 6c78859..23b0646 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -69,13 +69,13 @@
// already used to separate
// "extra parameters", so just
// hardcode it to a semicolon.
+   $allowedValuesArray = array();
if( 
$fieldDescription->mIsHierarchy == true ) {
// $paramValue contains 
"*" hierarchy structure

$fieldDescription->mHierarchyStructure = trim( $paramValue );
// now make the allowed 
values param similar to the syntax
// used by other fields
$hierarchyNodesArray = 
explode( "\n", $paramValue );
-   $allowedValuesArray = 
array();
foreach ( 
$hierarchyNodesArray as $node ) {
// Remove 
prefix of multiple "*"

$allowedValuesArray[] = preg_replace( '/^[*]*/', '', $node );
@@ -83,14 +83,15 @@
} else {
$delimiter = ',';
$allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
-   $allowedValuesArray = 
explode( $delimiter, $allowedValuesStr );
+   $allowedValuesTempArray 
= explode( $delimiter, $allowedValuesStr );
+   foreach ( 
$allowedValuesTempArray as $i => $value ) {
+   if ( $value == 
'' ) continue;
+   // Replace beep 
back with delimiter, trim.
+   $value = 
str_replace( "\a", $delimiter, trim( $value ) );
+   
$allowedValuesArray[] = $value;
+   }
}
-   foreach ( $allowedValuesArray 
as $i => $value ) {
-   if ( $value == '' ) 
continue;
-   // Replace beep back 
with delimiter, trim.
-   $value = str_replace( 
"\a", $delimiter, trim( $value ) );
-   
$fieldDescription->mAllowedValues[] = $value;
-   }
+   
$fieldDescription->mAllowedValues = $allowedValuesArray;
} elseif ( $paramKey == 'size' ) {
$fieldDescription->mSize = 
$paramValue;
} else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifbaaade0706ad5a6a008502ade782fcc6db58b50
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix : No comma escaping for hierarchy structure

2017-08-11 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371512 )

Change subject: Fix : No comma escaping for hierarchy structure
..

Fix : No comma escaping for hierarchy structure

Change-Id: I94210eddb59de4a4da80fae5a2e8eaad3fb889eb
---
M CargoFieldDescription.php
1 file changed, 4 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/12/371512/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 8c22c58..6c78859 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -80,11 +80,11 @@
// Remove 
prefix of multiple "*"

$allowedValuesArray[] = preg_replace( '/^[*]*/', '', $node );
}
-   $paramValue = implode( 
',', $allowedValuesArray );
+   } else {
+   $delimiter = ',';
+   $allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
+   $allowedValuesArray = 
explode( $delimiter, $allowedValuesStr );
}
-   $delimiter = ',';
-   $allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
-   $allowedValuesArray = explode( 
$delimiter, $allowedValuesStr );
foreach ( $allowedValuesArray 
as $i => $value ) {
if ( $value == '' ) 
continue;
// Replace beep back 
with delimiter, trim.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I94210eddb59de4a4da80fae5a2e8eaad3fb889eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Rename CargoHierarchy.php and its class variable

2017-08-10 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371206 )

Change subject: Rename CargoHierarchy.php and its class variable
..

Rename CargoHierarchy.php and its class variable

Change-Id: Iff9694bcc519851ee696e1881aa5bc07f792850c
---
M Cargo.php
R CargoHierarchyTree.php
M CargoUtils.php
M drilldown/CargoDrilldownHierarchy.php
M drilldown/CargoSpecialDrilldown.php
M extension.json
6 files changed, 16 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/06/371206/1

diff --git a/Cargo.php b/Cargo.php
index 35fe54f..e5e5508 100644
--- a/Cargo.php
+++ b/Cargo.php
@@ -82,7 +82,7 @@
 $wgAutoloadClasses['CargoUtils'] = $dir . '/CargoUtils.php';
 $wgAutoloadClasses['CargoFieldDescription'] = $dir . 
'/CargoFieldDescription.php';
 $wgAutoloadClasses['CargoTableSchema'] = $dir . '/CargoTableSchema.php';
-$wgAutoloadClasses['CargoHierarchy'] = $dir . '/CargoHierarchy.php';
+$wgAutoloadClasses['CargoHierarchyTree'] = $dir . '/CargoHierarchyTree.php';
 $wgAutoloadClasses['CargoDeclare'] = $dir . 
'/parserfunctions/CargoDeclare.php';
 $wgAutoloadClasses['CargoAttach'] = $dir . '/parserfunctions/CargoAttach.php';
 $wgAutoloadClasses['CargoStore'] = $dir . '/parserfunctions/CargoStore.php';
diff --git a/CargoHierarchy.php b/CargoHierarchyTree.php
similarity index 90%
rename from CargoHierarchy.php
rename to CargoHierarchyTree.php
index 18caaf8..3eec753 100644
--- a/CargoHierarchy.php
+++ b/CargoHierarchyTree.php
@@ -1,20 +1,20 @@
 mTitle = $curTitle;
+   $this->mRootValue = $curTitle;
$this->mChildren = array();
}
 
@@ -62,7 +62,7 @@
while ( !$stack->isEmpty() ) {
$node = $stack->pop();
$row = array();
-   $row['_value'] = $node->mTitle;
+   $row['_value'] = $node->mRootValue;
$row['_left'] = $node->mLeft;
$row['_right'] = $node->mRight;
$tableData[] = $row;
diff --git a/CargoUtils.php b/CargoUtils.php
index a1686be..d8628a4 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -732,7 +732,7 @@
$cdb->query( $createIndexSQL );
$fieldHelperTableNames[] = 
$fieldHelperTableName;
// Insert hierarchy information in the 
__hierarchy table
-   $hierarchyTree = 
CargoHierarchy::newFromWikiText( $fieldDescription->mHierarchyStructure );
+   $hierarchyTree = 
CargoHierarchyTree::newFromWikiText( $fieldDescription->mHierarchyStructure );
$hierarchyStructureTableData = 
$hierarchyTree->generateHierarchyStructureTableData();
foreach( $hierarchyStructureTableData as $entry 
) {
$cdb->insert( $fieldHelperTableName, 
$entry );
diff --git a/drilldown/CargoDrilldownHierarchy.php 
b/drilldown/CargoDrilldownHierarchy.php
index 42598a0..07f889b 100644
--- a/drilldown/CargoDrilldownHierarchy.php
+++ b/drilldown/CargoDrilldownHierarchy.php
@@ -6,7 +6,7 @@
  * @ingroup Cargo
  */
 
-class CargoDrilldownHierarchy extends CargoHierarchy {
+class CargoDrilldownHierarchy extends CargoHierarchyTree {
public $mWithinTreeMatchCount = 0;
public $mExactRootMatchCount = 0;
 
@@ -67,11 +67,11 @@
if ( $node->mLeft !== 1 ) {
// check if its not __pseudo_root__ node, then 
only add count

CargoDrilldownHierarchy::computeNodeCountByFilter( $node, $f, 
$fullTextSearchTerm, $appliedFilters );
-   $filter_values[$node->mTitle] = 
$node->mWithinTreeMatchCount;
+   $filter_values[$node->mRootValue] = 
$node->mWithinTreeMatchCount;
}
if ( count( $node->mChildren ) > 0 ) {
if ( $node->mLeft !== 1 ) {
-   $filter_values[$node->mTitle . " only"] 
= $node->mWithinTreeMatchCount;
+   $filter_values[$node->mRootValue . " 
only"] = $node->mWithinTreeMatchCount;
}
for ( $i = count( $node->mChildren ) - 1; $i >= 
0; $i-- ) {
$stack->push( $node->mChildren[$i] );
diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 7f7e062..b89561a 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -499,7 +499,7 @@
 
function printUnappliedFilterValuesForHierarchy( $cur_url, $f, 
$fullTextSearchTerm, $applied_filters ) {
$results_line = "";
-   // 

[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Work in Progress : Add hierarchy field creation in create te...

2017-08-10 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371160 )

Change subject: Work in Progress : Add hierarchy field creation in create 
template
..

Work in Progress : Add hierarchy field creation in create template

Change-Id: Icdac918b41d0456b720617f85b385a5c166ee4d9
---
M i18n/en.json
M i18n/qqq.json
M libs/PF_CreateTemplate.js
M specials/PF_CreateTemplate.php
4 files changed, 33 insertions(+), 3 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index 19f67e3..42f77cb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -51,6 +51,8 @@
"pf_createtemplate_displaylabel": "Display label:",
"pf_createtemplate_semanticproperty": "Semantic property:",
"pf_createtemplate_fieldislist": "Field holds a list of values",
+   "pf_createtemplate_fieldishierarchy": "Field holds hierarchy value(s)",
+   "pf_createtemplate_hierarchystructureplaceholder": 
"*Asia\n**India\n***New Delhi\n**China\n***Beijing\n*North America\n**United 
States\n***Washington\n",
"pf_createtemplate_delimiter": "Delimiter:",
"pf_createtemplate_aggregation": "Aggregation",
"pf_createtemplate_aggregationdesc": "To list, on any page using this 
template, all of the pages that have a certain property pointing to that page, 
specify the appropriate property below:",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ed55b48..6d43040 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -67,6 +67,8 @@
"pf_createtemplate_displaylabel": "The term for the text that shows up 
next to a field when it is displayed",
"pf_createtemplate_semanticproperty": "Used as label for the \"Property 
name\" select box.",
"pf_createtemplate_fieldislist": "Used as label for the checkbox.",
+   "pf_createtemplate_fieldishierarchy": "Used as label for the checkbox.",
+   "pf_createtemplate_hierarchystructureplaceholder": "Placeholder for 
hierarchy structure as allowed values",
"pf_createtemplate_delimiter": "Used as label for the input to set a 
list delimiter.\n{{Identical|Delimiter}}",
"pf_createtemplate_aggregation": "Used as fieldset label.\n\nFollowed 
by the following description:\n* {{msg-mw|pf createtemplate aggregationdesc}}",
"pf_createtemplate_aggregationdesc": "Used as description in the 
form.\n\nPreceded by the fieldset label {{msg-mw|pf createtemplate 
aggregation}}.",
diff --git a/libs/PF_CreateTemplate.js b/libs/PF_CreateTemplate.js
index cab466d..7f198b8 100644
--- a/libs/PF_CreateTemplate.js
+++ b/libs/PF_CreateTemplate.js
@@ -26,6 +26,10 @@
newField.find( ".isList" ).click( function () {
jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
} );
+   newField.find( ".isHierarchy" ).click( function () {
+   jQuery( this ).closest( ".fieldBox" ).find( 
".allowed_values_input" ).toggle();
+   jQuery( this ).closest( ".fieldBox" ).find( 
".hierarchy_structure_input" ).toggle();
+   } );
var combobox = new pf.select2.combobox();
combobox.apply( $( newField.find( '.pfComboBox' ) ) );
jQuery( '#fieldsList' ).append( newField );
@@ -66,6 +70,10 @@
jQuery( ".isList" ).click( function () {
jQuery( this ).closest( ".fieldBox" ).find( ".delimiter" 
).toggle();
} );
+   jQuery( ".isHierarchy" ).click( function () {
+   jQuery( this ).closest( ".fieldBox" ).find( 
".allowed_values_input" ).toggle();
+   jQuery( this ).closest( ".fieldBox" ).find( 
".hierarchy_structure_input" ).toggle();
+   } );
jQuery( '#createTemplateForm' ).submit( function () {
return validateCreateTemplateForm();
} );
diff --git a/specials/PF_CreateTemplate.php b/specials/PF_CreateTemplate.php
index 0ba2cce..b19b635 100644
--- a/specials/PF_CreateTemplate.php
+++ b/specials/PF_CreateTemplate.php
@@ -121,9 +121,19 @@
$text .= "\t\n";
if ( !defined( 'SMW_VERSION' ) && defined( 'CARGO_VERSION' ) ) {
$text .= "\t\n";
+   $text .= " " . wfMessage( 
'pf_createtemplate_fieldishierarchy' )->escaped() . 
"\n";
+   $text .= "\t\n";
+
+   $text .= "\t\n";
$text .= "\t" . 
wfMessage( 'pf_createproperty_allowedvalsinput' )->escaped();
$text .= Html::input( 'allowed_values_' . $id, null, 
'text',
array( 'size' => '80' ) ) . "\n";
+   $text .= "\t\n";
+
+   $text .= "\t\n";
+   $text .= "\t" . wfMessage( 'pf_createproperty_allowedvalsinput' 
)->escaped();
+   $text .= Html::textarea( 'hierarchy_structure_' . $id, 
null,
+   

[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Fix cargo table name blank validation error

2017-08-07 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370552 )

Change subject: Fix cargo table name blank validation error
..

Fix cargo table name blank validation error

Change-Id: I5b5f69650090c882fc6bdab9e2bacdf14e3a2688
---
M libs/PF_CreateTemplate.js
1 file changed, 1 insertion(+), 1 deletion(-)


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

diff --git a/libs/PF_CreateTemplate.js b/libs/PF_CreateTemplate.js
index 4dcb541..ad0cafc 100644
--- a/libs/PF_CreateTemplate.js
+++ b/libs/PF_CreateTemplate.js
@@ -34,7 +34,7 @@
 function validateCreateTemplateForm() {
var blankTemplateName = ( jQuery( '#template_name' ).val() === '' );
var blankCargoTableName = ( jQuery( '#use_cargo' ).is(':checked') ||
-   jQuery( '#table_name' ).val() === '' );
+   jQuery( '#cargo_table' ).val() === '' );
if ( blankTemplateName || blankCargoTableName ) {
scroll( 0, 0 );
if ( blankTemplateName ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b5f69650090c882fc6bdab9e2bacdf14e3a2688
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Make static function of CargoHierarchy suitable for extendin...

2017-07-25 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367808 )

Change subject: Make static function of CargoHierarchy suitable for extending 
the class
..

Make static function of CargoHierarchy suitable for extending the class

Change-Id: Ie38c8ce4f6cdc87edb3fa86476504fbf0cf77113
---
M CargoHierarchy.php
1 file changed, 6 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/08/367808/1

diff --git a/CargoHierarchy.php b/CargoHierarchy.php
index 983008c..18caaf8 100644
--- a/CargoHierarchy.php
+++ b/CargoHierarchy.php
@@ -30,7 +30,7 @@
public static function newFromWikiText( $wikitext ) {
// A dummy node (__pseudo_root__ is added so that
// multiple nodes can be added in the first level
-   $fullTree = new CargoHierarchy();
+   $fullTree = new static();
$lines = explode( "\n", $wikitext );
foreach ( $lines as $line ) {
$numBullets = 0;
@@ -40,8 +40,9 @@
if ( $numBullets == 0 ) continue;
$lineText = trim( substr( $line, $numBullets ) );
$curParentNode = $fullTree->getLastNodeForLevel( 
$numBullets );
-   $curParentNode->addChild( new CargoHierarchy( $lineText 
) );
+   $curParentNode->addChild( new static( $lineText ) );
}
+   $fullTree->computeLeftRight();
return $fullTree;
}
 
@@ -55,18 +56,17 @@
 
function generateHierarchyStructureTableData() {
$tableData = array();
-   $this->computeLeftRight();
//  Preorder traversal using Stack data structure
$stack = new SplStack();
$stack->push( $this );
-   while( !$stack->isEmpty() ) {
+   while ( !$stack->isEmpty() ) {
$node = $stack->pop();
$row = array();
$row['_value'] = $node->mTitle;
$row['_left'] = $node->mLeft;
$row['_right'] = $node->mRight;
$tableData[] = $row;
-   foreach( array_reverse( $node->mChildren ) as $child ) {
+   foreach ( array_reverse( $node->mChildren ) as $child ) 
{
$stack->push( $child );
}
}
@@ -77,7 +77,7 @@
$this->mLeft = $counter;
$counter += 1;
//  Visit mChildren of the current node
-   foreach( $this->mChildren as $child ) {
+   foreach ( $this->mChildren as $child ) {
$child->computeLeftRight( $counter );
}
$this->mRight = $counter;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie38c8ce4f6cdc87edb3fa86476504fbf0cf77113
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: fixing spaces

2017-07-22 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/367007 )

Change subject: fixing spaces
..

fixing spaces

Change-Id: I5deafd1f0a4e54cb9b83b2136af76f2081f65a0e
---
M CargoSQLQuery.php
1 file changed, 24 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/07/367007/1

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 5a5d6cd..0173d17 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -730,15 +730,15 @@
$fieldReplaced);
 
if ( preg_match( $patternSimple[$i], 
$this->mWhereStr ) ) {
-   if( $isHierarchy ) {
-throw new MWException( "Error: operator for the 
hierarchy field '" .
-"$tableName.$fieldName' must be 'HOLDS', 
'HOLDS NOT', '" .
-"HOLDS WITHIN', 'HOLDS LIKE' or 'HOLDS NOT 
LIKE'." );
-} else {
-throw new MWException( "Error: operator for the 
virtual field '" .
-"$tableName.$fieldName' must be 'HOLDS', 
'HOLDS NOT', '" .
-"HOLDS LIKE' or 'HOLDS NOT LIKE'." );
-}
+   if( $isHierarchy ) {
+   throw new MWException( 
"Error: operator for the hierarchy field '" .
+   
"$tableName.$fieldName' must be 'HOLDS', 'HOLDS NOT', '" .
+   "HOLDS WITHIN', 
'HOLDS LIKE' or 'HOLDS NOT LIKE'." );
+   } else {
+   throw new MWException( 
"Error: operator for the virtual field '" .
+   
"$tableName.$fieldName' must be 'HOLDS', 'HOLDS NOT', '" .
+   "HOLDS LIKE' or 
'HOLDS NOT LIKE'." );
+   }
}
}
}
@@ -1045,11 +1045,11 @@
 */
function handleHierarchyFields() {
// "where" - make sure that if
-   //  "WITHIN" (if not list) or "HOLDS 
WITHIN" (if list)
-   //  is specified, then translate the clause 
accordingly.
-// other translations like 'fields', 'join on', 'order by' and
-// additional 'where' capabilities in case of List fields, the
-// handling is done by handleVirtualFields().
+   //  "WITHIN" (if not list) or "HOLDS WITHIN" (if 
list)
+   //  is specified, then translate the clause 
accordingly.
+   // other translations like 'fields', 'join on', 'order by' and
+   // additional 'where' capabilities in case of List fields, the
+   // handling is done by handleVirtualFields().
 
// First, create an array of the hierarchy fields in the
// current set of tables.
@@ -1078,7 +1078,7 @@
$tableName = $hierarchyField['tableName'];
$tableAlias = $hierarchyField['tableAlias'];
$fieldIsList = $hierarchyField['isList'];
-$throwException = false;
+   $throwException = false;
 
$patternSimple = array(
CargoUtils::getSQLTableAndFieldPattern( 
$tableAlias, $fieldName ),
@@ -1146,21 +1146,20 @@
}
 
 
-if ( $completeMatch == false && !preg_match( $patternRoot . 
'(\s*=\s*)' . $patternSuffix,
-$this->mWhereStr ) ) {
-if( $fieldIsList == false ) {
-$throwException = true;
-}
+   if ( $completeMatch == false && !preg_match( 
$patternRoot . '(\s*=\s*)' . $patternSuffix, $this->mWhereStr ) ) {
+   if( $fieldIsList == false ) {
+   $throwException = true;
+   }
}
if( $completeMatch ) {
$this->substVirtualFieldName( 
$this->mWhereStr, $completeSearchPattern, $newWhere, $fieldReplaced);
$this->mWhereStr = preg_replace( 
$completeSearchPattern, $newWhere, $this->mWhereStr );
}
-if ( $throwException ) 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Work in progress Add support for hierarchy fields in Drilldown

2017-07-13 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365091 )

Change subject: Work in progress Add support for hierarchy fields in Drilldown
..

Work in progress
Add support for hierarchy fields in Drilldown

Change-Id: Ic465b978a1f40f00c66fbdf1b29f8ebe71f2fc55
---
M CargoHierarchy.php
M CargoUtils.php
M drilldown/CargoSpecialDrilldown.php
3 files changed, 172 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/91/365091/1

diff --git a/CargoHierarchy.php b/CargoHierarchy.php
index 983008c..8a41eba 100644
--- a/CargoHierarchy.php
+++ b/CargoHierarchy.php
@@ -13,6 +13,10 @@
public $mLeft = 0;
public $mRight = 0;
 
+   // Helper class member for Drilldown
+   public $mPageCount = 0;
+   public $mExclusivePageCount = 0;
+
function __construct( $curTitle = '__pseudo_root__' ) {
$this->mTitle = $curTitle;
$this->mChildren = array();
@@ -42,6 +46,7 @@
$curParentNode = $fullTree->getLastNodeForLevel( 
$numBullets );
$curParentNode->addChild( new CargoHierarchy( $lineText 
) );
}
+   $fullTree->computeLeftRight();
return $fullTree;
}
 
@@ -55,7 +60,6 @@
 
function generateHierarchyStructureTableData() {
$tableData = array();
-   $this->computeLeftRight();
//  Preorder traversal using Stack data structure
$stack = new SplStack();
$stack->push( $this );
@@ -83,4 +87,63 @@
$this->mRight = $counter;
$counter += 1;
}
+
+   function computeNodeCountByFilter( $f, $fullTextSearchTerm, 
$appliedFilters ) {
+   $cdb = CargoUtils::getDB();
+   $countArg = "";
+
+   list( $tableNames, $conds, $joinConds ) = $f->getQueryParts( 
$fullTextSearchTerm, $appliedFilters );
+   if ( $f->fieldDescription->mIsList ) {
+   $countArg = "_rowID";
+   $fieldTableName = $f->tableName . '__' . $f->name;
+   $tableNames[] = $fieldTableName;
+   // $fieldName = CargoUtils::escapedFieldName( $cdb, 
$fieldTableName, '_value' );
+   $fieldName = '_value';
+   $joinConds[$fieldTableName] = 
CargoUtils::joinOfMainAndFieldTable( $cdb, $f->tableName, $fieldTableName );
+   } else {
+   $countArg = "_ID";
+   $fieldName = $f->name;
+   $fieldTableName = $f->tableName;
+   }
+
+   // Join hierarchy structure table __hierarchy with the main 
table
+   $hierarchyTableName = $f->tableName . '__' . $f->name . 
'__hierarchy';
+   $tableNames[] = $hierarchyTableName;
+
+   $joinConds[$hierarchyTableName] = 
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb, 
+   $fieldTableName, $fieldName, $hierarchyTableName );
+
+   // Need of following?
+   // if ( $f->searchableFiles ) {
+   //  $countClause = "COUNT(DISTINCT 
cargo__{$f->tableName}._pageID) AS total";
+   // } else {
+   //  $countClause = "COUNT(*) AS total";
+   // }
+
+   $countClause = "COUNT(DISTINCT($countArg)) AS total";
+   $hierarchyConds = array();
+   $exclusiveHierarchyConds = array();
+   $hierarchyConds[] = "_left >= $this->mLeft";
+   $hierarchyConds[] = "_right <= $this->mRight";
+   $exclusiveHierarchyConds[] = "_left = $this->mLeft";
+
+   // Hierarchy Node Count
+   $res = $cdb->select( $tableNames, array( $countClause ), 
array_merge( $conds, $hierarchyConds ),
+   null, null, $joinConds );
+   $count = 0;
+   while ( $row = $cdb->fetchRow( $res ) ) {
+   $count = $row['total'];
+   }
+   $this->mPageCount = $count;
+   $cdb->freeResult( $res );
+   // Exclusive Node Count 
+   $res = $cdb->select( $tableNames, array( $countClause ), 
array_merge( $conds, $exclusiveHierarchyConds ),
+   null, null, $joinConds );
+   $count = 0;
+   while ( $row = $cdb->fetchRow( $res ) ) {
+   $count = $row['total'];
+   }
+   $this->mExclusivePageCount = $count;
+   $cdb->freeResult( $res );
+   }
 }
\ No newline at end of file
diff --git a/CargoUtils.php b/CargoUtils.php
index eaf1392..a1686be 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -908,6 +908,15 @@
);
}
 
+   public static function 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Work in progress : Fix db exception for delete join due to h...

2017-07-05 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/363523 )

Change subject: Work in progress : Fix db exception for delete join due to 
hierarchy table
..

Work in progress : Fix db exception for delete join due to hierarchy table

Change-Id: I05957afc898446878c3e799ca42afdda6601f061
---
M CargoUtils.php
M maintenance/setCargoFileData.php
M maintenance/setCargoPageData.php
M specials/CargoDeleteTable.php
M sql/Cargo.mssql.sql
M sql/Cargo.pg.sql
M sql/Cargo.sql
7 files changed, 26 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/23/363523/1

diff --git a/CargoUtils.php b/CargoUtils.php
index 1579405..6ef12a3 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -684,7 +684,8 @@
 
// Now also create tables for each of the 'list' fields,
// if there are any.
-   $fieldTableNames = array();
+   $fieldTableNames = array();  // Store table names of tables 
that store data regarding pages
+   $metaTableNames = array();  // Store table names of tables that 
store meta data regarding template or fields
foreach ( $tableSchema->mFieldDescriptions as $fieldName => 
$fieldDescription ) {
if ( $fieldDescription->mIsList ) {
// The double underscore in this table name 
should
@@ -714,27 +715,27 @@
$fieldTableNames[] = $tableName . '__' . 
$fieldName;
}
if ( $fieldDescription->mIsHierarchy ) {
-   $fieldTableName = $tableName . '__' . 
$fieldName . '__hierarchy';
-   $cdb->dropTable( $fieldTableName );
+   $metaTableName = $tableName . '__' . $fieldName 
. '__hierarchy';
+   $cdb->dropTable( $metaTableName );
$fieldType = $fieldDescription->mType;
-   $createSQL = "CREATE TABLE " . $cdb->tableName( 
$fieldTableName ) . ' ( ' ;
+   $createSQL = "CREATE TABLE " . $cdb->tableName( 
$metaTableName ) . ' ( ' ;
$createSQL .= $cdb->addIdentifierQuotes( 
'_value' ) . ' ' . self::fieldTypeToSQLType( $fieldType, $dbType, $size ) . ", 
";
$createSQL .= $cdb->addIdentifierQuotes( 
'_left' ) . " $intTypeString, ";
$createSQL .= $cdb->addIdentifierQuotes( 
'_right' ) . " $intTypeString ";
$createSQL .= ' )';
$cdb->query( $createSQL );
-   $createIndexSQL = 'CREATE INDEX ' . 
$cdb->addIdentifierQuotes( "nested_set_$fieldTableName" ) . ' ON ' ;
-   $createIndexSQL .= $cdb->tableName( 
$fieldTableName ) . ' (' ;
+   $createIndexSQL = 'CREATE INDEX ' . 
$cdb->addIdentifierQuotes( "nested_set_$metaTableName" ) . ' ON ' ;
+   $createIndexSQL .= $cdb->tableName( 
$metaTableName ) . ' (' ;
$createIndexSQL .= $cdb->addIdentifierQuotes( 
'_value' ) . ', ';
$createIndexSQL .= $cdb->addIdentifierQuotes( 
'_left' ) . ', ';
$createIndexSQL .= $cdb->addIdentifierQuotes( 
'_right' ) . ')';
$cdb->query( $createIndexSQL );
-   $fieldTableNames[] = $fieldTableName;
+   $metaTableNames[] = $metaTableName;
// Insert hierarchy information in the 
__hierarchy table
$hierarchyTree = 
CargoHierarchy::newFromWikiText( $fieldDescription->mHierarchyStructure );
$hierarchyStructureTableData = 
$hierarchyTree->generateHierarchyStructureTableData();
foreach( $hierarchyStructureTableData as $entry 
) {
-   $cdb->insert( $fieldTableName, $entry );
+   $cdb->insert( $metaTableName, $entry );
}
}
}
@@ -763,6 +764,7 @@
'template_id' => $templatePageID,
'main_table' => $tableName,
'field_tables' => serialize( $fieldTableNames ),
+   'meta_tables' => serialize( $metaTableNames ),
'table_schema' => $tableSchemaString
) );
}
diff --git a/maintenance/setCargoFileData.php b/maintenance/setCargoFileData.php
index 8f82b67..3dc9404 100644
--- a/maintenance/setCargoFileData.php
+++ b/maintenance/setCargoFileData.php
@@ -51,14 +51,15 @@

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Add feature for WITHIN and HOLDS WITHIN for hierarchy fields

2017-07-04 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/363178 )

Change subject: Add feature for WITHIN and HOLDS WITHIN for hierarchy fields
..

Add feature for WITHIN and HOLDS WITHIN for hierarchy fields

This commit adds support for querying data using WITHIN (for single valued 
hierarchy fields)
and HOLDS WITHIN (for list hierarchy fields).

Change-Id: I35819da62c9ecc8dfdb5081188ec6269de19dbe2
---
M CargoSQLQuery.php
1 file changed, 149 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/78/363178/1

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 82a5337..fe68a70 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -64,6 +64,7 @@
$sqlQuery->mGroupByStr = $sqlQuery->mOrigGroupByStr;
$sqlQuery->mHavingStr = $havingStr;
$sqlQuery->setDescriptionsForFields();
+   $sqlQuery->handleVirtualHierarchyFields();
$sqlQuery->handleVirtualFields();
$sqlQuery->handleVirtualCoordinateFields();
$sqlQuery->handleDateFields();
@@ -669,7 +670,8 @@
$virtualFields[] = array(
'fieldName' => 
$fieldName,
'tableAlias' => 
$tableAlias,
-   'tableName' => 
$tableName
+   'tableName' => 
$tableName,
+   'isHierarchy' => 
$fieldDescription->mIsHierarchy
);
}
}
@@ -682,6 +684,7 @@
$fieldName = $virtualField['fieldName'];
$tableAlias = $virtualField['tableAlias'];
$tableName = $virtualField['tableName'];
+   $isHierarchy = $virtualField['isHierarchy'];
 
$fieldTableName = $tableName . '__' . $fieldName;
$fieldTableAlias = $tableAlias . '__' . $fieldName;
@@ -726,7 +729,7 @@
"$replacementFieldName=",
$fieldReplaced);
 
-   if ( preg_match( $patternSimple[$i], 
$this->mWhereStr ) ) {
+   if ( preg_match( $patternSimple[$i], 
$this->mWhereStr ) && $isHierarchy === false ) {
throw new MWException( "Error: 
operator for the virtual field '" .
"$tableName.$fieldName' 
must be 'HOLDS', 'HOLDS NOT', '" .
"HOLDS LIKE' or 'HOLDS 
NOT LIKE'." );
@@ -1032,6 +1035,150 @@
}
 
/**
+* Similar to handleVirtualFields(), but handles Hierarchy fields
+* advanced "WHERE" operations of hierarchy
+*/
+   function handleVirtualHierarchyFields() {
+   // Hierarchy fields can be found in the "fields" and "where"
+   // clauses. The following handling is done:
+   // "fields" - since Hierarchy Field is a pseudo-field, it 
+   //  should be handled by its type handler
+   // "where" - make sure that if
+   //  "WITHIN", "NOT WITHIN" (if not list)
+   //  "HOLDS WITHIN", "HOLDS (if list)
+   //  are  specified, then translate the 
clause accordingly.
+   // "order by" - same as "fields".
+
+   // First, create an array of the hierarchy fields in the
+   // current set of tables.
+   $hierarchyFields = array();
+   foreach ( $this->mTableSchemas as $tableName => $tableSchema ) {
+   foreach ( $tableSchema->mFieldDescriptions as 
$fieldName => $fieldDescription ) {
+   if ( !$fieldDescription->mIsHierarchy ) {
+   continue;
+   }
+   foreach ( $this->mAliasedTableNames as 
$tableAlias => $tableName2 ) {
+   if ( $tableName == $tableName2 ) {
+   $hierarchyFields[] = array(
+   'fieldName' => 
$fieldName,
+   'tableAlias' => 
$tableAlias,
+   'tableName' => 
$tableName,
+   'isList'=> 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix: cargoRecreateData.php crash after the template is delet...

2017-06-25 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361291 )

Change subject: Fix: cargoRecreateData.php crash after the template is deleted 
by the user
..

Fix: cargoRecreateData.php crash after the template is deleted by the user

Change-Id: Ieb91d916bfaec5c45c687719a9abdeb9ec4eb9d4
---
M maintenance/cargoRecreateData.php
1 file changed, 5 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/91/361291/1

diff --git a/maintenance/cargoRecreateData.php 
b/maintenance/cargoRecreateData.php
index bb1aa09..ca04fec 100644
--- a/maintenance/cargoRecreateData.php
+++ b/maintenance/cargoRecreateData.php
@@ -112,6 +112,11 @@
 
foreach( $templatesForThisTable as $templatePageID ) {
$templateTitle = Title::newFromID( $templatePageID );
+   if( $templateTitle == null ) {
+   // It is possible that the Template to which 
the table is associated, is now deleted by the user
+   print "Template (Template Page ID = 
$templatePageID) does not exist, cannot recreate data corresponding to this 
template\n";
+   continue;
+   }
if ( !$quiet ) {
print "Handling template that adds to this 
table: " . $templateTitle->getText() . "\n";
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb91d916bfaec5c45c687719a9abdeb9ec4eb9d4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix: Drilldown crash after user deletes tables from Database

2017-06-25 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361287 )

Change subject: Fix: Drilldown crash after user deletes tables from Database
..

Fix: Drilldown crash after user deletes tables from Database

Change-Id: I7896e856c7341be2b46b7f188bd4a51f32fc888f
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/87/361287/1

diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 9e887fa..b5bf472 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -294,9 +294,15 @@
}
$cdb = CargoUtils::getDB();
foreach ( $tables as $table ) {
-   $res = $cdb->select( $table, 'COUNT(*) AS total' );
-   $row = $cdb->fetchRow( $res );
-   $tableRows = $row['total'];
+   try {
+   $res = $cdb->select( $table, 'COUNT(*) AS 
total' );
+   $row = $cdb->fetchRow( $res );
+   $tableRows = $row['total'];
+   } catch ( Exception $e ) {
+   // Probably the table does not exist due to 
deletion by the user (or other reasons)
+   continue;
+   }
+   
$tableStr = $this->displayTableName( $table ) . " 
($tableRows)";
if ( $this->tableName == $table ) {
$text .= '  
';

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7896e856c7341be2b46b7f188bd4a51f32fc888f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fix : Index naming for the Cargo Tables of multi valued fie...

2017-06-24 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361275 )

Change subject: Fix : Index naming for the Cargo Tables of  multi valued fields.
..

Fix : Index naming for the Cargo Tables of  multi valued fields.

The index name for the Cargo tables of multi valued fields was being generated 
as 'row_id_$fieldname'.
This patch fixes the issue.

Change-Id: I64cbcf10d515205892f5df398c0761a8870e61b3
---
M CargoUtils.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/75/361275/1

diff --git a/CargoUtils.php b/CargoUtils.php
index 50ecac6..1579405 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -707,7 +707,7 @@
$createSQL .= ' )';
$cdb->query( $createSQL );
$createIndexSQL = 'CREATE INDEX ' .
-   $cdb->addIdentifierQuotes( 
'row_id_$fieldTableName' ) . ' ON ' .
+   $cdb->addIdentifierQuotes( 
"row_id_$fieldTableName" ) . ' ON ' .
$cdb->tableName( $fieldTableName ) .
' (' . $cdb->addIdentifierQuotes( 
'_rowID' ) . ')';
$cdb->query( $createIndexSQL );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I64cbcf10d515205892f5df398c0761a8870e61b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Fixed : Populate hierarchy fields in Cargo Tables

2017-06-22 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/360916 )

Change subject: Fixed : Populate hierarchy fields in Cargo Tables
..

Fixed : Populate hierarchy fields in Cargo Tables

Hierarchy fields were not being populated.
This patch fixes the above issue.

Change-Id: I958d9c246d621b484f5acee3d6271a8ef4d3b86a
---
M CargoFieldDescription.php
M CargoUtils.php
2 files changed, 23 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/16/360916/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 727136c..296904e 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -15,6 +15,7 @@
public $mAllowedValues = null;
public $mIsHidden = false;
public $mIsHierarchy = false;
+   public $mHierarchyStructure = null;
public $mOtherParams = array();
 
/**
@@ -68,12 +69,29 @@
// already used to separate
// "extra parameters", so just
// hardcode it to a semicolon.
+   if( 
$fieldDescription->mIsHierarchy == true ) {
+   // $paramValue contains 
"*" hierarchy structure
+   
$fieldDescription->mHierarchyStructure = trim( $paramValue );
+   // now make the allowed 
values param similar to the syntax
+   // used by other fields
+   $hierarchyNodesArray = 
explode( "\n", $paramValue );
+   $allowedValuesArray = 
array();
+   foreach ( 
$hierarchyNodesArray as $node ) {
+   $node = trim( 
$node );
+   // Remove 
prefix of multiple "*"
+   $node = 
preg_replace( '/^[*]*/', '', $node );
+   $node = trim( 
$node );
+
+   
$allowedValuesArray[] = $node;
+   }
+   $paramValue = implode( 
',', $allowedValuesArray );
+   }
$delimiter = ',';
$allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
$allowedValuesArray = explode( 
$delimiter, $allowedValuesStr );
foreach ( $allowedValuesArray 
as $i => $value ) {
if ( $value == '' ) 
continue;
-   // Replace beep back 
with comma, trim.
+   // Replace beep back 
with delimiter, trim.
$value = str_replace( 
"\a", $delimiter, trim( $value ) );

$fieldDescription->mAllowedValues[] = $value;
}
@@ -114,6 +132,8 @@
$fieldDescription->mIsHidden = true;
} elseif ( $param == 'hierarchy' ) {
$fieldDescription->mIsHierarchy = true;
+   } elseif ( $param == 'hierarchyStructure' ) {
+   $fieldDescription->mHierarchyStructure = $value;
}
}
return $fieldDescription;
@@ -152,6 +172,7 @@
}
if ( $this->mIsHierarchy ) {
$descriptionData['hierarchy'] = true;
+   $descriptionData['hierarchyStructure'] = 
$this->mHierarchyStructure;
}
foreach ( $this->mOtherParams as $otherParam => $value ) {
$descriptionData[$otherParam] = $value;
diff --git a/CargoUtils.php b/CargoUtils.php
index eeb860b..2feb712 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -731,7 +731,7 @@
$cdb->query( $createIndexSQL );
$fieldTableNames[] = $fieldTableName;
//Insert Hierarchy Structure
-   $allowedValuesWikitext = 
$fieldDescription->mAllowedValues[0];
+  

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Add Hierarchy Structure Table creation for hierarchy field

2017-06-18 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/359793 )

Change subject: Add Hierarchy Structure Table creation for hierarchy field
..

Add Hierarchy Structure Table creation for hierarchy field

This commit adds the functionality to create hierarchy structure table with 
columns (_value, _left, _right) and also populated from the hierarchical 
enumeration provided using "*".

Change-Id: Idad419eb4dc78c70eb2efc6977a1f3a5ba4b
---
M Cargo.php
M CargoFieldDescription.php
A CargoHierarchy.php
M CargoUtils.php
M extension.json
M parserfunctions/CargoDeclare.php
6 files changed, 147 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/93/359793/1

diff --git a/Cargo.php b/Cargo.php
index 02249f3..301ae1b 100644
--- a/Cargo.php
+++ b/Cargo.php
@@ -82,6 +82,7 @@
 $wgAutoloadClasses['CargoUtils'] = $dir . '/CargoUtils.php';
 $wgAutoloadClasses['CargoFieldDescription'] = $dir . 
'/CargoFieldDescription.php';
 $wgAutoloadClasses['CargoTableSchema'] = $dir . '/CargoTableSchema.php';
+$wgAutoloadClasses['CargoHierarchy'] = $dir . '/CargoHierarchy.php';
 $wgAutoloadClasses['CargoDeclare'] = $dir . 
'/parserfunctions/CargoDeclare.php';
 $wgAutoloadClasses['CargoAttach'] = $dir . '/parserfunctions/CargoAttach.php';
 $wgAutoloadClasses['CargoStore'] = $dir . '/parserfunctions/CargoStore.php';
diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 2cc3202..727136c 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -50,7 +50,7 @@
if ( count( $extraParamParts ) == 1 ) {
$paramKey = trim( $extraParamParts[0] );
if ( $paramKey == 'hierarchy' ) {
-   $mIsHierarchy = true;
+   $fieldDescription->mIsHierarchy 
= true;
}

$fieldDescription->mOtherParams[$paramKey] = true;
} else {
diff --git a/CargoHierarchy.php b/CargoHierarchy.php
new file mode 100644
index 000..9b23bcf
--- /dev/null
+++ b/CargoHierarchy.php
@@ -0,0 +1,90 @@
+mTitle = $curTitle;
+   $this->mChildren = array();
+   }
+
+   function addChild( $child ) {
+   $this->mChildren[] = $child;
+   }
+
+   /**
+* Turn a manually-created "structure", defined as a bulleted list
+* in wikitext, into a tree. This code has been borrowed from PFTree 
class
+ * of PageForms Extension
+*/
+   public static function newFromWikiText( $wikitext ) {
+// __psuedo_root__ node is added so that multiple nodes can be added 
in the first level
+$fullTree = new CargoHierarchy( '__psuedo_root__' );
+   $lines = explode( "\n", $wikitext );
+   foreach ( $lines as $line ) {
+   $numBullets = 0;
+   for ( $i = 0; $i < strlen( $line ) && $line[$i] == '*'; 
$i++ ) {
+   $numBullets++;
+   }
+   if ( $numBullets == 0 ) continue;
+   $lineText = trim( substr( $line, $numBullets ) );
+   $curParentNode = $fullTree->getLastNodeForLevel( 
$numBullets );
+   $curParentNode->addChild( new CargoHierarchy( $lineText 
) );
+   }
+   return $fullTree;
+   }
+
+   function getLastNodeForLevel( $level ) {
+   if ( $level <= 1 || count( $this->mChildren ) == 0 ) {
+   return $this;
+   }
+   $lastNodeOnCurLevel = end( $this->mChildren );
+   return $lastNodeOnCurLevel->getLastNodeForLevel( $level - 1 );
+   }
+
+function generateHierarchyStructureTableData() {
+$tableData = array();
+$this->computeLeftRight();
+//Preorder traversal using Stack data structure
+$stack = new SplStack();
+$stack->push( $this );
+while( !$stack->isEmpty() ) {
+$node = $stack->pop();
+$row = array();
+$row['_value'] = $node->mTitle;
+$row['_left'] = $node->mLeft;
+$row['_right'] = $node->mRight; 
+$tableData[] = $row;
+foreach( array_reverse( $node->mChildren ) as $child ) {
+$stack->push( $child );
+}
+}
+return $tableData;   
+}
+
+private function __computeLeftRight( &$counter ) {
+$this->mLeft = $counter;
+$counter += 1;
+//visit mChildren
+foreach( $this->mChildren as $child ) {
+$child->__computeLeftRight( $counter );
+}
+$this->mRight = $counter;
+$counter += 1;
+}
+
+ 

[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Added support for hierarchy fields in the Page Forms extensi...

2017-06-02 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356928 )

Change subject: Added support for hierarchy fields in the Page Forms extension. 
Hierarchy fields automatically get the right input type ("tree"), with the 
right values filled in. According to the task T161034.
..

Added support for hierarchy fields in the Page Forms extension. Hierarchy 
fields automatically get the right input type ("tree"), with the right values 
filled in. According to the task T161034.

Change-Id: I03bc8cf413ce0969eee6397d652aa5d319a38c86
---
M includes/PF_TemplateField.php
M includes/forminputs/PF_TreeInput.php
2 files changed, 29 insertions(+), 3 deletions(-)


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

diff --git a/includes/PF_TemplateField.php b/includes/PF_TemplateField.php
index b3c11da..f866b32 100644
--- a/includes/PF_TemplateField.php
+++ b/includes/PF_TemplateField.php
@@ -127,7 +127,11 @@
// We have some "pseudo-types", used for setting the correct
// form input.
if ( $fieldDescription->mAllowedValues != null ) {
-   $this->mFieldType = 'Enumeration';
+   if( $fieldDescription->mIsHierarchy == true ) {
+   $this->mFieldType = 'hierarchy';
+   } else {
+   $this->mFieldType = 'Enumeration';
+   }   
} elseif ( $fieldDescription->mType == 'Text' && 
$fieldDescription->mSize != '' && $fieldDescription->mSize <= 100 ) {
$this->mFieldType = 'String';
} else {
diff --git a/includes/forminputs/PF_TreeInput.php 
b/includes/forminputs/PF_TreeInput.php
index 8758d51..e3c760b 100644
--- a/includes/forminputs/PF_TreeInput.php
+++ b/includes/forminputs/PF_TreeInput.php
@@ -40,6 +40,18 @@
}
}
 
+   public static function getDefaultCargoTypes() {
+   return array(
+   'hierarchy' => array()
+   );
+   }
+
+   public static function getDefaultCargoTypeLists() {
+   return array(
+   'hierarchy' => array()
+   );
+   }
+
public static function getOtherCargoTypesHandled() {
return array( 'String', 'Page' );
}
@@ -51,10 +63,10 @@
public static function getHTML( $cur_value, $input_name, $is_mandatory, 
$is_disabled, $other_args ) {
// Handle the now-deprecated 'category' and 'categories'
// input types.
-   if ( $other_args['input type'] == 'category' ) {
+   if ( array_key_exists( 'input type', $other_args ) && 
$other_args['input type'] == 'category' ) {
$inputType = "radio";
self::$multipleSelect = false;
-   } elseif ( $other_args['input type'] == 'categories' ) {
+   } elseif ( array_key_exists( 'input type', $other_args ) && 
$other_args['input type'] == 'categories' ) {
$inputType = "checkbox";
self::$multipleSelect = true;
} else {
@@ -107,6 +119,16 @@
$structure = $other_args['structure'];
$tree = PFTree::newFromWikiText( $structure );
$hideroot = true;
+   } elseif ( array_key_exists( 'possible_values', $other_args ) ) 
{
+   //The possibility of field being of type - 'hierarchy' 
pseudo-type
+   if ( count( $other_args['possible_values'] ) >= 
1) {
+   $structure = 
$other_args['possible_values'][0];
+   $tree = PFTree::newFromWikiText( 
$structure );
+   $hideroot = true;
+   } else {
+   return null;
+   }
+
} else {
// Escape - we can't do anything.
return null;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03bc8cf413ce0969eee6397d652aa5d319a38c86
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Added Hierarchy option to #cargo_declare in order to complet...

2017-06-02 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356901 )

Change subject: Added Hierarchy option to #cargo_declare in order to complete 
the first step in the task T161034.
..

Added Hierarchy option to #cargo_declare in order to complete the first step in 
the task T161034.

Change-Id: I53e57ab6b09773d99c983ebbcb7cc50991420014
---
M CargoFieldDescription.php
1 file changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/01/356901/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 982826a..18e72dd 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -14,6 +14,7 @@
private $mDelimiter;
public $mAllowedValues = null;
public $mIsHidden = false;
+   public $mIsHierarchy = false;
public $mOtherParams = array();
 
/**
@@ -27,7 +28,7 @@
 
if ( strpos( $fieldDescriptionStr, 'List' ) === 0 ) {
$matches = array();
-   $foundMatch = preg_match( '/List \((.*)\) of (.*)/', 
$fieldDescriptionStr, $matches );
+   $foundMatch = preg_match( '/List \((.*)\) of (.*)/s', 
$fieldDescriptionStr, $matches );
if ( !$foundMatch ) {
// Return a true error message here?
return null;
@@ -39,7 +40,7 @@
 
// There may be additional parameters, in/ parentheses.
$matches = array();
-   $foundMatch2 = preg_match( '/([^(]*)\s*\((.*)\)/', 
$fieldDescriptionStr, $matches );
+   $foundMatch2 = preg_match( '/([^(]*)\s*\((.*)\)/s', 
$fieldDescriptionStr, $matches );
if ( $foundMatch2 ) {
$fieldDescriptionStr = trim( $matches[1] );
$extraParamsString = $matches[2];
@@ -48,6 +49,9 @@
$extraParamParts = explode( '=', $extraParam, 2 
);
if ( count( $extraParamParts ) == 1 ) {
$paramKey = trim( $extraParamParts[0] );
+   if($paramKey == 'hierarchy') {
+   $mIsHierarchy = true;
+   }

$fieldDescription->mOtherParams[$paramKey] = true;
} else {
$paramKey = trim( $extraParamParts[0] );
@@ -108,6 +112,8 @@
$fieldDescription->mAllowedValues = $value;
} elseif ( $param == 'hidden' ) {
$fieldDescription->mIsHidden = true;
+   } elseif ( $param == 'hierarchy' ) {
+   $fieldDescription->mIsHierarchy = true;
}
}
return $fieldDescription;
@@ -144,6 +150,9 @@
if ( $this->mIsHidden ) {
$descriptionData['hidden'] = true;
}
+   if ( $this->mIsHierarchy ) {
+   $descriptionData['hierarchy'] = true;
+   }
foreach ( $this->mOtherParams as $otherParam => $value ) {
$descriptionData[$otherParam] = $value;
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I53e57ab6b09773d99c983ebbcb7cc50991420014
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Improvements for T159405 - Used the wgUrlProtocols in valid...

2017-03-21 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343870 )

Change subject: Improvements for  T159405 - Used the wgUrlProtocols in 
validateURLField()
..

Improvements for  T159405 - Used the wgUrlProtocols in validateURLField()

Now validateURLField() in libs/PageForms.js checks protocol part in URL using 
wgUrlProtocols variable, which is more complete.
Removed the comment "// code borrowed from 
http://snippets.dzone.com/posts/show/452; as the link appears to be broken.

Bug: T159405
Change-Id: I6b4fb4001334d753c5bc771089a2a56a56ddb03f
---
M libs/PageForms.js
1 file changed, 6 insertions(+), 2 deletions(-)


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

diff --git a/libs/PageForms.js b/libs/PageForms.js
index 598b6a5..5a9449d 100644
--- a/libs/PageForms.js
+++ b/libs/PageForms.js
@@ -821,8 +821,12 @@
 
 $.fn.validateURLField = function() {
var fieldVal = this.find("input").val();
-   // code borrowed from http://snippets.dzone.com/posts/show/452
-   var url_regexp = 
/(ftp|http|https|rtsp|news):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
+   var url_protocol = mw.config.get( 'wgUrlProtocols' );
+   //removing backslash before colon from url_protocol string
+   url_protocol = url_protocol.replace( /\\:/, ':' );
+   //removing '//' from wgUrlProtocols as this causes to match any 
protocol in regexp
+   url_protocol = url_protocol.replace( /\|\\\/\\\//, '' );
+   var url_regexp = new RegExp( '(' + url_protocol + ')' + 
'(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\/|\/([\\w#!:.?+=&%@!\\-\/]))?' );
if (fieldVal === "" || url_regexp.test(fieldVal)) {
return true;
} else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b4fb4001334d753c5bc771089a2a56a56ddb03f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Issue Solved - $wgMaxUploadSize being an array causes an err...

2017-03-18 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343534 )

Change subject: Issue Solved - $wgMaxUploadSize being an array causes an error 
in Page Forms
..

Issue Solved - $wgMaxUploadSize being an array causes an error in Page Forms

In the page form upload window, if $wgMaxUplaodSize was an array, a fatal error 
would be thrown by. This issue has been solved now and thus $wgMaxUploadSize 
can now be integer as well as an array.

Bug: T160687
Change-Id: I7b2da4803152470f82487a641512f6f9342ab5bc
---
M specials/PF_UploadForm.php
1 file changed, 15 insertions(+), 3 deletions(-)


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

diff --git a/specials/PF_UploadForm.php b/specials/PF_UploadForm.php
index f640520..16ba435 100644
--- a/specials/PF_UploadForm.php
+++ b/specials/PF_UploadForm.php
@@ -100,6 +100,19 @@
);
}
 
+   $maxUploadSizeFile = ini_get( 'upload_max_filesize' );
+   $maxUploadSizeURL =  ini_get( 'upload_max_filesize' );
+   global $wgMaxUploadSize;
+   if( isset( $wgMaxUploadSize ) ) {
+   if( gettype( $wgMaxUploadSize ) == "array" ) {
+   $maxUploadSizeFile = $wgMaxUploadSize['*'];
+   $maxUploadSizeURL = $wgMaxUploadSize['url'];
+   } else {
+   $maxUploadSizeFile = $wgMaxUploadSize;
+   $maxUploadSizeURL = $wgMaxUploadSize;
+   }
+   }
+
$descriptor['UploadFile'] = array(
'class' => 'PFUploadSourceField',
'section' => 'source',
@@ -110,13 +123,12 @@
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',

$this->getLanguage()->formatSize(
-   wfShorthandToInteger( 
ini_get( 'upload_max_filesize' ) )
+   wfShorthandToInteger( 
$maxUploadSizeFile )
)
)->parse() . ' ' . wfMessage( 
'upload_source_file' )->escaped(),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
-   global $wgMaxUploadSize;
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
@@ -125,7 +137,7 @@
'upload-type' => 'Url',
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',
-   
$this->getLanguage()->formatSize( $wgMaxUploadSize )
+   
$this->getLanguage()->formatSize( $maxUploadSizeURL )
)->parse() . ' ' . wfMessage( 
'upload_source_url' )->escaped(),
'checked' => $selectedSourceType == 'url',
);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b2da4803152470f82487a641512f6f9342ab5bc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...PageForms[master]: Issue Solved - $wgMaxUploadSize being an array causes an err...

2017-03-18 Thread Fz-29 (Code Review)
Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343457 )

Change subject: Issue Solved - $wgMaxUploadSize being an array causes an error 
in Page Forms
..

Issue Solved - $wgMaxUploadSize being an array causes an error in Page Forms

In the page form upload window, if wgMaxUplaodSize was an array, a fatal error 
would be thrown by. This issue has been solved now and thus $wgMaxUploadSize 
can now be integer as well as an array.

Bug: T160687
Change-Id: Ib9ea0fc5a5ce231cf0ade117946f5fb6b169c63e
---
M specials/PF_UploadForm.php
1 file changed, 19 insertions(+), 3 deletions(-)


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

diff --git a/specials/PF_UploadForm.php b/specials/PF_UploadForm.php
index f640520..14310e9 100644
--- a/specials/PF_UploadForm.php
+++ b/specials/PF_UploadForm.php
@@ -100,6 +100,23 @@
);
}
 
+   $maxUploadSizeFile = ini_get( 'upload_max_filesize' );
+   $maxUploadSizeURL =  ini_get( 'upload_max_filesize' );
+   global $wgMaxUploadSize;
+   if(isset($wgMaxUploadSize))
+   {
+   if(gettype($wgMaxUploadSize) == "array")
+   {
+   $maxUploadSizeFile = $wgMaxUploadSize['*'];
+   $maxUploadSizeURL = $wgMaxUploadSize['url'];
+   }
+   else
+   {
+   $maxUploadSizeFile = $wgMaxUploadSize;
+   $maxUploadSizeURL = $wgMaxUploadSize;
+   }
+   }
+
$descriptor['UploadFile'] = array(
'class' => 'PFUploadSourceField',
'section' => 'source',
@@ -110,13 +127,12 @@
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',

$this->getLanguage()->formatSize(
-   wfShorthandToInteger( 
ini_get( 'upload_max_filesize' ) )
+   wfShorthandToInteger( 
$maxUploadSizeFile )
)
)->parse() . ' ' . wfMessage( 
'upload_source_file' )->escaped(),
'checked' => $selectedSourceType == 'file',
);
if ( $canUploadByUrl ) {
-   global $wgMaxUploadSize;
$descriptor['UploadFileURL'] = array(
'class' => 'UploadSourceField',
'section' => 'source',
@@ -125,7 +141,7 @@
'upload-type' => 'Url',
'radio' => &$radio,
'help' => wfMessage( 'upload-maxfilesize',
-   
$this->getLanguage()->formatSize( $wgMaxUploadSize )
+   
$this->getLanguage()->formatSize( $maxUploadSizeURL )
)->parse() . ' ' . wfMessage( 
'upload_source_url' )->escaped(),
'checked' => $selectedSourceType == 'url',
);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib9ea0fc5a5ce231cf0ade117946f5fb6b169c63e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Fz-29 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits