r47312 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47311‎ | r47312 | r47313 >
Date:10:15, 16 February 2009
Author:catrope
Status:reverted
Tags:
Comment:
RecordAdmin: Revert r47304 ("rv last commit that broke it"): changed tabs to spaces throughout the file and did not mention what was being reverted or how what broke
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -4,505 +4,506 @@
55 */
66 class SpecialRecordAdmin extends SpecialPage {
77
8 - var $form = '';
9 - var $type = '';
10 - var $types = array();
11 - var $orderby = '';
12 - var $desc = false;
13 - var $guid = '';
 8+ var $form = '';
 9+ var $type = '';
 10+ var $types = array();
 11+ var $orderby = '';
 12+ var $desc = false;
 13+ var $guid = '';
1414
15 - function __construct() {
16 - # Name to use for creating a new record either via RecordAdmin or a public form
17 - # todo: should add a hook here for custom default-naming
18 - $this->guid = strftime( '%Y%m%d', time() ) . '-' . substr( strtoupper( uniqid() ), -5 );
19 - wfLoadExtensionMessages ( 'RecordAdmin' );
20 - SpecialPage::SpecialPage( 'RecordAdmin', 'recordadmin' );
21 - }
 15+ function __construct() {
 16+ # Name to use for creating a new record either via RecordAdmin or a public form
 17+ # todo: should add a hook here for custom default-naming
 18+ $this->guid = strftime( '%Y%m%d', time() ) . '-' . substr( strtoupper( uniqid() ), -5 );
 19+ wfLoadExtensionMessages ( 'RecordAdmin' );
 20+ SpecialPage::SpecialPage( 'RecordAdmin', 'recordadmin' );
 21+ }
2222
23 - /**
24 - * Override SpecialPage::execute()
25 - */
26 - function execute( $param ) {
27 - global $wgOut, $wgRequest, $wgRecordAdminUseNamespaces;
28 - $this->setHeaders();
29 - $type = $wgRequest->getText( 'wpType' ) or $type = $param;
30 - $record = $wgRequest->getText( 'wpRecord' );
31 - $invert = $wgRequest->getText( 'wpInvert' );
32 - $title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
33 - $wpTitle = trim( $wgRequest->getText( 'wpTitle' ) );
 23+ /**
 24+ * Override SpecialPage::execute()
 25+ */
 26+ function execute( $param ) {
 27+ global $wgOut, $wgRequest, $wgRecordAdminUseNamespaces, $wgLang;
 28+ $this->setHeaders();
 29+ $type = $wgRequest->getText( 'wpType' ) or $type = $param;
 30+ $record = $wgRequest->getText( 'wpRecord' );
 31+ $invert = $wgRequest->getText( 'wpInvert' );
 32+ $title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
 33+ $wpTitle = trim( $wgRequest->getText( 'wpTitle' ) );
3434
35 - if ( $type && $wgRecordAdminUseNamespaces ) {
36 - if ( $wpTitle && !ereg( "^$type:.+$", $wpTitle ) ) $wpTitle = "$type:$wpTitle";
37 - }
 35+ if ( $type && $wgRecordAdminUseNamespaces ) {
 36+ if ( $wpTitle && !ereg( "^$type:.+$", $wpTitle ) ) $wpTitle = "$type:$wpTitle";
 37+ }
3838
39 - $wgOut->addHTML( "<div class='center'><a href='" . $title->getLocalURL() . "/$type'>" . wfMsg( 'recordadmin-newsearch', $type ) . "</a> | "
40 - . "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a></div><br>\n"
41 - );
 39+ $wgOut->addHTML( $wgLang->pipeList( array(
 40+ "<div class='center'><a href='" . $title->getLocalURL() . "/$type'>" . wfMsg( 'recordadmin-newsearch', $type ) . "</a>",
 41+ "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a></div><br>\n"
 42+ ) ) );
4243
43 - # Get posted form values if any
44 - $posted = array();
45 - foreach ( $_POST as $k => $v ) if ( ereg( '^ra_(.+)$', $k, $m ) ) $posted[$m[1]] = $v;
 44+ # Get posted form values if any
 45+ $posted = array();
 46+ foreach ( $_POST as $k => $v ) if ( ereg( '^ra_(.+)$', $k, $m ) ) $posted[$m[1]] = $v;
4647
47 - # Read in and prepare the form for this record type if one has been selected
48 - if ( $type ) $this->preProcessForm( $type );
 48+ # Read in and prepare the form for this record type if one has been selected
 49+ if ( $type ) $this->preProcessForm( $type );
4950
50 - # Extract the input names and types used in the form
51 - $this->examineForm();
 51+ # Extract the input names and types used in the form
 52+ $this->examineForm();
5253
53 - # Clear any default values
54 - $this->populateForm( array() );
 54+ # Clear any default values
 55+ $this->populateForm( array() );
5556
56 - # If no type selected, render select list of record types from Category:Records
57 - if ( empty( $type ) ) {
58 - $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-select' ) . "==\n" );
 57+ # If no type selected, render select list of record types from Category:Records
 58+ if ( empty( $type ) ) {
 59+ $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-select' ) . "==\n" );
5960
60 - # Get titles in 'recordadmin-category' (default: Category:Records) and build option list
61 - $options = '';
62 - $dbr = wfGetDB( DB_SLAVE );
63 - $cl = $dbr->tableName( 'categorylinks' );
64 - $cat = $dbr->addQuotes( wfMsgForContent( 'recordadmin-category' ) );
65 - $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) );
66 - while ( $row = $dbr->fetchRow( $res ) ) $options .= '<option>' . Title::newFromID( $row[0] )->getText() . '</option>';
 61+ # Get titles in 'recordadmin-category' (default: Category:Records) and build option list
 62+ $options = '';
 63+ $dbr = wfGetDB( DB_SLAVE );
 64+ $cl = $dbr->tableName( 'categorylinks' );
 65+ $cat = $dbr->addQuotes( wfMsgForContent( 'recordadmin-category' ) );
 66+ $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) );
 67+ while ( $row = $dbr->fetchRow( $res ) ) $options .= '<option>' . Title::newFromID( $row[0] )->getText() . '</option>';
6768
68 - # Render type-selecting form
69 - $wgOut->addHTML( Xml::element( 'form', array( 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
70 - . "<select name='wpType'>$options</select> "
71 - . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
72 - . '</form>'
73 - );
74 - }
 69+ # Render type-selecting form
 70+ $wgOut->addHTML( Xml::element( 'form', array( 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
 71+ . "<select name='wpType'>$options</select> "
 72+ . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
 73+ . '</form>'
 74+ );
 75+ }
7576
76 - # Record type known, but no record selected, render form for searching or creating
77 - elseif ( empty( $record ) ) {
78 - $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-create', $type ) . "==\n" );
 77+ # Record type known, but no record selected, render form for searching or creating
 78+ elseif ( empty( $record ) ) {
 79+ $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-create', $type ) . "==\n" );
7980
80 - # Process Create submission
81 - if ( count( $posted ) && $wgRequest->getText( 'wpCreate' ) ) {
82 - if ( empty( $wpTitle ) ) {
83 - $wpTitle = $this->guid;
84 - if ( $wgRecordAdminUseNamespaces ) $wpTitle = "$type:$wpTitle";
85 - }
86 - $t = Title::newFromText( $wpTitle );
87 - if ( is_object( $t ) ) {
88 - if ( $t->exists() ) $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-alreadyexist' , $wpTitle ) . "</div>\n" );
89 - else {
 81+ # Process Create submission
 82+ if ( count( $posted ) && $wgRequest->getText( 'wpCreate' ) ) {
 83+ if ( empty( $wpTitle ) ) {
 84+ $wpTitle = $this->guid;
 85+ if ( $wgRecordAdminUseNamespaces ) $wpTitle = "$type:$wpTitle";
 86+ }
 87+ $t = Title::newFromText( $wpTitle );
 88+ if ( is_object( $t ) ) {
 89+ if ( $t->exists() ) $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-alreadyexist' , $wpTitle ) . "</div>\n" );
 90+ else {
9091
91 - # Attempt to create the article
92 - $article = new Article( $t );
93 - $summary = "[[Special:RecordAdmin/$type|RecordAdmin]]:" . wfMsg( 'recordadmin-summary-typecreated' );
94 - $text = '';
95 - foreach ( $posted as $k => $v ) if ( $v ) {
96 - if ( $this->types[$k] == 'bool' ) $v = 'yes';
97 - $text .= "| $k = $v\n";
98 - }
99 - $text = $text ? "{{" . "$type\n$text}}" : "{{" . "$type}}";
100 - $success = $article->doEdit( $text, $summary, EDIT_NEW );
 92+ # Attempt to create the article
 93+ $article = new Article( $t );
 94+ $summary = "[[Special:RecordAdmin/$type|RecordAdmin]]:" . wfMsg( 'recordadmin-summary-typecreated' );
 95+ $text = '';
 96+ foreach ( $posted as $k => $v ) if ( $v ) {
 97+ if ( $this->types[$k] == 'bool' ) $v = 'yes';
 98+ $text .= "| $k = $v\n";
 99+ }
 100+ $text = $text ? "{{" . "$type\n$text}}" : "{{" . "$type}}";
 101+ $success = $article->doEdit( $text, $summary, EDIT_NEW );
101102
102 - # Report success or error
103 - if ( $success ) $wgOut->addHTML( "<div class='successbox'>" . wfMsg( 'recordadmin-createsuccess', $wpTitle ) . "</div>\n" );
104 - else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $type ) . "</div>\n" );
105 - }
106 - } else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-badtitle' ) . "</div>\n" );
107 - $wgOut->addHTML( "<br><br><br><br>\n" );
108 - }
 103+ # Report success or error
 104+ if ( $success ) $wgOut->addHTML( "<div class='successbox'>" . wfMsg( 'recordadmin-createsuccess', $wpTitle ) . "</div>\n" );
 105+ else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $type ) . "</div>\n" );
 106+ }
 107+ } else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-badtitle' ) . "</div>\n" );
 108+ $wgOut->addHTML( "<br><br><br><br>\n" );
 109+ }
109110
110 - # Populate the search form with any posted values
111 - $this->populateForm( $posted );
 111+ # Populate the search form with any posted values
 112+ $this->populateForm( $posted );
112113
113 - # Render the form
114 - $wgOut->addHTML(
115 - Xml::element( 'form', array( 'class' => strtolower($type).'-record', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
116 - . '<b>' . wfMsg( 'recordadmin-recordid' ) . '</b> ' . Xml::element( 'input', array( 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) )
117 - . '&nbsp;&nbsp;&nbsp;' . Xml::element( 'input', array( 'name' => 'wpInvert', 'type' => 'checkbox' ) ) . ' ' . wfMsg( 'recordadmin-invert' )
118 - . "\n<br><br><hr><br>\n{$this->form}"
119 - . Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) )
120 - . '<br><hr><br><table width="100%"><tr>'
121 - . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpFind', 'value' => wfMsg( 'recordadmin-buttonsearch' ) ) ) . '</td>'
122 - . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpCreate', 'value' => wfMsg( 'recordadmin-buttoncreate' ) ) ) . '</td>'
123 - . '<td width="100%" align="left">' . Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) ) . '</td>'
124 - . '</tr></table></form>'
125 - );
 114+ # Render the form
 115+ $wgOut->addHTML(
 116+ Xml::element( 'form', array( 'class' => strtolower($type).'-record', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
 117+ . '<b>' . wfMsg( 'recordadmin-recordid' ) . '</b> ' . Xml::element( 'input', array( 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) )
 118+ . '&nbsp;&nbsp;&nbsp;' . Xml::element( 'input', array( 'name' => 'wpInvert', 'type' => 'checkbox' ) ) . ' ' . wfMsg( 'recordadmin-invert' )
 119+ . "\n<br><br><hr><br>\n{$this->form}"
 120+ . Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) )
 121+ . '<br><hr><br><table width="100%"><tr>'
 122+ . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpFind', 'value' => wfMsg( 'recordadmin-buttonsearch' ) ) ) . '</td>'
 123+ . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'name' => 'wpCreate', 'value' => wfMsg( 'recordadmin-buttoncreate' ) ) ) . '</td>'
 124+ . '<td width="100%" align="left">' . Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) ) . '</td>'
 125+ . '</tr></table></form>'
 126+ );
