[MediaWiki-commits] [Gerrit] Use parser options to provide context to CargoStore persistence - change (mediawiki...Cargo)

2015-12-28 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/261317

Change subject: Use parser options to provide context to CargoStore persistence
..

Use parser options to provide context to CargoStore persistence

This improves thread safety preventing conflicts between saving individual 
pages and Recreate Data jobs.  Note however that duplicate rows mat still be 
created if (a) multiple saves for the same page are taking place and the delete 
of 2 or more of these updates take place before the inserts, or (b) the page is 
on queue to be recreated and it is saved before the recreation job gets to it.

Bug: T122564
Change-Id: Iee7cc92f1dc0fc6e90698adf74bd6a9baaeeff14
---
M Cargo.hooks.php
M CargoPopulateTableJob.php
M CargoUtils.php
M maintenance/cargoRecreateData.php
M parserfunctions/CargoStore.php
5 files changed, 72 insertions(+), 30 deletions(-)


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

diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index 9abbb8c..f0dd488 100644
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -174,8 +174,7 @@
// Even though the page will get parsed again after the save,
// we need to parse it here anyway, for the settings we
// added to remain set.
-   CargoStore::$settings['origin'] = 'page save';
-   CargoUtils::parsePageForStorage( $article->getTitle(), 
$content->getNativeData() );
+   CargoUtils::parsePageForStorage( $article->getTitle(), 
$content->getNativeData(), 'PageSave' );
 
return true;
}
@@ -190,7 +189,7 @@
// this setting will be enough to get the correct revision of
// this page to be saved by Cargo, since the page will be
// parsed right after this.
-   CargoStore::$settings['origin'] = 'Approved Revs revision 
approved';
+   CargoStore::setParserContext($parser, 
'ApprovedRevsRevisionApproved');
return true;
}
 
@@ -201,7 +200,7 @@
$pageID = $title->getArticleID();
self::deletePageFromSystem( $pageID );
// This is all we need - see onARRevisionApproved(), above.
-   CargoStore::$settings['origin'] = 'Approved Revs revision 
unapproved';
+   CargoStore::setParserContext($parser, 
'ApprovedRevsRevisionUnapproved');
return true;
}
 
diff --git a/CargoPopulateTableJob.php b/CargoPopulateTableJob.php
index 8f0499c..8abec90 100644
--- a/CargoPopulateTableJob.php
+++ b/CargoPopulateTableJob.php
@@ -42,17 +42,10 @@
$cdb->delete( $this->params['dbTableName'], array( 
'_pageID' => $article->getID() ) );
}
 
-   // All we need to do here is set some global variables based
+   // All we need to do here is set some parser variables based
// on the parameters of this job, then parse the page -
// the #cargo_store function will take care of the rest.
-   CargoStore::$settings['origin'] = 'template';
-   CargoStore::$settings['dbTableName'] = 
$this->params['dbTableName'];
-   CargoUtils::parsePageForStorage( $this->title, 
$article->getContent() );
-
-   // We need to unset this, if the job was called via runJobs.php,
-   // so that it doesn't affect other (non-Cargo) jobs, like page
-   // refreshes.
-   unset( CargoStore::$settings['origin'] );
+   CargoUtils::parsePageForStorage( $this->title, 
$article->getContent(), 'Template', $this->params['dbTableName'] );
 
wfProfileOut( __METHOD__ );
return true;
diff --git a/CargoUtils.php b/CargoUtils.php
index e1ad9fd..9c33263 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -360,7 +360,7 @@
return $value;
}
 
-   public static function parsePageForStorage( $title, $pageContents ) {
+   public static function parsePageForStorage( $title, $pageContents, 
$savingContext, $populatedTable = false ) {
// @TODO - is there a "cleaner" way to get a page to be parsed?
global $wgParser;
 
@@ -375,7 +375,10 @@
} else {
$pageText = $pageContents;
}
-   $wgParser->parse( $pageText, $title, new ParserOptions() );
+
+   $parserOptions = new ParserOptions();
+   CargoStore::setParserOptionsContext( $parserOptions, 
$savingContext, $populatedTable );
+   $wgParser->parse( $pageText, $title, $parserOptions );
}
 
