161 foreach ( $code as $cmd ) |
161 foreach ( $code as $cmd ) |
162 { |
162 { |
163 eval($cmd); |
163 eval($cmd); |
164 } |
164 } |
165 |
165 |
166 if ( $page_cache = $cache->fetch('page_meta') ) |
|
167 { |
|
168 $this->pages = array_merge($this->pages, $page_cache); |
|
169 } |
|
170 else |
|
171 { |
|
172 $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n" |
|
173 . ' delvote_ips,wiki_mode,password,page_format FROM '.table_prefix.'pages ORDER BY name;'); |
|
174 |
|
175 if( !$e ) |
|
176 { |
|
177 $db->_die('The error seems to have occured while selecting the page information. File: includes/paths.php; line: '.__LINE__); |
|
178 } |
|
179 while($r = $db->fetchrow()) |
|
180 { |
|
181 $r = $this->calculate_metadata_from_row($r); |
|
182 |
|
183 $this->pages[$r['urlname']] = $r; |
|
184 $this->pages[] =& $this->pages[$r['urlname']]; |
|
185 } |
|
186 |
|
187 $this->update_metadata_cache(); |
|
188 } |
|
189 $db->free_result(); |
|
190 if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') ) |
166 if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') ) |
191 { |
167 { |
192 $title = $this->parse_url(false); |
168 $title = $this->parse_url(false); |
193 if ( empty($title) && get_main_page() != '' ) |
169 if ( empty($title) && get_main_page() != '' ) |
194 { |
170 { |
389 |
365 |
390 profiler_log('Paths and CMS core initted'); |
366 profiler_log('Paths and CMS core initted'); |
391 $session->init_permissions(); |
367 $session->init_permissions(); |
392 } |
368 } |
393 |
369 |
|
370 /** |
|
371 * Fetch cdata (metadata) for a page. |
|
372 * @param string Page ID |
|
373 * @param string Namespace |
|
374 * @return array |
|
375 */ |
|
376 |
|
377 function get_cdata($page_id, $namespace) |
|
378 { |
|
379 global $db, $session, $paths, $template, $plugins; // Common objects |
|
380 |
|
381 $pathskey = $this->get_pathskey($page_id, $namespace); |
|
382 if ( isset($this->pages[$pathskey]) ) |
|
383 return $this->pages[$pathskey]; |
|
384 |
|
385 $page = namespace_factory($page_id, $namespace); |
|
386 $cdata = $page->get_cdata(); |
|
387 |
|
388 $this->pages[$pathskey] = $cdata; |
|
389 return $cdata; |
|
390 } |
|
391 |
|
392 /** |
|
393 * For a given page ID and namespace, generate a flat string that can be used to access $paths->pages. |
|
394 * @param string Page ID |
|
395 * @param string Namespace |
|
396 */ |
|
397 |
|
398 function get_pathskey($page_id, $namespace) |
|
399 { |
|
400 return ( isset($this->nslist[$namespace]) ) ? "{$this->nslist[$namespace]}{$page_id}" : "{$namespace}:{$page_id}"; |
|
401 } |
|
402 |
394 function add_page($flags) |
403 function add_page($flags) |
395 { |
404 { |
396 global $lang; |
405 global $lang; |
397 $flags['urlname_nons'] = $flags['urlname']; |
406 $flags['urlname_nons'] = $flags['urlname']; |
398 $flags['urlname'] = $this->nslist[$flags['namespace']] . $flags['urlname']; // Applies the User:/File:/etc prefixes to the URL names |
407 $flags['urlname'] = $this->nslist[$flags['namespace']] . $flags['urlname']; // Applies the User:/File:/etc prefixes to the URL names |
402 if ( preg_match('/^[a-z0-9]+_[a-z0-9_]+$/', $flags['name']) ) |
411 if ( preg_match('/^[a-z0-9]+_[a-z0-9_]+$/', $flags['name']) ) |
403 $flags['name'] = $lang->get($flags['name']); |
412 $flags['name'] = $lang->get($flags['name']); |
404 } |
413 } |
405 |
414 |
406 $flags['require_admin'] = ( $flags['namespace'] === 'Admin' ); |
415 $flags['require_admin'] = ( $flags['namespace'] === 'Admin' ); |
407 |
416 $flags['page_exists'] = true; |
408 $pages_len = sizeof($this->pages) / 2; |
417 |
409 $this->pages[$pages_len] = $flags; |
418 $this->pages[$flags['urlname']] = $flags; |
410 $this->pages[$flags['urlname']] =& $this->pages[$pages_len]; |
|
411 } |
419 } |
412 |
420 |
413 function main_page() |
421 function main_page() |
414 { |
422 { |
415 if( is_string(get_main_page()) ) |
423 if( is_string(get_main_page()) ) |
562 function getParam($id = 0) |
570 function getParam($id = 0) |
563 { |
571 { |
564 $title = $this->parse_url(false); |
572 $title = $this->parse_url(false); |
565 list(, $ns) = RenderMan::strToPageID($title); |
573 list(, $ns) = RenderMan::strToPageID($title); |
566 $title = substr($title, strlen($this->nslist[$ns])); |
574 $title = substr($title, strlen($this->nslist[$ns])); |
567 $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$this->namespace])) . '\\/?/'; |
575 $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$ns])) . '\\/?/'; |
568 $title = preg_replace($regex, '', $title); |
576 $title = preg_replace($regex, '', $title); |
569 $title = explode('/', $title); |
577 $title = explode('/', $title); |
570 $id = $id + 1; |
578 $id = $id + 1; |
571 return ( isset($title[$id]) ) ? $title[$id] : false; |
579 return ( isset($title[$id]) ) ? $title[$id] : false; |
572 } |
580 } |
602 } |
610 } |
603 $this->nslist[$id] = $prefix; |
611 $this->nslist[$id] = $prefix; |
604 } |
612 } |
605 |
613 |
606 /** |
614 /** |
607 * Updates the cache containing all page metadata. |
615 * Deprecated. |
608 */ |
616 */ |
609 |
617 |
610 function update_metadata_cache() |
618 function update_metadata_cache() |
611 { |
619 { |
612 global $db, $session, $paths, $template, $plugins; // Common objects |
620 global $db, $session, $paths, $template, $plugins; // Common objects |
613 |
621 |
614 if ( getConfig('cache_thumbs') != '1' ) |
622 return false; |
615 return false; |
|
616 |
|
617 $e = $db->sql_unbuffered_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n" |
|
618 . ' delvote_ips,wiki_mode,password,page_format FROM '.table_prefix.'pages ORDER BY name;'); |
|
619 if ( !$e ) |
|
620 $db->_die(); |
|
621 |
|
622 $md_array = array(); |
|
623 |
|
624 while ( $row = $db->fetchrow() ) |
|
625 { |
|
626 $row = $this->calculate_metadata_from_row($row); |
|
627 $md_array[$row['urlname']] = $row; |
|
628 } |
|
629 |
|
630 // import cache functions |
|
631 global $cache; |
|
632 |
|
633 // store data (TTL 20 minutes) |
|
634 try |
|
635 { |
|
636 $cache->store('page_meta', $md_array, 20); |
|
637 } |
|
638 catch ( Exception $e ) |
|
639 { |
|
640 } |
|
641 |
|
642 return true; |
|
643 } |
623 } |
644 |
624 |
645 /** |
625 /** |
646 * Takes a result row from the pages table and calculates correct values for it. |
626 * Takes a result row from the pages table and calculates correct values for it. |
647 * @param array |
627 * @param array |
648 * @return array |
628 * @return array |
649 */ |
629 */ |
650 |
630 |
651 function calculate_metadata_from_row($r) |
631 function calculate_metadata_from_row($r) |
652 { |
632 { |
653 $r['urlname_nons'] = $r['urlname']; |
633 return Namespace_Default::bake_cdata($r); |
654 if ( isset($this->nslist[$r['namespace']]) ) |
|
655 { |
|
656 $r['urlname'] = $this->nslist[$r['namespace']] . $r['urlname']; // Applies the User:/File:/etc prefixes to the URL names |
|
657 } |
|
658 else |
|
659 { |
|
660 $ns_char = substr($this->nslist['Special'], -1); |
|
661 $r['urlname'] = $r['namespace'] . $ns_char . $r['urlname']; |
|
662 } |
|
663 |
|
664 if ( $r['delvotes'] == null) |
|
665 { |
|
666 $r['delvotes'] = 0; |
|
667 } |
|
668 if ( $r['protected'] == 0 || $r['protected'] == 1 ) |
|
669 { |
|
670 $r['really_protected'] = (int)$r['protected']; |
|
671 } |
|
672 else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '1') |
|
673 { |
|
674 $r['really_protected'] = 1; |
|
675 } |
|
676 else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '0' ) |
|
677 { |
|
678 $r['really_protected'] = 0; |
|
679 } |
|
680 return $r; |
|
681 } |
634 } |
682 |
635 |
683 /** |
636 /** |
684 * Registers a handler to manually process a namespace instead of the default PageProcessor behavior. |
637 * Registers a handler to manually process a namespace instead of the default PageProcessor behavior. |
685 * The first and only parameter passed to the processing function will be the PageProcessor instance. |
638 * The first and only parameter passed to the processing function will be the PageProcessor instance. |
1080 $db->_die('The search index was trying to rebuild itself when the error occured.'); |
1032 $db->_die('The search index was trying to rebuild itself when the error occured.'); |
1081 |
1033 |
1082 } |
1034 } |
1083 |
1035 |
1084 /** |
1036 /** |
1085 * Creates an instance of the Searcher class, including index info |
|
1086 * @return object |
|
1087 */ |
|
1088 |
|
1089 function makeSearcher($match_case = false) |
|
1090 { |
|
1091 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1092 $search = new Searcher(); |
|
1093 $q = $db->sql_query('SELECT word,page_names FROM '.table_prefix.'search_index;'); |
|
1094 if(!$q) |
|
1095 { |
|
1096 echo $db->get_error(); |
|
1097 return false; |
|
1098 } |
|
1099 $idx = Array(); |
|
1100 while($row = $db->fetchrow($q)) |
|
1101 { |
|
1102 $row['word'] = rtrim($row['word'], "\0"); |
|
1103 $idx[$row['word']] = $row['page_names']; |
|
1104 } |
|
1105 $db->free_result(); |
|
1106 $search->index = $idx; |
|
1107 if($match_case) |
|
1108 $search->match_case = true; |
|
1109 return $search; |
|
1110 } |
|
1111 |
|
1112 /** |
|
1113 * Creates an associative array filled with the values of all the page titles |
|
1114 * @return array |
|
1115 */ |
|
1116 |
|
1117 function get_page_titles() |
|
1118 { |
|
1119 $texts = Array(); |
|
1120 for ( $i = 0; $i < sizeof($this->pages) / 2; $i++ ) |
|
1121 { |
|
1122 $texts[$this->pages[$i]['urlname']] = $this->pages[$i]['name']; |
|
1123 } |
|
1124 return $texts; |
|
1125 } |
|
1126 |
|
1127 /** |
|
1128 * Creates an instance of the Searcher class, including index info for page titles |
|
1129 * @return object |
|
1130 */ |
|
1131 |
|
1132 function makeTitleSearcher($match_case = false) |
|
1133 { |
|
1134 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1135 $search = new Searcher(); |
|
1136 $texts = $this->get_page_titles(); |
|
1137 $search->buildIndex($texts); |
|
1138 if($match_case) |
|
1139 $search->match_case = true; |
|
1140 return $search; |
|
1141 } |
|
1142 |
|
1143 /** |
|
1144 * Returns a list of groups that a given page is a member of. |
1037 * Returns a list of groups that a given page is a member of. |
1145 * @param string Page ID |
1038 * @param string Page ID |
1146 * @param string Namespace |
1039 * @param string Namespace |
1147 * @return array |
1040 * @return array |
1148 */ |
1041 */ |