126127
127 - # Process Find submission
128 - if ( count( $posted ) && $wgRequest->getText( 'wpFind' ) ) {
129 - $wgOut->addWikiText( "<br>\n== " . wfMsg( 'recordadmin-searchresult' ) . " ==\n" );
 128+ # Process Find submission
 129+ if ( count( $posted ) && $wgRequest->getText( 'wpFind' ) ) {
 130+ $wgOut->addWikiText( "<br>\n== " . wfMsg( 'recordadmin-searchresult' ) . " ==\n" );
130131
131 - # Select records which use the template and exhibit a matching title and other fields
132 - $records = $this->getRecords( $type, $posted, $wpTitle, $invert );
 132+ # Select records which use the template and exhibit a matching title and other fields
 133+ $records = $this->getRecords( $type, $posted, $wpTitle, $invert );
133134
134 - # Render resulting records
135 - $wgOut->addHTML( $this->renderRecords($records) );
 135+ # Render resulting records
 136+ $wgOut->addHTML( $this->renderRecords($records) );
136137
137 - }
138 - }
 138+ }
 139+ }
139140
140 - # A specific record has been selected, render form for updating
141 - else {
142 - $wgOut->addWikiText( "== " . wfMsg( 'recordadmin-edit', $record ) . " ==\n" );
143 - $article = new Article( Title::newFromText( $record ) );
144 - $text = $article->fetchContent();
 141+ # A specific record has been selected, render form for updating
 142+ else {
 143+ $wgOut->addWikiText( "== " . wfMsg( 'recordadmin-edit', $record ) . " ==\n" );
 144+ $article = new Article( Title::newFromText( $record ) );
 145+ $text = $article->fetchContent();
145146
146 - # Update article if form posted
147 - if ( count( $posted ) ) {
 147+ # Update article if form posted
 148+ if ( count( $posted ) ) {
148149
149 - # Get the location and length of the record braces to replace
150 - foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
 150+ # Get the location and length of the record braces to replace
 151+ foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
151152
152 - # Attempt to save the article
153 - $summary = "[[Special:RecordAdmin/$type|" . wfMsgForContent( 'recordadmin' ) . "]]: " . wfMsgForContent( 'recordadmin-typeupdated', $type );
154 - $replace = '';
155 - foreach ( $posted as $k => $v ) if ( $v ) {
156 - if ( $this->types[$k] == 'bool' ) $v = 'yes';
157 - $replace .= "| $k = $v\n";
158 - }
159 - $replace = $replace ? "{{" . "$type\n$replace}}" : "{{" . "$type}}";
160 - $text = substr_replace( $text, $replace, $braces['OFFSET'], $braces['LENGTH'] );
161 - $success = $article->doEdit( $text, $summary, EDIT_UPDATE );
 153+ # Attempt to save the article
 154+ $summary = "[[Special:RecordAdmin/$type|" . wfMsgForContent( 'recordadmin' ) . "]]: " . wfMsgForContent( 'recordadmin-typeupdated', $type );
 155+ $replace = '';
 156+ foreach ( $posted as $k => $v ) if ( $v ) {
 157+ if ( $this->types[$k] == 'bool' ) $v = 'yes';
 158+ $replace .= "| $k = $v\n";
 159+ }
 160+ $replace = $replace ? "{{" . "$type\n$replace}}" : "{{" . "$type}}";
 161+ $text = substr_replace( $text, $replace, $braces['OFFSET'], $braces['LENGTH'] );
 162+ $success = $article->doEdit( $text, $summary, EDIT_UPDATE );
162163
163 - # Report success or error
164 - if ( $success ) $wgOut->addHTML( "<div class='successbox'>" . wfMsg( 'recordadmin-updatesuccess', $type ) . "</div>\n" );
165 - else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-updateerror' ) . "</div>\n" );
166 - $wgOut->addHTML( "<br><br><br><br>\n" );
167 - }
 164+ # Report success or error
 165+ if ( $success ) $wgOut->addHTML( "<div class='successbox'>" . wfMsg( 'recordadmin-updatesuccess', $type ) . "</div>\n" );
 166+ else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-updateerror' ) . "</div>\n" );
 167+ $wgOut->addHTML( "<br><br><br><br>\n" );
 168+ }
168169
169 - # Populate the form with the current values in the article
170 - foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
171 - $this->populateForm( substr( $text, $braces['OFFSET'], $braces['LENGTH'] ) );
 170+ # Populate the form with the current values in the article
 171+ foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
 172+ $this->populateForm( substr( $text, $braces['OFFSET'], $braces['LENGTH'] ) );
172173
173 - # Render the form
174 - $wgOut->addHTML( Xml::element( 'form', array( 'class' => 'recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null ) );
175 - $wgOut->addHTML( $this->form );
176 - $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) ) );
177 - $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpRecord', 'value' => $record ) ) );
178 - $wgOut->addHTML( '<br><hr><br><table width="100%"><tr>'
179 - . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-buttonsave' ) ) ) . '</td>'
180 - . '<td width="100%" align="left">' . Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) ) . '</td>'
181 - . '</tr></table></form>'
182 - );
183 - }
184 - }
 174+ # Render the form
 175+ $wgOut->addHTML( Xml::element( 'form', array( 'class' => 'recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null ) );
 176+ $wgOut->addHTML( $this->form );
 177+ $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) ) );
 178+ $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpRecord', 'value' => $record ) ) );
 179+ $wgOut->addHTML( '<br><hr><br><table width="100%"><tr>'
 180+ . '<td>' . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-buttonsave' ) ) ) . '</td>'
 181+ . '<td width="100%" align="left">' . Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'recordadmin-buttonreset' ) ) ) . '</td>'
 182+ . '</tr></table></form>'
 183+ );
 184+ }
 185+ }
