http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100727

Revision: 100727
Author:   dasch
Date:     2011-10-25 18:54:48 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
following r100719 cleanup
bug 31938

Modified Paths:
--------------
    trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php

Modified: trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php
===================================================================
--- trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php  
2011-10-25 18:45:01 UTC (rev 100726)
+++ trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php  
2011-10-25 18:54:48 UTC (rev 100727)
@@ -15,12 +15,8 @@
 class SRFValueRank extends SMWResultPrinter {
 
        protected $includeName;
-       protected $sizeMode;
-       protected $tagOrder;
        protected $minCount;
-       protected $maxSize;
        protected $maxTags;
-       protected $minTagSize;
        
        protected $tagsHtml = array();
        
@@ -45,17 +41,13 @@
                parent::handleParameters( $params, $outputmode );
                
                $this->includeName = $params['includesubject'];
-               $this->sizeMode = $params['increase'];
-               $this->tagOrder = $params['tagorder'];
                $this->minCount = $params['mincount'];
                $this->maxTags = $params['maxtags'];
-               $this->minTagSize = $params['minsize'];
-               $this->maxSize = $params['maxsize'];
        }
 
        public function getResultText( SMWQueryResult $results, $outputmode ) {
                $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
-               return $this->getValueRank( $this->getRank( $this->getTags( 
$results, $outputmode ) ) );
+               return $this->getVRValueRank( $this->getVRRank( 
$this->getVRValues( $results, $outputmode ) ) );
        }
        
        /**
@@ -68,7 +60,7 @@
         * 
         * @return array
         */
-       protected function getTags( SMWQueryResult $results, $outputmode ) {
+       protected function getVRValues( SMWQueryResult $results, $outputmode ) {
                $tags = array();
                
                while ( /* array of SMWResultArray */ $row = 
$results->getNext() ) { // Objects (pages)
@@ -107,7 +99,6 @@
                                unset( $tags[$name] );
                        }
                }
-               
                return $tags;
        }
        
@@ -121,89 +112,17 @@
         * 
         * @return array
         */     
-       protected function getRank( array $tags ) {
+       protected function getVRRank( array $tags ) {
                if ( count( $tags ) == 0 ) {
                        return $tags;
                }
                
-               // If the original order needs to be kept, we need a copy of 
the current order.
-               if ( $this->tagOrder == 'unchanged' ) {
-                       $unchangedTags = array_keys( $tags );
-               }
-               
                arsort( $tags, SORT_NUMERIC );
                
                if ( count( $tags ) > $this->maxTags ) {
                        $tags = array_slice( $tags, 0, $this->maxTags, true );
                }
-       
-               $min = end( $tags ) or $min = 0;
-               $max = reset( $tags ) or $max = 1;
-               $maxSizeIncrease = $this->maxSize - $this->minTagSize;
                
-               // Loop over the tags, and replace their count by a size.
-               /*
-               foreach ( $tags as &$tag ) {
-                       switch ( $this->sizeMode ) {
-                               case 'linear':
-                                       $divisor = ($max == $min) ? 1 : $max - 
$min;
-                                       $tag = $this->minTagSize + 
$maxSizeIncrease * ( $tag -$min ) / $divisor;
-                                       break;
-                               case 'log' : default :
-                                       $divisor = ($max == $min) ? 1 : log( 
$max ) - log( $min );
-                                       $tag = $this->minTagSize + 
$maxSizeIncrease * ( log( $tag ) - log( $min ) ) / $divisor ;
-                                       break;
-                       }
-               }
-               */
-               
-               switch ( $this->tagOrder ) {
-                       case 'desc' :
-                               // Tags are already sorted desc
-                               break;
-                       case 'asc' :
-                               asort( $tags );
-                               break;
-                       case 'alphabetical' :
-                               $tagNames = array_keys( $tags );
-                               natcasesort( $tagNames );
-                               $newTags = array();
-                               
-                               foreach ( $tagNames as $name ) {
-                                       $newTags[$name] = $tags[$name];
-                               }
-                               
-                               $tags = $newTags;
-                               break;
-                       case 'random' :
-                               $tagSizes = $tags;
-                               shuffle( $tagSizes );
-                               $newTags = array();
-                               
-                               foreach ( $tagSizes as $size ) {
-                                       foreach ( $tags as $tagName => $tagSize 
) {
-                                               if ( $tagSize == $size ) {
-                                                       $newTags[$tagName] =  
$tags[$tagName];
-                                                       break;
-                                               }
-                                       }
-                               }
-                               
-                               $tags = $newTags;
-                               break;
-                       case 'unchanged' : default : // Restore the original 
order.
-                               $changedTags = $tags;
-                               $tags = array();
-                               
-                               foreach ( $unchangedTags as $name ) {
-                                       // Original tags might have been left 
out at this point, so only add remaining ones.
-                                       if ( array_key_exists( $name, 
$changedTags ) ) {
-                                               $tags[$name] = 
$changedTags[$name];
-                                       }
-                               }
-                               break;
-               }
-               
                return $tags;
        }
        
@@ -216,19 +135,19 @@
         * 
         * @return string
         */
-       protected function getValueRank( array $tags ) {
+       protected function getVRValueRank( array $tags ) {
                $htmlTags = array();
 
                foreach ( $tags as $name => $size ) {
                        $htmlTags[] = Html::rawElement(
                                'li',
-                               array( 'style' => "font-size:100%" ),
-                               $this->tagsHtml[$name . '(' . $size . ')']
+                               array( 'style' => "font-size:$size" ),
+                               $this->tagsHtml[$name] . ' (' . $size . ')'
                        );
                }
                
                return Html::rawElement(
-                       'ul',
+                       'ol',
                        array( 'align' => 'left' ),
                        implode( ' ', $htmlTags )
                );
@@ -248,16 +167,6 @@
                $params['includesubject']->setMessage( 
'srf_paramdesc_includesubject' );
                $params['includesubject']->setDefault( false );
                
-               $params['increase'] = new Parameter( 'increase' );
-               $params['increase']->setMessage( 'srf_paramdesc_increase' );
-               $params['increase']->addCriteria( new CriterionInArray( 
'linear', 'log' ) );
-               $params['increase']->setDefault( 'log' );
-               
-               $params['tagorder'] = new Parameter( 'tagorder' );
-               $params['tagorder']->setMessage( 'srf_paramdesc_tagorder' );
-               $params['tagorder']->addCriteria( new CriterionInArray( 
'alphabetical', 'asc', 'desc', 'random', 'unchanged' ) );
-               $params['tagorder']->setDefault( 'desc' );
-               
                $params['mincount'] = new Parameter( 'mincount', 
Parameter::TYPE_INTEGER );
                $params['mincount']->setMessage( 'srf_paramdesc_mincount' );
                $params['mincount']->setDefault( 1 );
@@ -265,16 +174,8 @@
                $params['maxtags'] = new Parameter( 'maxtags', 
Parameter::TYPE_INTEGER );
                $params['maxtags']->setMessage( 'srf_paramdesc_maxtags' );
                $params['maxtags']->setDefault( 1000 );
-
-               $params['minsize'] = new Parameter( 'minsize', 
Parameter::TYPE_INTEGER );
-               $params['minsize']->setMessage( 'srf_paramdesc_minsize' );
-               $params['minsize']->setDefault( 77 );
-
-               $params['maxsize'] = new Parameter( 'maxsize', 
Parameter::TYPE_INTEGER );
-               $params['maxsize']->setMessage( 'srf_paramdesc_maxsize' );
-               $params['maxsize']->setDefault( 242 );
                
                return $params;
-       }       
+       }
        
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to