Index: trunk/extensions/UserOptionStats/UserOptionStats.alias.php |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages of UserOptionStats extension. |
| 5 | + * |
| 6 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 7 | + */ |
| 8 | + |
| 9 | +$aliases = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Nike |
| 13 | + */ |
| 14 | +$aliases['en'] = array( |
| 15 | + 'UserOptionStats' => array( 'UserOptionStats' ), |
| 16 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/UserOptionStats/UserOptionStats.alias.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 17 | + native |
Index: trunk/extensions/UserOptionStats/UserOptionStats.i18n.php |
— | — | @@ -0,0 +1,20 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Translations of UserOptionStats extension. |
| 5 | + * |
| 6 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 7 | + */ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Nike |
| 13 | + */ |
| 14 | +$messages['en'] = array( |
| 15 | + 'useroptionstats' => 'User option statistics', |
| 16 | + 'uos-warn' => 'PHPlot is not installed!', |
| 17 | + 'uos-choose' => 'Choose one of the following user options: $1', |
| 18 | + 'uos-unknown' => '*Default', |
| 19 | + 'uos-other' => '*Other', |
| 20 | + 'uos-title' => 'Distribution of values of user option $1', |
| 21 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/UserOptionStats/UserOptionStats.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 22 | + native |
Index: trunk/extensions/UserOptionStats/UserOptionStats.php |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) die(); |
| 4 | + |
| 5 | +/** |
| 6 | + * An useless extension for making pie charts of user options usage. |
| 7 | + * Requirements: PHPlot and FCFontFinder (for i18n fonts, optional). |
| 8 | + * FCFontFinder can be found with extension Translate at utils/Font.php. |
| 9 | + * Also need to install fonts for all languages! |
| 10 | + * |
| 11 | + * PHPlot needs to be in $wgAutoloadClasses: |
| 12 | + * $wgAutoloadClasses['PHPlot'] = '/path/to/phplot/phplot.php' |
| 13 | + * |
| 14 | + * Request params: |
| 15 | + * - pietitle 'Title of the chart' |
| 16 | + * - width 'Width of the image' 200..1000 |
| 17 | + * - height 'Height of the image' 200..1000 |
| 18 | + * - shading 'Shading of the pie' 0..1000 |
| 19 | + * |
| 20 | + * @addtogroup Extensions |
| 21 | + * |
| 22 | + * @author Niklas Laxström |
| 23 | + * @copyright Copyright © 2009, Niklas Laxström |
| 24 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 25 | + */ |
| 26 | + |
| 27 | +$dir = dirname( __FILE__ ); |
| 28 | +$wgAutoloadClasses['SpecialUserOptionStats'] = "$dir/SpecialUserOptionStats.php"; |
| 29 | +$wgExtensionMessagesFiles['UserOptionStats'] = "$dir/UserOptionStats.i18n.php"; |
| 30 | +$wgExtensionAliasesFiles['UserOptionStats'] = "$dir/UserOptionStats.alias.php"; |
| 31 | +$wgSpecialPages['UserOptionStats'] = 'SpecialUserOptionStats'; |
| 32 | +$wgSpecialPageGroups['UserOptionStats'] = 'wiki'; |
\ No newline at end of file |
Property changes on: trunk/extensions/UserOptionStats/UserOptionStats.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 33 | + native |
Index: trunk/extensions/UserOptionStats/SpecialUserOptionStats.php |
— | — | @@ -0,0 +1,136 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Special page for generating pie charts of user options |
| 6 | + * |
| 7 | + * @addtogroup SpecialPages |
| 8 | + * |
| 9 | + * @author Niklas Laxström |
| 10 | + * @copyright Copyright © 2009, Niklas Laxström |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + */ |
| 13 | +class SpecialUserOptionStats extends SpecialPage { |
| 14 | + |
| 15 | + function __construct() { |
| 16 | + SpecialPage::SpecialPage( 'UserOptionStats' ); |
| 17 | + } |
| 18 | + |
| 19 | + public $blacklist = array( 'nickname' ); |
| 20 | + |
| 21 | + |
| 22 | + public function execute( $par ) { |
| 23 | + global $wgRequest, $wgUser, $wgOut, $wgLang, $wgAutoloadClasses; |
| 24 | + |
| 25 | + wfLoadExtensionMessages( 'UserOptionStats' ); |
| 26 | + if ( !class_exists( 'PHPlot' ) && !isset($wgAutoloadClasses['PHPlot'] ) ) { |
| 27 | + $wgOut->addWikiMsg( 'uos-warn' ); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + $par = trim(strtolower($par)); |
| 32 | + |
| 33 | + foreach ( $this->blacklist as $b ) { |
| 34 | + if ( $b === $par ) { |
| 35 | + $par = false; |
| 36 | + break; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + if ( !$par ) { |
| 41 | + $opts = array(); |
| 42 | + $name = SpecialPage::getLocalNameFor( 'UserOptionStats' ); |
| 43 | + foreach ( $this->getOptions() as $k ) { |
| 44 | + $opts[] = "[[Special:$name/$k|$k]]"; |
| 45 | + } |
| 46 | + $wgOut->addWikiMsg( 'uos-choose', $wgLang->commaList( $opts ) ); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + $dbr = wfGetDB( DB_SLAVE ); |
| 54 | + |
| 55 | + $users = $dbr->select( 'user', '*', '', __METHOD__ ); |
| 56 | + $data = array(); |
| 57 | + $optionName = $par; |
| 58 | + foreach ( $users as $u ) { |
| 59 | + // New from row doesn't load user_properties, hence this is slow! |
| 60 | + $obj = User::newFromRow( $u ); |
| 61 | + $opt = $obj->getOption( $optionName, wfMsg( 'uos-unknown' ) ); |
| 62 | + |
| 63 | + if ( !isset($data[$opt]) ) $data[$opt] = 0; |
| 64 | + $data[$opt]++; |
| 65 | + } |
| 66 | + |
| 67 | + $realdata = array(); |
| 68 | + $labels = array(); |
| 69 | + |
| 70 | + // Most popular first, barring other |
| 71 | + arsort( $data ); |
| 72 | + |
| 73 | + // After more than 7 the default colors start to loop :( |
| 74 | + // So use the last free color for "other" which includes the rest |
| 75 | + $max = 7; |
| 76 | + $rest = array_slice( $data, $max ); |
| 77 | + $data = array_slice( $data, 0, $max ); |
| 78 | + foreach ( $data as $k => $d ) { |
| 79 | + $labels[] = "$k ($d)"; |
| 80 | + $realdata[] = array( $k, $d ); |
| 81 | + } |
| 82 | + if ( count($rest) ) { |
| 83 | + $other = 0; |
| 84 | + foreach ( $rest as $v ) $other += $v; |
| 85 | + $labels[] = wfMsg( 'uos-other' ) . " ($other)"; |
| 86 | + $realdata[] = array( 'other', $other ); |
| 87 | + } |
| 88 | + |
| 89 | + $title = $wgRequest->getText( 'pietitle', wfMsg( 'uos-title', $optionName ) ); |
| 90 | + $width = $wgRequest->getInt( 'width', 700 ); |
| 91 | + $height = $wgRequest->getInt( 'height', 500 ); |
| 92 | + $width = max( 200, min( 1000, $width ) ); |
| 93 | + $height = max( 200, min( 1000, $height ) ); |
| 94 | + $shading = $wgRequest->getInt( 'shading', 10 ); |
| 95 | + $height = max( 0, min( 1000, $height ) ); |
| 96 | + |
| 97 | + // Define the object |
| 98 | + $plot = new PHPlot( $width, $height ); |
| 99 | + $plot->SetDataType('text-data-single'); |
| 100 | + $plot->setDataValues( $realdata ); |
| 101 | + $plot->SetPlotType('pie'); |
| 102 | + $plot->SetLegend($labels); |
| 103 | + $plot->SetShading( $shading ); |
| 104 | + $plot->SetLabelScalePosition(0.3); |
| 105 | + $plot->SetTitle( $title ); |
| 106 | + |
| 107 | + // Better fonts |
| 108 | + if ( method_exists( 'FCFontFinder', 'find' ) ) { |
| 109 | + $font = FCFontFinder::find( $wgLang->getCode() ); |
| 110 | + if ( $font ) { |
| 111 | + $plot->SetDefaultTTFont( $font ); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + global $wgOut; |
| 116 | + $wgOut->disable(); |
| 117 | + $plot->DrawGraph(); |
| 118 | + } |
| 119 | + |
| 120 | + public function getOptions() { |
| 121 | + global $wgDefaultUserOptions; |
| 122 | + |
| 123 | + $opts = array(); |
| 124 | + foreach ( $wgDefaultUserOptions as $k => $v ) $opts[$k] = true; |
| 125 | + |
| 126 | + $dbr = wfGetDB( DB_SLAVE ); |
| 127 | + $res = $dbr->select( 'user_properties', 'DISTINCT(up_property) as value', '', __METHOD__ ); |
| 128 | + foreach ( $res as $r ) $opts[$r->value] = true; |
| 129 | + |
| 130 | + foreach ( $this->blacklist as $b ) unset( $opts[$b] ); |
| 131 | + |
| 132 | + $opts = array_keys( $opts ); |
| 133 | + sort($opts); |
| 134 | + |
| 135 | + return $opts; |
| 136 | + } |
| 137 | +} |
Property changes on: trunk/extensions/UserOptionStats/SpecialUserOptionStats.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 138 | + native |