r92609 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92608‎ | r92609 | r92610 >
Date:04:28, 20 July 2011
Author:yaron
Status:deferred (Comments)
Tags:
Comment:
Added three new methods to SFForm: setPageNameFormula(), setCreateTitle() and setEditTitle(), for use in creating the form definition; also renamed some existing class fields.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormClasses.php (modified) (history)
  • /trunk/extensions/SemanticForms/specials/SF_CreateForm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_CreateForm.php
@@ -206,12 +206,12 @@
207207 $preview_page = $wgRequest->getCheck( 'wpPreview' );
208208 if ( $save_page || $preview_page ) {
209209 // Validate form name
210 - if ( $form->form_name == "" ) {
 210+ if ( $form->mFormName == "" ) {
211211 $form_name_error_str = wfMsg( 'sf_blank_error' );
212212 } else {
213213 // Redirect to wiki interface
214214 $wgOut->setArticleBodyOnly( true );
215 - $title = Title::makeTitleSafe( SF_NS_FORM, $form->form_name );
 215+ $title = Title::makeTitleSafe( SF_NS_FORM, $form->mFormName );
216216 $full_text = $form->createMarkup();
217217 $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null );
218218 $wgOut->addHTML( $text );
Index: trunk/extensions/SemanticForms/includes/SF_FormClasses.php
@@ -13,30 +13,45 @@
1414 * @ingroup SF
1515 */
1616 class SFForm {
17 - var $form_name;
18 - var $templates;
 17+ var $mFormName = null;
 18+ var $mTemplates = null;
 19+ var $mPageNameFormula = null;
 20+ var $mCreateTitle = null;
 21+ var $mEditTitle = null;
1922
20 - static function create( $form_name, $templates ) {
 23+ static function create( $formName, $templates ) {
2124 $form = new SFForm();
22 - $form->form_name = ucfirst( str_replace( '_', ' ', $form_name ) );
23 - $form->templates = $templates;
 25+ $form->mFormName = ucfirst( str_replace( '_', ' ', $formName ) );
 26+ $form->mTemplates = $templates;
2427 return $form;
2528 }
2629
 30+ function setPageNameFormula( $pageNameFormula ) {
 31+ $this->mPageNameFormula = $pageNameFormula;
 32+ }
 33+
 34+ function setCreateTitle( $createTitle ) {
 35+ $this->mCreateTitle = $createTitle;
 36+ }
 37+
 38+ function setEditTitle( $editTitle ) {
 39+ $this->mEditTitle = $editTitle;
 40+ }
 41+
2742 function creationHTML() {
2843 $text = "";
29 - foreach ( $this->templates as $i => $ft ) {
 44+ foreach ( $this->mTemplates as $i => $ft ) {
3045 $text .= $ft->creationHTML( $i );
3146 }
3247 return $text;
3348 }
3449
3550 function createMarkup() {
36 - $title = Title::makeTitle( SF_NS_FORM, $this->form_name );
 51+ $title = Title::makeTitle( SF_NS_FORM, $this->mFormName );
3752 $fs = SpecialPage::getPage( 'FormStart' );
3853 $form_start_url = SFUtils::titleURLString( $fs->getTitle() ) . "/" . $title->getPartialURL();
39 - $form_description = wfMsgForContent( 'sf_form_docu', $this->form_name, $form_start_url );
40 - $form_input = "{{#forminput:form=" . $this->form_name . "}}\n";
 54+ $form_description = wfMsgForContent( 'sf_form_docu', $this->mFormName, $form_start_url );
 55+ $form_input = "{{#forminput:form=" . $this->mFormName . "}}\n";
4156 $text = <<<END
4257 <noinclude>
4358 $form_description
@@ -44,10 +59,26 @@
4560
4661 $form_input
4762 </noinclude><includeonly>
 63+
 64+END;
 65+ if ( !empty( $this->mPageNameFormula ) || !empty( $this->mCreateTitle ) || !empty( $this->mEditTitle ) ) {
 66+ $text .= "{{{info";
 67+ if ( !empty( $this->mPageNameFormula ) ) {
 68+ $text .= "|page name=" . $this->mPageNameFormula;
 69+ }
 70+ if ( !empty( $this->mCreateTitle ) ) {
 71+ $text .= "|create title=" . $this->mCreateTitle;
 72+ }
 73+ if ( !empty( $this->mEditTitle ) ) {
 74+ $text .= "|edit title=" . $this->mEditTitle;
 75+ }
 76+ $text .= "}}}\n";
 77+ }
 78+ $text .= <<<END
4879 <div id="wikiPreview" style="display: none; padding-bottom: 25px; margin-bottom: 25px; border-bottom: 1px solid #AAAAAA;"></div>
4980
5081 END;
51 - foreach ( $this->templates as $template ) {
 82+ foreach ( $this->mTemplates as $template ) {
5283 $text .= $template->createMarkup() . "\n";
5384 }
5485 $free_text_label = wfMsgForContent( 'sf_form_freetextlabel' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r93040Follow-up to r92609 - made all class fields private, removed unnecessary init...yaron04:14, 25 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:35, 20 July 2011

Is SMW still using var? I don't see the reason to add explicit null initializations, since it is the default anyway. Btw would be useful to document the member variables.

#Comment by Yaron Koren (talk | contribs)   12:49, 20 July 2011

Hi, I don't understand the "var" question - is there a preferred declaration to use instead? Also, how does Semantic MediaWiki relate to this? (This is part of the Semantic Forms extension.)

#Comment by Nikerabbit (talk | contribs)   12:50, 20 July 2011

In PHP4 all member variables were declared with var. In PHP5 we use protected/public/private instead.