r56570 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56569‎ | r56570 | r56571 >
Date:22:00, 17 September 2009
Author:thomasv
Status:ok
Tags:
Comment:
various fixes after brion's feedback
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/SpecialProofreadPages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -1153,6 +1153,19 @@
11541154
11551155
11561156
 1157+function pr_query_count( $dbr, $query, $cat ){
 1158+ $q = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( $cat ) ) );
 1159+ $res = $dbr->query( str_replace( '###', $q, $query) , __METHOD__ );
 1160+ if( $res && $dbr->numRows( $res ) > 0 ) {
 1161+ $row = $dbr->fetchObject( $res );
 1162+ $n = $row->count;
 1163+ $dbr->freeResult( $res );
 1164+ return $n;
 1165+ }
 1166+ return 0;
 1167+}
 1168+
 1169+
11571170 /*
11581171 * update the pr_index entry of an article
11591172 */
@@ -1190,53 +1203,29 @@
11911204 if($page != $deletedpage) array_push( $pages, $page );
11921205 }
11931206 }
1194 - $n0 = $n1 = $n2 = $n3 = $n4 = 0;
11951207
11961208 $dbr = wfGetDB( DB_SLAVE );
11971209 $catlinks = $dbr->tableName( 'categorylinks' );
11981210 $page = $dbr->tableName( 'page' );
11991211 $pagelist = "'".implode( "', '", $pages)."'";
1200 - $query = "SELECT COUNT(page_id) AS count FROM $page LEFT JOIN $catlinks ON cl_from=page_id WHERE cl_to='###' AND page_namespace=$page_ns_index AND page_title IN ( $pagelist )" ;
12011212
1202 - $q0 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality0_category' ) );
1203 - $res = $dbr->query( str_replace( '###', $q0, $query) , __METHOD__ );
1204 - if( $res && $dbr->numRows( $res ) > 0 ) {
1205 - $row = $dbr->fetchObject( $res );
1206 - $n0 = $row->count;
1207 - $dbr->freeResult( $res );
1208 - }
1209 -
1210 - $q2 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) );
1211 - $res = $dbr->query( str_replace( '###', $q2, $query) , __METHOD__ );
1212 - if( $res && $dbr->numRows( $res ) > 0 ) {
1213 - $row = $dbr->fetchObject( $res );
1214 - $n2 = $row->count;
1215 - $dbr->freeResult( $res );
1216 - }
1217 -
1218 - $q3 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) );
1219 - $res = $dbr->query( str_replace( '###', $q3, $query) , __METHOD__ );
1220 - if( $res && $dbr->numRows( $res ) > 0 ) {
1221 - $row = $dbr->fetchObject( $res );
1222 - $n3 = $row->count;
1223 - $dbr->freeResult( $res );
1224 - }
1225 -
1226 - $q4 = str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) );
1227 - $res = $dbr->query( str_replace( '###', $q4, $query) , __METHOD__ );
1228 - if( $res && $dbr->numRows( $res ) > 0 ) {
1229 - $row = $dbr->fetchObject( $res );
1230 - $n4 = $row->count;
1231 - $dbr->freeResult( $res );
1232 - }
1233 -
12341213 $query = "SELECT COUNT(page_id) AS count FROM $page WHERE page_namespace=$page_ns_index AND page_title IN ( $pagelist )" ;
12351214 $res = $dbr->query( $query , __METHOD__ );
12361215 if( $res && $dbr->numRows( $res ) > 0 ) {
12371216 $row = $dbr->fetchObject( $res );
1238 - $n1 = $row->count - $n0 - $n2 - $n3 - $n4;
 1217+ $total = $row->count;
12391218 $dbr->freeResult( $res );
 1219+ } else {
 1220+ return;
12401221 }
 1222+
 1223+ # proofreading status of pages
 1224+ $query = "SELECT COUNT(page_id) AS count FROM $page LEFT JOIN $catlinks ON cl_from=page_id WHERE cl_to='###' AND page_namespace=$page_ns_index AND page_title IN ( $pagelist )" ;
 1225+ $n0 = pr_query_count( $dbr, $query, 'proofreadpage_quality0_category' );
 1226+ $n2 = pr_query_count( $dbr, $query, 'proofreadpage_quality2_category' );
 1227+ $n3 = pr_query_count( $dbr, $query, 'proofreadpage_quality3_category' );
 1228+ $n4 = pr_query_count( $dbr, $query, 'proofreadpage_quality4_category' );
 1229+ $n1 = $total - $n0 - $n2 - $n3 - $n4;
12411230
12421231 $dbw = wfGetDB( DB_MASTER );
12431232 $pr_index = $dbw->tableName( 'pr_index' );
@@ -1292,40 +1281,11 @@
12931282
12941283 # find the proofreading status of transclusions
12951284 $query = "SELECT COUNT(page_id) AS count FROM $templatelinks LEFT JOIN $page ON page_title=tl_title LEFT JOIN $catlinks ON cl_from=page_id where tl_from=$id and tl_namespace=$page_ns_index AND cl_to='###'";
1296 -
1297 - $q4 = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality4_category' ) ) );
1298 - $res = $dbr->query( str_replace( '###', $q4, $query) , __METHOD__ );
1299 - if( $res && $dbr->numRows( $res ) > 0 ) {
1300 - $row = $dbr->fetchObject( $res );
1301 - $n4 = $row->count;
1302 - $dbr->freeResult( $res );
1303 - }
1304 -
1305 - $q3 = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality3_category' ) ) );
1306 - $res = $dbr->query( str_replace( '###', $q3, $query) , __METHOD__ );
1307 - if( $res && $dbr->numRows( $res ) > 0 ) {
1308 - $row = $dbr->fetchObject( $res );
1309 - $n3 = $row->count;
1310 - $dbr->freeResult( $res );
1311 - }
1312 -
1313 - $q2 = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality2_category' ) ) );
1314 - $res = $dbr->query( str_replace( '###', $q2, $query) , __METHOD__ );
1315 - if( $res && $dbr->numRows( $res ) > 0 ) {
1316 - $row = $dbr->fetchObject( $res );
1317 - $n2 = $row->count;
1318 - $dbr->freeResult( $res );
1319 - }
1320 -
1321 - $q0 = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( 'proofreadpage_quality0_category' ) ) );
1322 - $res = $dbr->query( str_replace( '###', $q0, $query) , __METHOD__ );
1323 - if( $res && $dbr->numRows( $res ) > 0 ) {
1324 - $row = $dbr->fetchObject( $res );
1325 - $n0 = $row->count;
1326 - $dbr->freeResult( $res );
1327 - }
1328 -
1329 - # q1 is default value
 1285+ $n0 = pr_query_count( $dbr, $query, 'proofreadpage_quality0_category' );
 1286+ $n2 = pr_query_count( $dbr, $query, 'proofreadpage_quality2_category' );
 1287+ $n3 = pr_query_count( $dbr, $query, 'proofreadpage_quality3_category' );
 1288+ $n4 = pr_query_count( $dbr, $query, 'proofreadpage_quality4_category' );
 1289+ # quality1 is the default value
13301290 $n1 = $n - $n0 - $n2 - $n3 - $n4;
13311291
13321292 # find the index page
Index: trunk/extensions/ProofreadPage/SpecialProofreadPages.php
@@ -45,7 +45,6 @@
4646 $dbr = wfGetDB( DB_SLAVE );
4747 $page = $dbr->tableName( 'page' );
4848 $pr_index = $dbr->tableName( 'pr_index' );
49 - $name = $dbr->addQuotes( $this->getName() );
5049
5150 return
5251 "SELECT pr_page_id as title,

Status & tagging log