68 '); |
68 '); |
69 |
69 |
70 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace> |
70 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace> |
71 |
71 |
72 function page_Special_CreatePage() |
72 function page_Special_CreatePage() |
|
73 { |
|
74 global $db, $session, $paths, $template, $plugins; // Common objects |
|
75 global $lang; |
|
76 |
|
77 $whitelist_ns = array('Article', 'User', 'Help', 'Template', 'Category', 'Project'); |
|
78 $code = $plugins->setHook('page_create_ns_whitelist'); |
|
79 foreach ( $code as $cmd ) |
|
80 { |
|
81 eval($cmd); |
|
82 } |
|
83 |
|
84 $errors = array(); |
|
85 |
|
86 switch ( isset($_POST['page_title']) ) |
|
87 { |
|
88 case true: |
|
89 // "Create page" was clicked |
|
90 |
|
91 // |
|
92 // VALIDATION CODE |
|
93 // |
|
94 |
|
95 // Check namespace |
|
96 $namespace = ( isset($_POST['namespace']) ) ? $_POST['namespace'] : 'Article'; |
|
97 if ( !in_array($namespace, $whitelist_ns) ) |
|
98 { |
|
99 $errors[] = $lang->get('pagetools_create_err_invalid_namespace'); |
|
100 } |
|
101 |
|
102 // Check title and figure out urlname |
|
103 $title = $_POST['page_title']; |
|
104 $urlname = $_POST['page_title']; |
|
105 if ( @$_POST['custom_url'] === 'yes' && isset($_POST['urlname']) ) |
|
106 { |
|
107 $urlname = $_POST['urlname']; |
|
108 } |
|
109 $urlname = sanitize_page_id($urlname); |
|
110 if ( $urlname == '.00' || empty($urlname) ) |
|
111 { |
|
112 $errors[] = $lang->get('pagetools_create_err_invalid_urlname'); |
|
113 } |
|
114 |
|
115 // Validate page existence |
|
116 $pathskey = $paths->nslist[$namespace] . $urlname; |
|
117 if ( isPage($pathskey) ) |
|
118 { |
|
119 $errors[] = $lang->get('pagetools_create_err_already_exists'); |
|
120 } |
|
121 |
|
122 // Validate permissions |
|
123 $perms = $session->fetch_page_acl($urlname, $namespace); |
|
124 if ( !$perms->get_permissions('create_page') ) |
|
125 { |
|
126 $errors[] = $lang->get('pagetools_create_err_no_permission'); |
|
127 } |
|
128 |
|
129 // Run hooks |
|
130 $code = $plugins->setHook('page_create_request'); |
|
131 foreach ( $code as $cmd ) |
|
132 { |
|
133 eval($cmd); |
|
134 } |
|
135 |
|
136 // Create the page |
|
137 if ( count($errors) < 1 ) |
|
138 { |
|
139 $page = new PageProcessor($urlname, $namespace); |
|
140 $page->create_page($title); |
|
141 if ( $error = $page->pop_error() ) |
|
142 { |
|
143 do |
|
144 { |
|
145 $errors[] = $error; |
|
146 } |
|
147 while ( $error = $page->pop_error() ); |
|
148 } |
|
149 else |
|
150 { |
|
151 redirect(makeUrlNS($namespace, $urlname) . '#do:edit', '', '', 0); |
|
152 return true; |
|
153 } |
|
154 } |
|
155 |
|
156 break; |
|
157 } |
|
158 |
|
159 $template->header(); |
|
160 |
|
161 echo $lang->get('pagetools_create_blurb'); |
|
162 |
|
163 if ( count($errors) > 0 ) |
|
164 { |
|
165 echo '<div class="error-box">' . implode("<br />\n ", $errors) . '</div>'; |
|
166 } |
|
167 |
|
168 ?> |
|
169 <enano:no-opt> |
|
170 <script type="text/javascript"> |
|
171 function cpGenPreviewUrl() |
|
172 { |
|
173 var frm = document.forms['create_form']; |
|
174 var radio_custom = frm.getElementsByTagName('input')[2]; |
|
175 var use_custom_url = radio_custom.checked; |
|
176 if ( use_custom_url ) |
|
177 { |
|
178 var title_src = frm.urlname.value; |
|
179 } |
|
180 else |
|
181 { |
|
182 var title_src = frm.page_title.value; |
|
183 } |
|
184 var url = window.location.protocol + '//' + window.location.hostname + contentPath + namespace_list[frm.namespace.value] + sanitize_page_id(title_src); |
|
185 document.getElementById('createpage_url_preview').firstChild.nodeValue = url; |
|
186 } |
|
187 </script> |
|
188 </enano:no-opt> |
|
189 <?php |
|
190 |
|
191 echo '<form action="' . makeUrlNS('Special', 'CreatePage') . '" method="post" name="create_form">'; |
|
192 |
|
193 echo '<p>'; |
|
194 echo $lang->get('pagetools_create_field_title'); |
|
195 echo ' <input onkeyup="cpGenPreviewUrl();" type="text" name="page_title" size="40" tabindex="1" />'; |
|
196 echo '</p>'; |
|
197 |
|
198 echo '<p>'; |
|
199 echo $lang->get('pagetools_create_field_namespace'); |
|
200 echo ' <select onchange="cpGenPreviewUrl();" name="namespace" tabindex="2">'; |
|
201 foreach ( $paths->nslist as $ns => $ns_prefix ) |
|
202 { |
|
203 if ( !in_array($ns, $whitelist_ns) ) |
|
204 continue; |
|
205 $lang_string = 'onpage_lbl_page_' . strtolower($ns); |
|
206 $str = $lang->get($lang_string); |
|
207 if ( $str == $lang_string ) |
|
208 $str = $ns; |
|
209 |
|
210 echo '<option value="' . $ns . '">' . ucwords($str) . '</option>'; |
|
211 } |
|
212 echo '</select>'; |
|
213 echo '</p>'; |
|
214 |
|
215 echo '<fieldset>'; |
|
216 echo '<legend>' . $lang->get('pagetools_create_group_advanced') . '</legend>'; |
|
217 |
|
218 echo '<p>'; |
|
219 echo '<label><input tabindex="3" type="radio" name="custom_url" value="no" checked="checked" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'none\';" /> ' . $lang->get('pagetools_create_field_url_auto') . '</label>'; |
|
220 echo '</p>'; |
|
221 |
|
222 echo '<p>'; |
|
223 echo '<label><input tabindex="3" type="radio" name="custom_url" value="yes" onclick="cpGenPreviewUrl(); document.getElementById(\'createpage_custom_url\').style.display = \'block\';" /> ' . $lang->get('pagetools_create_field_url_manual') . '</label>'; |
|
224 echo '</p>'; |
|
225 |
|
226 echo '<p id="createpage_custom_url" style="display: none; margin-left: 2em;">'; |
|
227 echo $lang->get('pagetools_create_field_url'); |
|
228 echo ' <input onkeyup="cpGenPreviewUrl();" tabindex="4" type="text" name="urlname" value="" size="40" />'; |
|
229 echo '</p>'; |
|
230 |
|
231 echo '<p>'; |
|
232 echo $lang->get('pagetools_create_field_preview') . ' <tt id="createpage_url_preview"> </tt><br />'; |
|
233 echo '<small>' . $lang->get('pagetools_create_field_preview_hint') . '</small>'; |
|
234 echo '</p>'; |
|
235 |
|
236 echo '</fieldset>'; |
|
237 |
|
238 echo '<p>'; |
|
239 echo '<input tabindex="5" type="submit" value="' . $lang->get('pagetools_create_btn_create') . '" />'; |
|
240 echo '</p>'; |
|
241 |
|
242 echo '</form>'; |
|
243 |
|
244 echo '<script type="text/javascript">cpGenPreviewUrl();</script>'; |
|
245 |
|
246 $template->footer(); |
|
247 } |
|
248 |
|
249 function page_Special_CreatePage_Old() |
73 { |
250 { |
74 global $db, $session, $paths, $template, $plugins; // Common objects |
251 global $db, $session, $paths, $template, $plugins; // Common objects |
75 global $lang; |
252 global $lang; |
76 |
253 |
77 if ( isset($_POST['do']) ) |
254 if ( isset($_POST['do']) ) |