r79326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79325‎ | r79326 | r79327 >
Date:04:53, 31 December 2010
Author:reedy
Status:ok (Comments)
Tags:brion 
Comment:
Rewrite some of the Raw SQL building
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -1310,9 +1310,16 @@
13111311 return true;
13121312 }
13131313
 1314+ /**
 1315+ * @param $dbr DatabaseBase
 1316+ * @param $query
 1317+ * @param $cat
 1318+ * @return int
 1319+ */
13141320 function query_count( $dbr, $query, $cat ) {
1315 - $q = $dbr->strencode( str_replace( ' ' , '_' , wfMsgForContent( $cat ) ) );
1316 - $res = $dbr->query( str_replace( '###', $q, $query ), __METHOD__ );
 1321+ $query['conds']['cl_to'] = $str_replace( ' ' , '_' , wfMsgForContent( $cat ) );
 1322+ $res = $dbr->select( $query['tables'], $query['fields'], $query['conds'], __METHOD__, $query['joins'] );
 1323+
13171324 if( $res && $dbr->numRows( $res ) > 0 ) {
13181325 $row = $dbr->fetchObject( $res );
13191326 $n = $row->count;
@@ -1375,6 +1382,7 @@
13761383 array( 'page_namespace' => $page_ns_index, 'page_title' => $pages ),
13771384 __METHOD__
13781385 );
 1386+
13791387 if( $res && $dbr->numRows( $res ) > 0 ) {
13801388 $row = $dbr->fetchObject( $res );
13811389 $total = $row->count;
@@ -1383,17 +1391,18 @@
13841392 return;
13851393 }
13861394
1387 - $pagelist = "'".implode( "', '", $pages)."'";
1388 - $catlinks = $dbr->tableName( 'categorylinks' );
1389 - $page = $dbr->tableName( 'page' );
1390 -
13911395 // proofreading status of pages
1392 - $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 )" ;
 1396+ $queryArr = array(
 1397+ 'tables' => array( 'page', 'categorylinks' ),
 1398+ 'fields' => array( 'COUNT(page_id) AS count' ),
 1399+ 'conds' => array( 'cl_to' => '', 'page_namespace' => $page_ns_index, 'page_title' => $pages ),
 1400+ 'joins' => array( 'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ) )
 1401+ );
13931402
1394 - $n0 = $this->query_count( $dbr, $query, 'proofreadpage_quality0_category' );
1395 - $n2 = $this->query_count( $dbr, $query, 'proofreadpage_quality2_category' );
1396 - $n3 = $this->query_count( $dbr, $query, 'proofreadpage_quality3_category' );
1397 - $n4 = $this->query_count( $dbr, $query, 'proofreadpage_quality4_category' );
 1403+ $n0 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' );
 1404+ $n2 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' );
 1405+ $n3 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' );
 1406+ $n4 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' );
13981407 $n1 = $total - $n0 - $n2 - $n3 - $n4;
13991408
14001409 $dbw = wfGetDB( DB_MASTER );
@@ -1424,9 +1433,6 @@
14251434 }
14261435
14271436 $dbr = wfGetDB( DB_SLAVE );
1428 - $page = $dbr->tableName( 'page' );
1429 - $templatelinks = $dbr->tableName( 'templatelinks' );
1430 - $catlinks = $dbr->tableName( 'categorylinks' );
14311437
14321438 // find the index page
14331439 $indextitle = null;
@@ -1497,11 +1503,20 @@
14981504 $dbr->freeResult( $res );
14991505 }
15001506 // find the proofreading status of transclusions
1501 - $query = "SELECT COUNT(page_id) AS count FROM $templatelinks LEFT JOIN $page ON page_title=tl_title AND page_namespace=tl_namespace LEFT JOIN $catlinks ON cl_from=page_id WHERE tl_from=$id AND tl_namespace=$page_ns_index AND cl_to='###'";
1502 - $n0 = $this->query_count( $dbr, $query, 'proofreadpage_quality0_category' );
1503 - $n2 = $this->query_count( $dbr, $query, 'proofreadpage_quality2_category' );
1504 - $n3 = $this->query_count( $dbr, $query, 'proofreadpage_quality3_category' );
1505 - $n4 = $this->query_count( $dbr, $query, 'proofreadpage_quality4_category' );
 1507+ $queryArr = array(
 1508+ 'tables' => array( 'templatelinks', 'page', 'categorylinks' ),
 1509+ 'fields' => array( 'COUNT(page_id) AS count' ),
 1510+ 'conds' => array( 'cl_to' => '', 'page_namespace' => $page_ns_index, 'page_title' => $pages ),
 1511+ 'joins' => array(
 1512+ 'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ),
 1513+ 'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ),
 1514+ )
 1515+ );
 1516+
 1517+ $n0 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality0_category' );
 1518+ $n2 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality2_category' );
 1519+ $n3 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality3_category' );
 1520+ $n4 = $this->query_count( $dbr, $queryArr, 'proofreadpage_quality4_category' );
15061521 // quality1 is the default value
15071522 $n1 = $n - $n0 - $n2 - $n3 - $n4;
15081523 $ne = 0;

Follow-up revisions

RevisionCommit summaryAuthorDate
r79328Minor followup to r79326, add missing parameter for optionsreedy04:55, 31 December 2010
r80956ProofreadPage partial fix for r79326: change "$str_replace()" to "str_replace...brion04:03, 25 January 2011
r80960Followup r79326, fixup wrong query, presumably copy paste artifactreedy08:24, 25 January 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   04:02, 25 January 2011

$str_replace -> FATAL ERROR

$pages -> not initialized, spews notice.

Status & tagging log