Revision: 46001
Author:   nad
Date:     2009-01-22 05:05:49 +0000 (Thu, 22 Jan 2009)

Log Message:
-----------
move record searching into a method ready for parser-function to use later

Modified Paths:
--------------
    trunk/extensions/RecordAdmin/RecordAdmin.php
    trunk/extensions/RecordAdmin/RecordAdmin_body.php

Modified: trunk/extensions/RecordAdmin/RecordAdmin.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin.php        2009-01-22 03:25:31 UTC 
(rev 46000)
+++ trunk/extensions/RecordAdmin/RecordAdmin.php        2009-01-22 05:05:49 UTC 
(rev 46001)
@@ -11,7 +11,7 @@
  * @licence GNU General Public Licence 2.0 or later
  */
 
-define( 'RECORDADMIN_VERSION', '0.4.1, 2008-11-04' );
+define( 'RECORDADMIN_VERSION', '0.5.0, 2009-01-22' );
 
 $wgRecordAdminUseNamespaces = false;     # Whether record articles should be 
in a namespace of the same name as their type
 
@@ -19,8 +19,8 @@
 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';
 $wgExtensionAliasesFiles['RecordAdmin']  = $dir . 'RecordAdmin.alias.php';
 $wgAutoloadClasses['SpecialRecordAdmin'] = $dir . 'RecordAdmin_body.php';
-$wgSpecialPages['RecordAdmin'] = 'SpecialRecordAdmin';
-$wgSpecialPageGroups['RecordAdmin'] = 'wiki';
+$wgSpecialPages['RecordAdmin']           = 'SpecialRecordAdmin';
+$wgSpecialPageGroups['RecordAdmin']      = 'wiki';
 
 $wgGroupPermissions['sysop']['recordadmin'] = true;
 $wgAvailableRights[] = 'recordadmin';

Modified: trunk/extensions/RecordAdmin/RecordAdmin_body.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin_body.php   2009-01-22 03:25:31 UTC 
(rev 46000)
+++ trunk/extensions/RecordAdmin/RecordAdmin_body.php   2009-01-22 05:05:49 UTC 
(rev 46001)
@@ -128,29 +128,7 @@
                                $wgOut->addWikiText( "<br>\n== " . wfMsg( 
'recordadmin-searchresult' ) . " ==\n" );
 
                                # Select records which use the template and 
exhibit a matching title and other fields
-                               $records = array();
-                               $dbr  = &wfGetDB( DB_SLAVE );
-                               $tbl  = $dbr->tableName( 'templatelinks' );
-                               $ty   = $dbr->addQuotes( $type );
-                               $res  = $dbr->select( $tbl, 'tl_from', 
"tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
-                               while ( $row = $dbr->fetchRow( $res ) ) {
-                                       $t = Title::newFromID( $row[0] );
-                                       if ( empty( $wpTitle ) || eregi( 
$wpTitle, $t->getPrefixedText() ) ) {
-                                               $a = new Article( $t );
-                                               $text = $a->getContent();
-                                               $match = true;
-                                               $r = array( $t );
-                                               foreach ( array_keys( 
$this->types ) as $k ) {
-                                                       $v = isset( $posted[$k] 
) ? ( $this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
-                                                       $i = preg_match( 
"|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
-                                                       if ( $v && !( $i && 
eregi( $v, $m[1] ) ) ) $match = false;
-                                                       $r[$k] = isset( $m[1] ) 
? $m[1] : '';
-                                               }
-                                               if ( $invert ) $match = !$match;
-                                               if ( $match ) 
$records[$t->getPrefixedText()] = $r;
-                                       }
-                               }
-                               $dbr->freeResult( $res );
+                               $records = $this->getRecords($type, $posted, 
$wpTitle, $invert);
 
                                # Render search results
                                if ( count( $records ) ) {
@@ -246,6 +224,35 @@
        }
 
        /**
+        * Return an array of records given type and other criteria
+        */
+       function getRecords($type, $posted, $wpTitle = '', $invert = false) {
+               $records = array();
+               $dbr  = &wfGetDB( DB_SLAVE );
+               $tbl  = $dbr->tableName( 'templatelinks' );
+               $ty   = $dbr->addQuotes( $type );
+               $res  = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND 
tl_title = $ty", __METHOD__ );
+               while ( $row = $dbr->fetchRow( $res ) ) {
+                       $t = Title::newFromID( $row[0] );
+                       if ( empty( $wpTitle ) || eregi( $wpTitle, 
$t->getPrefixedText() ) ) {
+                               $a = new Article( $t );
+                               $text = $a->getContent();
+                               $match = true;
+                               $r = array( $t );
+                               foreach ( array_keys( $this->types ) as $k ) {
+                                       $v = isset( $posted[$k] ) ? ( 
$this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
+                                       $i = preg_match( 
"|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
+                                       if ( $v && !( $i && eregi( $v, $m[1] ) 
) ) $match = false;
+                                       $r[$k] = isset( $m[1] ) ? $m[1] : '';
+                               }
+                               if ( $invert ) $match = !$match;
+                               if ( $match ) $records[$t->getPrefixedText()] = 
$r;
+                       }
+               }
+               $dbr->freeResult( $res );
+       }
+
+       /**
         * Read in and prepare the form (for use as a search filter) for passed 
record type
         * - we're using the record's own form as a filter for searching for 
records
         * - extract only the content from between the form tags and remove any 
submit inputs



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to