r48134 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48133‎ | r48134 | r48135 >
Date:17:20, 7 March 2009
Author:siebrand
Status:deferred
Tags:
Comment:
* update message 'recordadmin-needscontent'
* stylize.php run and trailing whitespace removed
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.i18n.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -35,7 +35,7 @@
3636 if ( $type && $wgRecordAdminUseNamespaces ) {
3737 if ( $wpTitle && !ereg( "^$type:.+$", $wpTitle ) ) $wpTitle = "$type:$wpTitle";
3838 }
39 - if (version_compare(substr($wgVersion, 0, 4), '1.13') > 0) {
 39+ if ( version_compare( substr( $wgVersion, 0, 4 ), '1.13' ) > 0 ) {
4040 $wgOut->addHTML( $wgLang->pipeList( array(
4141 "<div class='center'><a href='" . $title->getLocalURL() . "/$type'>" . wfMsg( 'recordadmin-newsearch', $type ) . "</a>",
4242 "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a></div><br />\n"
@@ -46,7 +46,7 @@
4747 . "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a><br />\n"
4848 );
4949 }
50 -
 50+
5151 # Get posted form values if any
5252 $posted = array();
5353 foreach ( $_POST as $k => $v ) if ( ereg( '^ra_(.+)$', $k, $m ) ) $posted[$m[1]] = $v;
@@ -80,7 +80,7 @@
8181 while ( $row = $dbr->fetchRow( $res ) ) $options .= '<option>' . Title::newFromID( $row[0] )->getText() . '</option>';
8282
8383 # Render type select list
84 - if ($options) $wgOut->addHTML(
 84+ if ( $options ) $wgOut->addHTML(
8585 "<select name='wpType'>$options</select> "
8686 . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
8787 );
@@ -117,7 +117,7 @@
118118
119119 # Attempt to create the article
120120 $article = new Article( $t );
121 - $summary = "[[Special:RecordAdmin/$type|".wfMsgForContent( 'recordadmin' )."]]: " . wfMsg( 'recordadmin-summary-typecreated', $type );
 121+ $summary = "[[Special:RecordAdmin/$type|" . wfMsgForContent( 'recordadmin' ) . "]]: " . wfMsg( 'recordadmin-summary-typecreated', $type );
122122 $text = '';
123123 foreach ( $posted as $k => $v ) if ( $v ) {
124124 if ( $this->types[$k] == 'bool' ) $v = 'yes';
@@ -139,7 +139,7 @@
140140
141141 # Render the form
142142 $wgOut->addHTML(
143 - Xml::element( 'form', array( 'class' => strtolower($type).'-record recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
 143+ Xml::element( 'form', array( 'class' => strtolower( $type ) . '-record recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
144144 . '<b>' . wfMsg( 'recordadmin-recordid' ) . '</b> ' . Xml::element( 'input', array( 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) )
145145 . '&nbsp;&nbsp;&nbsp;' . Xml::element( 'input', array( 'name' => 'wpInvert', 'type' => 'checkbox' ) ) . ' ' . wfMsg( 'recordadmin-invert' )
146146 . "\n<br><br><hr><br>\n{$this->form}"
@@ -159,7 +159,7 @@
160160 $records = $this->getRecords( $type, $posted, $wpTitle, $invert );
161161
162162 # Render resulting records
163 - $wgOut->addHTML( $this->renderRecords($records) );
 163+ $wgOut->addHTML( $this->renderRecords( $records ) );
164164
165165 }
166166 }
@@ -172,7 +172,7 @@
173173 $text = $article->fetchContent();
174174
175175 # Update article if form posted
176 - if ( count( $posted ) && $rtitle->userCan('edit', false)) {
 176+ if ( count( $posted ) && $rtitle->userCan( 'edit', false ) ) {
177177
178178 # Get the location and length of the record braces to replace
179179 foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
@@ -197,7 +197,7 @@
198198 # Extract current values from article
199199 $braces = false;
200200 foreach ( $this->examineBraces( $text ) as $brace ) if ( $brace['NAME'] == $type ) $braces = $brace;
201 - if ($braces) {
 201+ if ( $braces ) {
202202
203203 # Fill in current values
204204 $this->populateForm( substr( $text, $braces['OFFSET'], $braces['LENGTH'] ) );
@@ -213,16 +213,16 @@
214214 . '</tr></table></form>'
215215 );
216216 }
217 -
 217+
218218 # No instance of the template found, just display the article content
219 - else $wgOut->addWikiText($text);
 219+ else $wgOut->addWikiText( $text );
220220 }
221221 }
222222
223223 /**
224224 * Return an array of records given type and other criteria
225225 */
226 - function getRecords($type, $posted, $wpTitle = '', $invert = false, $orderby = 'created desc') {
 226+ function getRecords( $type, $posted, $wpTitle = '', $invert = false, $orderby = 'created desc' ) {
227227 $records = array();
228228 $dbr = wfGetDB( DB_SLAVE );
229229 $tbl = $dbr->tableName( 'templatelinks' );
@@ -246,7 +246,7 @@
247247 }
248248 }
249249 $dbr->freeResult( $res );
250 -
 250+
251251 # Add the creation date column to the records
252252 foreach ( $records as $i => $r ) {
253253 $t = $r[0];
@@ -263,19 +263,19 @@
264264 }
265265
266266 # Sort the records according to "orderby" parameter
267 - if ($this->desc = eregi(' +desc *$', $orderby)) $orderby = eregi_replace(' +desc *$', '', $orderby);
 267+ if ( $this->desc = eregi( ' +desc *$', $orderby ) ) $orderby = eregi_replace( ' +desc *$', '', $orderby );
268268 $this->orderby = $orderby;
269 - usort($records, array($this, 'sortCallback'));
 269+ usort( $records, array( $this, 'sortCallback' ) );
270270
271271 return $records;
272272 }
273 -
 273+
274274 /**
275275 * Compares to arrays by column
276276 */
277 - function sortCallback($row1, $row2) {
278 - if (!isset($row1[$this->orderby]) || !isset($row1[$this->orderby])) return 0;
279 - if ($row1[$this->orderby] == $row2[$this->orderby]) return 0;
 277+ function sortCallback( $row1, $row2 ) {
 278+ if ( !isset( $row1[$this->orderby] ) || !isset( $row1[$this->orderby] ) ) return 0;
 279+ if ( $row1[$this->orderby] == $row2[$this->orderby] ) return 0;
280280 $cmp = $row1[$this->orderby] > $row2[$this->orderby] ? 1 : -1;
281281 return $this->desc ? -$cmp : $cmp;
282282 }
@@ -283,16 +283,16 @@
284284 /**
285285 * Render a set of records returned by getRecords() as an HTML table
286286 */
287 - function renderRecords($records, $cols = false, $sortable = true) {
 287+ function renderRecords( $records, $cols = false, $sortable = true ) {
288288 global $wgUser;
289 - if (count($records) < 1) return wfMsg( 'recordadmin-nomatch' );
 289+ if ( count( $records ) < 1 ) return wfMsg( 'recordadmin-nomatch' );
290290
291291 $special = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
292292 $type = $this->type;
293293 $sortable = $sortable ? ' sortable' : '';
294294 $br = $sortable ? '<br />' : '';
295295 $parser = new Parser;
296 - $options = ParserOptions::newFromUser($wgUser);
 296+ $options = ParserOptions::newFromUser( $wgUser );
297297
298298 # Table header
299299 $table = "<table class='recordadmin$sortable $type-record'>\n<tr>";
@@ -301,11 +301,11 @@
302302 'actions' => "<th class='col1'>" . wfMsg( 'recordadmin-actions' ) . "$br</th>",
303303 'created' => "<th class='col2'>" . wfMsg( 'recordadmin-created' ) . "$br</th>"
304304 );
305 - foreach ( array_keys($this->types) as $col ) {
306 - $class = 'col'.preg_replace('|\W|', '-', $col);
 305+ foreach ( array_keys( $this->types ) as $col ) {
 306+ $class = 'col' . preg_replace( '|\W|', '-', $col );
307307 $th[$col] = "<th class='$class'>$col$br</th>";
308308 }
309 - foreach ( $cols ? $cols : array_keys($th) as $col ) $table .= $th[$col]."\n";
 309+ foreach ( $cols ? $cols : array_keys( $th ) as $col ) $table .= $th[$col] . "\n";
310310 $table .= "</tr>\n";
311311
312312 $stripe = '';
@@ -318,17 +318,17 @@
319319 $table .= "<tr$stripe>";
320320 $row = array(
321321 'title' => "<td class='col0'><a href='$u'>$col</a></td>",
322 - 'actions' => "<td class='col1'>(<a href='$u'>" . wfMsg( 'recordadmin-viewlink' ) . "</a>)".
 322+ 'actions' => "<td class='col1'>(<a href='$u'>" . wfMsg( 'recordadmin-viewlink' ) . "</a>)" .
323323 "(<a href='" . $special->getLocalURL( "wpType=$type&wpRecord=$col" ) . "'>" . wfMsg( 'recordadmin-editlink' ) . "</a>)</td>",
324324 'created' => "<td class='col2'>$ts</td>\n"
325325 );
326326 foreach ( array_keys( $this->types ) as $col ) {
327327 $v = isset( $r[$col] ) ? $parser->parse( $r[$col], $special, $options, true, true )->getText() : '&nbsp;';
328 - $class = 'col'.preg_replace('|\W|', '-', $col);
 328+ $class = 'col' . preg_replace( '|\W|', '-', $col );
329329 $row[$col] = "<td class='$class'>$v</td>";
330330 }
331 - foreach ($cols ? $cols : array_keys($th) as $col) $table .= $row[$col]."\n";
332 -
 331+ foreach ( $cols ? $cols : array_keys( $th ) as $col ) $table .= $row[$col] . "\n";
 332+
333333 $table .= "</tr>\n";
334334 }
335335 $table .= "</table>\n";
@@ -512,7 +512,7 @@
513513 $rtype = wfMsg( 'recordadmin-recordtype' ) . " ($newtype)";
514514 $ttitle = Title::newFromtext( $newtype, NS_TEMPLATE );
515515 $ftitle = Title::newFromtext( $newtype, NS_FORM );
516 - if ( !is_object($ttitle) || !is_object($ftitle) ) {
 516+ if ( !is_object( $ttitle ) || !is_object( $ftitle ) ) {
517517 $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $rtype ) . "</div>\n" );
518518 }
519519 $tttext = $ttitle->getPrefixedText();
@@ -530,27 +530,27 @@
531531
532532 # Attempt to create the template and form
533533 else {
534 - $summary = "[[Special:RecordAdmin/$newtype|".wfMsgForContent( 'recordadmin' )."]]: " . wfMsg( 'recordadmin-summary-typecreated', $rtype );
 534+ $summary = "[[Special:RecordAdmin/$newtype|" . wfMsgForContent( 'recordadmin' ) . "]]: " . wfMsg( 'recordadmin-summary-typecreated', $rtype );
535535
536536 # Compose the content of the new template
537537 $cat = Title::newFromText( $wgRecordAdminCategory, NS_CATEGORY )->getPrefixedText();
538 - $link = "[{{fullurl:$tttext|action=edit}} ".wfMsg('recordadmin-needscontent')."]";
 538+ $link = "[{{fullurl:$tttext|action=edit}} " . wfMsg( 'recordadmin-needscontent' ) . "]";
539539 $text = "<noinclude>[[$cat]]</noinclude>\n{| class=recordadmin-template\n\n$link\n\n|}<includeonly>[[Category:{$newtype}s]]</includeonly>";
540540 $article = new Article( $ttitle );
541541 $success = $article->doEdit( $text, $summary, EDIT_NEW );
542 - if (!$success) {
 542+ if ( !$success ) {
543543 $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $tttext ) . "</div>\n" );
544544 }
545545 else {
546546
547547 # Compose the content of the new form
548548 $cat = Title::newFromText( $wgRecordAdminCategory, NS_CATEGORY )->getPrefixedText();
549 - $url = $ftitle->getLocalUrl('action=edit');
550 - $link = "<a href=\"$url\">".wfMsg('recordadmin-needscontent')."</a>";
 549+ $url = $ftitle->getLocalUrl( 'action=edit' );
 550+ $link = "<a href=\"$url\">" . wfMsg( 'recordadmin-needscontent' ) . "</a>";
551551 $text = "<html>\n\t<form>\n\t\t<table>\n\t\t$link\n\t\t</table>\n\t</form>\n</html>";
552552 $article = new Article( $ftitle );
553553 $success = $article->doEdit( $text, $summary, EDIT_NEW );
554 - if (!$success) {
 554+ if ( !$success ) {
555555 $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $fttext ) . "</div>\n" );
556556 }
557557 }
@@ -563,7 +563,7 @@
564564 /**
565565 * Render a record search in a parser-function
566566 */
567 - function expandMagic(&$parser, $type) {
 567+ function expandMagic( &$parser, $type ) {
568568 $parser->mOutput->mCacheTime = -1;
569569 $filter = array();
570570 $title = '';
@@ -571,27 +571,27 @@
572572 $orderby = 'created desc';
573573 $cols = false;
574574 $sortable = true;
575 - foreach (func_get_args() as $arg) if (!is_object($arg)) {
576 - if (preg_match("/^(.+?)\\s*=\\s*(.+)$/", $arg, $match)) {
577 - list(, $k, $v) = $match;
578 - if ($k == 'title') $title = $v;
579 - elseif ($k == 'invert') $invert = $v;
580 - elseif ($k == 'orderby') $orderby = $v;
581 - elseif ($k == 'cols') $cols = preg_split('/\s*,\s*/', $v);
582 - elseif ($k == 'sortable') $sortable = eregi('1|yes|true|on', $v);
 575+ foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
 576+ if ( preg_match( "/^(.+?)\\s*=\\s*(.+)$/", $arg, $match ) ) {
 577+ list( , $k, $v ) = $match;
 578+ if ( $k == 'title' ) $title = $v;
 579+ elseif ( $k == 'invert' ) $invert = $v;
 580+ elseif ( $k == 'orderby' ) $orderby = $v;
 581+ elseif ( $k == 'cols' ) $cols = preg_split( '/\s*,\s*/', $v );
 582+ elseif ( $k == 'sortable' ) $sortable = eregi( '1|yes|true|on', $v );
583583 else $filter[$match[1]] = $match[2];
584584 }
585585 }
586 - $this->preProcessForm($type);
 586+ $this->preProcessForm( $type );
587587 $this->examineForm();
588 - $records = $this->getRecords($type, $filter, $title, $invert, $orderby);
589 - $table = $this->renderRecords($records, $cols, $sortable);
 588+ $records = $this->getRecords( $type, $filter, $title, $invert, $orderby );
 589+ $table = $this->renderRecords( $records, $cols, $sortable );
590590 return array(
591591 $table,
592592 'noparse' => true,
593593 'isHTML' => true
594594 );
595 -
 595+
596596 }
597597
598598 /**
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php
@@ -49,7 +49,7 @@
5050 'recordadmin-title' => '$1',
5151 'recordadmin-created' => 'Created',
5252 'recordadmin-actions' => 'Actions',
53 - 'recordadmin-needscontent' => 'Content needed, click here to add it...',
 53+ 'recordadmin-needscontent' => 'Add content...',
5454 'right-recordadmin' => 'Find and edit record pages',
5555 );
5656
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -64,8 +64,8 @@
6565 /**
6666 * Setup parser-function magic
6767 */
68 -function wfRecordAdminLanguageGetMagic(&$magicWords, $langCode = 0) {
 68+function wfRecordAdminLanguageGetMagic( &$magicWords, $langCode = 0 ) {
6969 global $wgRecordAdminMagic;
70 - $magicWords[$wgRecordAdminMagic] = array($langCode, $wgRecordAdminMagic);
 70+ $magicWords[$wgRecordAdminMagic] = array( $langCode, $wgRecordAdminMagic );
7171 return true;
7272 }

Status & tagging log