Index: trunk/extensions/SemanticForms/specials/SF_AddPage.php |
— | — | @@ -1,202 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Displays a form for entering the title of a page, which then redirects |
5 | | - * to either the form for adding the page, or a form for editing it, |
6 | | - * depending on whether the page already exists. |
7 | | - * |
8 | | - * @author Yaron Koren |
9 | | - * @author Jeffrey Stuckman |
10 | | - */ |
11 | | -if (!defined('MEDIAWIKI')) die(); |
12 | | - |
13 | | -class SFAddPage extends SpecialPage { |
14 | | - |
15 | | - /** |
16 | | - * Constructor |
17 | | - */ |
18 | | - function SFAddPage() { |
19 | | - SpecialPage::SpecialPage('AddPage'); |
20 | | - wfLoadExtensionMessages('SemanticForms'); |
21 | | - } |
22 | | - |
23 | | - function execute($query) { |
24 | | - $this->setHeaders(); |
25 | | - doSpecialAddPage($query); |
26 | | - } |
27 | | - |
28 | | - function doRedirect($form_name, $page_name, $params) { |
29 | | - global $wgOut; |
30 | | - |
31 | | - $page_title = Title::newFromText($page_name); |
32 | | - if ($page_title->exists()) { |
33 | | - // it exists - see if page is a redirect; if |
34 | | - // it is, edit the target page instead |
35 | | - $article = new Article($page_title); |
36 | | - $article->loadContent(); |
37 | | - $redirect_title = Title::newFromRedirect($article->fetchContent()); |
38 | | - if ($redirect_title != null) { |
39 | | - $page_title = $redirect_title; |
40 | | - } |
41 | | - // HACK - if this is the default form for |
42 | | - // this page, send to the regular 'formedit' |
43 | | - // tab page; otherwise, send to the 'Special:EditData' |
44 | | - // page, with the form name hardcoded. |
45 | | - // Is this logic necessary? Or should we just |
46 | | - // out-guess the user and always send to the |
47 | | - // standard form-edit page, with the 'correct' form? |
48 | | - $default_forms = SFLinkUtils::getFormsForArticle($article); |
49 | | - if (count($default_forms) > 0) |
50 | | - $default_form_name = $default_forms[0]; |
51 | | - else |
52 | | - $default_form_name = null; |
53 | | - if ($form_name == $default_form_name) { |
54 | | - $redirect_url = $page_title->getLocalURL('action=formedit'); |
55 | | - } else { |
56 | | - $ed = SpecialPage::getPage('EditData'); |
57 | | - $redirect_url = $ed->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
58 | | - } |
59 | | - } else { |
60 | | - $ad = SpecialPage::getPage('AddData'); |
61 | | - $redirect_url = $ad->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
62 | | - // of all the request values, send on to |
63 | | - // 'AddData' only 'preload' and specific form |
64 | | - // fields - we can tell the latter because |
65 | | - // they show up as 'arrays' |
66 | | - foreach ($_REQUEST as $key => $val) { |
67 | | - if (is_array($val)) { |
68 | | - $template_name = $key; |
69 | | - foreach ($val as $field_name => $value) { |
70 | | - $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
71 | | - $redirect_url .= $template_name . '[' . $field_name . ']=' . $value; |
72 | | - } |
73 | | - } elseif ($key == 'preload') { |
74 | | - $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
75 | | - $redirect_url .= "$key=$val"; |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - if ('' != $params) { |
81 | | - $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
82 | | - $redirect_url .= $params; |
83 | | - } |
84 | | - |
85 | | - $wgOut->setArticleBodyOnly( true ); |
86 | | - // show "loading" animated image while people wait for the redirect |
87 | | - global $sfgScriptPath; |
88 | | - $text = "<p style=\"position: absolute; left: 45%; top: 45%;\"><img src=\"$sfgScriptPath/skins/loading.gif\" /></p>\n"; |
89 | | - $text .=<<<END |
90 | | - <script type="text/javascript"> |
91 | | - window.onload = function() { |
92 | | - window.location="$redirect_url"; |
93 | | - } |
94 | | - </script> |
95 | | - |
96 | | -END; |
97 | | - $wgOut->addHTML($text); |
98 | | - return; |
99 | | - } |
100 | | -} |
101 | | - |
102 | | -function doSpecialAddPage($query = '') { |
103 | | - global $wgOut, $wgRequest, $sfgScriptPath; |
104 | | - |
105 | | - wfLoadExtensionMessages('SemanticForms'); |
106 | | - |
107 | | - $form_name = $wgRequest->getVal('form'); |
108 | | - $target_namespace = $wgRequest->getVal('namespace'); |
109 | | - $super_page = $wgRequest->getVal('super_page'); |
110 | | - $params = $wgRequest->getVal('params'); |
111 | | - |
112 | | - // if query string did not contain form name, try the URL |
113 | | - if (! $form_name) { |
114 | | - $queryparts = explode('/', $query, 2); |
115 | | - $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
116 | | - // if a target was specified, it means we should redirect |
117 | | - // to either 'AddData' or 'EditData' for this target page |
118 | | - if (isset($queryparts[1])) { |
119 | | - $target_name = $queryparts[1]; |
120 | | - SFAddPage::doRedirect($form_name, $target_name, $params); |
121 | | - } |
122 | | - |
123 | | - // get namespace from the URL, if it's there |
124 | | - if ($namespace_label_loc = strpos($form_name, "/Namespace:")) { |
125 | | - $target_namespace = substr($form_name, $namespace_label_loc + 11); |
126 | | - $form_name = substr($form_name, 0, $namespace_label_loc); |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - // remove forbidden characters from form name |
131 | | - $forbidden_chars = array('"', "'", '<', '>', '{', '}', '(', ')', '[', ']', '='); |
132 | | - $form_name = str_replace($forbidden_chars, "", $form_name); |
133 | | - |
134 | | - // get title of form |
135 | | - $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
136 | | - |
137 | | - // handle submission |
138 | | - $form_submitted = $wgRequest->getCheck('page_name'); |
139 | | - if ($form_submitted) { |
140 | | - $page_name = $wgRequest->getVal('page_name'); |
141 | | - // This form can be used to create a sub-page for an |
142 | | - // existing page |
143 | | - if ('' != $super_page) |
144 | | - { |
145 | | - $page_name = "$super_page/$page_name"; |
146 | | - } |
147 | | - if ('' != $page_name) { |
148 | | - // Append the namespace prefix to the page name, |
149 | | - // if a namespace was not already entered. |
150 | | - if (strpos($page_name,":") === false && $target_namespace != '') |
151 | | - $page_name = $target_namespace . ":" . $page_name; |
152 | | - // find out whether this page already exists, |
153 | | - // and send user to the appropriate form |
154 | | - $page_title = Title::newFromText($page_name); |
155 | | - if (! $page_title) { |
156 | | - // if there was no page title, it's probably |
157 | | - // an invalid page name, containing forbidden |
158 | | - // characters |
159 | | - $error_msg = wfMsg('sf_addpage_badtitle', $page_name); |
160 | | - $wgOut->addHTML($error_msg); |
161 | | - return; |
162 | | - } else { |
163 | | - SFAddPage::doRedirect($form_name, $page_name, $params); |
164 | | - return; |
165 | | - } |
166 | | - } |
167 | | - } |
168 | | - |
169 | | - if ((! $form_title || ! $form_title->exists()) && ($form_name != '')) { |
170 | | - $text = '<p>' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
171 | | - } else { |
172 | | - if ($form_name == '') |
173 | | - $description = wfMsg('sf_addpage_noform_docu', $form_name); |
174 | | - else |
175 | | - $description = wfMsg('sf_addpage_docu', $form_name); |
176 | | - $button_text = wfMsg('addoreditdata'); |
177 | | - $text =<<<END |
178 | | - <form action="" method="post"> |
179 | | - <p>$description</p> |
180 | | - <p><input type="text" size="40" name="page_name"> |
181 | | - |
182 | | -END; |
183 | | - // if no form was specified, display a dropdown letting |
184 | | - // the user choose the form |
185 | | - if ($form_name == '') |
186 | | - $text .= SFUtils::formDropdownHTML(); |
187 | | - |
188 | | - $hidden_target_namespace = htmlspecialchars($target_namespace); |
189 | | - $hidden_super_page = htmlspecialchars($super_page); |
190 | | - $hidden_params = htmlspecialchars($params); |
191 | | - |
192 | | - $text .=<<<END |
193 | | - </p> |
194 | | - <input type="hidden" name="namespace" value="$hidden_target_namespace"> |
195 | | - <input type="hidden" name="super_page" value="$hidden_super_page"> |
196 | | - <input type="hidden" name="params" value="$hidden_params"> |
197 | | - <input type="Submit" value="$button_text"> |
198 | | - </form> |
199 | | - |
200 | | -END; |
201 | | - } |
202 | | - $wgOut->addHTML($text); |
203 | | -} |
Index: trunk/extensions/SemanticForms/specials/SF_FormStart.php |
— | — | @@ -0,0 +1,202 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Displays a form for entering the title of a page, which then redirects |
| 5 | + * to either the form for adding the page, or a form for editing it, |
| 6 | + * depending on whether the page already exists. |
| 7 | + * |
| 8 | + * @author Yaron Koren |
| 9 | + * @author Jeffrey Stuckman |
| 10 | + */ |
| 11 | +if (!defined('MEDIAWIKI')) die(); |
| 12 | + |
| 13 | +class SFAddPage extends SpecialPage { |
| 14 | + |
| 15 | + /** |
| 16 | + * Constructor |
| 17 | + */ |
| 18 | + function SFAddPage() { |
| 19 | + SpecialPage::SpecialPage('AddPage'); |
| 20 | + wfLoadExtensionMessages('SemanticForms'); |
| 21 | + } |
| 22 | + |
| 23 | + function execute($query) { |
| 24 | + $this->setHeaders(); |
| 25 | + doSpecialAddPage($query); |
| 26 | + } |
| 27 | + |
| 28 | + function doRedirect($form_name, $page_name, $params) { |
| 29 | + global $wgOut; |
| 30 | + |
| 31 | + $page_title = Title::newFromText($page_name); |
| 32 | + if ($page_title->exists()) { |
| 33 | + // it exists - see if page is a redirect; if |
| 34 | + // it is, edit the target page instead |
| 35 | + $article = new Article($page_title); |
| 36 | + $article->loadContent(); |
| 37 | + $redirect_title = Title::newFromRedirect($article->fetchContent()); |
| 38 | + if ($redirect_title != null) { |
| 39 | + $page_title = $redirect_title; |
| 40 | + } |
| 41 | + // HACK - if this is the default form for |
| 42 | + // this page, send to the regular 'formedit' |
| 43 | + // tab page; otherwise, send to the 'Special:EditData' |
| 44 | + // page, with the form name hardcoded. |
| 45 | + // Is this logic necessary? Or should we just |
| 46 | + // out-guess the user and always send to the |
| 47 | + // standard form-edit page, with the 'correct' form? |
| 48 | + $default_forms = SFLinkUtils::getFormsForArticle($article); |
| 49 | + if (count($default_forms) > 0) |
| 50 | + $default_form_name = $default_forms[0]; |
| 51 | + else |
| 52 | + $default_form_name = null; |
| 53 | + if ($form_name == $default_form_name) { |
| 54 | + $redirect_url = $page_title->getLocalURL('action=formedit'); |
| 55 | + } else { |
| 56 | + $ed = SpecialPage::getPage('EditData'); |
| 57 | + $redirect_url = $ed->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
| 58 | + } |
| 59 | + } else { |
| 60 | + $ad = SpecialPage::getPage('AddData'); |
| 61 | + $redirect_url = $ad->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
| 62 | + // of all the request values, send on to |
| 63 | + // 'AddData' only 'preload' and specific form |
| 64 | + // fields - we can tell the latter because |
| 65 | + // they show up as 'arrays' |
| 66 | + foreach ($_REQUEST as $key => $val) { |
| 67 | + if (is_array($val)) { |
| 68 | + $template_name = $key; |
| 69 | + foreach ($val as $field_name => $value) { |
| 70 | + $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
| 71 | + $redirect_url .= $template_name . '[' . $field_name . ']=' . $value; |
| 72 | + } |
| 73 | + } elseif ($key == 'preload') { |
| 74 | + $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
| 75 | + $redirect_url .= "$key=$val"; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + if ('' != $params) { |
| 81 | + $redirect_url .= (strpos($redirect_url, "?") > -1) ? '&' : '?'; |
| 82 | + $redirect_url .= $params; |
| 83 | + } |
| 84 | + |
| 85 | + $wgOut->setArticleBodyOnly( true ); |
| 86 | + // show "loading" animated image while people wait for the redirect |
| 87 | + global $sfgScriptPath; |
| 88 | + $text = "<p style=\"position: absolute; left: 45%; top: 45%;\"><img src=\"$sfgScriptPath/skins/loading.gif\" /></p>\n"; |
| 89 | + $text .=<<<END |
| 90 | + <script type="text/javascript"> |
| 91 | + window.onload = function() { |
| 92 | + window.location="$redirect_url"; |
| 93 | + } |
| 94 | + </script> |
| 95 | + |
| 96 | +END; |
| 97 | + $wgOut->addHTML($text); |
| 98 | + return; |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +function doSpecialAddPage($query = '') { |
| 103 | + global $wgOut, $wgRequest, $sfgScriptPath; |
| 104 | + |
| 105 | + wfLoadExtensionMessages('SemanticForms'); |
| 106 | + |
| 107 | + $form_name = $wgRequest->getVal('form'); |
| 108 | + $target_namespace = $wgRequest->getVal('namespace'); |
| 109 | + $super_page = $wgRequest->getVal('super_page'); |
| 110 | + $params = $wgRequest->getVal('params'); |
| 111 | + |
| 112 | + // if query string did not contain form name, try the URL |
| 113 | + if (! $form_name) { |
| 114 | + $queryparts = explode('/', $query, 2); |
| 115 | + $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
| 116 | + // if a target was specified, it means we should redirect |
| 117 | + // to either 'AddData' or 'EditData' for this target page |
| 118 | + if (isset($queryparts[1])) { |
| 119 | + $target_name = $queryparts[1]; |
| 120 | + SFAddPage::doRedirect($form_name, $target_name, $params); |
| 121 | + } |
| 122 | + |
| 123 | + // get namespace from the URL, if it's there |
| 124 | + if ($namespace_label_loc = strpos($form_name, "/Namespace:")) { |
| 125 | + $target_namespace = substr($form_name, $namespace_label_loc + 11); |
| 126 | + $form_name = substr($form_name, 0, $namespace_label_loc); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + // remove forbidden characters from form name |
| 131 | + $forbidden_chars = array('"', "'", '<', '>', '{', '}', '(', ')', '[', ']', '='); |
| 132 | + $form_name = str_replace($forbidden_chars, "", $form_name); |
| 133 | + |
| 134 | + // get title of form |
| 135 | + $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
| 136 | + |
| 137 | + // handle submission |
| 138 | + $form_submitted = $wgRequest->getCheck('page_name'); |
| 139 | + if ($form_submitted) { |
| 140 | + $page_name = $wgRequest->getVal('page_name'); |
| 141 | + // This form can be used to create a sub-page for an |
| 142 | + // existing page |
| 143 | + if ('' != $super_page) |
| 144 | + { |
| 145 | + $page_name = "$super_page/$page_name"; |
| 146 | + } |
| 147 | + if ('' != $page_name) { |
| 148 | + // Append the namespace prefix to the page name, |
| 149 | + // if a namespace was not already entered. |
| 150 | + if (strpos($page_name,":") === false && $target_namespace != '') |
| 151 | + $page_name = $target_namespace . ":" . $page_name; |
| 152 | + // find out whether this page already exists, |
| 153 | + // and send user to the appropriate form |
| 154 | + $page_title = Title::newFromText($page_name); |
| 155 | + if (! $page_title) { |
| 156 | + // if there was no page title, it's probably |
| 157 | + // an invalid page name, containing forbidden |
| 158 | + // characters |
| 159 | + $error_msg = wfMsg('sf_addpage_badtitle', $page_name); |
| 160 | + $wgOut->addHTML($error_msg); |
| 161 | + return; |
| 162 | + } else { |
| 163 | + SFAddPage::doRedirect($form_name, $page_name, $params); |
| 164 | + return; |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + if ((! $form_title || ! $form_title->exists()) && ($form_name != '')) { |
| 170 | + $text = '<p>' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
| 171 | + } else { |
| 172 | + if ($form_name == '') |
| 173 | + $description = wfMsg('sf_addpage_noform_docu', $form_name); |
| 174 | + else |
| 175 | + $description = wfMsg('sf_addpage_docu', $form_name); |
| 176 | + $button_text = wfMsg('addoreditdata'); |
| 177 | + $text =<<<END |
| 178 | + <form action="" method="post"> |
| 179 | + <p>$description</p> |
| 180 | + <p><input type="text" size="40" name="page_name"> |
| 181 | + |
| 182 | +END; |
| 183 | + // if no form was specified, display a dropdown letting |
| 184 | + // the user choose the form |
| 185 | + if ($form_name == '') |
| 186 | + $text .= SFUtils::formDropdownHTML(); |
| 187 | + |
| 188 | + $hidden_target_namespace = htmlspecialchars($target_namespace); |
| 189 | + $hidden_super_page = htmlspecialchars($super_page); |
| 190 | + $hidden_params = htmlspecialchars($params); |
| 191 | + |
| 192 | + $text .=<<<END |
| 193 | + </p> |
| 194 | + <input type="hidden" name="namespace" value="$hidden_target_namespace"> |
| 195 | + <input type="hidden" name="super_page" value="$hidden_super_page"> |
| 196 | + <input type="hidden" name="params" value="$hidden_params"> |
| 197 | + <input type="Submit" value="$button_text"> |
| 198 | + </form> |
| 199 | + |
| 200 | +END; |
| 201 | + } |
| 202 | + $wgOut->addHTML($text); |
| 203 | +} |
Property changes on: trunk/extensions/SemanticForms/specials/SF_FormStart.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 204 | + native |