/**
diff --git a/maintenance/cargoRecreateData.php 
b/maintenance/cargoRecreateData.php
index c7e19ae..b0fc9c6 100644
--- a/maintenance/cargoRecreateData.php
+++ b/maintenance/cargoRecreateData.php
@@ -

[MediaWiki-commits] [Gerrit] Fix fatal error where SemanticForms accesses Cargo private p... - change (mediawiki...SemanticForms)

2015-12-28 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/261211

Change subject: Fix fatal error where SemanticForms accesses Cargo private 
property
..

Fix fatal error where SemanticForms accesses Cargo private property

Semantic Form accessing Cargo private property yields fatal error when editing 
form

class CargoFieldDescription {
...
public $mDelimiter;

was recently changed to

class CargoFieldDescription {
...
private $mDelimiter;

which causes the following error "Fatal error: Cannot access private property 
CargoFieldDescription::$mDelimiter in 
/www-wiki/core/extensions/SemanticForms/includes/SF_TemplateField.php on line 
160"

Bug: T122522
Change-Id: Ifb02896e8ca5c58c11ce5ceed9a9a6b261c82389
---
M includes/SF_TemplateField.php
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/11/261211/1

diff --git a/includes/SF_TemplateField.php b/includes/SF_TemplateField.php
index 2e660fb..bb778aa 100644
--- a/includes/SF_TemplateField.php
+++ b/includes/SF_TemplateField.php
@@ -157,7 +157,7 @@
$this->mFieldType = $fieldDescription->mType;
}
$this->mIsList = $fieldDescription->mIsList;
-   $this->mDelimiter = $fieldDescription->mDelimiter;
+   $this->mDelimiter = $fieldDescription->getDelimiter();
$this->mPossibleValues = $fieldDescription->mAllowedValues;
}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb02896e8ca5c58c11ce5ceed9a9a6b261c82389
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Ed Hoo 

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


[MediaWiki-commits] [Gerrit] Use of DB_MASTER in order to consider replication lag - change (mediawiki...Cargo)

2015-12-26 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/261106

Change subject: Use of DB_MASTER in order to consider replication lag
..

Use of DB_MASTER in order to consider replication lag

Fix 1:
Change calls from DB_SLAVE to DB_MASTER in order to ensure that slaves being 
out of date will not cause updates to be driven off stale information.

Fix 2:
Use of the naming convention 'dbw' to indicate connections to DB_MASTER.

Bug: T122469
Change-Id: I79020572366fa114f5ae724125fc94e160e5db56
---
M Cargo.hooks.php
M CargoUtils.php
M parserfunctions/CargoAttach.php
M parserfunctions/CargoStore.php
M specials/CargoDeleteTable.php
M specials/CargoPageValues.php
M specials/CargoRecreateData.php
7 files changed, 53 insertions(+), 53 deletions(-)


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

diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index 3ea7ddd..9abbb8c 100644
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -117,15 +117,15 @@
// efficiently delete from the former.)
 
// Get all the "main" tables that this page is contained in.
-   $dbr = wfGetDB( DB_MASTER );
+   $dbw = wfGetDB( DB_MASTER );
$cdb = CargoUtils::getDB();
-   $res = $dbr->select( 'cargo_pages', 'table_name', array( 
'page_id' => $pageID ) );
-   while ( $row = $dbr->fetchRow( $res ) ) {
+   $res = $dbw->select( 'cargo_pages', 'table_name', array( 
'page_id' => $pageID ) );
+   while ( $row = $dbw->fetchRow( $res ) ) {
$curMainTable = $row['table_name'];
 
// First, delete from the "field" tables.
-   $res2 = $dbr->select( 'cargo_tables', 'field_tables', 
array( 'main_table' => $curMainTable ) );
-   $row2 = $dbr->fetchRow( $res2 );
+   $res2 = $dbw->select( 'cargo_tables', 'field_tables', 
array( 'main_table' => $curMainTable ) );
+   $row2 = $dbw->fetchRow( $res2 );
$fieldTableNames = unserialize( $row2['field_tables'] );
foreach ( $fieldTableNames as $curFieldTable ) {
// Thankfully, the MW DB API already provides a
@@ -139,7 +139,7 @@
}
 
// Finally, delete from cargo_pages.
-   $dbr->delete( 'cargo_pages', array( 'page_id' => $pageID ) );
+   $dbw->delete( 'cargo_pages', array( 'page_id' => $pageID ) );
 
// This call is needed to get deletions to actually happen.
$cdb->close();
@@ -222,13 +222,13 @@
$newPageName = $newtitle->getPrefixedText();
$newPageTitle = $newtitle->getText();
$newPageNamespace = $newtitle->getNamespace();
-   $dbr = wfGetDB( DB_MASTER );
+   $dbw = wfGetDB( DB_MASTER );
$cdb = CargoUtils::getDB();
// We use $oldid, because that's the page ID - $newid is the
// ID of the redirect page.
// @TODO - do anything with the redirect?
-   $res = $dbr->select( 'cargo_pages', 'table_name', array( 
'page_id' => $oldid ) );
-   while ( $row = $dbr->fetchRow( $res ) ) {
+   $res = $dbw->select( 'cargo_pages', 'table_name', array( 
'page_id' => $oldid ) );
+   while ( $row = $dbw->fetchRow( $res ) ) {
$curMainTable = $row['table_name'];
$cdb->update( $curMainTable,
array(
diff --git a/CargoUtils.php b/CargoUtils.php
index 0ecd191..e1ad9fd 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -22,10 +22,10 @@
public static function getDB() {
global $wgDBuser, $wgDBpassword, $wgDBprefix;
global $wgCargoDBserver, $wgCargoDBname, $wgCargoDBuser, 
$wgCargoDBpassword, $wgCargoDBtype;
-   $dbr = wfGetDB( DB_SLAVE );
-   $server = $dbr->getServer();
-   $name = $dbr->getDBname();
-   $type = $dbr->getType();
+   $dbw = wfGetDB( DB_MASTER );
+   $server = $dbw->getServer();
+   $name = $dbw->getDBname();
+   $type = $dbw->getType();
 
$dbType = is_null( $wgCargoDBtype ) ? $type : $wgCargoDBtype;
$dbServer = is_null( $wgCargoDBserver ) ? $server : 
$wgCargoDBserver;
@@ -52,8 +52,8 @@
 * Gets a page property for the specified page ID and property name.
 */
