r48000 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47999‎ | r48000 | r48001 >
Date:23:45, 3 March 2009
Author:nad
Status:deferred
Tags:
Comment:
Add form inputs to create new record type
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.i18n.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -26,6 +26,7 @@
2727 global $wgVersion, $wgOut, $wgRequest, $wgRecordAdminUseNamespaces, $wgLang, $wgRecordAdminCategory;
2828 $this->setHeaders();
2929 $type = $wgRequest->getText( 'wpType' ) or $type = $param;
 30+ $newtype = $wgRequest->getText( 'wpNewType' );
3031 $record = $wgRequest->getText( 'wpRecord' );
3132 $invert = $wgRequest->getText( 'wpInvert' );
3233 $title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
@@ -37,12 +38,12 @@
3839 if (version_compare(substr($wgVersion, 0, 4), '1.13') > 0) {
3940 $wgOut->addHTML( $wgLang->pipeList( array(
4041 "<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+ "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a></div><br />\n"
4243 ) ) );
4344 }
4445 else {
45 - $wgOut->addHTML( "<div class='center'><a href='" . $title->getLocalURL() . "/$type'>" . wfMsg( 'recordadmin-newsearch', $type ) . "</a> | "
46 - . "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a></div><br>\n"
 46+ $wgOut->addHTML( "<a href='" . $title->getLocalURL() . "/$type'>" . wfMsg( 'recordadmin-newsearch', $type ) . "</a> | "
 47+ . "<a href='" . $title->getLocalURL() . "'>" . wfMsg( 'recordadmin-newrecord' ) . "</a><br />\n"
4748 );
4849 }
4950
@@ -59,9 +60,16 @@
6061 # Clear any default values
6162 $this->populateForm( array() );
6263
63 - # If no type selected, render select list of record types from Category:Records
 64+ # Process Create New Type form if submitted and user permitted
 65+ if ( $newtype ) {
 66+ $this->createRecordType( $newtype );
 67+ $type = '';
 68+ }
 69+
 70+ # If no type selected, render form for record types and create record-type
6471 if ( empty( $type ) ) {
65 - $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-select' ) . "==\n" );
 72+ $wgOut->addWikiText( "<div class='visualClear'></div>\n==" . wfMsg( 'recordadmin-select' ) . "==\n" );
 73+ $wgOut->addHTML( Xml::element( 'form', array( 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null ) );
6674
6775 # Get titles in $wgRecordAdminCategory and build option list
6876 $options = '';
@@ -71,19 +79,25 @@
7280 $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) );
7381 while ( $row = $dbr->fetchRow( $res ) ) $options .= '<option>' . Title::newFromID( $row[0] )->getText() . '</option>';
7482
75 - # Render type-selecting form
76 - if ($options) {
77 - $wgOut->addHTML( Xml::element( 'form', array( 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
78 - . "<select name='wpType'>$options</select> "
79 - . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
80 - . '</form>'
81 - );
82 - }
 83+ # Render type select list
 84+ if ($options) $wgOut->addHTML(
 85+ "<select name='wpType'>$options</select> "
 86+ . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-submit' ) ) )
 87+ );
8388 else {
8489 # No records found in $wgRecordAdminCategory
8590 $cat = Title::newFromText( $wgRecordAdminCategory, NS_CATEGORY );
8691 $wgOut->AddWikiText( wfMsg( 'recordadmin-categoryempty', $cat->getPrefixedText() ) );
8792 }
 93+
 94+ # Render type create
 95+ $wgOut->addWikiText( "<br />\n==" . wfMsg( 'recordadmin-createtype' ) . "==\n" );
 96+ $wgOut->addHTML( Xml::element( 'input', array( 'name' => 'wpNewType', 'type' => 'text' ) )
 97+ . '&nbsp;'
 98+ . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-buttoncreate' ) ) )
 99+ . '</form>'
 100+ );
 101+
88102 }
89103
90104 # Record type known, but no record selected, render form for searching or creating
@@ -103,7 +117,7 @@
104118
105119 # Attempt to create the article
106120 $article = new Article( $t );
107 - $summary = "[[Special:RecordAdmin/$type|RecordAdmin]]:" . wfMsg( 'recordadmin-summary-typecreated', $type );
 121+ $summary = "[[Special:RecordAdmin/$type|".wfMsgForContent( 'recordadmin' )."]]: " . wfMsg( 'recordadmin-summary-typecreated', $type );
108122 $text = '';
109123 foreach ( $posted as $k => $v ) if ( $v ) {
110124 if ( $this->types[$k] == 'bool' ) $v = 'yes';
@@ -490,6 +504,40 @@
491505 }
492506
493507 /**
 508+ * Create a new record type
 509+ */
 510+ function createRecordType( $newtype ) {
 511+ global $wgOut, $wgRecordAdminCategory;
 512+
 513+ # Compose the content of the new template
 514+ $cat = Title::newFromText( $wgRecordAdminCategory, NS_CATEGORY )->getPrefixedText();
 515+ $text = "<noinclude>[[$cat]]</noinclude>\n{| class=recordadmin-template\n|}\n<includeonly>[[Category:{$newtype}s]]</includeonly>";
 516+
 517+ $rtype = wfMsg( 'recordadmin-recordtype' ) . " ($newtype)";
 518+ $title = Title::newFromtext( $newtype, NS_TEMPLATE );
 519+ if (!is_object($title)) {
 520+ $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $rtype ) . "</div>\n" );
 521+ }
 522+ elseif ( $title->exists() ) {
 523+
 524+ # the template already exists
 525+ $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-alreadyexist', $title->getPrefixedText() ) . "</div>\n" );
 526+
 527+ }
 528+ else {
 529+
 530+ # Attempt to create the article
 531+ $article = new Article( $title );
 532+ $summary = "[[Special:RecordAdmin/$newtype|".wfMsgForContent( 'recordadmin' )."]]: " . wfMsg( 'recordadmin-summary-typecreated', $rtype );
 533+ $success = $article->doEdit( $text, $summary, EDIT_NEW );
 534+
 535+ # Report success or error
 536+ if ( $success ) $wgOut->addHTML( "<div class='successbox'>" . wfMsg( 'recordadmin-createsuccess', $rtype ) . "</div>\n" );
 537+ else $wgOut->addHTML( "<div class='errorbox'>" . wfMsg( 'recordadmin-createerror', $rtype ) . "</div>\n" );
 538+ }
 539+ }
 540+
 541+ /**
494542 * Render a record search in a parser-function
495543 */
496544 function expandMagic(&$parser, $type) {
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php
@@ -17,8 +17,9 @@
1818 'recordadmin' => 'Record administration',
1919 'recordadmin-desc' => 'A [[Special:RecordAdmin|special page]] for finding and editing record pages using a form',
2020 'recordadmin-categoryempty' => 'There are currently no record types. Please categorise record templates into [[:$1|$1]].',
21 - 'recordadmin-select' => 'Select the type of record to search for',
 21+ 'recordadmin-select' => 'Select the type of record to manage',
2222 'recordadmin-createtype' => 'Enter the name of a new record type to create',
 23+ 'recordadmin-recordtype' => 'record type',
2324 'recordadmin-newsearch' => 'New $1 search',
2425 'recordadmin-newrecord' => 'Select another record type',
2526 'recordadmin-submit' => 'Submit',

Status & tagging log