185186
186 - /**
187 - * Return an array of records given type and other criteria
188 - */
189 - function getRecords($type, $posted, $wpTitle = '', $invert = false, $orderby = 'created desc') {
190 - $records = array();
191 - $dbr = wfGetDB( DB_SLAVE );
192 - $tbl = $dbr->tableName( 'templatelinks' );
193 - $ty = $dbr->addQuotes( $type );
194 - $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
195 - while ( $row = $dbr->fetchRow( $res ) ) {
196 - $t = Title::newFromID( $row[0] );
197 - if ( empty( $wpTitle ) || eregi( $wpTitle, $t->getPrefixedText() ) ) {
198 - $a = new Article( $t );
199 - $text = $a->getContent();
200 - $match = true;
201 - $r = array( 0 => $t, 'title' => $t->getPrefixedText() );
202 - foreach ( array_keys( $this->types ) as $k ) {
203 - $v = isset( $posted[$k] ) ? ( $this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
204 - $i = preg_match( "|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
205 - if ( $v && !( $i && eregi( $v, $m[1] ) ) ) $match = false;
206 - $r[$k] = isset( $m[1] ) ? $m[1] : '';
207 - }
208 - if ( $invert ) $match = !$match;
209 - if ( $match ) $records[] = $r;
210 - }
211 - }
212 - $dbr->freeResult( $res );
213 -
214 - # Add the creation date column to the records
215 - foreach ( $records as $i => $r ) {
216 - $t = $r[0];
217 - $id = $t->getArticleID();
218 - $tbl = $dbr->tableName( 'revision' );
219 - $row = $dbr->selectRow(
220 - $tbl,
221 - 'rev_timestamp',
222 - "rev_page = $id",
223 - __METHOD__,
224 - array( 'ORDER BY' => 'rev_timestamp' )
225 - );
226 - $records[$i]['created'] = $row->rev_timestamp;
227 - }
 187+ /**
 188+ * Return an array of records given type and other criteria
 189+ */
 190+ function getRecords($type, $posted, $wpTitle = '', $invert = false, $orderby = 'created desc') {
 191+ $records = array();
 192+ $dbr = wfGetDB( DB_SLAVE );
 193+ $tbl = $dbr->tableName( 'templatelinks' );
 194+ $ty = $dbr->addQuotes( $type );
 195+ $res = $dbr->select( $tbl, 'tl_from', "tl_namespace = 10 AND tl_title = $ty", __METHOD__ );
 196+ while ( $row = $dbr->fetchRow( $res ) ) {
 197+ $t = Title::newFromID( $row[0] );
 198+ if ( empty( $wpTitle ) || eregi( $wpTitle, $t->getPrefixedText() ) ) {
 199+ $a = new Article( $t );
 200+ $text = $a->getContent();
 201+ $match = true;
 202+ $r = array( 0 => $t, 'title' => $t->getPrefixedText() );
 203+ foreach ( array_keys( $this->types ) as $k ) {
 204+ $v = isset( $posted[$k] ) ? ( $this->types[$k] == 'bool' ? 'yes' : $posted[$k] ) : '';
 205+ $i = preg_match( "|\s*\|\s*$k\s*=\s*(.*?)\s*(?=[\|\}])|si", $text, $m );
 206+ if ( $v && !( $i && eregi( $v, $m[1] ) ) ) $match = false;
 207+ $r[$k] = isset( $m[1] ) ? $m[1] : '';
 208+ }
 209+ if ( $invert ) $match = !$match;
 210+ if ( $match ) $records[] = $r;
 211+ }
 212+ }
 213+ $dbr->freeResult( $res );
 214+
 215+ # Add the creation date column to the records
 216+ foreach ( $records as $i => $r ) {
 217+ $t = $r[0];
 218+ $id = $t->getArticleID();
 219+ $tbl = $dbr->tableName( 'revision' );
 220+ $row = $dbr->selectRow(
 221+ $tbl,
 222+ 'rev_timestamp',
 223+ "rev_page = $id",
 224+ __METHOD__,
 225+ array( 'ORDER BY' => 'rev_timestamp' )
 226+ );
 227+ $records[$i]['created'] = $row->rev_timestamp;
 228+ }
228229
229 - # Sort the records according to "orderby" parameter
230 - if ($this->desc = eregi(' +desc *$', $orderby)) $orderby = eregi_replace(' +desc *$', '', $orderby);
231 - $this->orderby = $orderby;
232 - usort($records, array($this, 'sortCallback'));
 230+ # Sort the records according to "orderby" parameter
 231+ if ($this->desc = eregi(' +desc *$', $orderby)) $orderby = eregi_replace(' +desc *$', '', $orderby);
 232+ $this->orderby = $orderby;
 233+ usort($records, array($this, 'sortCallback'));
233234
234 - return $records;
235 - }
236 -
237 - /**
238 - * Compares to arrays by column
239 - */
240 - function sortCallback($row1, $row2) {
241 - if (!isset($row1[$this->orderby]) || !isset($row1[$this->orderby])) return 0;
242 - if ($row1[$this->orderby] == $row2[$this->orderby]) return 0;
243 - $cmp = $row1[$this->orderby] > $row2[$this->orderby] ? 1 : -1;
244 - return $this->desc ? -$cmp : $cmp;
245 - }
 235+ return $records;
 236+ }
 237+
 238+ /**
 239+ * Compares to arrays by column
 240+ */
 241+ function sortCallback($row1, $row2) {
 242+ if (!isset($row1[$this->orderby]) || !isset($row1[$this->orderby])) return 0;
 243+ if ($row1[$this->orderby] == $row2[$this->orderby]) return 0;
 244+ $cmp = $row1[$this->orderby] > $row2[$this->orderby] ? 1 : -1;
 245+ return $this->desc ? -$cmp : $cmp;
 246+ }
246247
247 - /**
248 - * Render a set of records returned by getRecords() as an HTML table
249 - */
250 - function renderRecords($records, $cols = false, $sortable = true) {
251 - if (count($records) < 1) return wfMsg( 'recordadmin-nomatch' );
 248+ /**
 249+ * Render a set of records returned by getRecords() as an HTML table
 250+ */
 251+ function renderRecords($records, $cols = false, $sortable = true) {
 252+ if (count($records) < 1) return wfMsg( 'recordadmin-nomatch' );
252253
253 - $special = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
254 - $type = $this->type;
255 - $sortable = $sortable ? ' sortable' : '';
256 - $br = $sortable ? '<br />' : '';
 254+ $special = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
 255+ $type = $this->type;
 256+ $sortable = $sortable ? ' sortable' : '';
 257+ $br = $sortable ? '<br />' : '';
257258
258 - # Table header
259 - $table = "<table class='recordadmin$sortable $type-record'>\n<tr>";
260 - $th = array(
261 - 'title' => "<th class='col0'>" . wfMsg( 'recordadmin-title', $type ) . "$br</th>",
262 - 'actions' => "<th class='col1'>" . wfMsg( 'recordadmin-actions' ) . "$br</th>",
263 - 'created' => "<th class='col2'>" . wfMsg( 'recordadmin-created' ) . "$br</th>"
264 - );
265 - foreach ( array_keys($this->types) as $col ) {
266 - $class = 'col'.preg_replace('|\W|', '-', $col);
267 - $th[$col] = "<th class='$class'>$col$br</th>";
268 - }
269 - foreach ( $cols ? $cols : array_keys($th) as $col ) $table .= $th[$col]."\n";
270 - $table .= "</tr>\n";
 259+ # Table header
 260+ $table = "<table class='recordadmin$sortable $type-record'>\n<tr>";
 261+ $th = array(
 262+ 'title' => "<th class='col0'>" . wfMsg( 'recordadmin-title', $type ) . "$br</th>",
 263+ 'actions' => "<th class='col1'>" . wfMsg( 'recordadmin-actions' ) . "$br</th>",
 264+ 'created' => "<th class='col2'>" . wfMsg( 'recordadmin-created' ) . "$br</th>"
 265+ );
 266+ foreach ( array_keys($this->types) as $col ) {
 267+ $class = 'col'.preg_replace('|\W|', '-', $col);
 268+ $th[$col] = "<th class='$class'>$col$br</th>";
 269+ }
 270+ foreach ( $cols ? $cols : array_keys($th) as $col ) $table .= $th[$col]."\n";
 271+ $table .= "</tr>\n";
271272
272 - $stripe = '';
273 - foreach ( $records as $r ) {
274 - $ts = preg_replace( '|^..(..)(..)(..)(..)(..)..$|', '$3/$2/$1&nbsp;$4:$5', $r['created'] );
275 - $t = $r[0];
276 - $u = $t->getLocalURL();
277 - $col = $r['title'];
278 - $stripe = $stripe ? '' : ' class="stripe"';
279 - $table .= "<tr$stripe>";
280 - $row = array(
281 - 'title' => "<td class='col0'><a href='$u'>$col</a></td>",
282 - 'actions' => "<td class='col1'>(<a href='$u'>" . wfMsg( 'recordadmin-viewlink' ) . "</a>)".
283 - "(<a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$col" ) . "'>" . wfMsg( 'recordadmin-editlink' ) . "</a>)</td>",
284 - 'created' => "<td class='col2'>$ts</td>\n"
285 - );
286 - foreach ( array_keys( $this->types ) as $col ) {
287 - $v = isset( $r[$col] ) ? $r[$col] : '&nbsp;';
288 - $class = 'col'.preg_replace('|\W|', '-', $col);
289 - $row[$col] = "<td class='$class'>$v</td>";
290 - }
291 - foreach ($cols ? $cols : array_keys($th) as $col) $table .= $row[$col]."\n";
292 -
293 - $table .= "</tr>\n";
294 - }
295 - $table .= "</table>\n";
 273+ $stripe = '';
 274+ foreach ( $records as $r ) {
 275+ $ts = preg_replace( '|^..(..)(..)(..)(..)(..)..$|', '$3/$2/$1&nbsp;$4:$5', $r['created'] );
 276+ $t = $r[0];
 277+ $u = $t->getLocalURL();
 278+ $col = $r['title'];
 279+ $stripe = $stripe ? '' : ' class="stripe"';
 280+ $table .= "<tr$stripe>";
 281+ $row = array(
 282+ 'title' => "<td class='col0'><a href='$u'>$col</a></td>",
 283+ 'actions' => "<td class='col1'>(<a href='$u'>" . wfMsg( 'recordadmin-viewlink' ) . "</a>)".
 284+ "(<a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$col" ) . "'>" . wfMsg( 'recordadmin-editlink' ) . "</a>)</td>",
 285+ 'created' => "<td class='col2'>$ts</td>\n"
 286+ );
 287+ foreach ( array_keys( $this->types ) as $col ) {
 288+ $v = isset( $r[$col] ) ? $r[$col] : '&nbsp;';
 289+ $class = 'col'.preg_replace('|\W|', '-', $col);
 290+ $row[$col] = "<td class='$class'>$v</td>";
 291+ }
 292+ foreach ($cols ? $cols : array_keys($th) as $col) $table .= $row[$col]."\n";
 293+
 294+ $table .= "</tr>\n";
 295+ }
 296+ $table .= "</table>\n";
296297
297 - return $table;
298 - }
 298+ return $table;
 299+ }
