Index: trunk/phase3/includes/Article.php |
— | — | @@ -799,46 +799,47 @@ |
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
803 | | - * FIXME: this does what? |
804 | | - * @param $limit Integer: default 0. |
805 | | - * @param $offset Integer: default 0. |
806 | | - * @return UserArrayFromResult object with User objects of article contributors for requested range |
| 803 | + * Get a list of users who have edited this article, not including the user who made |
| 804 | + * the most recent revision, which you can get from $article->getUser() if you want it |
| 805 | + * @return UserArray |
807 | 806 | */ |
808 | | - public function getContributors( $limit = 0, $offset = 0 ) { |
| 807 | + public function getContributors() { |
809 | 808 | # FIXME: this is expensive; cache this info somewhere. |
810 | 809 | |
811 | 810 | $dbr = wfGetDB( DB_SLAVE ); |
812 | | - $revTable = $dbr->tableName( 'revision' ); |
813 | 811 | $userTable = $dbr->tableName( 'user' ); |
814 | 812 | |
815 | | - $pageId = $this->getId(); |
| 813 | + $tables = array( 'revision', 'user' ); |
816 | 814 | |
| 815 | + $fields = array( |
| 816 | + "$userTable.*", |
| 817 | + 'rev_user_text AS user_name', |
| 818 | + 'MAX(rev_timestamp) AS timestamp', |
| 819 | + ); |
| 820 | + |
| 821 | + $conds = array( 'rev_page' => $this->getId() ); |
| 822 | + |
| 823 | + // The user who made the top revision gets credited as "this page was last edited by |
| 824 | + // John, based on contributions by Tom, Dick and Harry", so don't include them twice. |
817 | 825 | $user = $this->getUser(); |
818 | | - |
819 | 826 | if ( $user ) { |
820 | | - $excludeCond = "AND rev_user != $user"; |
| 827 | + $conds[] = "rev_user != $user"; |
821 | 828 | } else { |
822 | | - $userText = $dbr->addQuotes( $this->getUserText() ); |
823 | | - $excludeCond = "AND rev_user_text != $userText"; |
| 829 | + $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}"; |
824 | 830 | } |
825 | 831 | |
826 | | - $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden? |
| 832 | + $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden? |
827 | 833 | |
828 | | - $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp |
829 | | - FROM $revTable LEFT JOIN $userTable ON rev_user = user_id |
830 | | - WHERE rev_page = $pageId |
831 | | - $excludeCond |
832 | | - AND $deletedBit = 0 |
833 | | - GROUP BY rev_user, rev_user_text |
834 | | - ORDER BY timestamp DESC"; |
| 834 | + $jconds = array( |
| 835 | + 'user' => array( 'LEFT JOIN', 'rev_user = user_id' ), |
| 836 | + ); |
835 | 837 | |
836 | | - if ( $limit > 0 ) { |
837 | | - $sql = $dbr->limitResult( $sql, $limit, $offset ); |
838 | | - } |
839 | | - |
840 | | - $sql .= ' ' . $this->getSelectOptions(); |
841 | | - $res = $dbr->query( $sql, __METHOD__ ); |
842 | | - |
| 838 | + $options = array( |
| 839 | + 'GROUP BY' => array( 'rev_user', 'rev_user_text' ), |
| 840 | + 'ORDER BY' => 'timestamp DESC', |
| 841 | + ); |
| 842 | + |
| 843 | + $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds ); |
843 | 844 | return new UserArrayFromResult( $res ); |
844 | 845 | } |
845 | 846 | |
— | — | @@ -3618,10 +3619,11 @@ |
3619 | 3620 | |
3620 | 3621 | $dbw = wfGetDB( DB_MASTER ); |
3621 | 3622 | $cutoff = $dbw->timestamp( time() - $wgRCMaxAge ); |
3622 | | - $recentchanges = $dbw->tableName( 'recentchanges' ); |
3623 | | - $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'"; |
3624 | | - |
3625 | | - $dbw->query( $sql ); |
| 3623 | + $dbw->delete( |
| 3624 | + 'recentchanges', |
| 3625 | + array( "rc_timestamp < '$cutoff'" ), |
| 3626 | + __METHOD__ |
| 3627 | + ); |
3626 | 3628 | } |
3627 | 3629 | } |
3628 | 3630 | |
Index: trunk/phase3/includes/parser/LinkHolderArray.php |
— | — | @@ -270,6 +270,7 @@ |
271 | 271 | # Generate query |
272 | 272 | $query = false; |
273 | 273 | $current = null; |
| 274 | + $queries = array(); |
274 | 275 | foreach ( $this->internals as $ns => $entries ) { |
275 | 276 | foreach ( $entries as $entry ) { |
276 | 277 | $title = $entry['title']; |
— | — | @@ -294,25 +295,28 @@ |
295 | 296 | $colours[$pdbk] = 'new'; |
296 | 297 | } else { |
297 | 298 | # Not in the link cache, add it to the query |
298 | | - if ( !isset( $current ) ) { |
299 | | - $current = $ns; |
300 | | - $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len, page_latest"; |
301 | | - $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN("; |
302 | | - } elseif ( $current != $ns ) { |
303 | | - $current = $ns; |
304 | | - $query .= ")) OR (page_namespace=$ns AND page_title IN("; |
305 | | - } else { |
306 | | - $query .= ', '; |
307 | | - } |
308 | | - |
309 | | - $query .= $dbr->addQuotes( $title->getDBkey() ); |
| 299 | + $queries[$ns][] = $title->getDBkey(); |
310 | 300 | } |
311 | 301 | } |
312 | 302 | } |
313 | | - if ( $query ) { |
314 | | - $query .= '))'; |
| 303 | + if ( $queries ) { |
| 304 | + $where = array(); |
| 305 | + foreach( $queries as $ns => $pages ){ |
| 306 | + $where[] = $dbr->makeList( |
| 307 | + array( |
| 308 | + 'page_namespace' => $ns, |
| 309 | + 'page_title' => $pages, |
| 310 | + ), |
| 311 | + LIST_AND |
| 312 | + ); |
| 313 | + } |
315 | 314 | |
316 | | - $res = $dbr->query( $query, __METHOD__ ); |
| 315 | + $res = $dbr->select( |
| 316 | + 'page', |
| 317 | + array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest' ), |
| 318 | + $dbr->makeList( $where, LIST_OR ), |
| 319 | + __METHOD__ |
| 320 | + ); |
317 | 321 | |
318 | 322 | # Fetch data and form into an associative array |
319 | 323 | # non-existent = broken |
Index: trunk/phase3/includes/Export.php |
— | — | @@ -157,17 +157,23 @@ |
158 | 158 | # Generates the distinct list of authors of an article |
159 | 159 | # Not called by default (depends on $this->list_authors) |
160 | 160 | # Can be set by Special:Export when not exporting whole history |
161 | | - protected function do_list_authors( $page , $revision , $cond ) { |
| 161 | + protected function do_list_authors( $cond ) { |
162 | 162 | wfProfileIn( __METHOD__ ); |
163 | 163 | $this->author_list = "<contributors>"; |
164 | 164 | // rev_deleted |
165 | | - $nothidden = '(' . $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ') = 0'; |
166 | 165 | |
167 | | - $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision} |
168 | | - WHERE page_id=rev_page AND $nothidden AND " . $cond ; |
169 | | - $result = $this->db->query( $sql, __METHOD__ ); |
170 | | - $resultset = $this->db->resultObject( $result ); |
171 | | - foreach ( $resultset as $row ) { |
| 166 | + $res = $this->db->select( |
| 167 | + array( 'page', 'revision' ), |
| 168 | + array( 'DISTINCT rev_user_text', 'rev_user' ), |
| 169 | + array( |
| 170 | + $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0', |
| 171 | + $cond, |
| 172 | + 'page_id = rev_id', |
| 173 | + ), |
| 174 | + __METHOD__ |
| 175 | + ); |
| 176 | + |
| 177 | + foreach ( $res as $row ) { |
172 | 178 | $this->author_list .= "<contributor>" . |
173 | 179 | "<username>" . |
174 | 180 | htmlentities( $row->rev_user_text ) . |
— | — | @@ -240,8 +246,7 @@ |
241 | 247 | } elseif ( $this->history & WikiExporter::CURRENT ) { |
242 | 248 | # Latest revision dumps... |
243 | 249 | if ( $this->list_authors && $cond != '' ) { // List authors, if so desired |
244 | | - list( $page, $revision ) = $this->db->tableNamesN( 'page', 'revision' ); |
245 | | - $this->do_list_authors( $page, $revision, $cond ); |
| 250 | + $this->do_list_authors( $cond ); |
246 | 251 | } |
247 | 252 | $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' ); |
248 | 253 | } elseif ( $this->history & WikiExporter::STABLE ) { |