diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Query/Excerpts.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/src/Query/Excerpts.php | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Query/Excerpts.php b/www/wiki/extensions/SemanticMediaWiki/src/Query/Excerpts.php new file mode 100644 index 00000000..d16f5e8f --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/src/Query/Excerpts.php @@ -0,0 +1,102 @@ +<?php + +namespace SMW\Query; + +use SMW\DIWikiPage; + +/** + * Record excerpts for query results that support an excerpt retrieval function. + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class Excerpts { + + /** + * @var [] + */ + protected $excerpts = []; + + /** + * @var boolean + */ + protected $noHighlight = false; + + /** + * @var boolean + */ + protected $hasHighlight = false; + + /** + * @var boolean + */ + protected $stripTags = true; + + /** + * @since 3.0 + */ + public function noHighlight() { + $this->noHighlight = true; + } + + /** + * @note The hash is expected to be equivalent to DIWikiPage::getHash to + * easily match result subjects available in an QueryResult instance. + * + * @since 3.0 + * + * @param DIWikiPage|string $hash + * @param string|integer $score + */ + public function addExcerpt( $hash, $excerpt ) { + + if ( $hash instanceof DIWikiPage ) { + $hash = $hash->getHash(); + } + + $this->excerpts[] = [ $hash, $excerpt ]; + } + + /** + * @since 3.0 + * + * @param DIWikiPage|string $hash + * + * @return string|integer|false + */ + public function getExcerpt( $hash ) { + + if ( $hash instanceof DIWikiPage ) { + $hash = $hash->getHash(); + } + + foreach ( $this->excerpts as $map ) { + if ( $map[0] === $hash ) { + return $map[1]; + } + } + + return false; + } + + /** + * @since 3.0 + * + * @return [] + */ + public function getExcerpts() { + return $this->excerpts; + } + + /** + * @since 3.0 + * + * @return boolean + */ + public function hasHighlight() { + return $this->hasHighlight; + } + +} |