Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -128,29 +128,7 @@ |
129 | 129 | $wgOut->addWikiText( "<br>\n== " . wfMsg( 'recordadmin-searchresult' ) . " ==\n" ); |
130 | 130 | |
131 | 131 | # 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); |
155 | 133 | |
156 | 134 | # Render search results |
157 | 135 | if ( count( $records ) ) { |
— | — | @@ -246,6 +224,35 @@ |
247 | 225 | } |
248 | 226 | |
249 | 227 | /** |
| 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 | + /** |
250 | 257 | * Read in and prepare the form (for use as a search filter) for passed record type |
251 | 258 | * - we're using the record's own form as a filter for searching for records |
252 | 259 | * - extract only the content from between the form tags and remove any submit inputs |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'RECORDADMIN_VERSION', '0.4.1, 2008-11-04' ); |
| 15 | +define( 'RECORDADMIN_VERSION', '0.5.0, 2009-01-22' ); |
16 | 16 | |
17 | 17 | $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type |
18 | 18 | |
— | — | @@ -19,8 +19,8 @@ |
20 | 20 | $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php'; |
21 | 21 | $wgExtensionAliasesFiles['RecordAdmin'] = $dir . 'RecordAdmin.alias.php'; |
22 | 22 | $wgAutoloadClasses['SpecialRecordAdmin'] = $dir . 'RecordAdmin_body.php'; |
23 | | -$wgSpecialPages['RecordAdmin'] = 'SpecialRecordAdmin'; |
24 | | -$wgSpecialPageGroups['RecordAdmin'] = 'wiki'; |
| 23 | +$wgSpecialPages['RecordAdmin'] = 'SpecialRecordAdmin'; |
| 24 | +$wgSpecialPageGroups['RecordAdmin'] = 'wiki'; |
25 | 25 | |
26 | 26 | $wgGroupPermissions['sysop']['recordadmin'] = true; |
27 | 27 | $wgAvailableRights[] = 'recordadmin'; |