r24090 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24089‎ | r24090 | r24091 >
Date:18:24, 14 July 2007
Author:robchurch
Status:old
Tags:
Comment:
* Clean up database code
* Honour forthcoming rev_deleted
Modified paths:
  • /trunk/extensions/Contributors/Contributors.page.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contributors/Contributors.page.php
@@ -144,16 +144,21 @@
145145 $contributors = $wgMemc->get( $k );
146146 if( !$contributors ) {
147147 $contributors = array();
148 - $dbr =& wfGetDB( DB_SLAVE );
149 - $rev = $dbr->tableName( 'revision' );
150 - $aid = $this->target->getArticleId();
151 - $sql = "SELECT COUNT(*) AS count, rev_user, rev_user_text FROM {$rev} WHERE rev_page = {$aid}";
152 - $groupby = "GROUP BY rev_user_text";
153 - if( !$dbr->implicitGroupby() )
154 - $groupby .= ",rev_user";
155 - $orderby = "ORDER BY count DESC";
156 - $sql .= " $groupby $orderby";
157 - $res = $dbr->query( $sql, __METHOD__ );
 148+ $dbr = wfGetDB( DB_SLAVE );
 149+ $res = $dbr->select(
 150+ 'revision',
 151+ array(
 152+ 'COUNT(*) AS count',
 153+ 'rev_user',
 154+ 'rev_user_text',
 155+ ),
 156+ $this->getConditions(),
 157+ __METHOD__,
 158+ array(
 159+ 'GROUP BY' => 'rev_user_text',
 160+ 'ORDER BY' => 'count DESC',
 161+ )
 162+ );
158163 if( $res && $dbr->numRows( $res ) > 0 ) {
159164 while( $row = $dbr->fetchObject( $res ) )
160165 $contributors[ $row->rev_user_text ] = array( $row->rev_user, $row->count );
@@ -165,6 +170,19 @@
166171 }
167172
168173 /**
 174+ * Get conditions for the main query
 175+ *
 176+ * @return array
 177+ */
 178+ private function getConditions() {
 179+ global $wgVersion;
 180+ $conds['rev_page'] = $this->target->getArticleId();
 181+ if( version_compare( $wgVersion, '1.11alpha', '>=' ) )
 182+ $conds[] = 'rev_deleted & ' . Revision::DELETED_USER . ' = 0';
 183+ return $conds;
 184+ }
 185+
 186+ /**
169187 * Given the web request, and a possible override from a subpage, work
170188 * out which we want to use
171189 *

Status & tagging log