http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73275

Revision: 73275
Author:   nad
Date:     2010-09-18 09:00:54 +0000 (Sat, 18 Sep 2010)

Log Message:
-----------
separate the special page out to its own include file and class

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

Modified: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin.i18n.php   2010-09-18 08:48:20 UTC 
(rev 73274)
+++ trunk/extensions/RecordAdmin/RecordAdmin.i18n.php   2010-09-18 09:00:54 UTC 
(rev 73275)
@@ -15,8 +15,9 @@
  */
 $messages['en'] = array(
        'recordadmin' => 'Record administration',
-       'recordadmin-desc' => 'A [[Special:RecordAdmin|special page]] for 
finding and editing record pages using a form',
-       'recordadmin-categoryempty' => 'There are currently no record types. 
Please categorise record templates into [[:$1|$1]].',
+       'recordadmin-desc' => 'Search, queries, forms and reporting of wiki 
data derived from template parameters',
+       'recordadmin-specialdesc' => 'A [[Special:RecordAdmin|special page]] 
for finding and creating pages using associated forms',
+       'recordadmin-noforms' => 'There are currently no forms defined to use 
for searching and creating',
        'recordadmin-select' => 'Select the type of record to manage',
        'recordadmin-createtype' => 'Enter the name of a new record type to 
create',
        'recordadmin-recordtype' => 'record type',
@@ -49,7 +50,7 @@
        'recordadmin-title' => '$1',
        'recordadmin-created' => 'Created',
        'recordadmin-modified' => 'Modified',
-       'recordadmin-actions' => 'Actions',
+       'recordadmin-actions' => 'Edit',
        'recordadmin-select' => 'Select',
        'recordadmin-needscontent' => 'Add content...',
        'recordadmin-editwithform' => 'Properties',

Modified: trunk/extensions/RecordAdmin/RecordAdmin.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin.php        2010-09-18 08:48:20 UTC 
(rev 73274)
+++ trunk/extensions/RecordAdmin/RecordAdmin.php        2010-09-18 09:00:54 UTC 
(rev 73275)
@@ -10,44 +10,37 @@
  * @author Siebrand Mazeland
  * @licence GNU General Public Licence 2.0 or later
  */
+define( 'RECORDADMIN_VERSION', '1.0.0, 2010-09-18' );
 
-define( 'RECORDADMIN_VERSION', '0.12.3, 2010-08-21' );
-
-$wgRecordAdminUseNamespaces = false;     # Whether record articles should be 
in a namespace of the same name as their type
-$wgRecordAdminCategory      = 'Records'; # Category containing record types
-
 $dir = dirname( __FILE__ ) . '/';
 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';
 $wgExtensionAliasesFiles['RecordAdmin']  = $dir . 'RecordAdmin.alias.php';
-$wgAutoloadClasses['SpecialRecordAdmin'] = $dir . 'RecordAdmin_body.php';
-$wgSpecialPages['RecordAdmin']           = 'SpecialRecordAdmin';
-$wgSpecialPageGroups['RecordAdmin']      = 'wiki';
-$wgRecordAdminTableMagic                 = 'recordtable';
-$wgRecordAdminDataMagic                  = 'recorddata';
-$wgRecordAdminTag                        = 'recordid';
-$wgRecordAdminEditWithForm               = true;
-$wgRecordAdminAddTitleInfo               = false;
+$wgAutoloadClasses['RecordAdmin']        = $dir . 'RecordAdmin_body.php';
 
+$wgRecordAdminTableMagic = 'recordtable';
+$wgRecordAdminDataMagic  = 'recorddata';
+$wgRecordAdminTag        = 'recordid';
+
 $wgGroupPermissions['sysop']['recordadmin'] = true;
 $wgAvailableRights[] = 'recordadmin';
 
-$wgExtensionCredits['specialpage'][] = array(
+$wgExtensionCredits['other'][] = array(
        'path'           => __FILE__,
        'name'           => 'Record administration',
-       'author'         => array( '[http://www.organicdesign.co.nz/nad 
User:Nad]', 'Bertrand GRONDIN', 'Siebrand Mazeland' ),
+       'author'         => array( '[http://www.organicdesign.co.nz/nad Aran 
Dunkley]', 'Bertrand GRONDIN', 'Siebrand Mazeland' ),
        'descriptionmsg' => 'recordadmin-desc',
        'url'            => 
'http://www.mediawiki.org/wiki/Extension:RecordAdmin',
        'version'        => RECORDADMIN_VERSION,
 );
 
-$wgExtensionFunctions[] = 'efSetupRecordAdmin';
-function efSetupRecordAdmin() {
-       global $wgSpecialRecordAdmin;
-       $wgSpecialRecordAdmin = new SpecialRecordAdmin();
+$wgExtensionFunctions[] = 'wfSetupRecordAdmin';
+function wfSetupRecordAdmin() {
+       global $wgRecordAdmin;
+       $wgRecordAdmin = new RecordAdmin();
 }
 
-$wgHooks['LanguageGetMagic'][] = 'efRecordAdminLanguageGetMagic';
-function efRecordAdminLanguageGetMagic( &$magicWords, $langCode = 0 ) {
+$wgHooks['LanguageGetMagic'][] = 'wfRecordAdminLanguageGetMagic';
+function wfRecordAdminLanguageGetMagic( &$magicWords, $langCode = 0 ) {
        global $wgRecordAdminTableMagic, $wgRecordAdminDataMagic;
        $magicWords[$wgRecordAdminTableMagic] = array( $langCode, 
$wgRecordAdminTableMagic );
        $magicWords[$wgRecordAdminDataMagic]  = array( $langCode, 
$wgRecordAdminDataMagic );

Modified: trunk/extensions/RecordAdmin/RecordAdmin_body.php
===================================================================
--- trunk/extensions/RecordAdmin/RecordAdmin_body.php   2010-09-18 08:48:20 UTC 
(rev 73274)
+++ trunk/extensions/RecordAdmin/RecordAdmin_body.php   2010-09-18 09:00:54 UTC 
(rev 73275)
@@ -1,25 +1,18 @@
 <?php
-/**
- * Define a new class based on the SpecialPage class
- */
-class SpecialRecordAdmin extends SpecialPage {
+class RecordAdmin {
 
-       var $form      = '';
-       var $formClass = '';
-       var $formAtts  = '';
-       var $type      = '';
-       var $editable  = false;
-       var $record    = '';
-       var $types     = array();
-       var $values    = array();
-       var $orderBy   = '';
-       var $desc      = false;
-       var $guid      = '';
-       var $quid      = '';
-       var $filter    = array();
-       var $request   = array();
-       var $acturl    = '';
-       var $done      = false;
+       var $form        = '';
+       var $formClass   = '';
+       var $formAtts    = '';
+       var $recordTypes = false;
+       var $types       = array();
+       var $values      = array();
+       var $orderBy     = '';
+       var $desc        = false;
+       var $guid        = '';
+       var $quid        = '';
+       var $request     = array();
+       var $done        = false;
 
        function __construct() {
                global $wgHooks, $wgParser, $wgRequest, $wgRecordAdminTag, 
$wgRecordAdminCategory,
@@ -28,7 +21,6 @@
                # Name to use for creating a new record either via RecordAdmin 
or a public form
                $this->guid();
                wfLoadExtensionMessages ( 'RecordAdmin' );
-               parent::__construct( 'RecordAdmin', 'recordadmin', true, false, 
'default', true );
 
                # Make recordID's of articles created with public forms 
available via recordid tag
                $wgParser->setHook( $wgRecordAdminTag, array( $this, 
'expandTag' ) );
@@ -37,300 +29,74 @@
                $wgParser->setFunctionHook( $wgRecordAdminTableMagic, array( 
$this, 'expandTableMagic' ) );
                $wgParser->setFunctionHook( $wgRecordAdminDataMagic,  array( 
$this, 'expandDataMagic'  ) );
 
-               # A minimal hook so we know if the page has been rendered or not
-               # (so that record tables don't execute when run from the 
job-queue - looking for a better way to do this)
+               # Add the hooks to handle cache invalidation and edit-forms
                $wgHooks['BeforePageDisplay'][] = $this;
+               $wgHooks['ArticleSaveComplete'][] = $this;
+               $wgHooks['EditPage::showEditForm:initial'][] = array( $this, 
'onEditPage' );
 
                # If this is not a request for the current page, don't run 
record-admin queries
                $this->done = ( $wgRequest->getText( 'oldid' ) > 0 );
-
-               # Get the current title accounting for redirect
-               $title = Title::newFromText( $wgRequest->getText( 'title' ) );
-               if ( is_object( $title ) && $title->isRedirect() ) {
-                       $article = new Article( $title );
-                       $content = $article->getContent();
-                       if ( preg_match( "|\[\[(.+?)\]\]|", $content, $m ) ) 
$title = Title::newFromText( $m[1] );
-               }
-
-               if ( is_object( $title ) ) {
-
-                       # Check if posting a public creation form
-                       if ( $title->getNamespace() != NS_SPECIAL && 
$wgRequest->getText( 'wpType' ) && $wgRequest->getText( 'wpCreate' ) )
-                               $this->createRecord();
-
-                       # Add some hooks if the current title is a record
-                       $uses = '';
-                       $id   = $title->getArticleID();
-                       $dbr  = &wfGetDB( DB_SLAVE );
-                       $cat  = $dbr->addQuotes( $wgRecordAdminCategory );
-                       $cl   = $dbr->tableName( 'categorylinks' );
-                       $tl   = $dbr->tableName( 'templatelinks' );
-                       $res  = $dbr->select( $cl, 'cl_from', "cl_to = $cat" );
-                       while ( $row = $dbr->fetchRow( $res ) ) $uses .= " OR 
tl_title=" . $dbr->addQuotes( Title::newFromID( $row[0] )->getText() );
-                       $dbr->freeResult( $res );
-                       if ( $uses && $row = $dbr->selectRow( $tl, 'tl_title', 
"tl_from = $id AND (0 $uses)" ) ) {
-                               global $wgRecordAdminEditWithForm, 
$wgRecordAdminAddTitleInfo;
-                               $this->type = $row->tl_title;
-
-                               # Add title info
-                               if ( $wgRecordAdminAddTitleInfo ) 
$wgHooks['OutputPageBeforeHTML'][] = $this;
-
-                               # Add an "edit with form" action link
-                               if ( $wgRecordAdminEditWithForm ) {
-                                       $wgHooks['SkinTemplateTabs'][] = $this;
-                                       $qs = "wpType={$this->type}&wpRecord=" 
. urlencode( $title->getPrefixedText() );
-                                       $this->acturl = 
SpecialPage::getTitleFor( 'RecordAdmin' )->getLocalURL( $qs );
-                               }
-                       }
-               }
        }
 
+
        /**
-        * Store the fact that this hook has executed so we don't run record 
tables from job queue
-        */
+       * Store the fact that this hook has executed so we don't run record 
tables from job queue
+       */
        function onBeforePageDisplay( &$out, $skin = false ) {
                return $this->done = true;
        }
 
+
        /**
-        * Add record type info below title
+        * Add record forms to page edit view
         */
-       function onOutputPageBeforeHTML( &$out, &$text ) {
-               $text = '<div class="recordadmin-typeinfo">' . wfMsg( 
'recordadmin-typeinfo', $this->type ) . "</div>\n" . $text;
+       function onEditPage( $editPage ) {
+               global $wgOut;
+               $type = false;
+               if( $type ) {
+                       $this->preProcessForm( $type );
+                       $this->examineForm();
+                       $this->populateForm( array() );
+                       $editPage->editFormTextTop = "<form 
class=\"{$type}-record recordadmin\">$this->form</form>";
+
+                       # Add the forms from QS:default and RA::templates to 
divs
+                       # - since the forms are being rendered here they should 
include values (from current state then preload)
+                       # - since these are added, they should be removed from 
the text at this point not in JS
+                       
+                       # Add the JS that converts the divs into a single form
+                       $wgOut->addScript( "<script>
+                               var forms = 
document.getElementById('ra-editforms');
+                               var form = document.getElementById('editform');
+                               for( i in forms) {
+                                       form.innerHTML = form.innerHTML + 
'<fieldset>' + i.innerHTML + '</fieldset>';
+                               }
+                       </script>");
+                       
+                       # Allow tabset to execute if exists
+                       
+                       # NOTE: The form now submits all the data in one go so 
no need to rebuild into wikitext
+                       # - but therefore the onsave hook is needed to build 
the wikitext at that point instead
+               }
                return true;
        }
 
+
        /**
-        * Add action link
+        * Incorprate any posted form data into the article wikitext before 
saving
         */
-       function onSkinTemplateTabs( $skin, &$actions ) {
-               $tmp = array();
-               foreach ( $actions as $k => $v ) {
-                       $tmp[$k] = $v;
-                       if ( $k == 'edit' ) $tmp['editwithform'] = array(
-                               'text' => wfMsg( 'recordadmin-editwithform' ),
-                               'class' => false,
-                               'href' => $this->acturl
-                       );
-               }
-               $actions = $tmp;
+       function onArticleSave( &$article, &$user, &$text ) {
                return true;
        }
 
+
        /**
-        * Override SpecialPage::execute()
+        * Handles cache invalidation after a page is saved
         */
-       function execute( $param ) {
-               global $wgVersion, $wgOut, $wgRequest, 
$wgRecordAdminUseNamespaces, $wgLang, $wgRecordAdminCategory, 
$wgSecurityProtectRecords;
-               if ( !isset( $wgSecurityProtectRecords ) ) 
$wgSecurityProtectRecords = false;
-               $this->setHeaders();
-               $type     = $wgRequest->getText( 'wpType' ) or $type = $param;
-               $newtype  = $wgRequest->getText( 'wpNewType' );
-               $invert   = $wgRequest->getText( 'wpInvert' );
-               $record   = $this->record = $wgRequest->getText( 'wpRecord' );
-               $title    = $this->title = SpecialPage::getTitleFor( 
'RecordAdmin' );
-               $action   = $title->getLocalURL( 'action=submit' );
-               $wpTitle  = trim( $wgRequest->getText( 'wpTitle' ) );
-               $this->template = Title::makeTitle( NS_TEMPLATE, $type );
-
-               if ( $type && $wgRecordAdminUseNamespaces ) {
-                       if ( $wpTitle && !preg_match( "|^$type:.+$|", $wpTitle 
) ) $wpTitle = "$type:$wpTitle";
-               }
-               $wgOut->addHTML(
-                       '<div class="recordadmin-menubar"><a href="' . 
$title->getLocalURL() . "/$type\">" . wfMsg( 'recordadmin-newsearch', $type ) . 
'</a>'
-                       . '&#160;'
-                       . '<a href="' . $title->getLocalURL() . '">' . wfMsg( 
'recordadmin-newrecord' ) . '</a></div>'."\n"
-               );
-
-               # Get posted form values if any
-               $posted = array();
-               foreach ( $_REQUEST as $k => $v ) if ( preg_match( 
"|^ra_(\\w+)|", $k, $m ) ) $posted[$m[1]] = is_array( $v ) ? join( "\n", $v ) : 
$v;
-               $this->filter = $posted;
-
-               # Read in and prepare the form for this record type if one has 
been selected
-               if ( $type ) $this->preProcessForm( $type );
-
-               # Extract the input names and types used in the form
-               $this->examineForm();
-
-               # Process Create New Type form if submitted and user permitted
-               if ( $newtype ) {
-                       $this->createRecordType( $newtype );
-                       $type = '';
-               }
-
-               # If no type selected, render form for record types and create 
record-type
-               if ( empty( $type ) ) {
-                       $wgOut->addHTML( Xml::element( 'form', array( 'class' 
=> 'recordadmin', 'action' => $action, 'method' => 'post' ), null ) );
-                       $wgOut->addWikiText( "<div 
class='visualClear'></div>\n==" . wfMsg( 'recordadmin-select' ) . "==\n" );
-
-                       # Get titles in $wgRecordAdminCategory and build option 
list
-                       $options = '';
-                       $dbr  = wfGetDB( DB_SLAVE );
-                       $cl   = $dbr->tableName( 'categorylinks' );
-                       $cat  = $dbr->addQuotes( $wgRecordAdminCategory );
-                       $res  = $dbr->select( $cl, 'cl_from', "cl_to = $cat", 
__METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) );
-                       while ( $row = $dbr->fetchRow( $res ) ) $options .= 
'<option>' . Title::newFromID( $row[0] )->getText() . '</option>';
-
-                       # Render type select list
-                       if ( $options ) $wgOut->addHTML(
-                               "<select name='wpType'>$options</select>&#160;"
-                               . Xml::element( 'input', array( 'type' => 
'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
-                       );
-                       else {
-                               # No records found in $wgRecordAdminCategory
-                               $cat = Title::newFromText( 
$wgRecordAdminCategory, NS_CATEGORY );
-                               $wgOut->AddWikiText( wfMsg( 
'recordadmin-categoryempty', $cat->getPrefixedText() ) );
-                       }
-
-                       # Render type create
-                       $wgOut->addWikiText( "<br />\n==" . wfMsg( 
'recordadmin-createtype' ) . "==\n" );
-                       $wgOut->addHTML( Xml::element( 'input', array( 'name' 
=> 'wpNewType', 'type' => 'text' ) )
-                               . '&#160;'
-                               . Xml::element( 'input', array( 'type' => 
'submit', 'value' => wfMsg( 'recordadmin-buttoncreate' ) ) )
-                               . '</form>'
-                       );
-
-               }
-
-               # Record type known, but no record selected, render form for 
searching or creating
-               elseif ( empty( $record ) ) {
-
-                       # Process Create submission
-                       if ( count( $posted ) && $wgRequest->getText( 
'wpCreate' ) ) {
-                               if ( empty( $wpTitle ) ) {
-                                       $wpTitle = $this->guid;
-                                       if ( $wgRecordAdminUseNamespaces ) 
$wpTitle = "$type:$wpTitle";
-                               }
-                               $t = Title::newFromText( $wpTitle );
-                               if ( is_object( $t ) ) {
-                                       if ( $t->exists() ) $wgOut->addHTML( 
"<div class='errorbox'>" . wfMsg( 'recordadmin-alreadyexist' , $wpTitle ) . 
"</div>\n" );
-                                       else {
-
-                                               # Attempt to create the article
-                                               $article = new Article( $t );
-                                               $summary = 
"[[Special:RecordAdmin/$type|" . wfMsgForContent( 'recordadmin' ) . "]]: " . 
wfMsg( 'recordadmin-summary-typecreated', $type );
-                                               $success = $article->doEdit( 
$this->valuesToText( $type, $posted ), $summary, EDIT_NEW );
-
-                                               # Redirect to view the record 
if successfully updated
-                                               if ( $success ) {
-                                                       $wgOut->disable();
-                                                       wfResetOutputBuffers();
-                                                       header( "Location: " . 
$t->getFullUrl() );
-                                               }
-
-                                               # Or stay in edit view and 
report error
-                                               else $wgOut->addHTML( "<div 
class='errorbox'>" . wfMsg( 'recordadmin-createerror', $type ) . "</div>\n" );
-                                       }
-                               } else $wgOut->addHTML( "<div 
class='errorbox'>" . wfMsg( 'recordadmin-badtitle' ) . "</div>\n" );
-                               $wgOut->addHTML( "<br /><br /><br /><br />\n" );
-                       }
-
-                       # Populate the search form with any posted values
-                       $this->populateForm( $posted );
-
-                       # Process Find submission (select and render records)
-                       if ( count( $posted ) && $wgRequest->getText( 'wpFind' 
) ) {
-                               $wgOut->addWikiText( "== " . wfMsg( 
'recordadmin-searchresult' ) . " ==\n" );
-                               $records = $this->getRecords( $type, $posted, 
'=', $wpTitle, $invert );
-                               $wgOut->addHTML( $this->renderRecords( $records 
) );
-                       }
-
-                       # Render the form
-                       $wgOut->addHTML( "<br /><form 
class=\"{$this->formClass}\"{$this->formAtts} action=\"$action\" 
method=\"POST\">" );
-                       $wgOut->addWikiText( "==" . wfMsg( 
'recordadmin-create', $type ) . "==\n" );
-                       $wgOut->addHTML(
-                               '<table class="recordadmin-create">'
-                               . '<tr><td class="recordadmin-create-id"><b>' . 
wfMsg( 'recordadmin-recordid' ) . '</b>&#160;' . Xml::element( 'input', array( 
'id' => 'ra-title', 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) )
-                               . '&#160;&#160;&#160;' . Xml::element( 'input', 
array( 'name' => 'wpInvert', 'type' => 'checkbox' ) ) . ' ' . wfMsg( 
'recordadmin-invert' )
-                               . '</td></tr>'
-                               . '<tr><td>' . $this->form . '</td></tr>'
-                               . '<tr><td>' . Xml::element( 'input', array( 
'type' => 'hidden', 'id' => 'ra-type', 'name' => 'wpType', 'value' => $type ) ) 
. '</td></tr>'
-                               . '<tr><td>'
-                               . Xml::element( 'input', array( 'type' => 
'submit', 'name' => 'wpFind', 'id' => 'ra-find', 'value' => wfMsg( 
'recordadmin-buttonsearch' ) ) )
-                               . Xml::element( 'input', array( 'type' => 
'submit', 'name' => 'wpCreate', 'id' => 'ra-create', 'value' => wfMsg( 
'recordadmin-buttoncreate' ) ) )
-                               . Xml::element( 'input', array( 'type' => 
'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) )
-                               . '</td></tr>'
-                               . '</table></form>'
-                       );
-               }
-
-               # A specific record has been selected, render form for updating
-               else {
-                       if ( !$wgSecurityProtectRecords || 
$this->template->userCan( 'read' ) ) {
-                               $rtitle = Title::newFromText( $record );
-                               $article = new Article( $rtitle );
-                               $text = $article->fetchContent();
-                               $wgOut->addWikiText( "== " . wfMsg( 
'recordadmin-edit', $rtitle->getPrefixedText(), $type ) . " ==\n" );
-
-                               # Update article if form posted
-                               if ( count( $posted ) && $rtitle->userCan( 
'edit', false ) ) {
-                                       $summary = $wgRequest->getText( 
'wpSummary' ) or $summary = wfMsgForContent( 'recordadmin-typeupdated', $type );
-                                       $minor   = $wgRequest->getText( 
'wpMinoredit' ) ? EDIT_MINOR : 0;
-                                       $watch   = $wgRequest->getText( 
'wpWatchthis' );
-
-                                       # Get the location and length of the 
record braces to replace
-                                       foreach ( self::examineBraces( $text ) 
as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
-
-                                       # Attempt to save the article if allowed
-                                       if ( !$wgSecurityProtectRecords || 
$this->template->userCan( 'edit' ) ) {
-                                               $summary = 
"[[Special:RecordAdmin/$type|" . wfMsgForContent( 'recordadmin' ) . "]]: 
$summary";
-                                               $text = substr_replace( $text, 
$this->valuesToText( $type, $posted, $text ), $braces['OFFSET'], 
$braces['LENGTH'] );
-                                               $success = $article->doEdit( 
$text, $summary, EDIT_UPDATE|$minor );
-                                               if ($watch) $article->doWatch();
-                                       } else $success = false;
-
-                                       # Redirect to view the record if 
successfully updated
-                                       if ( $success ) {
-                                               $wgOut->disable();
-                                               wfResetOutputBuffers();
-                                               header( "Location: " . 
$rtitle->getFullUrl() );
-                                       }
-
-                                       # Stay at edit form and render error if 
not edited successfully
-                                       else $wgOut->addHTML( "<div 
class='errorbox'>" . wfMsg( 'recordadmin-updateerror' ) . "</div>\n" );
-                                       $wgOut->addHTML( "<br /><br /><br /><br 
/>\n" );
-                               }
-
-                               # Extract current values from article
-                               $braces = false;
-                               foreach ( self::examineBraces( $text ) as 
$brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
-                               if ( $braces ) {
-
-                                       # Fill in current values
-                                       $this->populateForm( substr( $text, 
$braces['OFFSET'], $braces['LENGTH'] ) );
-
-                                       # Render the form
-                                       $wgOut->addHTML( "<form 
class=\"{$this->formClass}\"{$this->formAtts} action=\"$action\" 
method=\"POST\">" );
-                                       $wgOut->addHTML( $this->form );
-                                       $wgOut->addHTML( Xml::element( 'input', 
array( 'type' => 'hidden', 'name' => 'wpType', 'id' => 'ra-type', 'value' => 
$type ) ) );
-                                       $wgOut->addHTML( Xml::element( 'input', 
array( 'type' => 'hidden', 'name' => 'wpRecord', 'id' => 'ra-record', 'value' 
=> $record ) ) );
-                                       $wgOut->addHTML( '<br /><hr /><br />'
-                                               . "<span 
id='wpSummaryLabel'><label for='wpSummary'>Summary:</label></span>&#160;"
-                                               . Xml::element( 'input', array( 
'type' => 'text', 'name' => 'wpSummary', 'id' => 'wpSummary', 'maxlength' => 
'200', 'size' => '60' ) )
-                                               . "<br />\n"
-                                               . Xml::element( 'input', array( 
'type' => 'checkbox', 'name' => 'wpMinoredit', 'value' => '1', 'id' => 
'wpMinoredit', 'accesskey' => 'i' ) )
-                                               . "&#160;<label 
for='wpMinoredit' title='Mark this as a minor edit [i]' accesskey='i'>This is a 
minor edit</label>&#160;"
-                                               . Xml::element( 'input', array( 
'type' => 'checkbox', 'name' => 'wpWatchthis', 'value' => '1', 'id' => 
'wpWatchthis', 'accesskey' => 'w' ) )
-                                               . "&#160;<label 
for='wpWatchthis' title='Add this page to your watchlist [w]' 
accesskey='w'>Watch this page</label>\n"
-                                               . "<br />\n"
-                                               . ( ( 
!$wgSecurityProtectRecords || $this->template->userCan( 'edit' ) )
-                                                       ? Xml::element( 
'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-buttonsave' 
) ) ) . '&#160;'
-                                                       : '' )
-                                               . Xml::element( 'input', array( 
'type' => 'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) ) . '</form>'
-                                       );
-                               }
-
-                               # No instance of the template found, just 
display the article content
-                               else $wgOut->addWikiText( $text );
-                       }
-                       
-                       else {
-                               $wgOut->addWikiText( wfMsg( 'badaccess-read', 
$record ) );
-                       }
-               }
+       function onArticleSaveComplete( &$article, &$user, $text ) {
+               return true;
        }
 
+
        /**
         * Return an array of records given type and other criteria
         */
@@ -338,35 +104,35 @@
                global $wgRequest;
 
                # If the page is already rendered, don't run this query
-               if ( $this->done ) return array();
+               if( $this->done ) return array();
 
                # Remember all the args required to reproduce this result (for 
building export URL's)
                $this->request = array_merge( $posted, $_GET, $_POST );
 
                # Loop through all records of this type adding only those that 
match the regex fields
                $records = array();
-               foreach ( self::getRecordsByType( $type ) as $t ) {
-                       if ( empty( $wpTitle ) || preg_match( "|$wpTitle|i", 
$t->getPrefixedText() ) ) {
+               foreach( self::getRecordsByType( $type ) as $t ) {
+                       if( empty( $wpTitle ) || preg_match( "|$wpTitle|i", 
$t->getPrefixedText() ) ) {
                                $a = new Article( $t );
                                $text = $a->getContent();
                                $match = true;
                                $r = array( 0 => $t, 'title' => 
$t->getPrefixedText() );
-                               foreach ( array_keys( $this->types ) as $k ) {
+                               foreach( array_keys( $this->types ) as $k ) {
                                        $v = isset( $posted[$k] ) ? ( 
$this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
                                        $ek = str_replace( '|', '\|', $k );
-                                       if ( !preg_match( "|\s*\|\s*$ek\s*=|", 
$text ) ) $text .= "\n|$k=\n|"; # Treat non-existent fields as existing but 
empty
+                                       if( !preg_match( "|\s*\|\s*$ek\s*=|", 
$text ) ) $text .= "\n|$k=\n|"; # Treat non-existent fields as existing but 
empty
                                        $i = preg_match( "|^\s*\|\s*$ek\s*= 
*(.*?) *(?=^\s*[\|\}])|sm", $text, $m );
                                        $r[$k] = trim( isset( $m[1] ) ? $m[1] : 
'' );
-                                       if ( $v && !( $i && $this->cmpCallback( 
$r[$k], $v, $operator[$k] ) ) ) $match = false;
+                                       if( $v && !( $i && $this->cmpCallback( 
$r[$k], $v, $operator[$k] ) ) ) $match = false;
                                }
-                               if ( $invert ) $match = !$match;
-                               if ( $match ) $records[] = $r;
+                               if( $invert ) $match = !$match;
+                               if( $match ) $records[] = $r;
                        }
                }
 
                # Add the creation and modified date columns to the records
                $dbr  = wfGetDB( DB_SLAVE );
-               foreach ( $records as $i => $r ) {
+               foreach( $records as $i => $r ) {
                        $t = $r[0];
                        $id = $t->getArticleID();
                        $tbl = $dbr->tableName( 'revision' );
@@ -389,22 +155,22 @@
                }
 
                # Sort the records according to "orderby" parameter
-               if ( $this->desc = preg_match( "| +desc *$|", $orderby ) ) 
$orderby = preg_replace( "| +desc *$|", "", $orderby );
+               if( $this->desc = preg_match( "| +desc *$|", $orderby ) ) 
$orderby = preg_replace( "| +desc *$|", "", $orderby );
                $this->orderBy = $orderby;
                usort( $records, array( $this, 'sortCallback' ) );
 
                # Group the records according to the "groupby" parameter
-               if ( $groupby ) {
+               if( $groupby ) {
                        $groupby = self::split( $groupby, ',' );
                        $tmp = array();
-                       foreach ( $records as $r ) {
+                       foreach( $records as $r ) {
                                $v0 = $r[$groupby[0]];
                                unset( $r[$groupby[0]] );
-                               if ( !isset( $tmp[$v0] ) || !is_array( 
$tmp[$v0] ) ) $tmp[$v0] = array();
-                               if ( isset( $groupby[1] ) ) {
+                               if( !isset( $tmp[$v0] ) || !is_array( $tmp[$v0] 
) ) $tmp[$v0] = array();
+                               if( isset( $groupby[1] ) ) {
                                        $v1 = $r[$groupby[1]];
                                        unset( $r[$groupby[1]] );
-                                       if ( !isset( $tmp[$v0][$v1] ) || 
!is_array( $tmp[$v0][$v1] ) ) $tmp[$v0][$v1] = array();
+                                       if( !isset( $tmp[$v0][$v1] ) || 
!is_array( $tmp[$v0][$v1] ) ) $tmp[$v0][$v1] = array();
                                        $tmp[$v0][$v1][] = $r;
                                } else $tmp[$v0][] = $r;
                        }
@@ -415,6 +181,7 @@
                return $records;
        }
 
+
        /**
         * Compares a field value according to its operator
         * - $a is the field value for the current row
@@ -434,7 +201,7 @@
                        default:
                                $a = preg_replace( 
"|(\d\d)[-/](\d\d)[-/](\d\d\d\d)|", "$3/$2/$1", $a ); # hack for dd/mm/yyyy 
format - best to use yyyy-mm-dd
                                $b = preg_replace( 
"|(\d\d)[-/](\d\d)[-/](\d\d\d\d)|", "$3/$2/$1", $b );
-                               if ( !is_numeric( $b ) && preg_match( 
"|[0-9]{4}|", $b ) && $tmp = strtotime( $b ) ) {
+                               if( !is_numeric( $b ) && preg_match( 
"|[0-9]{4}|", $b ) && $tmp = strtotime( $b ) ) {
                                        $b = $tmp;
                                        $a = strtotime( $a );
                                }
@@ -444,32 +211,33 @@
                return $cond;
        }
 
+
        /**
         * Compares two arrays by column
         */
        function sortCallback( $row1, $row2 ) {
-               if ( !isset( $row1[$this->orderBy] ) || !isset( 
$row1[$this->orderBy] ) ) return 0;
-               if ( $row1[$this->orderBy] == $row2[$this->orderBy] ) return 0;
+               if( !isset( $row1[$this->orderBy] ) || !isset( 
$row1[$this->orderBy] ) ) return 0;
+               if( $row1[$this->orderBy] == $row2[$this->orderBy] ) return 0;
                $cmp = $row1[$this->orderBy] > $row2[$this->orderBy] ? 1 : -1;
                return $this->desc ? -$cmp : $cmp;
        }
 
+
        /**
         * Render a set of records returned by getRecords() as an HTML table
         */
        function renderRecords( $records, $cols = false, $sortable = true, 
$template = false, $name = 'wpSelect', $export = true, $groupby = false ) {
                global $wgOut, $wgParser, $wgTitle, $wgRequest;
-               if ( count( $records ) < 1 ) return wfMsg( 
'recordadmin-nomatch' );
-               if ( $groupby ) $groupby = self::split( $groupby, ',' );
+               if( count( $records ) < 1 ) return wfMsg( 'recordadmin-nomatch' 
);
+               if( $groupby ) $groupby = self::split( $groupby, ',' );
 
-               $special  = SpecialPage::getTitleFor( 'RecordAdmin' );
                $type     = $this->type;
                $sortable = $sortable ? ' sortable' : '';
                $br       = $sortable ? '<br />' : '';
                $format   = $wgRequest->getText( 'export' );
 
                # If exporting as pdf, ensure the parser renders full URL's
-               if ( $format == 'pdf' ) {
+               if( $format == 'pdf' ) {
                        global $wgServer, $wgScript, $wgArticlePath, 
$wgScriptPath, $wgUploadPath;
                        $wgArticlePath = $wgServer . $wgArticlePath;
                        $wgScriptPath  = $wgServer . $wgScriptPath;
@@ -486,14 +254,14 @@
                        'created'  => "<th class='col2 col-created'>"  . wfMsg( 
'recordadmin-created' )      . "$br</th>",
                        'modified' => "<th class='col3 col-modified'>" . wfMsg( 
'recordadmin-modified' )     . "$br</th>"
                );
-               foreach ( array_keys( $this->types ) as $col ) {
+               foreach( array_keys( $this->types ) as $col ) {
                        $class = 'col' . preg_replace( "|\W|", "-", $col );
                        $th[$col] = "<th class='$class'>$col$br</th>";
                }
                $tmp = array();
                $cols = $cols ? $cols : array_keys( $th );
-               foreach ( $cols as $col ) {
-                       if ( $groupby == false || !in_array( $col, $groupby ) ) 
{
+               foreach( $cols as $col ) {
+                       if( $groupby == false || !in_array( $col, $groupby ) ) {
                                $html = isset( $th[$col] ) ? $th[$col] : 
"<th>$col</th>";
                                $table .= "$html\n";
                                $tmp[] = $col;
@@ -504,17 +272,17 @@
                $table .= "</tr>\n";
 
                # If using grouping, reconstruct the record tree as a list 
including headings
-               if ( $groupby ) {
+               if( $groupby ) {
                        $td  = "<td colspan=\"$ncol\">";
                        $tmp = array();
                        foreach( $records as $k1 => $v1 ) {
-                               if ( empty( $k1 ) ) {
+                               if( empty( $k1 ) ) {
                                        $k1 = wfMsg( 'recordadmin-notset', 
$groupby[0] );
                                }
                                $tmp[] = "$td<h2>$k1</h2></td>\n";
                                foreach( $v1 as $k2 => $v2 ) {
-                                       if ( isset( $groupby[1] ) ) {
-                                               if ( empty( $k2 ) ) {
+                                       if( isset( $groupby[1] ) ) {
+                                               if( empty( $k2 ) ) {
                                                        $k2 = wfMsg( 
'recordadmin-notset', $groupby[1] );
                                                }
                                                $tmp[] = 
"$td<h3>$k2</h3></td>\n";
@@ -527,9 +295,9 @@
 
                # Table rows
                $stripe = '';
-               foreach ( $records as $r ) {
+               foreach( $records as $r ) {
                        $stripe = $stripe ? '' : ' class="stripe"';
-                       if ( !is_array( $r ) ) {
+                       if( !is_array( $r ) ) {
                                $stripe = '';
                                $table .= "<tr>$r</tr>"; # Just add as HTML 
content if not a row
                        } else {
@@ -545,9 +313,9 @@
                                $sel    = "<input type='checkbox' 
name='{$name}[]' value='$col' checked />";
 
                                # Render this row
-                               if ( $template ) {
+                               if( $template ) {
                                        $text = 
'{'.'{'."$template|select=%SELECT%|title=$col|created=$tsc|modified=$tsm";
-                                       foreach ( array_keys( $this->types ) as 
$col ) {
+                                       foreach( array_keys( $this->types ) as 
$col ) {
                                                $v = isset( $r[$col] ) ? 
$r[$col] : '';
                                                $text .= "|$col=$v";
                                        }
@@ -560,13 +328,13 @@
                                        $row = array(
                                                'select'   => "<td 
class='col-select'>$sel</td>\n",
                                                'title'    => "<td class='col0 
col-title'><a href='$u'>$col</a></td>",
-                                               'actions'  => "<td class='col1 
col-actions'><a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$ecol" 
) . "'>"
+                                               'actions'  => "<td class='col1 
col-actions'><a href='" . $t->getLocalURL( "action=edit" ) . "'>"
                                                                          . 
wfMsg( 'recordadmin-editlink' ) . "</a></td>",
                                                'created'  => "<td class='col2 
col-created'>$tsc</td>\n",
                                                'modified' => "<td class='col3 
col-modified'>$tsm</td>\n",
                                        );
-                                       foreach ( $cols as $col ) {
-                                               if ( !isset( $row[$col] ) ) {
+                                       foreach( $cols as $col ) {
+                                               if( !isset( $row[$col] ) ) {
                                                        $v = isset( $r[$col] ) 
? $wgParser->parse( $r[$col], $wgTitle, $wgParser->mOptions, true, false 
)->getText() : '&#160;';
                                                        $class = 'col' . 
preg_replace( "|\W|", "-", $col );
                                                        $row[$col] = "<td 
class='$class'>$v</td>";
@@ -580,12 +348,12 @@
                $table .= "</table>\n";
 
                # If export requested convert the table to csv and disable 
output etc
-               if ( $format ) {
+               if( $format ) {
                        $wgOut->disable();
                        $filename = $wgTitle->getText();
 
                        # PDF export
-                       if ( $format == 'pdf' ) {
+                       if( $format == 'pdf' ) {
                                global $wgUploadDirectory;
                                $file = "$wgUploadDirectory/" . uniqid( 
'recordadmin' );
                                $table = str_replace( '<table', '<table 
border', $table );
@@ -605,8 +373,8 @@
                                preg_match_all( "|<td.*?>\s*(.*?)\s*</td>|s", 
$table, $data );
                                $cols = $cols ? $cols : array_keys( $th );
                                $csv = join( ',', $cols );
-                               foreach ( $data[1] as $i => $cell ) {
-                                       if ( $i % count( $cols ) == 0 ) {
+                               foreach( $data[1] as $i => $cell ) {
+                                       if( $i % count( $cols ) == 0 ) {
                                                $csv .= "\n";
                                                $sep = '';
                                        } else $sep = ',';
@@ -621,16 +389,16 @@
                }
 
                # Otherwise add export links
-               elseif ( $export ) {
+               elseif( $export ) {
                        $export = $export === true ? array( 'pdf', 'csv' ) : 
self::split( strtolower( $export ), ',' );
                        $qs = "wpType=$type&wpFind=1";
-                       foreach ( $this->request as $k => $v ) $qs .= "&$k=$v";
+                       foreach( $this->request as $k => $v ) $qs .= "&$k=$v";
                        $url = $wgTitle->getLocalURL( $qs );
                        $table .= "\n<a class=\"recordadmin-export-url\" 
href=\"$url\">URL</a>";
-                       if ( in_array( 'csv', $export ) ) {
+                       if( in_array( 'csv', $export ) ) {
                                $table .= "\n<a 
class=\"recordadmin-export-csv\" href=\"$url&export=csv\">" . wfMsg( 
'recordadmin-export-csv' ) . "</a>";
                        }
-                       if ( in_array( 'pdf', $export ) ) {
+                       if( in_array( 'pdf', $export ) ) {
                                $table .= "\n<a 
class=\"recordadmin-export-pdf\" href=\"$url&export=pdf\">" . wfMsg( 
'recordadmin-export-pdf' ) . "</a>";
                        }
                }
@@ -638,6 +406,7 @@
                return $table;
        }
 
+
        /**
         * Take a MediaWiki timestamp and return a formatted date appropriate 
for sortable table
         */
@@ -647,6 +416,7 @@
                return date( 'd M Y, H:i', strtotime( $ts ) );
        }
 
+
        /**
         * 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
@@ -658,16 +428,16 @@
                $this->formClass = strtolower( $type ) . '-record recordadmin';
                $this->formAtts = '';
                $title = Title::newFromText( $type, NS_FORM );
-               if ( is_object( $title ) ) {
-                       if ( $title->exists() ) {
+               if( is_object( $title ) ) {
+                       if( $title->exists() ) {
 
                                # Get the form content
                                $form = new Article( $title );
                                $form = $form->getContent();
                                
                                # Extract form's class and other attributes 
(except method and action)
-                               if ( preg_match( 
"|<form\s*([^>]+)\s*>.+</form>|is", $form, $atts )) {
-                                       if ( preg_match( 
"|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . 
$m[1];
+                               if( preg_match( 
"|<form\s*([^>]+)\s*>.+</form>|is", $form, $atts )) {
+                                       if( preg_match( 
"|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . 
$m[1];
                                        $this->formAtts = ' ' . trim( 
preg_replace( "/(class|action|method)\s*=\s*[\"'](.*?)['\"]/", "", $atts[1] ) );
                                }
                                
@@ -698,7 +468,7 @@
        function populateForm( $values ) {
 
                # If values are wikitext, convert to hash
-               if ( !is_array( $values ) ) $values = $this->values = 
self::valuesFromText( $values );
+               if( !is_array( $values ) ) $values = $this->values = 
self::valuesFromText( $values );
 
                # Add the values into the form's HTML depending on their type
                foreach( $this->types as $k => $type ) {
@@ -714,16 +484,16 @@
                        switch ( $type ) {
                                case 'text':
                                        $html = preg_replace( 
"|value\s*=\s*\".*?\"|i", "", $html );
-                                       if ( $v ) $html = preg_replace( 
"|(/?>)$|", " value=\"$v\" $1", $html );
+                                       if( $v ) $html = preg_replace( 
"|(/?>)$|", " value=\"$v\" $1", $html );
                                break;
                                case 'bool':
                                        $html = preg_replace( "|checked|i", "", 
$html );
-                                       if ( $v ) $html = preg_replace( 
"|(/?>)$|", " checked $1", $html );
+                                       if( $v ) $html = preg_replace( 
"|(/?>)$|", " checked $1", $html );
                                break;
                                case 'list':
                                        $html = preg_replace_callback( 
"|\{\{.+?\}\}|s", array( $this, 'parsePart' ), $html );
                                        $html = preg_replace( "|(<option[^<>]*) 
selected|i", "$1", $html ); # remove the currently selected option
-                                       if ( $v ) {
+                                       if( $v ) {
                                                foreach( self::split( $v ) as 
$v ) {
                                                        $v = htmlentities( 
preg_replace( "|([\[\]\|\\\(\)])|", "\\$1", $v ) );
                                                        $html = preg_match( 
"|<option[^>]+value\s*=|is", $html )
@@ -747,18 +517,18 @@
                $max = 25;
                do {
                        $braces = false;
-                       foreach ( self::examineBraces( $this->form ) as $brace 
) {
-                               if ( $brace['DEPTH'] == 2 ) $braces = $brace;
+                       foreach( self::examineBraces( $this->form ) as $brace ) 
{
+                               if( $brace['DEPTH'] == 2 ) $braces = $brace;
                        }
-                       if ( $braces ) {
+                       if( $braces ) {
                                $part = substr( $this->form, $braces['OFFSET'], 
$braces['LENGTH'] );
                                $html = $wgParser->parse( $part, $wgTitle, 
$options, true, true )->getText();
                                $this->form = substr_replace( $this->form, 
$html, $braces['OFFSET'], $braces['LENGTH'] );
                        }
-               } while ( --$max > 0 && $braces );
-
+               } while( --$max > 0 && $braces );
        }
 
+
        /**
         * Used to parse any braces in select lists when populating form
         */
@@ -769,6 +539,7 @@
                return preg_match( "|(<option.+</option>)|is", $html, $m ) ? 
$m[1] : '';
        }
 
+
        /**
         * Returns an array of types used by the passed HTML text form
         * - supported types, text, select, checkbox, textarea
@@ -776,7 +547,7 @@
        function examineForm() {
                $this->types = array();
                preg_match_all( 
"|<([a-z]+)[^<]+?name=\"ra_(.+?)\\[?\\]?\".*?>|i", $this->form, $m );
-               foreach ( $m[2] as $i => $k ) {
+               foreach( $m[2] as $i => $k ) {
                        $tag = $m[1][$i];
                        $type = preg_match( "|type\s*=\s*\"(.+?)\"|i", 
$m[0][$i], $n ) ? $n[1] : '';
                        switch ( $tag ) {
@@ -800,6 +571,7 @@
                }
        }
 
+
        /**
         * Return array of braces used and the name, position, length and depth
         * See http://www.organicdesign.co.nz/MediaWiki_code_snippets
@@ -809,15 +581,15 @@
                $depths = array();
                $depth = 1;
                $index = 0;
-               while ( preg_match( "/\\{\\{\\s*([#a-z0-9_]*)|\\}\\}/is", 
$content, $match, PREG_OFFSET_CAPTURE, $index ) ) {
+               while( preg_match( "/\\{\\{\\s*([#a-z0-9_]*)|\\}\\}/is", 
$content, $match, PREG_OFFSET_CAPTURE, $index ) ) {
                        $index = $match[0][1] + 2;
-                       if ( $match[0][0] == '}}' ) {
-                               if ( $depth > 0 && array_key_exists( $depth - 
1, $depths ) ) {
+                       if( $match[0][0] == '}}' ) {
+                               if( $depth > 0 && array_key_exists( $depth - 1, 
$depths ) ) {
                                        $brace =& $braces[$depths[$depth - 1]];
                                        $brace['LENGTH'] = $match[0][1] - 
$brace['OFFSET'] + 2;
                                        $brace['DEPTH']  = $depth--;
                                }
-                               if ( $depth < 0 ) $depth = 0;
+                               if( $depth < 0 ) $depth = 0;
                        }
                        else {
                                $depths[$depth++] = count( $braces );
@@ -830,7 +602,23 @@
                return $braces;
        }
 
+
        /**
+        * Get record types (items in the NS_FORM namespace)
+        */
+       function getRecordTypes() {
+               if ( $this->recordTypes === false ) {
+                       $this->recordTypes = array();
+                       $dbr  = wfGetDB( DB_SLAVE );
+                       $tbl  = $dbr->tableName( 'page' );
+                       $res  = $dbr->select( $tbl, 'page_title', 
"page_namespace = " . NS_FORM, __METHOD__ );
+                       while( $row = $dbr->fetchRow( $res ) ) 
$this->recordTypes[] = $row[0];
+                       $dbr->freeResult( $res );
+               }
+               return $this->recordTypes;
+       }
+
+       /**
         * Return a list of title objects of a specified record type
         * - set $count to true to return just the number of results
         */
@@ -839,17 +627,18 @@
                $dbr  = wfGetDB( DB_SLAVE );
                $tbl  = $dbr->tableName( 'templatelinks' );
                $ty   = $dbr->addQuotes( $type );
-               if ( $count ) {
+               if( $count ) {
                        $row = $dbr->selectRow( $tbl, 'count(0) as count', 
"tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
                        $records = $row->count;
                } else {
                        $res  = $dbr->select( $tbl, 'tl_from', "tl_namespace = 
10 AND tl_title = $ty", __METHOD__ );
-                       while ( $row = $dbr->fetchRow( $res ) ) $records[] = 
Title::newFromID( $row[0] );
+                       while( $row = $dbr->fetchRow( $res ) ) $records[] = 
Title::newFromID( $row[0] );
                        $dbr->freeResult( $res );
                }
                return $records;
        }
 
+
        /**
         * Get a field value from a record
         */
@@ -857,22 +646,22 @@
                $result = '';
 
                # Build SQL condition from the supplied args, if any
-        $regexp = '';
-        foreach ( $args as $k => $v ) {
-                       if ( $k == 'type' ) $type = $v;
-                       elseif ( $k == 'record' ) $record = $v;
-                       elseif ( $k == 'field' ) $field = $v;
+               $regexp = '';
+               foreach( $args as $k => $v ) {
+                       if( $k == 'type' ) $type = $v;
+                       elseif( $k == 'record' ) $record = $v;
+                       elseif( $k == 'field' ) $field = $v;
                        else $regexp .= "AND old_text REGEXP('[|] *{$k} *= 
*{$v}[[:space:]]*[|}]')";
-        }
+               }
 
                # If a record and field name are specified, return the field 
value
-               if ( isset( $type ) && isset( $record ) && isset( $field ) ) {
+               if( isset( $type ) && isset( $record ) && isset( $field ) ) {
                        $values = self::getRecordArgs( $record, $type );
                        $result = isset( $values[$field] ) ? $values[$field] : 
'';
                }
 
                # If record is not set, find first record matching the supplied 
field values
-               if ( isset( $type ) && !isset( $record ) ) {
+               if( isset( $type ) && !isset( $record ) ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        $row = $dbr->selectRow(
                                array( 'page', 'revision', 'text', 
'templatelinks' ),
@@ -880,13 +669,14 @@
                                "rev_id=page_latest AND old_id=rev_text_id AND 
tl_from=page_id AND tl_title='$type' $regexp",
                                __METHOD__
                        );
-                       if ( $row ) $result = Title::newFromId( $row->page_id 
)->getPrefixedText();
+                       if( $row ) $result = Title::newFromId( $row->page_id 
)->getPrefixedText();
                }
 
-               if ( $multi ) $result = self::split( $result );
+               if( $multi ) $result = self::split( $result );
                return $result;
        }
 
+
        /**
         * Common function for splitting items by a separator character
         * - default is newline
@@ -896,55 +686,58 @@
                return preg_split( "/\s*$sep\s*/", trim( $text ) );
        }
 
+
        /**
         * Get args from a record article
         * - if type not specified, first template is used
         */
        static function getRecordArgs( &$record, $type = false ) {
                $values = array();
-               if ( is_object( $record ) ) $title =& $record; else $title = 
Title::newFromText( $record );
-               if ( is_object( $title ) ) {
+               if( is_object( $record ) ) $title =& $record; else $title = 
Title::newFromText( $record );
+               if( is_object( $title ) ) {
                        $article = new Article( $title );
                        $text = $article->getContent();
                        $eb = self::examineBraces( $text );
                        $braces = false;
-                       if ( $type ) {
-                               foreach ( $eb as $brace ) if ( $brace['NAME'] 
== $type ) $braces = $brace;
-                       } elseif ( count( $eb ) >= 0 ) $braces = $eb[0];
-                       if ( $braces ) $values = self::valuesFromText( substr( 
$text, $braces['OFFSET'], $braces['LENGTH'] ) );
+                       if( $type ) {
+                               foreach( $eb as $brace ) if( $brace['NAME'] == 
$type ) $braces = $brace;
+                       } elseif( count( $eb ) >= 0 ) $braces = $eb[0];
+                       if( $braces ) $values = self::valuesFromText( substr( 
$text, $braces['OFFSET'], $braces['LENGTH'] ) );
                }
                return $values;
        }
 
+
        /**
         * Return array of args represented by passed template syntax
         */
        static function valuesFromText( $text ) {
                $values = array();
                preg_match_all( "|^\s*\|\s*(.+?)\s*= *(.*?) 
*(?=^\s*[\|\}])|sm", $text, $m );
-               foreach ( $m[1] as $i => $k ) $values[trim( $k )] = trim( 
$m[2][$i] );
+               foreach( $m[1] as $i => $k ) $values[trim( $k )] = trim( 
$m[2][$i] );
                return $values;
        }
 
+
        /**
         * Return template syntax from passed array of values
         * - use $current to pass existing text to preserve any values not 
present in the array
         * - if $current is not set, then only values defined in the form are 
used
         */
        function valuesToText( $type, $values, $current = false ) {
-               
+
                # If there are current values, preserve any that aren't in the 
passed array
-               if ( $current ) {
-                       foreach ( self::valuesFromText( $current ) as $k => $v 
) {
-                               if ( !isset( $values[$k] ) ) $values[$k] = $v;
+               if( $current ) {
+                       foreach( self::valuesFromText( $current ) as $k => $v ) 
{
+                               if( !isset( $values[$k] ) ) $values[$k] = $v;
                        }
                }
-               
+
                # Build the text from the array
                $text = '';
-               foreach ( $values as $k => $v ) if ( $v && ($current || isset( 
$this->types[$k] ) ) ) {
+               foreach( $values as $k => $v ) if( $v && ($current || isset( 
$this->types[$k] ) ) ) {
                        $v = trim( $v );
-                       if ( $this->types[$k] == 'bool' ) $v = 'yes';
+                       if( $this->types[$k] == 'bool' ) $v = 'yes';
                        $text .= " | $k = $v\n";
                }
                $text = $text ? "{{" . "$type\n$text}}" : "{{" . "$type}}";
@@ -952,6 +745,7 @@
                return $text;
        }
 
+
        /**
         * A callback for processing public forms
         */
@@ -965,20 +759,21 @@
                $this->examineForm();
 
                # Use guid if no title specified
-               if ( empty( $title ) ) {
+               if( empty( $title ) ) {
                        $title = $this->guid;
-                       if ( $wgRecordAdminUseNamespaces ) $title = 
"$type:$title";
+                       if( $wgRecordAdminUseNamespaces ) $title = 
"$type:$title";
                }
 
                # Attempt to create the article
                $title = Title::newFromText( $title );
-               if ( is_object( $title ) && !$title->exists() ) {
+               if( is_object( $title ) && !$title->exists() ) {
                        $article = new Article( $title );
                        $summary = wfMsg( 'recordadmin-newcreated' );
                        $success = $article->doEdit( $this->valuesToText( 
$type, $_POST ), $summary, EDIT_NEW );
                }
        }
 
+
        /**
         * Create a new record type
         */
@@ -988,19 +783,19 @@
                $rtype = wfMsg( 'recordadmin-recordtype' ) . " ($newtype)";
                $ttitle = Title::newFromtext( $newtype, NS_TEMPLATE );
                $ftitle = Title::newFromtext( $newtype, NS_FORM );
-               if ( !is_object( $ttitle ) || !is_object( $ftitle ) ) {
+               if( !is_object( $ttitle ) || !is_object( $ftitle ) ) {
                        $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 
'recordadmin-createerror', $rtype ) . "</div>\n" );
                }
                $tttext = $ttitle->getPrefixedText();
                $fttext = $ftitle->getPrefixedText();
 
                # check if the template already exists
-               if ( $ttitle->exists() ) {
+               if( $ttitle->exists() ) {
                        $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 
'recordadmin-alreadyexist', $tttext ) . "</div>\n" );
                }
 
                # check if the form already exists
-               elseif ( $ftitle->exists() ) {
+               elseif( $ftitle->exists() ) {
                        $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 
'recordadmin-alreadyexist', $fttext ) . "</div>\n" );
                }
 
@@ -1016,21 +811,22 @@
                        $success = $article->doEdit( $text, $summary, EDIT_NEW 
);
 
                        # If Template created successfully, try and create the 
form
-                       if ( $success ) {
+                       if( $success ) {
                                $cat = Title::newFromText( 
$wgRecordAdminCategory, NS_CATEGORY )->getPrefixedText();
                                $url = $ftitle->getLocalUrl( 'action=edit' );
                                $link = "<a href=\"$url\">" . wfMsg( 
'recordadmin-needscontent' ) . "</a>";
                                $text = 
"<html>\n\t<form>\n\t\t<table>\n\t\t$link\n\t\t</table>\n\t</form>\n</html>";
                                $article = new Article( $ftitle );
                                $success = $article->doEdit( $text, $summary, 
EDIT_NEW );
-                               if ( !$success ) $wgOut->addHTML( "<div 
class='errorbox'>" . wfMsg( 'recordadmin-createerror', $fttext ) . "</div>\n" );
+                               if( !$success ) $wgOut->addHTML( "<div 
class='errorbox'>" . wfMsg( 'recordadmin-createerror', $fttext ) . "</div>\n" );
                        } else $wgOut->addHTML( "<div class='errorbox'>" . 
wfMsg( 'recordadmin-createerror', $tttext ) . "</div>\n" );
 
                        # Report success
-                       if ( $success ) $wgOut->addHTML( "<div 
class='successbox'>" . wfMsg( 'recordadmin-createsuccess', $rtype ) . 
"</div>\n" );
+                       if( $success ) $wgOut->addHTML( "<div 
class='successbox'>" . wfMsg( 'recordadmin-createsuccess', $rtype ) . 
"</div>\n" );
                }
        }
 
+
        /**
         * Render a record search in a parser-function
         */
@@ -1050,46 +846,44 @@
                $template = false;
                $count    = false;
                $export   = false;
-               foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
-                       if ( preg_match( "|^(.+?)\s*([=!<>]+)\s*(.+)$|i", $arg, 
$match ) ) {
+               foreach( func_get_args() as $arg ) if( !is_object( $arg ) ) {
+                       if( preg_match( "|^(.+?)\s*([=!<>]+)\s*(.+)$|i", $arg, 
$match ) ) {
                                list( , $k, $o, $v ) = $match;
-                               if ( $k == 'title' ) $title = $v;
-                               elseif ( $k == 'name' )     $name     = $v;
-                               elseif ( $k == 'invert' )   $invert   = $v;
-                               elseif ( $k == 'orderby' )  $orderby  = $v;
-                               elseif ( $k == 'groupby' )  $groupby  = $v;
-                               elseif ( $k == 'format' )   $format   = $v;
-                               elseif ( $k == 'cols' )     $cols     = 
self::split( $v, ',' );
-                               elseif ( $k == 'sortable' ) $sortable = 
preg_match( '/(1|yes|true|on)/i', $v );
-                               elseif ( $k == 'template' ) $template = $v;
-                               elseif ( $k == 'count' )    $count    = $v;
-                               elseif ( $k == 'export' )   $export   = $v;
+                               if( $k == 'title' ) $title = $v;
+                               elseif( $k == 'name' )     $name     = $v;
+                               elseif( $k == 'invert' )   $invert   = $v;
+                               elseif( $k == 'orderby' )  $orderby  = $v;
+                               elseif( $k == 'groupby' )  $groupby  = $v;
+                               elseif( $k == 'format' )   $format   = $v;
+                               elseif( $k == 'cols' )     $cols     = 
self::split( $v, ',' );
+                               elseif( $k == 'sortable' ) $sortable = 
preg_match( "/(1|yes|true|on)/i", $v );
+                               elseif( $k == 'template' ) $template = $v;
+                               elseif( $k == 'count' )    $count    = $v;
+                               elseif( $k == 'export' )   $export   = $v;
                                else {
                                        $filter[$k] = $v;
                                        $op[$k] = $o;
                                }
                        }
                }
-               $this->filter = $filter;
-               $tmp = $this->type;
                $this->preProcessForm( $type );
                $this->examineForm();
                $records = $this->getRecords( $type, $filter, $op, $title, 
$invert, $orderby, $groupby, $format );
-               if ( $count ) while ( count( $records ) > $count ) array_pop( 
$records );
+               if( $count ) while( count( $records ) > $count ) array_pop( 
$records );
                $table = $this->renderRecords( $records, $cols, $sortable, 
$template, $name, $export, $groupby, $format );
-               $this->type = $tmp;
 
                return array( $table, 'noparse' => true, 'isHTML' => true );
        }
 
+
        /**
         * Obtain a record or record field value from passed parameters
         */
        function expandDataMagic( &$parser ) {
                $parser->mOutput->mCacheTime = -1;
                $args = array();
-               foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
-                       if ( preg_match( "|^(.+?)\s*=\s*(.+)$|", $arg, $match ) 
) {
+               foreach( func_get_args() as $arg ) if( !is_object( $arg ) ) {
+                       if( preg_match( "|^(.+?)\s*=\s*(.+)$|", $arg, $match ) 
) {
                                list( , $k, $v ) = $match;
                                $args[$k] = $v;
                        }
@@ -1097,6 +891,7 @@
                return self::getFieldValue( $args );
        }
 
+
        /**
         * If a record was created by a public form, make last 5 digits of ID 
available via a tag
         */
@@ -1105,11 +900,11 @@
                return $this->guid ? substr( $this->guid, -5 ) : '';
        }
 
+
        /**
         * Generate a guid - check $wgRecordAdminGuidFormat array for 
specialised formats
         */
        function guid() {
                return $this->guid = strftime( '%Y%m%d', time() ) . '-' . 
substr( strtoupper( uniqid('', true) ), -5 );
        }
-
 }



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

Reply via email to