r46001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46000‎ | r46001 | r46002 >
Date:05:05, 22 January 2009
Author:nad
Status:deferred
Tags:
Comment:
move record searching into a method ready for parser-function to use later
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
@@ -128,29 +128,7 @@
129129 $wgOut->addWikiText( "<br>\n== " . wfMsg( 'recordadmin-searchresult' ) . " ==\n" );
130130
131131 # Select records which use the template and exhibit a matching title and other fields
132 - $records = array();
133 - $dbr = &wfGetDB( DB_SLAVE );
134 - $tbl = $dbr->tableName( 'templatelinks' );
135 - $ty = $dbr->addQuotes( $type );
136 - $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
137 - while ( $row = $dbr->fetchRow( $res ) ) {
138 - $t = Title::newFromID( $row[0] );
139 - if ( empty( $wpTitle ) || eregi( $wpTitle, $t->getPrefixedText() ) ) {
140 - $a = new Article( $t );
141 - $text = $a->getContent();
142 - $match = true;
143 - $r = array( $t );
144 - foreach ( array_keys( $this->types ) as $k ) {
145 - $v = isset( $posted[$k] ) ? ( $this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
146 - $i = preg_match( "|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
147 - if ( $v && !( $i && eregi( $v, $m[1] ) ) ) $match = false;
148 - $r[$k] = isset( $m[1] ) ? $m[1] : '';
149 - }
150 - if ( $invert ) $match = !$match;
151 - if ( $match ) $records[$t->getPrefixedText()] = $r;
152 - }
153 - }
154 - $dbr->freeResult( $res );
 132+ $records = $this->getRecords($type, $posted, $wpTitle, $invert);
155133
156134 # Render search results
157135 if ( count( $records ) ) {
@@ -246,6 +224,35 @@
247225 }
248226
249227 /**
 228+ * Return an array of records given type and other criteria
 229+ */
 230+ function getRecords($type, $posted, $wpTitle = '', $invert = false) {
 231+ $records = array();
 232+ $dbr = &wfGetDB( DB_SLAVE );
 233+ $tbl = $dbr->tableName( 'templatelinks' );
 234+ $ty = $dbr->addQuotes( $type );
 235+ $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
 236+ while ( $row = $dbr->fetchRow( $res ) ) {
 237+ $t = Title::newFromID( $row[0] );
 238+ if ( empty( $wpTitle ) || eregi( $wpTitle, $t->getPrefixedText() ) ) {
 239+ $a = new Article( $t );
 240+ $text = $a->getContent();
 241+ $match = true;
 242+ $r = array( $t );
 243+ foreach ( array_keys( $this->types ) as $k ) {
 244+ $v = isset( $posted[$k] ) ? ( $this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
 245+ $i = preg_match( "|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
 246+ if ( $v && !( $i && eregi( $v, $m[1] ) ) ) $match = false;
 247+ $r[$k] = isset( $m[1] ) ? $m[1] : '';
 248+ }
 249+ if ( $invert ) $match = !$match;
 250+ if ( $match ) $records[$t->getPrefixedText()] = $r;
 251+ }
 252+ }
 253+ $dbr->freeResult( $res );
 254+ }
 255+
 256+ /**
250257 * Read in and prepare the form (for use as a search filter) for passed record type
251258 * - we're using the record's own form as a filter for searching for records
252259 * - extract only the content from between the form tags and remove any submit inputs
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.4.1, 2008-11-04' );
 15+define( 'RECORDADMIN_VERSION', '0.5.0, 2009-01-22' );
1616
1717 $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type
1818
@@ -19,8 +19,8 @@
2020 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';
2121 $wgExtensionAliasesFiles['RecordAdmin'] = $dir . 'RecordAdmin.alias.php';
2222 $wgAutoloadClasses['SpecialRecordAdmin'] = $dir . 'RecordAdmin_body.php';
23 -$wgSpecialPages['RecordAdmin'] = 'SpecialRecordAdmin';
24 -$wgSpecialPageGroups['RecordAdmin'] = 'wiki';
 23+$wgSpecialPages['RecordAdmin'] = 'SpecialRecordAdmin';
 24+$wgSpecialPageGroups['RecordAdmin'] = 'wiki';
2525
2626 $wgGroupPermissions['sysop']['recordadmin'] = true;
2727 $wgAvailableRights[] = 'recordadmin';

Status & tagging log