Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -73,8 +73,8 @@ |
74 | 74 | $wgAutoloadClasses['SpecialCode'] = $dir . 'ui/SpecialCode.php'; |
75 | 75 | $wgAutoloadClasses['CodeView'] = $dir . 'ui/SpecialCode.php'; |
76 | 76 | $wgAutoloadClasses['SpecialRepoAdmin'] = $dir . 'ui/SpecialRepoAdmin.php'; |
| 77 | +$wgAutoloadClasses['WordCloud'] = $dir . 'ui/WordCloud.php'; |
77 | 78 | |
78 | | - |
79 | 79 | $wgSpecialPages['Code'] = 'SpecialCode'; |
80 | 80 | $wgSpecialPageGroups['Code'] = 'developer'; |
81 | 81 | $wgSpecialPages['RepoAdmin'] = 'SpecialRepoAdmin'; |
Index: trunk/extensions/CodeReview/codereview.css |
— | — | @@ -121,3 +121,48 @@ |
122 | 122 | .mw-codereview-live td { |
123 | 123 | border-color: #33cc99 !important; |
124 | 124 | } |
| 125 | + |
| 126 | +.mw-wordcloud-size-1, .mw-wordcloud-size-2, |
| 127 | +.mw-wordcloud-size-3, .mw-wordcloud-size-4, |
| 128 | +.mw-wordcloud-size-5, .mw-wordcloud-size-6, |
| 129 | +.mw-wordcloud-size-7, .mw-wordcloud-size-8, |
| 130 | +.mw-wordcloud-size-0 { |
| 131 | + padding: 4px 4px 4px 4px; |
| 132 | + letter-spacing: 3px; |
| 133 | +} |
| 134 | +.mw-wordcloud-size-1 { |
| 135 | + color: #000; |
| 136 | + font-size: 2.4em; |
| 137 | +} |
| 138 | +.mw-wordcloud-size-2 { |
| 139 | + color: #333; |
| 140 | + font-size:2.2em; |
| 141 | +} |
| 142 | +.mw-wordcloud-size-3 { |
| 143 | + color: #666; |
| 144 | + font-size: 2.0em; |
| 145 | +} |
| 146 | +.mw-wordcloud-size-4 { |
| 147 | + color: #999; |
| 148 | + font-size: 1.0em; |
| 149 | +} |
| 150 | +.mw-wordcloud-size-5 { |
| 151 | + color: #aaa; |
| 152 | + font-size: 1.6em; |
| 153 | +} |
| 154 | +.mw-wordcloud-size-6 { |
| 155 | + color: #bbb; |
| 156 | + font-size: 1.4em; |
| 157 | +} |
| 158 | +.mw-wordcloud-size-7 { |
| 159 | + color: #ccc; |
| 160 | + font-size: 1.2em; |
| 161 | +} |
| 162 | +.mw-wordcloud-size-8 { |
| 163 | + color: #ddd; |
| 164 | + font-size: .8em; |
| 165 | +} |
| 166 | +mw-wordcloud-size-0 { |
| 167 | + color: #ccc; |
| 168 | + font-size: .6em; |
| 169 | +} |
Index: trunk/extensions/CodeReview/backend/CodeRepository.php |
— | — | @@ -153,7 +153,7 @@ |
154 | 154 | ); |
155 | 155 | $tags = array(); |
156 | 156 | foreach( $res as $row ) { |
157 | | - $tags[] = $row->ct_tag; |
| 157 | + $tags[$row->ct_tag] = $row->revs; |
158 | 158 | } |
159 | 159 | $wgMemc->set( $key, $tags, 3600 * 3 ); |
160 | 160 | return $tags; |
Index: trunk/extensions/CodeReview/ui/CodeTagListView.php |
— | — | @@ -9,12 +9,17 @@ |
10 | 10 | |
11 | 11 | function execute() { |
12 | 12 | global $wgOut; |
13 | | - $tags = $this->mRepo->getTagList(); |
14 | 13 | $name = $this->mRepo->getName(); |
15 | | - $text = ''; |
16 | | - foreach ( $tags as $tag ) { |
17 | | - $text .= "* [[Special:Code/$name/tag/$tag|$tag]]\n"; |
18 | | - } |
19 | | - $wgOut->addWikiText( $text ); |
| 14 | + $list = $this->mRepo->getTagList(); |
| 15 | + |
| 16 | + $tc = new WordCloud( $list, array( $this, 'linkCallback' ) ); |
| 17 | + $wgOut->addHTML( $tc->showCloud() ); |
20 | 18 | } |
| 19 | + |
| 20 | + public function linkCallback( $tag, $weight ) { |
| 21 | + $query = $this->mRepo->getName() . '/tag/' . $tag; |
| 22 | + return Html::element( 'a', array( |
| 23 | + 'href' => SpecialPage::getTitleFor( 'Code', $query )->getFullURL(), |
| 24 | + 'class' => 'plainlinks mw-wordcloud-size-' . $weight ), $tag ); |
| 25 | + } |
21 | 26 | } |
Index: trunk/extensions/CodeReview/ui/WordCloud.php |
— | — | @@ -0,0 +1,144 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * wordCloud Copyright 2007 Derek Harvey |
| 5 | + * www.lotsofcode.com |
| 6 | + * |
| 7 | + * This file is part of wordCloud. |
| 8 | + * |
| 9 | + * wordCloud is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * wordCloud is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with wordCloud; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | + * |
| 23 | + * --- |
| 24 | + * Adapted for use with MediaWiki, cleaned up coding style, etc on 2010-11-03 |
| 25 | + */ |
| 26 | +class WordCloud { |
| 27 | + /** |
| 28 | + * Nice big array of words and their weights |
| 29 | + * @var Array |
| 30 | + */ |
| 31 | + private $wordsArray = array(); |
| 32 | + |
| 33 | + /** |
| 34 | + * An optional callback to format the text before outputting |
| 35 | + */ |
| 36 | + private $callback; |
| 37 | + |
| 38 | + /* |
| 39 | + * Constructor |
| 40 | + * |
| 41 | + * @param $words Array of word => rank pairs |
| 42 | + */ |
| 43 | + public function __construct( Array $words = array(), $callback = null ) { |
| 44 | + foreach( $words as $word => $rank ) { |
| 45 | + $this->addWord( $word, $rank ); |
| 46 | + } |
| 47 | + $this->callback = $callback ? $callback : array( $this, 'defaultTextCallback' ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Assign word to array |
| 52 | + * |
| 53 | + * @param $word String The word to add |
| 54 | + * @param $value Int the weight to give it |
| 55 | + */ |
| 56 | + public function addWord( $word, $value = 1 ) { |
| 57 | + $word = strtolower( $word ); |
| 58 | + if( array_key_exists( $word, $this->wordsArray ) ) { |
| 59 | + $this->wordsArray[$word] += $value; |
| 60 | + } else { |
| 61 | + $this->wordsArray[$word] = $value; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Calculate size of words array |
| 67 | + * |
| 68 | + * @return Int |
| 69 | + */ |
| 70 | + public function getCloudSize() { |
| 71 | + return array_sum( $this->wordsArray ); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Create the HTML code for each word and apply font size. |
| 76 | + * |
| 77 | + * @return String |
| 78 | + */ |
| 79 | + public function showCloud() { |
| 80 | + $this->shuffleCloud(); |
| 81 | + $max = max( $this->wordsArray ); |
| 82 | + if( is_array( $this->wordsArray ) ) { |
| 83 | + $return = ''; |
| 84 | + foreach ( $this->wordsArray as $word => $popularity ) { |
| 85 | + $sizeRange = $this->getClassFromPercent( ( $popularity / $max ) * 100 ); |
| 86 | + $return .= call_user_func_array( $this->callback, array( $word, $sizeRange ) ); |
| 87 | + } |
| 88 | + return '<div class="mw-wordcloud">' . $return . '</div>'; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Default text callback for word display |
| 94 | + */ |
| 95 | + public function defaultTextCallback( $word, $sizeRange ) { |
| 96 | + return "<span class=\"mw-wordcloud-size-$sizeRange\"> {$word} </span>"; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Shuffle associated names in array |
| 101 | + */ |
| 102 | + private function shuffleCloud() { |
| 103 | + $keys = array_keys( $this->wordsArray ); |
| 104 | + |
| 105 | + shuffle( $keys ); |
| 106 | + |
| 107 | + if( count( $keys ) && is_array( $keys ) ) { |
| 108 | + $tmpArray = $this->wordsArray; |
| 109 | + $this->wordsArray = array(); |
| 110 | + foreach( $keys as $key => $value ) { |
| 111 | + $this->wordsArray[$value] = $tmpArray[$value]; |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Get the class range using a percentage |
| 118 | + * |
| 119 | + * @return Int |
| 120 | + */ |
| 121 | + private function getClassFromPercent( $percent ) { |
| 122 | + if ( $percent >= 99 ) { |
| 123 | + $class = 1; |
| 124 | + } elseif( $percent >= 70 ) { |
| 125 | + $class = 2; |
| 126 | + } elseif( $percent >= 60 ) { |
| 127 | + $class = 3; |
| 128 | + } elseif( $percent >= 50 ) { |
| 129 | + $class = 4; |
| 130 | + } elseif( $percent >= 40 ) { |
| 131 | + $class = 5; |
| 132 | + } elseif( $percent >= 30 ) { |
| 133 | + $class = 6; |
| 134 | + } elseif( $percent >= 20 ) { |
| 135 | + $class = 7; |
| 136 | + } elseif( $percent >= 10 ) { |
| 137 | + $class = 8; |
| 138 | + } elseif( $percent >= 5 ) { |
| 139 | + $class = 9; |
| 140 | + } else { |
| 141 | + $class = 0; |
| 142 | + } |
| 143 | + return $class; |
| 144 | + } |
| 145 | +} |
Property changes on: trunk/extensions/CodeReview/ui/WordCloud.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 146 | + native |