Cicalese has submitted this change and it was merged.
Change subject: added handling of deletion
......................................................................
added handling of deletion
Change-Id: I83ce29c957bbd09faaa9f89845f330d32272cd19
---
M SemanticDependency.class.php
M SemanticDependency.php
2 files changed, 100 insertions(+), 22 deletions(-)
Approvals:
Cicalese: Verified; Looks good to me, approved
diff --git a/SemanticDependency.class.php b/SemanticDependency.class.php
index 52c3ce2..005d6a1 100644
--- a/SemanticDependency.class.php
+++ b/SemanticDependency.class.php
@@ -1,7 +1,7 @@
<?php
/*
- * Copyright (c) 2014 The MITRE Corporation
+ * Copyright (c) 2014-2015 The MITRE Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -24,24 +24,7 @@
class SemanticDependency {
- /**
- * @since 1.0
- *
- * @param Parser &$parser
- */
- public static function setup( &$parser ) {
-
- if ( !isset( $GLOBALS['SemanticDependency_Properties'] ) ) {
- $GLOBALS['SemanticDependency_Properties'] = array();
- }
-
- if ( !isset( $GLOBALS['SemanticDependency_JobThreshold'] ) ) {
- $GLOBALS['SemanticDependency_JobThreshold'] = 1;
- }
-
- return true;
-
- }
+ private static $titles = array();
/**
* @since 1.0
@@ -52,6 +35,7 @@
public static function updateDataAfter( \SMW\Store $store,
\SMW\SemanticData $semanticData ) {
+ self::setup();
$instance = new self( $store, $semanticData );
$instance->setConfiguration(
$GLOBALS['SemanticDependency_Properties'],
@@ -59,6 +43,72 @@
$instance->performUpdate();
return true;
+ }
+
+ /**
+ * @since 1.1
+ *
+ * @param WikiPage &$article
+ * @param User &$user
+ * @param &$reason
+ * @param &$error
+ */
+ public static function articleDelete( WikiPage &$article,
+ User &$user, &$reason, &$error ) {
+
+ self::setup();
+ $store = \SMW\StoreFactory::getStore();
+ $page = SMWDIWikiPage::newFromTitle( $article->getTitle() );
+ $semanticData = $store->getSemanticData( $page );
+ $instance = new self( $store, $semanticData );
+ $instance->setConfiguration(
+ $GLOBALS['SemanticDependency_Properties'],
+ $GLOBALS['SemanticDependency_JobThreshold'] );
+ $instance->saveDependentTitles();
+
+ return true;
+ }
+
+ /**
+ * @since 1.1
+ *
+ * @param WikiPage &$article
+ * @param User &$user
+ * @param $reason
+ * @param $id
+ * @param $content
+ * @param $logEntry
+ */
+ public static function articleDeleteComplete( WikiPage &$article,
+ User &$user, $reason, $id, $content, $logEntry ) {
+
+ self::setup();
+ $store = \SMW\StoreFactory::getStore();
+ $page = SMWDIWikiPage::newFromTitle( $article->getTitle() );
+ $semanticData = $store->getSemanticData( $page );
+ $instance = new self( $store, $semanticData );
+ $instance->setConfiguration(
+ $GLOBALS['SemanticDependency_Properties'],
+ $GLOBALS['SemanticDependency_JobThreshold'] );
+ $instance->performUpdate();
+
+ return true;
+ }
+
+ /**
+ * @since 1.0
+ *
+ * @param Parser &$parser
+ */
+ private static function setup() {
+
+ if ( !isset( $GLOBALS['SemanticDependency_Properties'] ) ) {
+ $GLOBALS['SemanticDependency_Properties'] = array();
+ }
+
+ if ( !isset( $GLOBALS['SemanticDependency_JobThreshold'] ) ) {
+ $GLOBALS['SemanticDependency_JobThreshold'] = 1;
+ }
}
private $store;
@@ -90,6 +140,20 @@
}
/**
+ * @since 1.1
+ */
+ public function saveDependentTitles() {
+
+ $title = $this->semanticData->getSubject()->getTitle();
+
+ $dependentTitles = $this->getDependentTitles( $title );
+
+ $titleText = $title->getPrefixedText();
+
+ self::$titles[$titleText] = $dependentTitles;
+ }
+
+ /**
* @since 1.0
*/
public function performUpdate() {
@@ -98,6 +162,18 @@
$dependentTitles = $this->getDependentTitles( $title );
+ if ( $dependentTitles == array() ) {
+
+ // page may have been deleted; see if we've saved info
for it
+ $titleText = $title->getPrefixedText();
+
+ if ( array_key_exists( $titleText, self::$titles ) ) {
+
+ // page was deleted; get saved list of
dependent titles
+ $dependentTitles = self::$titles[$titleText];
+ }
+ }
+
$jobs = array();
$count = 1;
diff --git a/SemanticDependency.php b/SemanticDependency.php
index 00365bd..c005aa5 100644
--- a/SemanticDependency.php
+++ b/SemanticDependency.php
@@ -1,7 +1,7 @@
<?php
/*
- * Copyright (c) 2014 The MITRE Corporation
+ * Copyright (c) 2014-2015 The MITRE Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -29,7 +29,7 @@
$GLOBALS['wgExtensionCredits']['semantic'][] = array (
'path' => __FILE__,
'name' => 'Semantic Dependency',
- 'version' => '1.0',
+ 'version' => '1.1',
'author' => array(
'[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy
Cicalese]'
),
@@ -40,9 +40,11 @@
$GLOBALS['wgAutoloadClasses']['SemanticDependency'] =
__DIR__ . '/SemanticDependency.class.php';
-$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'SemanticDependency::setup';
$GLOBALS['wgHooks']['SMWStore::updateDataAfter'][] =
'SemanticDependency::updateDataAfter';
+$GLOBALS['wgHooks']['ArticleDelete'][] = 'SemanticDependency::articleDelete';
+$GLOBALS['wgHooks']['ArticleDeleteComplete'][] =
+ 'SemanticDependency::articleDeleteComplete';
$GLOBALS['wgMessagesDirs']['SemanticDependency'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['SemanticDependency'] =
--
To view, visit https://gerrit.wikimedia.org/r/237650
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I83ce29c957bbd09faaa9f89845f330d32272cd19
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticDependency
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
Gerrit-Reviewer: Cicalese <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits