Index: trunk/extensions/SemanticForms/specials/SF_CreateCategory.php |
— | — | @@ -20,11 +20,6 @@ |
21 | 21 | parent::__construct( 'CreateCategory' ); |
22 | 22 | } |
23 | 23 | |
24 | | - function execute( $query ) { |
25 | | - $this->setHeaders(); |
26 | | - doSpecialCreateCategory(); |
27 | | - } |
28 | | - |
29 | 24 | static function createCategoryText( $default_form, $category_name, $parent_category ) { |
30 | 25 | |
31 | 26 | if ( $default_form === '' ) { |
— | — | @@ -43,86 +38,95 @@ |
44 | 39 | } |
45 | 40 | return $text; |
46 | 41 | } |
47 | | -} |
48 | 42 | |
49 | | -function doSpecialCreateCategory() { |
50 | | - global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; |
| 43 | + function execute( $query ) { |
| 44 | + global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; |
51 | 45 | |
52 | | - # cycle through the query values, setting the appropriate local variables |
53 | | - $category_name = $wgRequest->getVal( 'category_name' ); |
54 | | - $default_form = $wgRequest->getVal( 'default_form' ); |
55 | | - $parent_category = $wgRequest->getVal( 'parent_category' ); |
| 46 | + $this->setHeaders(); |
56 | 47 | |
57 | | - $category_name_error_str = ''; |
58 | | - $save_page = $wgRequest->getCheck( 'wpSave' ); |
59 | | - $preview_page = $wgRequest->getCheck( 'wpPreview' ); |
60 | | - if ( $save_page || $preview_page ) { |
61 | | - # validate category name |
62 | | - if ( $category_name === '' ) { |
63 | | - $category_name_error_str = wfMsg( 'sf_blank_error' ); |
64 | | - } else { |
65 | | - # redirect to wiki interface |
66 | | - $wgOut->setArticleBodyOnly( true ); |
67 | | - $title = Title::makeTitleSafe( NS_CATEGORY, $category_name ); |
68 | | - $full_text = SFCreateCategory::createCategoryText( $default_form, $category_name, $parent_category ); |
69 | | - $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); |
70 | | - $wgOut->addHTML( $text ); |
71 | | - return; |
| 48 | + // Cycle through the query values, setting the appropriate |
| 49 | + // local variables. |
| 50 | + $category_name = $wgRequest->getVal( 'category_name' ); |
| 51 | + $default_form = $wgRequest->getVal( 'default_form' ); |
| 52 | + $parent_category = $wgRequest->getVal( 'parent_category' ); |
| 53 | + |
| 54 | + $category_name_error_str = null; |
| 55 | + $save_page = $wgRequest->getCheck( 'wpSave' ); |
| 56 | + $preview_page = $wgRequest->getCheck( 'wpPreview' ); |
| 57 | + if ( $save_page || $preview_page ) { |
| 58 | + // Validate category name |
| 59 | + if ( $category_name === '' ) { |
| 60 | + $category_name_error_str = wfMsg( 'sf_blank_error' ); |
| 61 | + } else { |
| 62 | + // Redirect to wiki interface |
| 63 | + $wgOut->setArticleBodyOnly( true ); |
| 64 | + $title = Title::makeTitleSafe( NS_CATEGORY, $category_name ); |
| 65 | + $full_text = SFCreateCategory::createCategoryText( $default_form, $category_name, $parent_category ); |
| 66 | + $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); |
| 67 | + $wgOut->addHTML( $text ); |
| 68 | + return; |
| 69 | + } |
72 | 70 | } |
73 | | - } |
74 | 71 | |
75 | | - $all_forms = SFUtils::getAllForms(); |
| 72 | + $all_forms = SFUtils::getAllForms(); |
76 | 73 | |
77 | | - // set 'title' as hidden field, in case there's no URL niceness |
78 | | - global $wgContLang; |
79 | | - $mw_namespace_labels = $wgContLang->getNamespaces(); |
80 | | - $special_namespace = $mw_namespace_labels[NS_SPECIAL]; |
81 | | - $name_label = wfMsg( 'sf_createcategory_name' ); |
82 | | - $form_label = wfMsg( 'sf_createcategory_defaultform' ); |
83 | | - $text = <<<END |
| 74 | + // Set 'title' as hidden field, in case there's no URL niceness |
| 75 | + global $wgContLang; |
| 76 | + $mw_namespace_labels = $wgContLang->getNamespaces(); |
| 77 | + $special_namespace = $mw_namespace_labels[NS_SPECIAL]; |
| 78 | + $text = <<<END |
84 | 79 | <form action="" method="get"> |
85 | 80 | |
86 | 81 | END; |
87 | | - $text .= SFFormUtils::hiddenFieldHTML( 'title', "$special_namespace:CreateCategory" ); |
88 | | - $text .= <<<END |
89 | | - <p>$name_label <input size="25" name="category_name" value="" /> |
90 | | - <span style="color: red;">$category_name_error_str</span> |
91 | | - $form_label |
92 | | - <select id="form_dropdown" name="default_form"> |
93 | | - <option></option> |
| 82 | + $text .= SFFormUtils::hiddenFieldHTML( 'title', "$special_namespace:CreateCategory" ); |
| 83 | + $firstRow = wfMsg( 'sf_createcategory_name' ) . ' ' . |
| 84 | + Xml::element( 'input', |
| 85 | + array( |
| 86 | + 'size' => 25, |
| 87 | + 'name' => 'category_name', |
| 88 | + ), null ) . "\n"; |
| 89 | + if ( !is_null( $category_name_error_str ) ) { |
| 90 | + $firstRow .= Xml::element( 'span', |
| 91 | + array( 'style' => 'color: red;' ), |
| 92 | + $category_name_error_str ) . "\n"; |
| 93 | + } |
| 94 | + $firstRow .= "\t" . wfMsg( 'sf_createcategory_defaultform' ) . "\n"; |
| 95 | + $formSelector = "\t" . Xml::element( 'option', null, null ). "\n"; |
| 96 | + foreach ( $all_forms as $form ) { |
| 97 | + $formSelector .= "\t" . Xml::element( 'option', null, $form ) . "\n"; |
| 98 | + } |
94 | 99 | |
95 | | -END; |
96 | | - foreach ( $all_forms as $form ) { |
97 | | - $text .= "\t" . Xml::element( 'option', null, $form ) . "\n"; |
98 | | - } |
99 | | - |
100 | | - $subcategory_label = wfMsg( 'sf_createcategory_makesubcategory' ); |
101 | | - $categories = SFUtils::getCategoriesForPage(); |
102 | | - $sk = $wgUser->getSkin(); |
103 | | - $create_form_link = SFUtils::linkForSpecialPage( $sk, 'CreateForm' ); |
104 | | - $text .= <<<END |
105 | | - </select> |
| 100 | + $firstRow .= Xml::tags( 'select', |
| 101 | + array( 'id' => 'form_dropdown', 'name' => 'default_form' ), |
| 102 | + $formSelector ); |
| 103 | + $text .= Xml::tags( 'p', null, $firstRow ); |
| 104 | + $subcategory_label = wfMsg( 'sf_createcategory_makesubcategory' ); |
| 105 | + $text .= <<<END |
106 | 106 | <p>$subcategory_label |
107 | 107 | <select id="category_dropdown" name="parent_category"> |
108 | 108 | <option></option> |
109 | 109 | |
110 | 110 | END; |
111 | | - foreach ( $categories as $category ) { |
112 | | - $category = str_replace( '_', ' ', $category ); |
113 | | - $text .= "\t" . Xml::element( 'option', null, $category ) . "\n"; |
114 | | - } |
115 | | - $text .= "\t</select>\n"; |
116 | | - $editButtonsText = "\t" . Xml::element( 'input', array( 'type' => 'submit', 'id' => 'wpSave', 'name' => 'wpSave', 'value' => wfMsg( 'savearticle' ) ) ) . "\n"; |
117 | | - $editButtonsText .= "\t" . Xml::element( 'input', array( 'type' => 'submit', 'id' => 'wpPreview', 'name' => 'wpPreview', 'value' => wfMsg( 'preview' ) ) ) . "\n"; |
118 | | - $text .= "\t" . Xml::tags( 'div', array( 'class' => 'editButtons' ), $editButtonsText ) . "\n"; |
119 | | - $text .= <<<END |
| 111 | + $categories = SFUtils::getCategoriesForPage(); |
| 112 | + foreach ( $categories as $category ) { |
| 113 | + $category = str_replace( '_', ' ', $category ); |
| 114 | + $text .= "\t" . Xml::element( 'option', null, $category ) . "\n"; |
| 115 | + } |
| 116 | + $text .= "\t</select>\n"; |
| 117 | + $editButtonsText = "\t" . Xml::element( 'input', array( 'type' => 'submit', 'id' => 'wpSave', 'name' => 'wpSave', 'value' => wfMsg( 'savearticle' ) ) ) . "\n"; |
| 118 | + $editButtonsText .= "\t" . Xml::element( 'input', array( 'type' => 'submit', 'id' => 'wpPreview', 'name' => 'wpPreview', 'value' => wfMsg( 'preview' ) ) ) . "\n"; |
| 119 | + $text .= "\t" . Xml::tags( 'div', array( 'class' => 'editButtons' ), $editButtonsText ) . "\n"; |
| 120 | + $text .= <<<END |
120 | 121 | <br /><hr /<br /> |
121 | 122 | |
122 | 123 | END; |
123 | 124 | |
124 | | - $text .= " " . Xml::tags( 'p', null, $create_form_link . '.' ) . "\n"; |
125 | | - $text .= " </form>\n"; |
| 125 | + $sk = $wgUser->getSkin(); |
| 126 | + $create_form_link = SFUtils::linkForSpecialPage( $sk, 'CreateForm' ); |
| 127 | + $text .= "\t" . Xml::tags( 'p', null, $create_form_link . '.' ) . "\n"; |
| 128 | + $text .= "\t</form>\n"; |
126 | 129 | |
127 | | - $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); |
128 | | - $wgOut->addHTML( $text ); |
| 130 | + $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); |
| 131 | + $wgOut->addHTML( $text ); |
| 132 | + } |
129 | 133 | } |