152 } |
152 } |
153 |
153 |
154 public static function fetch_template_text($id) |
154 public static function fetch_template_text($id) |
155 { |
155 { |
156 global $db, $session, $paths, $template, $plugins; // Common objects |
156 global $db, $session, $paths, $template, $plugins; // Common objects |
|
157 $fetch_ns = 'Template'; |
157 if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
158 if(!isset($paths->pages[$paths->nslist['Template'].$id])) |
158 { |
159 { |
159 return '[['.$paths->nslist['Template'].$id.']]'; |
160 // Transclusion of another page |
|
161 // 1.1.5: Now You, Too, Can Be A Template, Even If You're Just A Plain Old Article! (TM) |
|
162 $nssep = substr($paths->nslist['Special'], -1); |
|
163 $nslist = $paths->nslist; |
|
164 foreach ( $nslist as &$ns ) |
|
165 { |
|
166 if ( $ns == '' ) |
|
167 $ns = $nssep; |
|
168 } |
|
169 $prefixlist = array_flip($nslist); |
|
170 foreach ( $nslist as &$ns ) |
|
171 { |
|
172 $ns = preg_quote($ns); |
|
173 } |
|
174 $nslist = implode('|', $nslist); |
|
175 if ( preg_match("/^($nslist)(.*?)$/", $id, $match) ) |
|
176 { |
|
177 // in practice this should always be true but just to be safe... |
|
178 if ( isset($prefixlist[$match[1]]) ) |
|
179 { |
|
180 $new_id = $paths->nslist[ $prefixlist[$match[1]] ] . sanitize_page_id($match[2]); |
|
181 if ( !isset($paths->pages[$new_id]) ) |
|
182 { |
|
183 return "[[$new_id]]"; |
|
184 } |
|
185 $fetch_ns = $prefixlist[$match[1]]; |
|
186 $id = sanitize_page_id($match[2]); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 return '[['.$paths->nslist['Template'].$id.']]'; |
|
192 } |
160 } |
193 } |
161 if(isset($paths->template_cache[$id])) |
194 if(isset($paths->template_cache[$id])) |
162 { |
195 { |
163 $text = $paths->template_cache[$id]; |
196 $text = $paths->template_cache[$id]; |
164 } |
197 } |
165 else |
198 else |
166 { |
199 { |
167 $text = RenderMan::getPage($id, 'Template', 0, false, false, false, false); |
200 $text = RenderMan::getPage($id, $fetch_ns, 0, false, false, false, false); |
168 $paths->template_cache[$id] = $text; |
201 $paths->template_cache[$id] = $text; |
169 } |
202 } |
170 |
203 |
171 if ( is_string($text) ) |
204 if ( is_string($text) ) |
172 { |
205 { |