[MediaWiki-commits] [Gerrit] added Cargo support - change (mediawiki...SafeDelete)

2015-09-25 Thread Cicalese (Code Review)
Cicalese has submitted this change and it was merged.

Change subject: added Cargo support
..


added Cargo support

Change-Id: I855d1d0635a9b1db01554b89cf4c6b3c1a076e5e
---
M SafeDelete.class.php
M SafeDelete.php
2 files changed, 53 insertions(+), 5 deletions(-)

Approvals:
  Cicalese: Verified; Looks good to me, approved



diff --git a/SafeDelete.class.php b/SafeDelete.class.php
index 8c15faf..80c7eb0 100644
--- a/SafeDelete.class.php
+++ b/SafeDelete.class.php
@@ -53,7 +53,7 @@
$title = Title::newFromURL( $par );
$this->getSkin()->setRelevantTitle( $title );
 
-   if ( class_exists ("SemanticTitle" ) ) {
+   if ( class_exists( "SemanticTitle" ) ) {
$displaytitle = SemanticTitle::getText( $title );
} else {
$displaytitle = $title->getPrefixedText();
@@ -63,12 +63,27 @@
 
$this->getOutput()->addBacklinkSubtitle( $title );
 
-   if ( isset($GLOBALS['SafeDeleteSemantic']) &&
-   $GLOBALS['SafeDeleteSemantic'] === true ) {
+   $done = false;
+
+   $result = array();
+
+   if ( isset( $GLOBALS['SafeDeleteSemantic'] ) &&
+   $GLOBALS['SafeDeleteSemantic'] ) {
 
$result = $this->querySemantic( $title );
+   $done = true;
+   }
 
-   } else {
+   if ( isset( $GLOBALS['SafeDeleteCargo'] ) &&
+   is_array( $GLOBALS['SafeDeleteCargo'] ) &&
+   count( $GLOBALS['SafeDeleteCargo'] ) > 0 ) {
+
+   $result = array_merge( $result,
+   $this->queryCargo( $title, 
$GLOBALS['SafeDeleteCargo'] ) );
+   $done = true;
+   }
+
+   if ( !$done ) {
 
$result = $this->queryNonSemantic( $title );
 
@@ -129,6 +144,39 @@
return $result;
}
 
+   private function queryCargo( $title, $cargo_fields ) {
+
+   $targetpage = $title->getPrefixedText();
+
+   $result = array();
+
+   foreach ( $cargo_fields as $field ) {
+
+   if ( isset( $field[2] ) && $field[2] == true ) {
+   $operator = ' HOLDS ';
+   } else {
+   $operator = ' = ';
+   }
+
+   $query = CargoSQLQuery::newFromValues( $field[0], 
'_pageName',
+   $field[1] . $operator .'"' . $targetpage . '"', 
null,
+   '_pageName', null, null, '' );
+   $rows = $query->run();
+
+   foreach ( $rows as $row ) {
+
+   $sourcepage = $row['_pageName'];
+
+   if ( ( $sourcepage != $targetpage ) &&
+   ! array_key_exists( $targetpage, 
$result ) ) {
+   $result[$sourcepage] = 
Title::newFromText( $sourcepage );
+   }
+   }
+   }
+
+   return $result;
+   }
+
public function queryNonSemantic ( $title ) {
 
$dbr = wfGetDB( DB_SLAVE );
diff --git a/SafeDelete.php b/SafeDelete.php
index 78ec089..7118040 100644
--- a/SafeDelete.php
+++ b/SafeDelete.php
@@ -27,7 +27,7 @@
 
 $wgExtensionCredits['special'][] = array (
'name' => 'Safe Delete',
-   'version' => '1.1',
+   'version' => '1.2',
'author' => '[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]',
'descriptionmsg' => 'safedelete-desc',
'path' => __FILE__,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I855d1d0635a9b1db01554b89cf4c6b3c1a076e5e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SafeDelete
Gerrit-Branch: master
Gerrit-Owner: Cicalese 
Gerrit-Reviewer: Cicalese 

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


[MediaWiki-commits] [Gerrit] added Cargo support - change (mediawiki...SafeDelete)

2015-09-24 Thread Cicalese (Code Review)
Cicalese has uploaded a new change for review.

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

Change subject: added Cargo support
..

added Cargo support

Change-Id: I855d1d0635a9b1db01554b89cf4c6b3c1a076e5e
---
M SafeDelete.class.php
M SafeDelete.php
2 files changed, 53 insertions(+), 5 deletions(-)


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

diff --git a/SafeDelete.class.php b/SafeDelete.class.php
index 8c15faf..80c7eb0 100644
--- a/SafeDelete.class.php
+++ b/SafeDelete.class.php
@@ -53,7 +53,7 @@
$title = Title::newFromURL( $par );
$this->getSkin()->setRelevantTitle( $title );
 
-   if ( class_exists ("SemanticTitle" ) ) {
+   if ( class_exists( "SemanticTitle" ) ) {
$displaytitle = SemanticTitle::getText( $title );
} else {
$displaytitle = $title->getPrefixedText();
@@ -63,12 +63,27 @@
 
$this->getOutput()->addBacklinkSubtitle( $title );
 
-   if ( isset($GLOBALS['SafeDeleteSemantic']) &&
-   $GLOBALS['SafeDeleteSemantic'] === true ) {
+   $done = false;
+
+   $result = array();
+
+   if ( isset( $GLOBALS['SafeDeleteSemantic'] ) &&
+   $GLOBALS['SafeDeleteSemantic'] ) {
 
$result = $this->querySemantic( $title );
+   $done = true;
+   }
 
-   } else {
+   if ( isset( $GLOBALS['SafeDeleteCargo'] ) &&
+   is_array( $GLOBALS['SafeDeleteCargo'] ) &&
+   count( $GLOBALS['SafeDeleteCargo'] ) > 0 ) {
+
+   $result = array_merge( $result,
+   $this->queryCargo( $title, 
$GLOBALS['SafeDeleteCargo'] ) );
+   $done = true;
+   }
+
+   if ( !$done ) {
 
$result = $this->queryNonSemantic( $title );
 
@@ -129,6 +144,39 @@
return $result;
}
 
+   private function queryCargo( $title, $cargo_fields ) {
+
+   $targetpage = $title->getPrefixedText();
+
+   $result = array();
+
+   foreach ( $cargo_fields as $field ) {
+
+   if ( isset( $field[2] ) && $field[2] == true ) {
+   $operator = ' HOLDS ';
+   } else {
+   $operator = ' = ';
+   }
+
+   $query = CargoSQLQuery::newFromValues( $field[0], 
'_pageName',
+   $field[1] . $operator .'"' . $targetpage . '"', 
null,
+   '_pageName', null, null, '' );
+   $rows = $query->run();
+
+   foreach ( $rows as $row ) {
+
+   $sourcepage = $row['_pageName'];
+
+   if ( ( $sourcepage != $targetpage ) &&
+   ! array_key_exists( $targetpage, 
$result ) ) {
+   $result[$sourcepage] = 
Title::newFromText( $sourcepage );
+   }
+   }
+   }
+
+   return $result;
+   }
+
public function queryNonSemantic ( $title ) {
 
$dbr = wfGetDB( DB_SLAVE );
diff --git a/SafeDelete.php b/SafeDelete.php
index 78ec089..7118040 100644
--- a/SafeDelete.php
+++ b/SafeDelete.php
@@ -27,7 +27,7 @@
 
 $wgExtensionCredits['special'][] = array (
'name' => 'Safe Delete',
-   'version' => '1.1',
+   'version' => '1.2',
'author' => '[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]',
'descriptionmsg' => 'safedelete-desc',
'path' => __FILE__,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I855d1d0635a9b1db01554b89cf4c6b3c1a076e5e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SafeDelete
Gerrit-Branch: master
Gerrit-Owner: Cicalese 

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