public static function getPageProp( $pageID, $pageProp ) {
-   $dbr = wfGetDB( DB_SLAVE );
-   $res = $dbr->select( 'page_props', array(
+   $dbw = wfGetDB( DB_MASTER );
+   $res = $dbw->select( 'page_props', array(
'pp_valu

[MediaWiki-commits] [Gerrit] Use of DB_MASTER in order to consider replication lag - change (mediawiki...Cargo)

2015-12-26 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/261105

Change subject: Use of DB_MASTER in order to consider replication lag
..

Use of DB_MASTER in order to consider replication lag

Fix 1:
Change calls from DB_SLAVE to DB_MASTER in order to ensure that slaves being 
out of date will not cause updates to be driven off stale information.

Fix 2:
Use of the naming convention 'dbw' to indicate connections to DB_MASTER.

Bug: T122469
Change-Id: Ic610746ee997f41e37345f9ac01a3d459ce584ad
---
M Cargo.hooks.php
M CargoUtils.php
M parserfunctions/CargoAttach.php
M parserfunctions/CargoStore.php
M specials/CargoDeleteTable.php
M specials/CargoPageValues.php
M specials/CargoRecreateData.php
7 files changed, 50 insertions(+), 50 deletions(-)


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

diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index 3ea7ddd..9abbb8c 100644
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -117,15 +117,15 @@
// efficiently delete from the former.)
 
// Get all the "main" tables that this page is contained in.
-   $dbr = wfGetDB( DB_MASTER );
+   $dbw = wfGetDB( DB_MASTER );
$cdb = CargoUtils::getDB();
-   $res = $dbr->select( 'cargo_pages', 'table_name', array( 
'page_id' => $pageID ) );
-   while ( $row = $dbr->fetchRow( $res ) ) {
+   $res = $dbw->select( 'cargo_pages', 'table_name', array( 
'page_id' => $pageID ) );
+   while ( $row = $dbw->fetchRow( $res ) ) {
$curMainTable = $row['table_name'];
 
// First, delete from the "field" tables.
-   $res2 = $dbr->select( 'cargo_tables', 'field_tables', 
array( 'main_table' => $curMainTable ) );
-   $row2 = $dbr->fetchRow( $res2 );
+   $res2 = $dbw->select( 'cargo_tables', 'field_tables', 
array( 'main_table' => $curMainTable ) );
+   $row2 = $dbw->fetchRow( $res2 );
$fieldTableNames = unserialize( $row2['field_tables'] );
foreach ( $fieldTableNames as $curFieldTable ) {
// Thankfully, the MW DB API already provides a
@@ -139,7 +139,7 @@
}
 
// Finally, delete from cargo_pages.
-   $dbr->delete( 'cargo_pages', array( 'page_id' => $pageID ) );
+   $dbw->delete( 'cargo_pages', array( 'page_id' => $pageID ) );
 
// This call is needed to get deletions to actually happen.
$cdb->close();
@@ -222,13 +222,13 @@
$newPageName = $newtitle->getPrefixedText();
$newPageTitle = $newtitle->getText();
$newPageNamespace = $newtitle->getNamespace();
-   $dbr = wfGetDB( DB_MASTER );
+   $dbw = wfGetDB( DB_MASTER );
$cdb = CargoUtils::getDB();
// We use $oldid, because that's the page ID - $newid is the
// ID of the redirect page.
// @TODO - do anything with the redirect?
-   $res = $dbr->select( 'cargo_pages', 'table_name', array( 
'page_id' => $oldid ) );
-   while ( $row = $dbr->fetchRow( $res ) ) {
+   $res = $dbw->select( 'cargo_pages', 'table_name', array( 
'page_id' => $oldid ) );
+   while ( $row = $dbw->fetchRow( $res ) ) {
$curMainTable = $row['table_name'];
$cdb->update( $curMainTable,
array(
diff --git a/CargoUtils.php b/CargoUtils.php
index 0ecd191..e1ad9fd 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -22,10 +22,10 @@
public static function getDB() {
global $wgDBuser, $wgDBpassword, $wgDBprefix;
global $wgCargoDBserver, $wgCargoDBname, $wgCargoDBuser, 
$wgCargoDBpassword, $wgCargoDBtype;
-   $dbr = wfGetDB( DB_SLAVE );
-   $server = $dbr->getServer();
-   $name = $dbr->getDBname();
-   $type = $dbr->getType();
+   $dbw = wfGetDB( DB_MASTER );
+   $server = $dbw->getServer();
+   $name = $dbw->getDBname();
+   $type = $dbw->getType();
 
$dbType = is_null( $wgCargoDBtype ) ? $type : $wgCargoDBtype;
$dbServer = is_null( $wgCargoDBserver ) ? $server : 
$wgCargoDBserver;
@@ -52,8 +52,8 @@
 * Gets a page property for the specified page ID and property name.
 */
public static function getPageProp( $pageID, $pageProp ) {
-   $dbr = wfGetDB( DB_SLAVE );
-   $res = $dbr->select( 'page_props', array(
+   $dbw = wfGetDB( DB_MASTER );
+   $res = $dbw->select( 'page_props', array(
'pp_valu

[MediaWiki-commits] [Gerrit] Fix HOLDS operator parsing and adds corresponding NOT functi... - change (mediawiki...Cargo)

2015-12-24 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/260951

Change subject: Fix HOLDS operator parsing and adds corresponding NOT 
functionality
..

Fix HOLDS operator parsing and adds corresponding NOT functionality

The expanded functionality enables HOLDS to be used as follows:
Author HOLDS "John Smith"
Author HOLDS NOT "Jane Smith"
Author HOLDS LIKE "% Smith"
Author HOLDS NOT LIKE "% Johnson"
Book.Author HOLDS "John Smith"
Book.Author HOLDS NOT "Jane Smith"
Book.Author HOLDS LIKE "% Smith"
Book.Author HOLDS NOT LIKE "% Johnson"

Change-Id: I46f3e052901420f0c6d68c6291b16b52299d43f5
---
M CargoSQLQuery.php
1 file changed, 62 insertions(+), 41 deletions(-)


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

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 23722ee..c892f2e 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -558,6 +558,22 @@
return false;
}
 
+   /*
+* Provides HOLDS functionality to WHERE clause by replacing $pattern
+* in $subject with $replacement and setting $found to true if
+* successful (leaves it untouched otehrwise). Includes modifying
+* the regex beginning from a non-valid identifier character to word
+* boundary.
+*/
+   function substVirtualFieldName( &$subject, $pattern, $replacement, 
&$found ) {
+   if ( preg_match( $pattern, $subject ) ) {
+   $pattern = str_replace( '([^\w$]|^)', '\b', $pattern);
+   $pattern = str_replace( '([^\w$.]|^)', '\b', $pattern);
+   $subject = preg_replace( $pattern, $replacement, 
$subject );
+   $found = true;
+   }
+   }
+
function handleVirtualFields() {
// The array-field alias can be found in a number of different
// clauses. Handling depends on which clause it is:
@@ -592,38 +608,57 @@
foreach ( $virtualFields as $virtualField ) {
$fieldName = $virtualField['fieldName'];
$tableName = $virtualField['tableName'];
-   $foundLikeMatch1 = $foundMatch1 = $foundLikeMatch2 = 
$foundMatch2 = false;
-   $likePattern1 = $likePattern2 = '';
-   $patternSuffix = '\s+(HOLDS)\s+(LIKE)?/i';
+   $fieldTableName = $tableName . '__' . $fieldName;
+   $replacementFieldName = $fieldTableName . '._value';
+   $patternSuffix = '\b\s*/i';
+   $fieldReplaced = false;
$throwException = false;
 
-   $simplePattern1 = 
CargoUtils::getSQLTableAndFieldPattern( $tableName, $fieldName );
-   if ( preg_match( $simplePattern1, $this->mWhereStr ) ) {
-   $likePattern1 = 
CargoUtils::getSQLTableAndFieldPattern( $tableName, $fieldName, false ).
-   $patternSuffix;
-   if ( preg_match( $likePattern1, 
$this->mWhereStr, $matches ) ) {
-   $foundMatch1 = count( $matches ) == 3;
-   $foundLikeMatch1 = count( $matches ) == 
4;
+   $patternSimple = array(
+   CargoUtils::getSQLTableAndFieldPattern( 
$tableName, $fieldName ),
+   CargoUtils::getSQLFieldPattern( $fieldName )
+   );
+   $patternRoot = array(
+   CargoUtils::getSQLTableAndFieldPattern( 
$tableName, $fieldName, false ) . '\s+',
+   CargoUtils::getSQLFieldPattern( $fieldName, 
false ) . '\s+'
+   );
+
+   for ( $i = 0 ; $i < 2 ; $i++ ) {
+   if ( preg_match( $patternSimple[$i], 
$this->mWhereStr ) ) {
+
+   $this->substVirtualFieldName(
+   $this->mWhereStr,
+   $patternRoot[$i] . 
'HOLDS\s+NOT\s+LIKE' . $patternSuffix,
+   "$replacementFieldName NOT LIKE 
",
+   $fieldReplaced);
+
+   $this->substVirtualFieldName(
+   $this->mWhereStr,
+   $patternRoot[$i] . 
'HOLDS\s+LIKE' . $patternSuffix,
+   "$replacementFieldName LIKE ",
+   $fieldReplaced);
+
+   $this->substVirtualField

[MediaWiki-commits] [Gerrit] Fix HOLDS RegEx eating non-identifier characters when replac... - change (mediawiki...Cargo)

2015-12-21 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/260531

Change subject: Fix HOLDS RegEx eating non-identifier characters when replacing 
field name
..

Fix HOLDS RegEx eating non-identifier characters when replacing field name

Fix HOLDS RegEx eating non-identifier characters when replacing field name

Change-Id: Iebd2cdaa294a4f97022da87a89d90d79d111de90
---
M CargoSQLQuery.php
1 file changed, 4 insertions(+), 0 deletions(-)


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

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 69c30ea..a10f2e4 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -593,6 +593,7 @@
$fieldName = $virtualField['fieldName'];
$tableName = $virtualField['tableName'];
$foundLikeMatch1 = $foundMatch1 = $foundLikeMatch2 = 
$foundMatch2 = false;
+   $likePattern1 = $likePattern2 = '';
$patternSuffix = '\s+(HOLDS)\s+(LIKE)?/i';
$throwException = false;
 
@@ -631,6 +632,9 @@
'table2' => $fieldTableName,
'field2' => '_rowID'
);
+   $likePattern1 = str_replace( '([^\w$.]|^)', 
'\\b', $likePattern1);
+   $likePattern2 = str_replace( '([^\w$.]|^)', 
'\\b', $likePattern2);
+
if ( $foundLikeMatch1 ) {
$this->mWhereStr = preg_replace( 
$likePattern1, "$fieldTableName._value LIKE ",
$this->mWhereStr );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebd2cdaa294a4f97022da87a89d90d79d111de90
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Ed Hoo 

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


[MediaWiki-commits] [Gerrit] [Cargo] #cargo_query Fix issues with quotes and other parsing - change (mediawiki...Cargo)

2015-12-13 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/258753

Change subject: [Cargo] #cargo_query Fix issues with quotes and other parsing
..

[Cargo] #cargo_query Fix issues with quotes and other parsing

Apologies, the description of the changes will be provided as a separate 
comment due to commit issues with git

Change-Id: I56e9bee6237e1bfd66889bf9a63b2b3216ebd2d3
---
M CargoSQLQuery.php
M CargoUtils.php
2 files changed, 158 insertions(+), 118 deletions(-)


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

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index defc8ba..e1eaf17 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -95,19 +95,18 @@
'/\-\-/' => '--',
'/#/' => '#',
);
-   // HTML-decode the string - this is necessary if the query
-   // contains a call to {{PAGENAME}} and the page name has any
-   // special characters, because {{PAGENAME]] unfortunately
-   // HTML-encodes the value, which leads to a '#' in the string.
-   $decodedWhereStr = html_entity_decode( $whereStr );
foreach ( $whereStrRegexps as $regexp => $displayString ) {
-   if ( preg_match( $regexp, $decodedWhereStr ) ) {
+   if ( preg_match( $regexp, $whereStr ) ) {
throw new MWException( "Error in \"where\" 
parameter: the string \"$displayString\" cannot be used within #cargo_query." );
}
}
-   $simplifiedWhereStr = str_replace( array( '\"', "\'" ), '', 
$whereStr );
-   $simplifiedWhereStr = preg_replace( '/"[^"]*"/', '', 
$simplifiedWhereStr );
-   $simplifiedWhereStr = preg_replace( "/'[^']*'/", '', 
$simplifiedWhereStr );
+   $noQuotesPattern = '/([\'"]).*?\1/';
+   $noQuotesFieldsStr = preg_replace( $noQuotesPattern, '', 
$fieldsStr );
+   $noQuotesWhereStr = preg_replace( $noQuotesPattern, '', 
$whereStr );
+   $noQuotesJoinOnStr = preg_replace( $noQuotesPattern, '', 
$joinOnStr );
+   $noQuotesGroupByStr = preg_replace( $noQuotesPattern, '', 
$groupByStr );
+   $noQuotesHavingStr = preg_replace( $noQuotesPattern, '', 
$havingStr );
+   $noQuotesOrderByStr = preg_replace( $noQuotesPattern, '', 
$orderByStr );
 
$regexps = array(
'/\bselect\b/i' => 'SELECT',
@@ -123,22 +122,22 @@
);
foreach ( $regexps as $regexp => $displayString ) {
if ( preg_match( $regexp, $tablesStr ) ||
-   preg_match( $regexp, $fieldsStr ) ||
-   preg_match( $regexp, $simplifiedWhereStr ) ||
-   preg_match( $regexp, $joinOnStr ) ||
-   preg_match( $regexp, $groupByStr ) ||
-   preg_match( $regexp, $havingStr ) ||
-   preg_match( $regexp, $orderByStr ) ||
+   preg_match( $regexp, $noQuotesFieldsStr ) ||
+   preg_match( $regexp, $noQuotesWhereStr ) ||
+   preg_match( $regexp, $noQuotesJoinOnStr ) ||
+   preg_match( $regexp, $noQuotesGroupByStr ) ||
+   preg_match( $regexp, $noQuotesHavingStr ) ||
+   preg_match( $regexp, $noQuotesOrderByStr ) ||
preg_match( $regexp, $limitStr ) ) {
throw new MWException( "Error: the string 
\"$displayString\" cannot be used within #cargo_query." );
}
}
 
-   self::getAndValidateSQLFunctions( $simplifiedWhereStr );
-   self::getAndValidateSQLFunctions( $joinOnStr );
-   self::getAndValidateSQLFunctions( $groupByStr );
-   self::getAndValidateSQLFunctions( $havingStr );
-   self::getAndValidateSQLFunctions( $orderByStr );
+   self::getAndValidateSQLFunctions( $noQuotesWhereStr );
+   self::getAndValidateSQLFunctions( $noQuotesJoinOnStr );
+   self::getAndValidateSQLFunctions( $noQuotesGroupByStr );
+   self::getAndValidateSQLFunctions( $noQuotesHavingStr );
+   self::getAndValidateSQLFunctions( $noQuotesOrderByStr );
self::getAndValidateSQLFunctions( $limitStr );
}
 
@@ -340,7 +339,7 @@
global $wgCargoAllowedSQLFunctions;
 
$sqlFunctionMatches = array();
-   $sqlFunctionRegex = '/(\b|\W)(\w*?)\s?\(/';
+   $sqlFunctionRegex = '/(\b|\W)(\w*?)\s*\(/';
preg_match_all( $s

[MediaWiki-commits] [Gerrit] [Cargo] Fix T120583: #cargo_query HOLDS check used in multi-... - change (mediawiki...Cargo)

2015-12-06 Thread Ed Hoo (Code Review)
Ed Hoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/257266

Change subject: [Cargo] Fix T120583: #cargo_query HOLDS check used in 
multi-value fields
..

[Cargo] Fix T120583: #cargo_query HOLDS check used in multi-value fields

Change the HOLDS check to match the field "book", but not the field "bookworm" 
when the field that allows for multiple values is "book".  Makes the match 
case-insensitive since table and column names are usually not case sensitive.

Bug: T120583
Change-Id: I22cffe0ffed72fed72cdf2f83673a0d871313986
---
M CargoSQLQuery.php
1 file changed, 4 insertions(+), 4 deletions(-)


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

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index acc0512..83d5b8e 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -556,19 +556,19 @@
$fieldName = $virtualField['fieldName'];
$tableName = $virtualField['tableName'];
 
-   $likePattern1 = "/\b$tableName\.$fieldName(\s*HOLDS 
LIKE\s*)/";
+   $likePattern1 = 
"/\b$tableName\.$fieldName".'[^0-9a-zA-Z$_](\s*HOLDS LIKE\s*)/i';
$foundLikeMatch1 = preg_match( $likePattern1, 
$this->mWhereStr, $matches );
$foundLikeMatch2 = $foundMatch1 = $foundMatch2 = false;
if ( !$foundLikeMatch1 ) {
-   $likePattern2 = "/\b$fieldName(\s*HOLDS 
LIKE\s*)/";
+   $likePattern2 = 
"/\b$fieldName".'[^0-9a-zA-Z$_](\s*HOLDS LIKE\s*)/i';
$foundLikeMatch2 = preg_match( $likePattern2, 
$this->mWhereStr, $matches );
}
 
if ( !$foundLikeMatch1 && !$foundLikeMatch2 ) {
-   $pattern1 = 
"/\b$tableName\.$fieldName(\s*HOLDS\s*)?/";
+   $pattern1 = 
"/\b$tableName\.$fieldName".'[^0-9a-zA-Z$_](\s*HOLDS\s*)?/i';
$foundMatch1 = preg_match( $pattern1, 
$this->mWhereStr, $matches );
if ( !$foundMatch1 ) {
-   $pattern2 = 
"/\b$fieldName(\s*HOLDS\s*)?/";
+   $pattern2 = 
"/\b$fieldName".'[^0-9a-zA-Z$_](\s*HOLDS\s*)?/i';
$foundMatch2 = preg_match( $pattern2, 
$this->mWhereStr, $matches );
}
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22cffe0ffed72fed72cdf2f83673a0d871313986
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Ed Hoo 

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