r65353 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65352‎ | r65353 | r65354 >
Date:02:29, 21 April 2010
Author:nad
Status:deferred
Tags:
Comment:
add optional $count param to getRecordsByType()
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -819,15 +819,21 @@
820820
821821 /**
822822 * Return a list of title objects of a specified record type
 823+ * - set $count to true to return just the number of results
823824 */
824 - static function getRecordsByType( $type ) {
 825+ static function getRecordsByType( $type, $count = false ) {
825826 $records = array();
826827 $dbr = wfGetDB( DB_SLAVE );
827828 $tbl = $dbr->tableName( 'templatelinks' );
828829 $ty = $dbr->addQuotes( $type );
829 - $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
830 - while ( $row = $dbr->fetchRow( $res ) ) $records[] = Title::newFromID( $row[0] );
831 - $dbr->freeResult( $res );
 830+ if ( $count ) {
 831+ $row = $dbr->selectRow( $tbl, 'count(0)', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
 832+ $records = $row[0];
 833+ } else {
 834+ $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
 835+ while ( $row = $dbr->fetchRow( $res ) ) $records[] = Title::newFromID( $row[0] );
 836+ $dbr->freeResult( $res );
 837+ }
832838 return $records;
833839 }
834840
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -11,7 +11,7 @@
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
1414
15 -define( 'RECORDADMIN_VERSION', '0.11.10, 2010-04-11' );
 15+define( 'RECORDADMIN_VERSION', '0.11.11, 2010-04-21' );
1616
1717 $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type
1818 $wgRecordAdminCategory = 'Records'; # Category containing record types

Status & tagging log