Index: trunk/extensions/SemanticResultFormats/TagCloud/SRF_TagCloud.php |
— | — | @@ -33,6 +33,18 @@ |
34 | 34 | protected function readParameters( $params, $outputmode ) { |
35 | 35 | parent::readParameters( $params, $outputmode ); |
36 | 36 | |
| 37 | + if ( !array_key_exists( 'includename', $params ) || !in_array( $params['includename'], array( 'yes', 'no' ) ) ) { |
| 38 | + $params['includename'] = 'no'; |
| 39 | + } |
| 40 | + |
| 41 | + $this->includeName = $params['includename'] == 'yes'; |
| 42 | + |
| 43 | + if ( !array_key_exists( 'linkpages', $params ) || !in_array( $params['linkpages'], array( 'yes', 'no' ) ) ) { |
| 44 | + $params['linkpages'] = 'yes'; |
| 45 | + } |
| 46 | + |
| 47 | + $this->linkPages = $params['linkpages'] == 'yes'; |
| 48 | + |
37 | 49 | if ( !array_key_exists( 'increase', $params ) || !in_array( $params['increase'], array( 'linear', 'log' ) ) ) { |
38 | 50 | $params['increase'] = 'log'; |
39 | 51 | } |
— | — | @@ -71,7 +83,11 @@ |
72 | 84 | } |
73 | 85 | |
74 | 86 | public function getResultText( /* SMWQueryResult */ $results, $outputmode ) { |
75 | | - return $this->getTagCloud( $this->getTagSizes( $this->getTags( $results, $outputmode ) ) ); |
| 87 | + return array( |
| 88 | + $this->getTagCloud( $this->getTagSizes( $this->getTags( $results, $outputmode ) ) ), |
| 89 | + 'noparse' => true, |
| 90 | + 'isHTML' => true |
| 91 | + ); |
76 | 92 | } |
77 | 93 | |
78 | 94 | /** |
— | — | @@ -85,14 +101,28 @@ |
86 | 102 | * @return array |
87 | 103 | */ |
88 | 104 | protected function getTags( SMWQueryResult $results, $outputmode ) { |
89 | | - $minCount = 1; // TODO |
| 105 | + global $wgUser; |
90 | 106 | |
91 | 107 | $tags = array(); |
| 108 | + $skin = $wgUser->getSkin(); |
92 | 109 | |
93 | 110 | while ( /* array of SMWResultArray */ $row = $results->getNext() ) { // Objects (pages) |
94 | 111 | for ( $i = 0, $n = count( $row ); $i < $n; $i++ ) { // Properties |
95 | 112 | while ( ( $obj = $row[$i]->getNextObject() ) !== false ) { // Property values |
96 | | - $value = $obj->getTypeID() == '_wpg' ? $obj->getTitle()->getText() : $obj->getShortText( $outputmode ); |
| 113 | + |
| 114 | + // If the main object should not be included, skip it. |
| 115 | + // The isMainObject method was added in SMW 1.5.6, so this can only be done correctly if it's available. |
| 116 | + if ( $i == 0 && !$this->includeName && method_exists( $obj, 'isMainObject' ) && $obj->isMainObject() ) { |
| 117 | + continue; |
| 118 | + } |
| 119 | + |
| 120 | + // Get the HTML for the tag content. Pages are linked, other stuff is just plaintext. |
| 121 | + if ( $obj->getTypeID() == '_wpg' ) { |
| 122 | + $value = $this->linkPages ? $obj->getLongText( $outputmode, $skin ) : $obj->getTitle()->getText(); |
| 123 | + } |
| 124 | + else { |
| 125 | + $value = $obj->getShortText( $outputmode, $skin ); |
| 126 | + } |
97 | 127 | |
98 | 128 | if ( !array_key_exists( $value, $tags ) ) { |
99 | 129 | $tags[$value] = 0; |
— | — | @@ -216,9 +246,9 @@ |
217 | 247 | */ |
218 | 248 | protected function getTagCloud( array $tags ) { |
219 | 249 | $htmlTags = array(); |
220 | | - |
| 250 | + |
221 | 251 | foreach ( $tags as $name => $size ) { |
222 | | - $htmlTags[] = Html::element( |
| 252 | + $htmlTags[] = Html::rawElement( |
223 | 253 | 'span', |
224 | 254 | array( 'style' => "font-size:$size%" ), |
225 | 255 | $name |
— | — | @@ -242,6 +272,8 @@ |
243 | 273 | public function getParameters() { |
244 | 274 | $params = parent::getParameters(); |
245 | 275 | |
| 276 | + $params[] = array( 'name' => 'includename', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_includename' ), 'values' => array( 'yes', 'no' ) ); |
| 277 | + $params[] = array( 'name' => 'linkpages', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_linkpages' ), 'values' => array( 'yes', 'no' ) ); |
246 | 278 | $params[] = array( 'name' => 'increase', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_increase' ), 'values' => array( 'linear', 'log' ) ); |
247 | 279 | $params[] = array( 'name' => 'tagorder', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_tagorder' ), 'values' => array( 'alphabetic', 'asc', 'desc', 'random', 'unchanged' ) ); |
248 | 280 | |
Index: trunk/extensions/SemanticResultFormats/SRF_Messages.php |
— | — | @@ -80,6 +80,8 @@ |
81 | 81 | |
82 | 82 | // "tagcloud" format |
83 | 83 | 'srf_printername_tagcloud' => 'Tag cloud', |
| 84 | + 'srf_paramdesc_includename' => 'If the names of the object themselves should be included', |
| 85 | + 'srf_paramdesc_linkpages' => 'If pages should be linked', |
84 | 86 | 'srf_paramdesc_increase' => 'How to increase the size of tags', |
85 | 87 | 'srf_paramdesc_tagorder' => 'The order of the tags', |
86 | 88 | 'srf_paramdesc_mincount' => 'The minimum amount of times a value needs to occur to be listed', |