299300
300 - /**
301 - * Read in and prepare the form (for use as a search filter) for passed record type
302 - * - we're using the record's own form as a filter for searching for records
303 - * - extract only the content from between the form tags and remove any submit inputs
304 - */
305 - function preProcessForm( $type ) {
306 - $this->type = $type;
307 - $title = Title::newFromText( $type, NS_FORM );
308 - if ( $title->exists() ) {
309 - $form = new Article( $title );
310 - $form = $form->getContent();
311 - $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#', '', $form ); # remove submits
312 - $form = preg_replace( '#^.+?<form.+?>#s', '', $form ); # remove up to and including form open
313 - $form = preg_replace( '#</form>.+?$#s', '', $form ); # remove form close and everything after
314 - $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#s', 'name="ra_$2"', $form ); # prefix input names with ra_
315 - $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#s', '$1<option selected/>', $form ); # ensure all select lists have default blank
316 - }
 301+ /**
 302+ * Read in and prepare the form (for use as a search filter) for passed record type
 303+ * - we're using the record's own form as a filter for searching for records
 304+ * - extract only the content from between the form tags and remove any submit inputs
 305+ */
 306+ function preProcessForm( $type ) {
 307+ $this->type = $type;
 308+ $title = Title::newFromText( $type, NS_FORM );
 309+ if ( $title->exists() ) {
 310+ $form = new Article( $title );
 311+ $form = $form->getContent();
 312+ $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#', '', $form ); # remove submits
 313+ $form = preg_replace( '#^.+?<form.+?>#s', '', $form ); # remove up to and including form open
 314+ $form = preg_replace( '#</form>.+?$#s', '', $form ); # remove form close and everything after
 315+ $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#s', 'name="ra_$2"', $form ); # prefix input names with ra_
 316+ $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#s', '$1<option selected/>', $form ); # ensure all select lists have default blank
 317+ }
317318
318 - # Create a red link to the form if it doesn't exist
319 - else {
320 - $form = "<b>" . wfMsg( 'recordadmin-noform', $type ) . "</b>"
321 - . "<br><br>" . wfMsg( 'recordadmin-createlink', $title->getLocalURL( 'action=edit' ) ) . "</div>";
322 - }
323 - $this->form = $form;
324 - }
 319+ # Create a red link to the form if it doesn't exist
 320+ else {
 321+ $form = "<b>" . wfMsg( 'recordadmin-noform', $type ) . "</b>"
 322+ . "<br><br>" . wfMsg( 'recordadmin-createlink', $title->getLocalURL( 'action=edit' ) ) . "</div>";
 323+ }
 324+ $this->form = $form;
 325+ }
