Index: trunk/extensions/SemanticForms/specials/SF_AddData.php |
— | — | @@ -1,211 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Displays a pre-defined form for adding data. |
5 | | - * |
6 | | - * @author Yaron Koren |
7 | | - */ |
8 | | -if (!defined('MEDIAWIKI')) die(); |
9 | | - |
10 | | -class SFAddData extends SpecialPage { |
11 | | - |
12 | | - /** |
13 | | - * Constructor |
14 | | - */ |
15 | | - function SFAddData() { |
16 | | - SpecialPage::SpecialPage('AddData'); |
17 | | - wfLoadExtensionMessages('SemanticForms'); |
18 | | - } |
19 | | - |
20 | | - function execute($query) { |
21 | | - global $wgRequest; |
22 | | - |
23 | | - $this->setHeaders(); |
24 | | - $form_name = $wgRequest->getVal('form'); |
25 | | - $target_name = $wgRequest->getVal('target'); |
26 | | - |
27 | | - // if query string did not contain these variables, try the URL |
28 | | - if (! $form_name && ! $target_name) { |
29 | | - $queryparts = explode('/', $query, 2); |
30 | | - $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
31 | | - $target_name = isset($queryparts[1]) ? $queryparts[1] : ''; |
32 | | - } |
33 | | - |
34 | | - $alt_forms = $wgRequest->getArray('alt_form'); |
35 | | - |
36 | | - self::printAddForm($form_name, $target_name, $alt_forms); |
37 | | - } |
38 | | - |
39 | | - static function printAltFormsList($alt_forms, $target_name) { |
40 | | - $text = ""; |
41 | | - $ad = SpecialPage::getPage('AddData'); |
42 | | - $i = 0; |
43 | | - foreach ($alt_forms as $alt_form) { |
44 | | - if ($i++ > 0) { $text .= ", "; } |
45 | | - $text .= '<a href="' . $ad->getTitle()->getFullURL() . "/" . $alt_form . "/" . $target_name . '">' . str_replace('_', ' ', $alt_form) . "</a>"; |
46 | | - } |
47 | | - return $text; |
48 | | - } |
49 | | - |
50 | | -static function printAddForm($form_name, $target_name, $alt_forms) { |
51 | | - global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $sfgYUIBase; |
52 | | - |
53 | | - wfLoadExtensionMessages('SemanticForms'); |
54 | | - |
55 | | - // initialize some variables |
56 | | - $page_title = null; |
57 | | - $target_title = null; |
58 | | - $page_name_formula = null; |
59 | | - |
60 | | - // get contents of form and target page - if there's only one, |
61 | | - // it might be a target with only alternate forms |
62 | | - if ($form_name == '') { |
63 | | - $wgOut->addHTML( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
64 | | - return; |
65 | | - } elseif ($target_name == '') { |
66 | | - // parse the form to see if it has a 'page name' value set |
67 | | - $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
68 | | - $form_article = new Article($form_title); |
69 | | - $form_definition = $form_article->getContent(); |
70 | | - $form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition); |
71 | | - $matches; |
72 | | - if (preg_match('/{{{info.*page name=([^\|}]*)/m', $form_definition, $matches)) { |
73 | | - $page_name_formula = str_replace('_', ' ', $matches[1]); |
74 | | - } elseif (count($alt_forms) == 0) { |
75 | | - $wgOut->addWikiText( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
76 | | - return; |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
81 | | - |
82 | | - if ($target_name != '') { |
83 | | - $target_title = Title::newFromText($target_name); |
84 | | - $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText()); |
85 | | - $wgOut->setPageTitle($s); |
86 | | - } |
87 | | - |
88 | | - // target_title should be null - we shouldn't be adding a page that |
89 | | - // already exists |
90 | | - if ($target_title && $target_title->exists()) { |
91 | | - $wgOut->addWikiText( "<p class='error'>" . wfMsg('articleexists') . '</p>'); |
92 | | - return; |
93 | | - } elseif ($target_name != '') { |
94 | | - $page_title = str_replace('_', ' ', $target_name); |
95 | | - } |
96 | | - |
97 | | - if (! $form_title || ! $form_title->exists()) { |
98 | | - if ($form_name == '') |
99 | | - $text = '<p class="error">' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
100 | | - else { |
101 | | - if (count($alt_forms) > 0) { |
102 | | - $text .= '<div class="infoMessage">' . wfMsg('sf_adddata_altformsonly') . ' '; |
103 | | - $text .= self::printAltFormsList($alt_forms, $form_name); |
104 | | - $text .= "</div>\n"; |
105 | | - } else |
106 | | - $text = '<p class="error">' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
107 | | - } |
108 | | - } elseif ($target_name == '' && $page_name_formula == '') { |
109 | | - $text = '<p class="error">' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
110 | | - } else { |
111 | | - $form_article = new Article($form_title); |
112 | | - $form_definition = $form_article->getContent(); |
113 | | - |
114 | | - $save_page = $wgRequest->getCheck('wpSave'); |
115 | | - $preview_page = $wgRequest->getCheck('wpPreview'); |
116 | | - $diff_page = $wgRequest->getCheck('wpDiff'); |
117 | | - $form_submitted = ($save_page || $preview_page || $diff_page); |
118 | | - // get 'preload' query value, if it exists |
119 | | - if (! $form_submitted) { |
120 | | - if ($wgRequest->getCheck('preload')) { |
121 | | - $page_is_source = true; |
122 | | - $page_contents = SFFormUtils::getPreloadedText($wgRequest->getVal('preload')); |
123 | | - } else { |
124 | | - // let other extensions preload the page, if they want |
125 | | - wfRunHooks('sfEditFormPreloadText', array(&$page_contents, $target_title, $form_title)); |
126 | | - $page_is_source = ($page_contents != null); |
127 | | - } |
128 | | - } else { |
129 | | - $page_is_source = false; |
130 | | - $page_contents = null; |
131 | | - } |
132 | | - list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
133 | | - $sfgFormPrinter->formHTML($form_definition, $form_article->getID(), $form_submitted, $page_is_source, $page_contents, $page_title, $page_name_formula); |
134 | | - if ($form_submitted) { |
135 | | - if ($page_name_formula != '') { |
136 | | - $target_name = $generated_page_name; |
137 | | - // prepend a super-page, if one was specified |
138 | | - if ($wgRequest->getCheck('super_page')) { |
139 | | - $target_name = $wgRequest->getVal('super_page') . '/' . $target_name; |
140 | | - } |
141 | | - // prepend a namespace, if one was specified |
142 | | - if ($wgRequest->getCheck('namespace')) { |
143 | | - $target_name = $wgRequest->getVal('namespace') . ':' . $target_name; |
144 | | - } |
145 | | - // replace "unique number" tag with one that |
146 | | - // won't get erased by the next line |
147 | | - $target_name = preg_replace('/<unique number(.*)>/', '{num\1}', $target_name, 1); |
148 | | - // if any formula stuff is still in the name |
149 | | - // after the parsing, just remove it |
150 | | - $target_name = StringUtils::delimiterReplace('<', '>', '', $target_name); |
151 | | - if (strpos($target_name, '{num')) { |
152 | | - // get unique number start value from |
153 | | - // target name; if it's not there, or |
154 | | - // it's not a positive number, |
155 | | - // start it out as blank |
156 | | - preg_match('/{num.*start=([^;]*).*}/', $target_name, $matches); |
157 | | - if (count($matches) == 2 && is_numeric($matches[1]) && $matches[1] >= 0) { |
158 | | - $title_number = $matches[1]; |
159 | | - } else { |
160 | | - $title_number = ""; |
161 | | - } |
162 | | - // cycle through numbers for this tag |
163 | | - // until we find one that gives a |
164 | | - // nonexistent page title |
165 | | - do { |
166 | | - $target_title = Title::newFromText(preg_replace('/{num.*}/', $title_number, $target_name)); |
167 | | - // if title number is blank, |
168 | | - // change it to 2; otherwise, |
169 | | - // increment it, and if necessary |
170 | | - // pad it with leading 0s as well |
171 | | - if ($title_number == "") { |
172 | | - $title_number = 2; |
173 | | - } else { |
174 | | - $title_number = str_pad($title_number + 1, strlen($title_number), '0', STR_PAD_LEFT); |
175 | | - } |
176 | | - } while ($target_title->exists()); |
177 | | - } else { |
178 | | - $target_title = Title::newFromText($target_name); |
179 | | - } |
180 | | - } |
181 | | - $wgOut->setArticleBodyOnly( true ); |
182 | | - $text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime')); |
183 | | - } else { |
184 | | - // override the default title for this page if |
185 | | - // a title was specified in the form |
186 | | - if ($form_page_title != null) { |
187 | | - if ($target_name == '') { |
188 | | - $wgOut->setPageTitle($form_page_title); |
189 | | - } else { |
190 | | - $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}"); |
191 | | - } |
192 | | - } |
193 | | - $text = ""; |
194 | | - if (count($alt_forms) > 0) { |
195 | | - $text .= '<div class="infoMessage">' . wfMsg('sf_adddata_altforms') . ' '; |
196 | | - $text .= self::printAltFormsList($alt_forms, $target_name); |
197 | | - $text .= "</div>\n"; |
198 | | - } |
199 | | - $text .=<<<END |
200 | | - <form name="createbox" onsubmit="return validate_all()" action="" method="post" class="createbox"> |
201 | | - |
202 | | -END; |
203 | | - $text .= $form_text; |
204 | | - } |
205 | | - } |
206 | | - SFUtils::addJavascriptAndCSS(); |
207 | | - if (! empty($javascript_text)) |
208 | | - $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n"); |
209 | | - $wgOut->addHTML($text); |
210 | | -} |
211 | | - |
212 | | -} |
Index: trunk/extensions/SemanticForms/specials/SF_FormEdit.php |
— | — | @@ -0,0 +1,211 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Displays a pre-defined form for adding data. |
| 5 | + * |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
| 8 | +if (!defined('MEDIAWIKI')) die(); |
| 9 | + |
| 10 | +class SFAddData extends SpecialPage { |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + */ |
| 15 | + function SFAddData() { |
| 16 | + SpecialPage::SpecialPage('AddData'); |
| 17 | + wfLoadExtensionMessages('SemanticForms'); |
| 18 | + } |
| 19 | + |
| 20 | + function execute($query) { |
| 21 | + global $wgRequest; |
| 22 | + |
| 23 | + $this->setHeaders(); |
| 24 | + $form_name = $wgRequest->getVal('form'); |
| 25 | + $target_name = $wgRequest->getVal('target'); |
| 26 | + |
| 27 | + // if query string did not contain these variables, try the URL |
| 28 | + if (! $form_name && ! $target_name) { |
| 29 | + $queryparts = explode('/', $query, 2); |
| 30 | + $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
| 31 | + $target_name = isset($queryparts[1]) ? $queryparts[1] : ''; |
| 32 | + } |
| 33 | + |
| 34 | + $alt_forms = $wgRequest->getArray('alt_form'); |
| 35 | + |
| 36 | + self::printAddForm($form_name, $target_name, $alt_forms); |
| 37 | + } |
| 38 | + |
| 39 | + static function printAltFormsList($alt_forms, $target_name) { |
| 40 | + $text = ""; |
| 41 | + $ad = SpecialPage::getPage('AddData'); |
| 42 | + $i = 0; |
| 43 | + foreach ($alt_forms as $alt_form) { |
| 44 | + if ($i++ > 0) { $text .= ", "; } |
| 45 | + $text .= '<a href="' . $ad->getTitle()->getFullURL() . "/" . $alt_form . "/" . $target_name . '">' . str_replace('_', ' ', $alt_form) . "</a>"; |
| 46 | + } |
| 47 | + return $text; |
| 48 | + } |
| 49 | + |
| 50 | +static function printAddForm($form_name, $target_name, $alt_forms) { |
| 51 | + global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $sfgYUIBase; |
| 52 | + |
| 53 | + wfLoadExtensionMessages('SemanticForms'); |
| 54 | + |
| 55 | + // initialize some variables |
| 56 | + $page_title = null; |
| 57 | + $target_title = null; |
| 58 | + $page_name_formula = null; |
| 59 | + |
| 60 | + // get contents of form and target page - if there's only one, |
| 61 | + // it might be a target with only alternate forms |
| 62 | + if ($form_name == '') { |
| 63 | + $wgOut->addHTML( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
| 64 | + return; |
| 65 | + } elseif ($target_name == '') { |
| 66 | + // parse the form to see if it has a 'page name' value set |
| 67 | + $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
| 68 | + $form_article = new Article($form_title); |
| 69 | + $form_definition = $form_article->getContent(); |
| 70 | + $form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition); |
| 71 | + $matches; |
| 72 | + if (preg_match('/{{{info.*page name=([^\|}]*)/m', $form_definition, $matches)) { |
| 73 | + $page_name_formula = str_replace('_', ' ', $matches[1]); |
| 74 | + } elseif (count($alt_forms) == 0) { |
| 75 | + $wgOut->addWikiText( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
| 76 | + return; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
| 81 | + |
| 82 | + if ($target_name != '') { |
| 83 | + $target_title = Title::newFromText($target_name); |
| 84 | + $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText()); |
| 85 | + $wgOut->setPageTitle($s); |
| 86 | + } |
| 87 | + |
| 88 | + // target_title should be null - we shouldn't be adding a page that |
| 89 | + // already exists |
| 90 | + if ($target_title && $target_title->exists()) { |
| 91 | + $wgOut->addWikiText( "<p class='error'>" . wfMsg('articleexists') . '</p>'); |
| 92 | + return; |
| 93 | + } elseif ($target_name != '') { |
| 94 | + $page_title = str_replace('_', ' ', $target_name); |
| 95 | + } |
| 96 | + |
| 97 | + if (! $form_title || ! $form_title->exists()) { |
| 98 | + if ($form_name == '') |
| 99 | + $text = '<p class="error">' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
| 100 | + else { |
| 101 | + if (count($alt_forms) > 0) { |
| 102 | + $text .= '<div class="infoMessage">' . wfMsg('sf_adddata_altformsonly') . ' '; |
| 103 | + $text .= self::printAltFormsList($alt_forms, $form_name); |
| 104 | + $text .= "</div>\n"; |
| 105 | + } else |
| 106 | + $text = '<p class="error">' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
| 107 | + } |
| 108 | + } elseif ($target_name == '' && $page_name_formula == '') { |
| 109 | + $text = '<p class="error">' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
| 110 | + } else { |
| 111 | + $form_article = new Article($form_title); |
| 112 | + $form_definition = $form_article->getContent(); |
| 113 | + |
| 114 | + $save_page = $wgRequest->getCheck('wpSave'); |
| 115 | + $preview_page = $wgRequest->getCheck('wpPreview'); |
| 116 | + $diff_page = $wgRequest->getCheck('wpDiff'); |
| 117 | + $form_submitted = ($save_page || $preview_page || $diff_page); |
| 118 | + // get 'preload' query value, if it exists |
| 119 | + if (! $form_submitted) { |
| 120 | + if ($wgRequest->getCheck('preload')) { |
| 121 | + $page_is_source = true; |
| 122 | + $page_contents = SFFormUtils::getPreloadedText($wgRequest->getVal('preload')); |
| 123 | + } else { |
| 124 | + // let other extensions preload the page, if they want |
| 125 | + wfRunHooks('sfEditFormPreloadText', array(&$page_contents, $target_title, $form_title)); |
| 126 | + $page_is_source = ($page_contents != null); |
| 127 | + } |
| 128 | + } else { |
| 129 | + $page_is_source = false; |
| 130 | + $page_contents = null; |
| 131 | + } |
| 132 | + list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
| 133 | + $sfgFormPrinter->formHTML($form_definition, $form_article->getID(), $form_submitted, $page_is_source, $page_contents, $page_title, $page_name_formula); |
| 134 | + if ($form_submitted) { |
| 135 | + if ($page_name_formula != '') { |
| 136 | + $target_name = $generated_page_name; |
| 137 | + // prepend a super-page, if one was specified |
| 138 | + if ($wgRequest->getCheck('super_page')) { |
| 139 | + $target_name = $wgRequest->getVal('super_page') . '/' . $target_name; |
| 140 | + } |
| 141 | + // prepend a namespace, if one was specified |
| 142 | + if ($wgRequest->getCheck('namespace')) { |
| 143 | + $target_name = $wgRequest->getVal('namespace') . ':' . $target_name; |
| 144 | + } |
| 145 | + // replace "unique number" tag with one that |
| 146 | + // won't get erased by the next line |
| 147 | + $target_name = preg_replace('/<unique number(.*)>/', '{num\1}', $target_name, 1); |
| 148 | + // if any formula stuff is still in the name |
| 149 | + // after the parsing, just remove it |
| 150 | + $target_name = StringUtils::delimiterReplace('<', '>', '', $target_name); |
| 151 | + if (strpos($target_name, '{num')) { |
| 152 | + // get unique number start value from |
| 153 | + // target name; if it's not there, or |
| 154 | + // it's not a positive number, |
| 155 | + // start it out as blank |
| 156 | + preg_match('/{num.*start=([^;]*).*}/', $target_name, $matches); |
| 157 | + if (count($matches) == 2 && is_numeric($matches[1]) && $matches[1] >= 0) { |
| 158 | + $title_number = $matches[1]; |
| 159 | + } else { |
| 160 | + $title_number = ""; |
| 161 | + } |
| 162 | + // cycle through numbers for this tag |
| 163 | + // until we find one that gives a |
| 164 | + // nonexistent page title |
| 165 | + do { |
| 166 | + $target_title = Title::newFromText(preg_replace('/{num.*}/', $title_number, $target_name)); |
| 167 | + // if title number is blank, |
| 168 | + // change it to 2; otherwise, |
| 169 | + // increment it, and if necessary |
| 170 | + // pad it with leading 0s as well |
| 171 | + if ($title_number == "") { |
| 172 | + $title_number = 2; |
| 173 | + } else { |
| 174 | + $title_number = str_pad($title_number + 1, strlen($title_number), '0', STR_PAD_LEFT); |
| 175 | + } |
| 176 | + } while ($target_title->exists()); |
| 177 | + } else { |
| 178 | + $target_title = Title::newFromText($target_name); |
| 179 | + } |
| 180 | + } |
| 181 | + $wgOut->setArticleBodyOnly( true ); |
| 182 | + $text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime')); |
| 183 | + } else { |
| 184 | + // override the default title for this page if |
| 185 | + // a title was specified in the form |
| 186 | + if ($form_page_title != null) { |
| 187 | + if ($target_name == '') { |
| 188 | + $wgOut->setPageTitle($form_page_title); |
| 189 | + } else { |
| 190 | + $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}"); |
| 191 | + } |
| 192 | + } |
| 193 | + $text = ""; |
| 194 | + if (count($alt_forms) > 0) { |
| 195 | + $text .= '<div class="infoMessage">' . wfMsg('sf_adddata_altforms') . ' '; |
| 196 | + $text .= self::printAltFormsList($alt_forms, $target_name); |
| 197 | + $text .= "</div>\n"; |
| 198 | + } |
| 199 | + $text .=<<<END |
| 200 | + <form name="createbox" onsubmit="return validate_all()" action="" method="post" class="createbox"> |
| 201 | + |
| 202 | +END; |
| 203 | + $text .= $form_text; |
| 204 | + } |
| 205 | + } |
| 206 | + SFUtils::addJavascriptAndCSS(); |
| 207 | + if (! empty($javascript_text)) |
| 208 | + $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n"); |
| 209 | + $wgOut->addHTML($text); |
| 210 | +} |
| 211 | + |
| 212 | +} |
Property changes on: trunk/extensions/SemanticForms/specials/SF_FormEdit.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 213 | + native |