r73745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73744‎ | r73745 | r73746 >
Date:15:51, 25 September 2010
Author:thomasv
Status:resolved
Tags:
Comment:
replace queries with select wrapper
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -1263,9 +1263,10 @@
12641264 $catlinks = $dbr->tableName( 'categorylinks' );
12651265 $page = $dbr->tableName( 'page' );
12661266 $pagelist = "'".implode( "', '", $pages)."'";
1267 -
1268 - $query = "SELECT COUNT(page_id) AS count FROM $page WHERE page_namespace=$page_ns_index AND page_title IN ( $pagelist )" ;
1269 - $res = $dbr->query( $query , __METHOD__ );
 1267+ $res = $dbr->select( array( 'page' ),
 1268+ array( 'COUNT(page_id) AS count'),
 1269+ array( "page_namespace=$page_ns_index", "page_title IN ( $pagelist )"),
 1270+ __METHOD__ );
12701271 if( $res && $dbr->numRows( $res ) > 0 ) {
12711272 $row = $dbr->fetchObject( $res );
12721273 $total = $row->count;
@@ -1319,8 +1320,11 @@
13201321 $catlinks = $dbr->tableName( 'categorylinks' );
13211322
13221323 // count transclusions from page namespace
1323 - $query = "SELECT COUNT(page_id) AS count FROM $templatelinks LEFT JOIN $page ON page_title=tl_title AND page_namespace=tl_namespace WHERE tl_from=$id AND tl_namespace=$page_ns_index";
1324 - $res = $dbr->query( $query , __METHOD__ );
 1324+ $res = $dbr->select( array( 'templatelinks', 'page' ),
 1325+ array( 'COUNT(page_id) AS count' ),
 1326+ array( "tl_from=$id", "tl_namespace=$page_ns_index" ),
 1327+ __METHOD__, null,
 1328+ array( 'page' => array( 'LEFT JOIN', 'page_title=tl_title AND page_namespace=tl_namespace' ) ) ) ;
13251329 if( $res && $dbr->numRows( $res ) > 0 ) {
13261330 $row = $dbr->fetchObject( $res );
13271331 $n = $row->count;
@@ -1340,23 +1344,31 @@
13411345 $n1 = $n - $n0 - $n2 - $n3 - $n4;
13421346
13431347 // find the index page
1344 - $indexlink="";
1345 - $query1 = "SELECT tl_title AS title FROM $templatelinks WHERE tl_from=$id AND tl_namespace=$page_ns_index LIMIT 1";
1346 - $res = $dbr->query( $query1 , __METHOD__ );
 1348+ $indextitle = null;
 1349+ $res = $dbr->select( array( 'templatelinks' ),
 1350+ array( 'tl_title AS title' ),
 1351+ array( "tl_from=$id", "tl_namespace=$page_ns_index" ),
 1352+ __METHOD__, array( 'LIMIT' => 1 ) );
13471353 if( $res && $dbr->numRows( $res ) > 0 ) {
13481354 $row = $dbr->fetchObject( $res );
13491355 $title = $dbr->strencode( $row->title );
13501356 $dbr->freeResult( $res );
1351 - $query2 = "SELECT page_title AS title FROM $pagelinks LEFT JOIN $page ON page_id=pl_from WHERE pl_title=\"$title\" AND pl_namespace=$page_ns_index AND page_namespace=$index_ns_index LIMIT 1";
1352 - $res2 = $dbr->query( $query2 , __METHOD__ );
 1357+ $res2 = $dbr->select( array( 'pagelinks', 'page' ),
 1358+ array( 'page_title AS title' ),
 1359+ array( "pl_title='$title'","pl_namespace=$page_ns_index","page_namespace=$index_ns_index"),
 1360+ __METHOD__, array( 'LIMIT' => 1 ),
 1361+ array( 'page' => array( 'LEFT JOIN', 'page_id=pl_from' ) ) ) ;
13531362 if( $res2 && $dbr->numRows( $res2 ) > 0 ) {
13541363 $row = $dbr->fetchObject( $res2 );
13551364 $indextitle = $row->title;
13561365 $dbr->freeResult( $res2 );
1357 - $sk = $wgUser->getSkin();
1358 - $indexlink = $sk->makeKnownLink( "$index_namespace:$indextitle", "[index]" );
13591366 }
13601367 }
 1368+ $indexlink = '';
 1369+ if( $indextitle ) {
 1370+ $sk = $wgUser->getSkin();
 1371+ $indexlink = $sk->makeKnownLink( "$index_namespace:$indextitle", "[index]" );
 1372+ }
13611373 $output = wfMsgForContent( 'proofreadpage_quality_message', $n0*100/$n, $n1*100/$n, $n2*100/$n, $n3*100/$n, $n4*100/$n, $n, $indexlink );
13621374 $out->setSubtitle( $out->getSubtitle() . $output );
13631375 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r79322Followup r73745, don't manually quote, use 'blah' => $blah...reedy04:28, 31 December 2010

Status & tagging log