325326
326327
327 - /**
328 - * Populates the form values from the passed values
329 - * - $form is HTML text
330 - * - $values may be a hash or wikitext template syntax
331 - */
332 - function populateForm( $values ) {
 328+ /**
 329+ * Populates the form values from the passed values
 330+ * - $form is HTML text
 331+ * - $values may be a hash or wikitext template syntax
 332+ */
 333+ function populateForm( $values ) {
333334
334 - # If values are wikitext, convert to hash
335 - if ( !is_array( $values ) ) {
336 - $text = $values;
337 - $values = array();
338 - preg_match_all( "|\|\s*(.+?)\s*=\s*(.*?)\s*(?=[\|\}])|s", $text, $m );
339 - foreach ( $m[1] as $i => $k ) $values[$k] = $m[2][$i];
340 - }
 335+ # If values are wikitext, convert to hash
 336+ if ( !is_array( $values ) ) {
 337+ $text = $values;
 338+ $values = array();
 339+ preg_match_all( "|\|\s*(.+?)\s*=\s*(.*?)\s*(?=[\|\}])|s", $text, $m );
 340+ foreach ( $m[1] as $i => $k ) $values[$k] = $m[2][$i];
 341+ }
341342
342 - # Add the values into the form's HTML depending on their type
343 - foreach ( $this->types as $k => $type ) {
 343+ # Add the values into the form's HTML depending on their type
 344+ foreach ( $this->types as $k => $type ) {
344345
345 - # Get this input element's html text and position and length
346 - preg_match( "|<([a-zA-Z]+)[^<]+?name=\"ra_$k\".*?>(.*?</\\1>)?|s", $this->form, $m, PREG_OFFSET_CAPTURE );
347 - list( $html, $pos ) = $m[0];
348 - $len = strlen( $html );
 346+ # Get this input element's html text and position and length
 347+ preg_match( "|<([a-zA-Z]+)[^<]+?name=\"ra_$k\".*?>(.*?</\\1>)?|s", $this->form, $m, PREG_OFFSET_CAPTURE );
 348+ list( $html, $pos ) = $m[0];
 349+ $len = strlen( $html );
349350
350 - # Modify the element according to its type
351 - # - clears default value, then adds new value
352 - $v = isset( $values[$k] ) ? $values[$k] : '';
353 - switch ( $type ) {
354 - case 'text':
355 - $html = preg_replace( "|value\s*=\s*\".*?\"|", "", $html );
356 - if ( $v ) $html = preg_replace( "|(/?>)$|", " value=\"$v\" $1", $html );
357 - break;
358 - case 'bool':
359 - $html = preg_replace( "|checked|", "", $html );
360 - if ( $v ) $html = preg_replace( "|(/?>)$|", " checked $1", $html );
361 - break;
362 - case 'list':
363 - $html = preg_replace( "|(<option[^<>]*) selected|", "$1", $html );
364 - if ( $v ) $html = preg_replace( "|(?<=<option)(?=>$v</option>)|s", " selected", $html );
365 - break;
366 - case 'blob':
367 - $html = preg_replace( "|>.*?(?=</textarea>)|s", ">$v", $html );
368 - break;
369 - }
 351+ # Modify the element according to its type
 352+ # - clears default value, then adds new value
 353+ $v = isset( $values[$k] ) ? $values[$k] : '';
 354+ switch ( $type ) {
 355+ case 'text':
 356+ $html = preg_replace( "|value\s*=\s*\".*?\"|", "", $html );
 357+ if ( $v ) $html = preg_replace( "|(/?>)$|", " value=\"$v\" $1", $html );
 358+ break;
 359+ case 'bool':
 360+ $html = preg_replace( "|checked|", "", $html );
 361+ if ( $v ) $html = preg_replace( "|(/?>)$|", " checked $1", $html );
 362+ break;
 363+ case 'list':
 364+ $html = preg_replace( "|(<option[^<>]*) selected|", "$1", $html );
 365+ if ( $v ) $html = preg_replace( "|(?<=<option)(?=>$v</option>)|s", " selected", $html );
 366+ break;
 367+ case 'blob':
 368+ $html = preg_replace( "|>.*?(?=</textarea>)|s", ">$v", $html );
 369+ break;
 370+ }
370371
371 - # Replace the element in the form with the modified html
372 - $this->form = substr_replace( $this->form, $html, $pos, $len );
373 - }
374 - }
 372+ # Replace the element in the form with the modified html
 373+ $this->form = substr_replace( $this->form, $html, $pos, $len );
 374+ }
 375+ }
