Index: trunk/extensions/CooprationStatistics/CooperationStatistics_body.php |
— | — | @@ -0,0 +1,148 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special:CooperationStatistics |
| 5 | + */ |
| 6 | +class CooperationStatistics extends SpecialPage { |
| 7 | + public function __construct() { |
| 8 | + parent::__construct( 'CooperationStatistics' ); |
| 9 | + } |
| 10 | + |
| 11 | + public function execute( $par ) { |
| 12 | + global $wgCooperationStatsGoogleCharts, $wgOut; |
| 13 | + |
| 14 | + wfLoadExtensionMessages( 'CooperationStatistics' ); |
| 15 | + $nb_of_revuser = wfMsg( 'cooperationstatistics-limit-few-revisors' ); |
| 16 | + $nbpages = $this->getNbOfPages($nb_of_revuser,'<='); |
| 17 | + $this->OutputTableRaw( $nbpages, $nb_of_revuser, 'init' ); |
| 18 | + |
| 19 | + $retval = array(); |
| 20 | + $retval[$nb_of_revuser] = $this->getNbOfPages($nb_of_revuser,'='); |
| 21 | + $nb_of_revuser++; |
| 22 | + $range = 1 + wfMsg( 'cooperationstatistics-limit-many-revisors' ) - $nb_of_revuser; |
| 23 | + for ( $j = 0; $j < $range; $j++ ) { |
| 24 | + $nbpages = $this->getNbOfPages($nb_of_revuser,'='); |
| 25 | + $this->OutputTableRaw( $nbpages, $nb_of_revuser, '=' ); |
| 26 | + $retval[$nb_of_revuser] = $nbpages; |
| 27 | + $nb_of_revuser++; |
| 28 | + } |
| 29 | + |
| 30 | + $nbpages = $this->getNbOfPages($nb_of_revuser,'>='); |
| 31 | + $this->OutputTableRaw( $nbpages, $nb_of_revuser, 'end' ); |
| 32 | + $retval[$nb_of_revuser] = $nbpages; |
| 33 | + |
| 34 | + if ( $wgCooperationStatsGoogleCharts == True ) { |
| 35 | + $wgOut->addHTML( Xml::element( 'img', array( 'src' => |
| 36 | + $this->getGoogleChartBarParams( $retval ) ) ) |
| 37 | + . Xml::element( 'img', array( 'src' => |
| 38 | + $this->getGoogleChartParams( $retval ) ) ) ); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + private function getGoogleChartBarParams( $stats ) { |
| 43 | + global $wgCoopStatsChartBarDimensions; |
| 44 | + return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
| 45 | + array( |
| 46 | + 'chs' => $wgCoopStatsChartBarDimensions, |
| 47 | + 'cht' => 'bvs', |
| 48 | + 'chds' => '0,' . max( $stats ), |
| 49 | + 'chd' => 't:' . implode( ',', $stats ), |
| 50 | + 'chxt' => 'x,y', |
| 51 | + 'chxr' => '1,' . 0 . ',' . max( $stats ), |
| 52 | + 'chl' => implode( '|', array_keys( $stats ) ) . "++" |
| 53 | + ) ); |
| 54 | + } |
| 55 | + private function getGoogleChartParams( $stats ) { |
| 56 | + global $wgCoopStatsChartDimensions; |
| 57 | + return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
| 58 | + array( |
| 59 | + 'chs' => $wgCoopStatsChartDimensions, |
| 60 | + 'cht' => 'p3', |
| 61 | + 'chd' => 't:' . implode( ',', $stats ), |
| 62 | + 'chl' => implode( ' '.wfMsg( 'cooperationstatistics-users' ) . ' |', array_keys( $stats ) ) . wfMsg('cooperationstatistics-legendmore') |
| 63 | + ) ); |
| 64 | + } |
| 65 | + |
| 66 | + private function InitPageAndHtmlTable( ) { |
| 67 | + global $wgOut; |
| 68 | + $this->setHeaders(); |
| 69 | + $wgOut->setPagetitle( wfMsg( "cooperationstatistics" ) ); |
| 70 | + $wgOut->addWikiMsg( "cooperationstatistics-text" ); |
| 71 | + $wgOut->addHTML( "<table class=\"wikitable sortable\"><tr><td>"); |
| 72 | + $wgOut->addWikiMsg( "cooperationstatistics-tablearticle" ); |
| 73 | + $wgOut->addHTML("</td> |
| 74 | + <td>"); |
| 75 | + $wgOut->addWikiMsg( "cooperationstatistics-tablevalue" ); |
| 76 | + $wgOut->addHTML("</td> |
| 77 | + </tr>"); |
| 78 | + } |
| 79 | + private function OutputTableRaw( $nbpages, $nb_of_revuser, $msg ) { |
| 80 | + global $wgOut; |
| 81 | + if ($msg == 'init') $this->InitPageAndHtmlTable(); |
| 82 | + $wgOut->addHTML(" |
| 83 | +<tr> |
| 84 | + <td align='left'>"); |
| 85 | + $wgOut->addWikiMsg( 'cooperationstatistics-articles', $nbpages ); |
| 86 | + $wgOut->addHTML("</td> |
| 87 | + <td align='left'>"); |
| 88 | + if ($msg == 'init') $wgOut->addWikiMsg( 'cooperationstatistics-nblessusers', $nb_of_revuser ); |
| 89 | + if ($msg == '=' ) $wgOut->addWikiMsg( 'cooperationstatistics-nbusers', $nb_of_revuser ); |
| 90 | + if ($msg == 'end') $wgOut->addWikiMsg( 'cooperationstatistics-nbmoreusers', $nb_of_revuser ); |
| 91 | + $wgOut->addHTML("</td> |
| 92 | +</tr>"); |
| 93 | + if ($msg == 'end') $wgOut->addHTML("</table>"); |
| 94 | + } |
| 95 | + |
| 96 | + private function getNbOfPages( $nb, $relation ) { |
| 97 | + if ($relation == '<=') $sql = self::getSQLlower($nb); |
| 98 | + if ($relation == '=') $sql = self::getSQL($nb); |
| 99 | + if ($relation == '>=') $sql = self::getSQLupper($nb); |
| 100 | + $db = wfGetDB( DB_SLAVE ); |
| 101 | + $res = $db->query( $sql, __METHOD__ ); |
| 102 | + return $db->numRows( $res ); |
| 103 | + } |
| 104 | + private function getSQL($nb_of_revuser) { |
| 105 | + $dbr = wfGetDB( DB_SLAVE ); |
| 106 | + list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' ); |
| 107 | + return |
| 108 | + " |
| 109 | + SELECT |
| 110 | + page_title as title, |
| 111 | + COUNT(distinct rev_user) as value |
| 112 | + FROM $revision |
| 113 | + JOIN $page ON page_id = rev_page |
| 114 | + WHERE page_is_redirect=0 AND page_namespace = " . NS_MAIN . " |
| 115 | + GROUP BY page_namespace, page_title |
| 116 | + HAVING COUNT(distinct rev_user)=$nb_of_revuser |
| 117 | + "; |
| 118 | + } |
| 119 | + private function getSQLupper($nb_of_revuser) { |
| 120 | + $dbr = wfGetDB( DB_SLAVE ); |
| 121 | + list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' ); |
| 122 | + return |
| 123 | + " |
| 124 | + SELECT |
| 125 | + page_title as title, |
| 126 | + COUNT(distinct rev_user) as value |
| 127 | + FROM $revision |
| 128 | + JOIN $page ON page_id = rev_page |
| 129 | + WHERE page_is_redirect=0 AND page_namespace = " . NS_MAIN . " |
| 130 | + GROUP BY page_namespace, page_title |
| 131 | + HAVING COUNT(distinct rev_user)>=$nb_of_revuser |
| 132 | + "; |
| 133 | + } |
| 134 | + private function getSQLlower($nb_of_revuser) { |
| 135 | + $dbr = wfGetDB( DB_SLAVE ); |
| 136 | + list( $revision, $page ) = $dbr->tableNamesN( 'revision', 'page' ); |
| 137 | + return |
| 138 | + " |
| 139 | + SELECT |
| 140 | + page_title as title, |
| 141 | + COUNT(distinct rev_user) as value |
| 142 | + FROM $revision |
| 143 | + JOIN $page ON page_id = rev_page |
| 144 | + WHERE page_is_redirect=0 AND page_namespace = " . NS_MAIN . " |
| 145 | + GROUP BY page_namespace, page_title |
| 146 | + HAVING COUNT(distinct rev_user)<=$nb_of_revuser |
| 147 | + "; |
| 148 | + } |
| 149 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/CooprationStatistics/CooperationStatistics_body.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 150 | + native |
Index: trunk/extensions/CooprationStatistics/CooperationStatistics.i18n.php |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for extension cooperationstatistics. |
| 5 | + * |
| 6 | + * @addtogroup Extensions |
| 7 | +*/ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +$messages['en'] = array( |
| 12 | + 'cooperationstatistics' => 'Cooperation statistics', |
| 13 | + 'cooperationstatistics-desc' => 'Show [[Special:CooperationStatistics|cooperation statistics on main namespace]].', |
| 14 | + 'cooperationstatistics-text' => 'Show cooperation statistics on main namespace. (From [[MediaWiki:cooperationstatistics-limit-few-revisors|{{MediaWiki:cooperationstatistics-limit-few-revisors}}]] to [[MediaWiki:cooperationstatistics-limit-many-revisors|{{MediaWiki:cooperationstatistics-limit-many-revisors}}+]] revisors)' . |
| 15 | + '<br>See also the [[Special:MostRevisors|\'\'\'pages with the most revisors\'\'\']] and [[Special:MostRevisions|with the most revisions]].', |
| 16 | + 'cooperationstatistics-tablearticle' => 'Article count', |
| 17 | + 'cooperationstatistics-tablevalue' => 'Number of editors', |
| 18 | + 'cooperationstatistics-users' => 'editors', |
| 19 | + 'cooperationstatistics-articles' => '$1 articles', |
| 20 | + 'cooperationstatistics-nbusers' => 'have $1 editors', |
| 21 | + 'cooperationstatistics-nblessusers' => 'have $1 or less editors', |
| 22 | + 'cooperationstatistics-nbmoreusers' => 'have $1 or more editors', |
| 23 | + 'cooperationstatistics-legendmore' => ' or more editors.', |
| 24 | + 'cooperationstatistics-limit-few-revisors' => '1', |
| 25 | + 'cooperationstatistics-limit-many-revisors' => '5', |
| 26 | +); |
| 27 | + |
| 28 | +/** Message documentation (Message documentation) |
| 29 | + * @author Fryed-peach |
| 30 | + * @author Jon Harald Søby |
| 31 | + * @author Lejonel |
| 32 | + * @author Purodha |
| 33 | + * @author Siebrand |
| 34 | + */ |
| 35 | +$messages['qqq'] = array( |
| 36 | + 'cooperationstatistics' => '{{Identical|Most Revisors}}', |
| 37 | + 'cooperationstatistics-desc' => 'Short description of the extension, shown on [[Special:Version]].', |
| 38 | +); |
Property changes on: trunk/extensions/CooprationStatistics/CooperationStatistics.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 39 | + native |
Index: trunk/extensions/CooprationStatistics/CooperationStatistics.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page to show Cooperation Statistics. |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +// If this is run directly from the web die as this is not a valid entry point. |
| 9 | +if( !defined( 'MEDIAWIKI' ) ) die( 'Invalid entry point.' ); |
| 10 | + |
| 11 | +$wgCooperationStatsGoogleCharts = True; // false to disable charts |
| 12 | +$wgCoopStatsChartDimensions = '520x200'; |
| 13 | +$wgCoopStatsChartBarDimensions = '180x200'; |
| 14 | + |
| 15 | +// Set extension files. |
| 16 | +$dir = dirname( __FILE__ ) . '/'; |
| 17 | +$wgExtensionMessagesFiles['CooperationStatistics'] = $dir . 'CooperationStatistics.i18n.php'; |
| 18 | +$wgExtensionAliasesFiles['CooperationStatistics'] = $dir . 'CooperationStatistics.alias.php'; |
| 19 | +$wgAutoloadClasses['CooperationStatistics'] = $dir . 'CooperationStatistics_body.php'; |
| 20 | +$wgSpecialPages['CooperationStatistics'] = 'CooperationStatistics'; |
| 21 | +$wgSpecialPageGroups['CooperationStatistics'] = 'wiki'; |
| 22 | + |
| 23 | +// Extension credits. |
| 24 | +$wgExtensionCredits['specialpage'][] = array( |
| 25 | + 'path' => __FILE__, |
| 26 | + 'name' => 'CooperationStatistics', |
| 27 | + 'version' => '1.0', |
| 28 | + 'author' => 'Al Maghi', |
| 29 | + 'email' => 'alfred.maghi@gmail.com', |
| 30 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:CooperationStatistics', |
| 31 | + 'description' => '', |
| 32 | + 'descriptionmsg' => 'cooperationstatistics-desc', |
| 33 | +); |
Property changes on: trunk/extensions/CooprationStatistics/CooperationStatistics.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 34 | + native |
Index: trunk/extensions/CooprationStatistics/CooperationStatistics.alias.php |
— | — | @@ -0,0 +1,14 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for special pages |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +$aliases = array(); |
| 9 | + |
| 10 | +/** English |
| 11 | + * |
| 12 | + */ |
| 13 | +$aliases['en'] = array( |
| 14 | + 'CooperationStatistics' => array( 'CooperationStatistics' ), |
| 15 | +); |
Property changes on: trunk/extensions/CooprationStatistics/CooperationStatistics.alias.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 16 | + native |