Index: trunk/extensions/SemanticResultFormats/TagCloud/SRF_TagCloud.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | | - * Print query results as a tag cloud. |
| 5 | + * Result printer that prints query results as a tag cloud. |
5 | 6 | * |
6 | 7 | * @since 1.5.3 |
7 | 8 | * |
— | — | @@ -10,12 +11,6 @@ |
11 | 12 | * @licence GNU GPL v3 |
12 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
13 | 14 | */ |
14 | | - |
15 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
16 | | - |
17 | | -/** |
18 | | - * Result printer that prints query results as a tag cloud. |
19 | | - */ |
20 | 15 | class SRFTagCloud extends SMWResultPrinter { |
21 | 16 | |
22 | 17 | public function getName() { |
— | — | @@ -29,25 +24,50 @@ |
30 | 25 | } |
31 | 26 | |
32 | 27 | public function getResultText( /* SMWQueryResult */ $results, $outputmode ) { |
33 | | - return $this->getTagCloud( $this->getTags( $results ) ); |
| 28 | + return $this->getTagCloud( $this->getTags( $results, $outputmode ) ); |
34 | 29 | } |
35 | 30 | |
36 | | - protected function getTags( SMWQueryResult $results ) { |
| 31 | + /** |
| 32 | + * Returns an array with the tags (keys) and the number of times they occur (values). |
| 33 | + * |
| 34 | + * @since 1.5.3 |
| 35 | + * |
| 36 | + * @param SMWQueryResult $results |
| 37 | + * @param $outputmode |
| 38 | + * |
| 39 | + * @return array |
| 40 | + */ |
| 41 | + protected function getTags( SMWQueryResult $results, $outputmode ) { |
37 | 42 | $tags = array(); |
38 | 43 | |
39 | 44 | while ( /* array of SMWResultArray */ $row = $results->getNext() ) { // Objects (pages) |
40 | 45 | for ( $i = 0, $n = count( $row ); $i < $n; $i++ ) { // Properties |
41 | 46 | while ( ( $obj = $row[$i]->getNextObject() ) !== false ) { // Property values |
42 | | - if ( $obj->getTypeID() == '_wpg' ) { |
43 | | - $images[] = $obj->getTitle(); |
44 | | - } |
| 47 | + $value = $obj->getTypeID() == '_wpg' ? $obj->getTitle()->getText() : $obj->getShortText( $outputmode ); |
| 48 | + |
| 49 | + if ( !array_key_exists( $value, $tags ) ) { |
| 50 | + $tags[$value] = 0; |
| 51 | + } |
| 52 | + |
| 53 | + $tags[$value]++; |
45 | 54 | } |
46 | 55 | } |
47 | 56 | } |
| 57 | + |
| 58 | + return $tags; |
48 | 59 | } |
49 | 60 | |
| 61 | + /** |
| 62 | + * Returns the HTML for the tag cloud. |
| 63 | + * |
| 64 | + * @since 1.5.3 |
| 65 | + * |
| 66 | + * @param array $tags |
| 67 | + * |
| 68 | + * @return string |
| 69 | + */ |
50 | 70 | protected function getTagCloud( array $tags ) { |
51 | | - |
| 71 | + return ''; |
52 | 72 | } |
53 | 73 | |
54 | 74 | } |