375376
376 - /**
377 - * Returns an array of types used by the passed HTML text form
378 - * - supported types, text, select, checkbox, textarea
379 - */
380 - function examineForm() {
381 - $this->types = array();
382 - preg_match_all( "|<([a-zA-Z]+)[^<]+?name=\"ra_(.+?)\".*?>|", $this->form, $m );
383 - foreach ( $m[2] as $i => $k ) {
384 - $tag = $m[1][$i];
385 - $type = preg_match( "|type\s*=\s*\"(.+?)\"|", $m[0][$i], $n ) ? $n[1] : '';
386 - switch ( $tag ) {
387 - case 'input':
388 - switch ( $type ) {
389 - case 'checkbox':
390 - $this->types[$k] = 'bool';
391 - break;
392 - default:
393 - $this->types[$k] = 'text';
394 - break;
395 - }
396 - break;
397 - case 'select':
398 - $this->types[$k] = 'list';
399 - break;
400 - case 'textarea':
401 - $this->types[$k] = 'blob';
402 - break;
403 - }
404 - }
405 - }
 377+ /**
 378+ * Returns an array of types used by the passed HTML text form
 379+ * - supported types, text, select, checkbox, textarea
 380+ */
 381+ function examineForm() {
 382+ $this->types = array();
 383+ preg_match_all( "|<([a-zA-Z]+)[^<]+?name=\"ra_(.+?)\".*?>|", $this->form, $m );
 384+ foreach ( $m[2] as $i => $k ) {
 385+ $tag = $m[1][$i];
 386+ $type = preg_match( "|type\s*=\s*\"(.+?)\"|", $m[0][$i], $n ) ? $n[1] : '';
 387+ switch ( $tag ) {
 388+ case 'input':
 389+ switch ( $type ) {
 390+ case 'checkbox':
 391+ $this->types[$k] = 'bool';
 392+ break;
 393+ default:
 394+ $this->types[$k] = 'text';
 395+ break;
 396+ }
 397+ break;
 398+ case 'select':
 399+ $this->types[$k] = 'list';
 400+ break;
 401+ case 'textarea':
 402+ $this->types[$k] = 'blob';
 403+ break;
 404+ }
 405+ }
 406+ }
