r81793 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81792‎ | r81793 | r81794 >
Date:23:30, 8 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added some more options
Modified paths:
  • /trunk/extensions/SemanticResultFormats/SRF_Messages.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/TagCloud/SRF_TagCloud.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/TagCloud/SRF_TagCloud.php
@@ -33,6 +33,18 @@
3434 protected function readParameters( $params, $outputmode ) {
3535 parent::readParameters( $params, $outputmode );
3636
 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+
3749 if ( !array_key_exists( 'increase', $params ) || !in_array( $params['increase'], array( 'linear', 'log' ) ) ) {
3850 $params['increase'] = 'log';
3951 }
@@ -71,7 +83,11 @@
7284 }
7385
7486 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+ );
7692 }
7793
7894 /**
@@ -85,14 +101,28 @@
86102 * @return array
87103 */
88104 protected function getTags( SMWQueryResult $results, $outputmode ) {
89 - $minCount = 1; // TODO
 105+ global $wgUser;
90106
91107 $tags = array();
 108+ $skin = $wgUser->getSkin();
92109
93110 while ( /* array of SMWResultArray */ $row = $results->getNext() ) { // Objects (pages)
94111 for ( $i = 0, $n = count( $row ); $i < $n; $i++ ) { // Properties
95112 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+ }
97127
98128 if ( !array_key_exists( $value, $tags ) ) {
99129 $tags[$value] = 0;
@@ -216,9 +246,9 @@
217247 */
218248 protected function getTagCloud( array $tags ) {
219249 $htmlTags = array();
220 -
 250+
221251 foreach ( $tags as $name => $size ) {
222 - $htmlTags[] = Html::element(
 252+ $htmlTags[] = Html::rawElement(
223253 'span',
224254 array( 'style' => "font-size:$size%" ),
225255 $name
@@ -242,6 +272,8 @@
243273 public function getParameters() {
244274 $params = parent::getParameters();
245275
 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' ) );
246278 $params[] = array( 'name' => 'increase', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_increase' ), 'values' => array( 'linear', 'log' ) );
247279 $params[] = array( 'name' => 'tagorder', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_tagorder' ), 'values' => array( 'alphabetic', 'asc', 'desc', 'random', 'unchanged' ) );
248280
Index: trunk/extensions/SemanticResultFormats/SRF_Messages.php
@@ -80,6 +80,8 @@
8181
8282 // "tagcloud" format
8383 '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',
8486 'srf_paramdesc_increase' => 'How to increase the size of tags',
8587 'srf_paramdesc_tagorder' => 'The order of the tags',
8688 'srf_paramdesc_mincount' => 'The minimum amount of times a value needs to occur to be listed',

Status & tagging log