summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php b/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php
new file mode 100644
index 00000000..b3aff967
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/SQLStore/Lookup/RedirectTargetLookup.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace SMW\SQLStore\Lookup;
+
+use SMW\DIProperty;
+use SMW\DIWikiPage;
+use SMW\Store;
+use SMW\Utils\CircularReferenceGuard;
+
+/**
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class RedirectTargetLookup {
+
+ /**
+ * @var Store
+ */
+ private $store;
+
+ /**
+ * @var CircularReferenceGuard
+ */
+ private $circularReferenceGuard;
+
+ /**
+ * @since 2.5
+ *
+ * @param Store $store
+ * @param CircularReferenceGuard $circularReferenceGuard
+ */
+ public function __construct( Store $store, CircularReferenceGuard $circularReferenceGuard ) {
+ $this->store = $store;
+ $this->circularReferenceGuard = $circularReferenceGuard;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param $dataItem
+ *
+ * @return DataItem
+ */
+ public function findRedirectTarget( $dataItem ) {
+
+ if ( !$dataItem instanceof DIWikiPage && !$dataItem instanceof DIProperty ) {
+ return $dataItem;
+ }
+
+ $hash = $dataItem->getSerialization();
+
+ // Guard against a dataItem that points to itself
+ $this->circularReferenceGuard->mark( $hash );
+
+ if ( !$this->circularReferenceGuard->isCircular( $hash ) ) {
+ $dataItem = $this->store->getRedirectTarget( $dataItem );
+ }
+
+ $this->circularReferenceGuard->unmark( $hash );
+
+ return $dataItem;
+ }
+
+}