406407
407 - /**
408 - * Return array of braces used and the name, position, length and depth
409 - * See http://www.organicdesign.co.nz/MediaWiki_code_snippets
410 - */
411 - function examineBraces( &$content ) {
412 - $braces = array();
413 - $depths = array();
414 - $depth = 1;
415 - $index = 0;
416 - while ( preg_match( "/\\{\\{\\s*([#a-z0-9_]*)|\\}\\}/is", $content, $match, PREG_OFFSET_CAPTURE, $index ) ) {
417 - $index = $match[0][1] + 2;
418 - if ( $match[0][0] == '}}' ) {
419 - $brace =& $braces[$depths[$depth - 1]];
420 - $brace['LENGTH'] = $match[0][1] - $brace['OFFSET'] + 2;
421 - $brace['DEPTH'] = $depth--;
422 - }
423 - else {
424 - $depths[$depth++] = count( $braces );
425 - $braces[] = array(
426 - 'NAME' => $match[1][0],
427 - 'OFFSET' => $match[0][1]
428 - );
429 - }
430 - }
431 - return $braces;
432 - }
 408+ /**
 409+ * Return array of braces used and the name, position, length and depth
 410+ * See http://www.organicdesign.co.nz/MediaWiki_code_snippets
 411+ */
 412+ function examineBraces( &$content ) {
 413+ $braces = array();
 414+ $depths = array();
 415+ $depth = 1;
 416+ $index = 0;
 417+ while ( preg_match( "/\\{\\{\\s*([#a-z0-9_]*)|\\}\\}/is", $content, $match, PREG_OFFSET_CAPTURE, $index ) ) {
 418+ $index = $match[0][1] + 2;
 419+ if ( $match[0][0] == '}}' ) {
 420+ $brace =& $braces[$depths[$depth - 1]];
 421+ $brace['LENGTH'] = $match[0][1] - $brace['OFFSET'] + 2;
 422+ $brace['DEPTH'] = $depth--;
 423+ }
 424+ else {
 425+ $depths[$depth++] = count( $braces );
 426+ $braces[] = array(
 427+ 'NAME' => $match[1][0],
 428+ 'OFFSET' => $match[0][1]
 429+ );
 430+ }
 431+ }
 432+ return $braces;
 433+ }
