r100727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100726‎ | r100727 | r100728 >
Date:18:54, 25 October 2011
Author:dasch
Status:deferred
Tags:
Comment:
following r100719 cleanup
bug 31938
Modified paths:
  • /trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/ValueRank/SRF_ValueRank.php
@@ -15,12 +15,8 @@
1616 class SRFValueRank extends SMWResultPrinter {
1717
1818 protected $includeName;
19 - protected $sizeMode;
20 - protected $tagOrder;
2119 protected $minCount;
22 - protected $maxSize;
2320 protected $maxTags;
24 - protected $minTagSize;
2521
2622 protected $tagsHtml = array();
2723
@@ -45,17 +41,13 @@
4642 parent::handleParameters( $params, $outputmode );
4743
4844 $this->includeName = $params['includesubject'];
49 - $this->sizeMode = $params['increase'];
50 - $this->tagOrder = $params['tagorder'];
5145 $this->minCount = $params['mincount'];
5246 $this->maxTags = $params['maxtags'];
53 - $this->minTagSize = $params['minsize'];
54 - $this->maxSize = $params['maxsize'];
5547 }
5648
5749 public function getResultText( SMWQueryResult $results, $outputmode ) {
5850 $this->isHTML = $outputmode == SMW_OUTPUT_HTML;
59 - return $this->getValueRank( $this->getRank( $this->getTags( $results, $outputmode ) ) );
 51+ return $this->getVRValueRank( $this->getVRRank( $this->getVRValues( $results, $outputmode ) ) );
6052 }
6153
6254 /**
@@ -68,7 +60,7 @@
6961 *
7062 * @return array
7163 */
72 - protected function getTags( SMWQueryResult $results, $outputmode ) {
 64+ protected function getVRValues( SMWQueryResult $results, $outputmode ) {
7365 $tags = array();
7466
7567 while ( /* array of SMWResultArray */ $row = $results->getNext() ) { // Objects (pages)
@@ -107,7 +99,6 @@
108100 unset( $tags[$name] );
109101 }
110102 }
111 -
112103 return $tags;
113104 }
114105
@@ -121,89 +112,17 @@
122113 *
123114 * @return array
124115 */
125 - protected function getRank( array $tags ) {
 116+ protected function getVRRank( array $tags ) {
126117 if ( count( $tags ) == 0 ) {
127118 return $tags;
128119 }
129120
130 - // If the original order needs to be kept, we need a copy of the current order.
131 - if ( $this->tagOrder == 'unchanged' ) {
132 - $unchangedTags = array_keys( $tags );
133 - }
134 -
135121 arsort( $tags, SORT_NUMERIC );
136122
137123 if ( count( $tags ) > $this->maxTags ) {
138124 $tags = array_slice( $tags, 0, $this->maxTags, true );
139125 }
140 -
141 - $min = end( $tags ) or $min = 0;
142 - $max = reset( $tags ) or $max = 1;
143 - $maxSizeIncrease = $this->maxSize - $this->minTagSize;
144126
145 - // Loop over the tags, and replace their count by a size.
146 - /*
147 - foreach ( $tags as &$tag ) {
148 - switch ( $this->sizeMode ) {
149 - case 'linear':
150 - $divisor = ($max == $min) ? 1 : $max - $min;
151 - $tag = $this->minTagSize + $maxSizeIncrease * ( $tag -$min ) / $divisor;
152 - break;
153 - case 'log' : default :
154 - $divisor = ($max == $min) ? 1 : log( $max ) - log( $min );
155 - $tag = $this->minTagSize + $maxSizeIncrease * ( log( $tag ) - log( $min ) ) / $divisor ;
156 - break;
157 - }
158 - }
159 - */
160 -
161 - switch ( $this->tagOrder ) {
162 - case 'desc' :
163 - // Tags are already sorted desc
164 - break;
165 - case 'asc' :
166 - asort( $tags );
167 - break;
168 - case 'alphabetical' :
169 - $tagNames = array_keys( $tags );
170 - natcasesort( $tagNames );
171 - $newTags = array();
172 -
173 - foreach ( $tagNames as $name ) {
174 - $newTags[$name] = $tags[$name];
175 - }
176 -
177 - $tags = $newTags;
178 - break;
179 - case 'random' :
180 - $tagSizes = $tags;
181 - shuffle( $tagSizes );
182 - $newTags = array();
183 -
184 - foreach ( $tagSizes as $size ) {
185 - foreach ( $tags as $tagName => $tagSize ) {
186 - if ( $tagSize == $size ) {
187 - $newTags[$tagName] = $tags[$tagName];
188 - break;
189 - }
190 - }
191 - }
192 -
193 - $tags = $newTags;
194 - break;
195 - case 'unchanged' : default : // Restore the original order.
196 - $changedTags = $tags;
197 - $tags = array();
198 -
199 - foreach ( $unchangedTags as $name ) {
200 - // Original tags might have been left out at this point, so only add remaining ones.
201 - if ( array_key_exists( $name, $changedTags ) ) {
202 - $tags[$name] = $changedTags[$name];
203 - }
204 - }
205 - break;
206 - }
207 -
208127 return $tags;
209128 }
210129
@@ -216,19 +135,19 @@
217136 *
218137 * @return string
219138 */
220 - protected function getValueRank( array $tags ) {
 139+ protected function getVRValueRank( array $tags ) {
221140 $htmlTags = array();
222141
223142 foreach ( $tags as $name => $size ) {
224143 $htmlTags[] = Html::rawElement(
225144 'li',
226 - array( 'style' => "font-size:100%" ),
227 - $this->tagsHtml[$name . '(' . $size . ')']
 145+ array( 'style' => "font-size:$size" ),
 146+ $this->tagsHtml[$name] . ' (' . $size . ')'
228147 );
229148 }
230149
231150 return Html::rawElement(
232 - 'ul',
 151+ 'ol',
233152 array( 'align' => 'left' ),
234153 implode( ' ', $htmlTags )
235154 );
@@ -248,16 +167,6 @@
249168 $params['includesubject']->setMessage( 'srf_paramdesc_includesubject' );
250169 $params['includesubject']->setDefault( false );
251170
252 - $params['increase'] = new Parameter( 'increase' );
253 - $params['increase']->setMessage( 'srf_paramdesc_increase' );
254 - $params['increase']->addCriteria( new CriterionInArray( 'linear', 'log' ) );
255 - $params['increase']->setDefault( 'log' );
256 -
257 - $params['tagorder'] = new Parameter( 'tagorder' );
258 - $params['tagorder']->setMessage( 'srf_paramdesc_tagorder' );
259 - $params['tagorder']->addCriteria( new CriterionInArray( 'alphabetical', 'asc', 'desc', 'random', 'unchanged' ) );
260 - $params['tagorder']->setDefault( 'desc' );
261 -
262171 $params['mincount'] = new Parameter( 'mincount', Parameter::TYPE_INTEGER );
263172 $params['mincount']->setMessage( 'srf_paramdesc_mincount' );
264173 $params['mincount']->setDefault( 1 );
@@ -265,16 +174,8 @@
266175 $params['maxtags'] = new Parameter( 'maxtags', Parameter::TYPE_INTEGER );
267176 $params['maxtags']->setMessage( 'srf_paramdesc_maxtags' );
268177 $params['maxtags']->setDefault( 1000 );
269 -
270 - $params['minsize'] = new Parameter( 'minsize', Parameter::TYPE_INTEGER );
271 - $params['minsize']->setMessage( 'srf_paramdesc_minsize' );
272 - $params['minsize']->setDefault( 77 );
273 -
274 - $params['maxsize'] = new Parameter( 'maxsize', Parameter::TYPE_INTEGER );
275 - $params['maxsize']->setMessage( 'srf_paramdesc_maxsize' );
276 - $params['maxsize']->setDefault( 242 );
277178
278179 return $params;
279 - }
 180+ }
280181
281182 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100719added new format value rank #31938 clean up will be done step by step if it's...dasch18:11, 25 October 2011