Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | global $wgVersion, $wgOut, $wgRequest, $wgRecordAdminUseNamespaces, $wgLang, $wgRecordAdminCategory; |
28 | 28 | $this->setHeaders(); |
29 | 29 | $type = $wgRequest->getText( 'wpType' ) or $type = $param; |
| 30 | + $newtype = $wgRequest->getText( 'wpNewType' ); |
30 | 31 | $record = $wgRequest->getText( 'wpRecord' ); |
31 | 32 | $invert = $wgRequest->getText( 'wpInvert' ); |
32 | 33 | $title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' ); |
— | — | @@ -37,12 +38,12 @@ |
38 | 39 | if (version_compare(substr($wgVersion, 0, 4), '1.13') > 0) { |
39 | 40 | $wgOut->addHTML( $wgLang->pipeList( array( |
40 | 41 | "<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" |
42 | 43 | ) ) ); |
43 | 44 | } |
44 | 45 | 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" |
47 | 48 | ); |
48 | 49 | } |
49 | 50 | |
— | — | @@ -59,9 +60,16 @@ |
60 | 61 | # Clear any default values |
61 | 62 | $this->populateForm( array() ); |
62 | 63 | |
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 |
64 | 71 | 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 ) ); |
66 | 74 | |
67 | 75 | # Get titles in $wgRecordAdminCategory and build option list |
68 | 76 | $options = ''; |
— | — | @@ -71,19 +79,25 @@ |
72 | 80 | $res = $dbr->select( $cl, 'cl_from', "cl_to = $cat", __METHOD__, array( 'ORDER BY' => 'cl_sortkey' ) ); |
73 | 81 | while ( $row = $dbr->fetchRow( $res ) ) $options .= '<option>' . Title::newFromID( $row[0] )->getText() . '</option>'; |
74 | 82 | |
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 | + ); |
83 | 88 | else { |
84 | 89 | # No records found in $wgRecordAdminCategory |
85 | 90 | $cat = Title::newFromText( $wgRecordAdminCategory, NS_CATEGORY ); |
86 | 91 | $wgOut->AddWikiText( wfMsg( 'recordadmin-categoryempty', $cat->getPrefixedText() ) ); |
87 | 92 | } |
| 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 | + . ' ' |
| 98 | + . Xml::element( 'input', array( 'type' => 'submit', 'value' => wfMsg( 'recordadmin-buttoncreate' ) ) ) |
| 99 | + . '</form>' |
| 100 | + ); |
| 101 | + |
88 | 102 | } |
89 | 103 | |
90 | 104 | # Record type known, but no record selected, render form for searching or creating |
— | — | @@ -103,7 +117,7 @@ |
104 | 118 | |
105 | 119 | # Attempt to create the article |
106 | 120 | $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 ); |
108 | 122 | $text = ''; |
109 | 123 | foreach ( $posted as $k => $v ) if ( $v ) { |
110 | 124 | if ( $this->types[$k] == 'bool' ) $v = 'yes'; |
— | — | @@ -490,6 +504,40 @@ |
491 | 505 | } |
492 | 506 | |
493 | 507 | /** |
| 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 | + /** |
494 | 542 | * Render a record search in a parser-function |
495 | 543 | */ |
496 | 544 | function expandMagic(&$parser, $type) { |
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php |
— | — | @@ -17,8 +17,9 @@ |
18 | 18 | 'recordadmin' => 'Record administration', |
19 | 19 | 'recordadmin-desc' => 'A [[Special:RecordAdmin|special page]] for finding and editing record pages using a form', |
20 | 20 | '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', |
22 | 22 | 'recordadmin-createtype' => 'Enter the name of a new record type to create', |
| 23 | + 'recordadmin-recordtype' => 'record type', |
23 | 24 | 'recordadmin-newsearch' => 'New $1 search', |
24 | 25 | 'recordadmin-newrecord' => 'Select another record type', |
25 | 26 | 'recordadmin-submit' => 'Submit', |