433434
434 - /**
435 - * A callback for processing public forms
436 - */
437 - function createRecord() {
438 - global $wgRequest, $wgRecordAdminUseNamespaces;
439 - $type = $wgRequest->getText( 'wpType' );
440 - $title = $wgRequest->getText( 'wpTitle' );
 435+ /**
 436+ * A callback for processing public forms
 437+ */
 438+ function createRecord() {
 439+ global $wgRequest, $wgRecordAdminUseNamespaces;
 440+ $type = $wgRequest->getText( 'wpType' );
 441+ $title = $wgRequest->getText( 'wpTitle' );
441442
442 - # Get types in this kind of record from form
443 - $this->preProcessForm( $type );
444 - $this->examineForm();
 443+ # Get types in this kind of record from form
 444+ $this->preProcessForm( $type );
 445+ $this->examineForm();
445446
446 - # Use guid if no title specified
447 - if ( empty( $title ) ) {
448 - $title = $this->guid;
449 - if ( $wgRecordAdminUseNamespaces ) $title = "$type:$title";
450 - }
 447+ # Use guid if no title specified
 448+ if ( empty( $title ) ) {
 449+ $title = $this->guid;
 450+ if ( $wgRecordAdminUseNamespaces ) $title = "$type:$title";
 451+ }
451452
452 - # Attempt to create the article
453 - $title = Title::newFromText( $title );
454 - if ( is_object( $title ) && !$title->exists() ) {
455 - $article = new Article( $title );
456 - $summary = wfMsg( 'recordadmin-newcreated' );
457 - $text = '';
458 - foreach ( $_POST as $k => $v ) if ( $v && isset( $this->types[$k] ) ) {
459 - if ( $this->types[$k] == 'bool' ) $v = 'yes';
460 - $text .= "| $k = $v\n";
461 - }
462 - $text = $text ? "{{" . "$type\n$text}}" : "{{" . "$type}}";
463 - $success = $article->doEdit( $text, $summary, EDIT_NEW );
464 - }
465 - }
 453+ # Attempt to create the article
 454+ $title = Title::newFromText( $title );
 455+ if ( is_object( $title ) && !$title->exists() ) {
 456+ $article = new Article( $title );
 457+ $summary = wfMsg( 'recordadmin-newcreated' );
 458+ $text = '';
 459+ foreach ( $_POST as $k => $v ) if ( $v && isset( $this->types[$k] ) ) {
 460+ if ( $this->types[$k] == 'bool' ) $v = 'yes';
 461+ $text .= "| $k = $v\n";
 462+ }
 463+ $text = $text ? "{{" . "$type\n$text}}" : "{{" . "$type}}";
 464+ $success = $article->doEdit( $text, $summary, EDIT_NEW );
 465+ }
 466+ }
466467
467 - /**
468 - * Render a record search in a parser-function
469 - */
470 - function expandMagic(&$parser, $type) {
471 - $parser->mOutput->mCacheTime = -1;
472 - $filter = array();
473 - $title = '';
474 - $invert = false;
475 - $orderby = 'created desc';
476 - $cols = false;
477 - $sortable = true;
478 - foreach (func_get_args() as $arg) if (!is_object($arg)) {
479 - if (preg_match("/^(.+?)\\s*=\\s*(.+)$/", $arg, $match)) {
480 - list(, $k, $v) = $match;
481 - if ($k == 'title') $title = $v;
482 - elseif ($k == 'invert') $invert = $v;
483 - elseif ($k == 'orderby') $orderby = $v;
484 - elseif ($k == 'cols') $cols = preg_split('/\s*,\s*/', $v);
485 - elseif ($k == 'sortable') $sortable = eregi('1|yes|true|on', $v);
486 - else $filter[$match[1]] = $match[2];
487 - }
488 - }
489 - $this->preProcessForm($type);
490 - $this->examineForm();
491 - $records = $this->getRecords($type, $filter, $title, $invert, $orderby);
492 - $table = $this->renderRecords($records, $cols, $sortable);
493 - return array(
494 - $table,
495 - 'noparse' => true,
496 - 'isHTML' => true
497 - );
498 -
499 - }
 468+ /**
 469+ * Render a record search in a parser-function
 470+ */
 471+ function expandMagic(&$parser, $type) {
 472+ $parser->mOutput->mCacheTime = -1;
 473+ $filter = array();
 474+ $title = '';
 475+ $invert = false;
 476+ $orderby = 'created desc';
 477+ $cols = false;
 478+ $sortable = true;
 479+ foreach (func_get_args() as $arg) if (!is_object($arg)) {
 480+ if (preg_match("/^(.+?)\\s*=\\s*(.+)$/", $arg, $match)) {
 481+ list(, $k, $v) = $match;
 482+ if ($k == 'title') $title = $v;
 483+ elseif ($k == 'invert') $invert = $v;
 484+ elseif ($k == 'orderby') $orderby = $v;
 485+ elseif ($k == 'cols') $cols = preg_split('/\s*,\s*/', $v);
 486+ elseif ($k == 'sortable') $sortable = eregi('1|yes|true|on', $v);
 487+ else $filter[$match[1]] = $match[2];
 488+ }
 489+ }
 490+ $this->preProcessForm($type);
 491+ $this->examineForm();
 492+ $records = $this->getRecords($type, $filter, $title, $invert, $orderby);
 493+ $table = $this->renderRecords($records, $cols, $sortable);
 494+ return array(
 495+ $table,
 496+ 'noparse' => true,
 497+ 'isHTML' => true
 498+ );
 499+
 500+ }
500501
501 - /**
502 - * If a record was created by a public form, make last 5 digits of ID available via a tag
503 - */
504 - function expandTag( $text, $argv, &$parser ) {
505 - $parser->mOutput->mCacheTime = -1;
506 - return $this->guid ? substr( $this->guid, -5 ) : '';
507 - }
 502+ /**
 503+ * If a record was created by a public form, make last 5 digits of ID available via a tag
 504+ */
 505+ function expandTag( $text, $argv, &$parser ) {
 506+ $parser->mOutput->mCacheTime = -1;
 507+ return $this->guid ? substr( $this->guid, -5 ) : '';
 508+ }
508509
509510 }
Property changes on: trunk/extensions/RecordAdmin/RecordAdmin_body.php
___________________________________________________________________
Name: svn:mergeinfo
510511 -

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r47304rv that last change broke itnad04:12, 16 February 2009

Status & tagging log