includes/functions.php
changeset 308 25691e0841f1
parent 307 145b70bb8999
child 316 42419c99471c
equal deleted inserted replaced
307:145b70bb8999 308:25691e0841f1
  2434     }
  2434     }
  2435   }
  2435   }
  2436   
  2436   
  2437   // Remove character escapes
  2437   // Remove character escapes
  2438   $page_id = dirtify_page_id($page_id);
  2438   $page_id = dirtify_page_id($page_id);
  2439 
  2439   
  2440   $pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id);
  2440   $pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id);
  2441   $pid_dirty = enano_str_split($pid_clean, 1);
  2441   $pid_dirty = enano_str_split($pid_clean, 1);
  2442 
  2442 
  2443   foreach ( $pid_dirty as $id => $char )
  2443   foreach ( $pid_dirty as $id => $char )
  2444   {
  2444   {
  2490   // Exception for userpages for IP addresses
  2490   // Exception for userpages for IP addresses
  2491   if ( is_valid_ip($page_id) )
  2491   if ( is_valid_ip($page_id) )
  2492   {
  2492   {
  2493     return $page_id;
  2493     return $page_id;
  2494   }
  2494   }
       
  2495   
       
  2496   $ns_fixed = false;
       
  2497   if ( !empty($paths->nslist) )
       
  2498   {
       
  2499     $namespaces = array();
       
  2500     foreach ( $paths->nslist as $ns )
       
  2501     {
       
  2502       if ( !empty($ns) )
       
  2503         $namespaces[] = preg_quote($ns);
       
  2504     }
       
  2505     $namespaces = implode('|', $namespaces);
       
  2506     if ( preg_match("/^($namespaces)/", $page_id, $match) )
       
  2507     {
       
  2508       $ns_fixed = true;
       
  2509       $page_id = preg_replace("/^($namespaces)/", '', $page_id);
       
  2510     }
       
  2511   }
  2495 
  2512 
  2496   preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
  2513   preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
  2497 
  2514 
  2498   foreach ( $matches[0] as $id => $char )
  2515   foreach ( $matches[0] as $id => $char )
  2499   {
  2516   {
  2500     $char = substr($char, 1);
  2517     $char = substr($char, 1);
  2501     $char = strtolower($char);
  2518     $char = strtolower($char);
  2502     $char = intval(hexdec($char));
  2519     $char = intval(hexdec($char));
  2503     $char = chr($char);
  2520     $char = chr($char);
  2504     $page_id = str_replace($matches[0][$id], $char, $page_id);
  2521     $page_id = str_replace($matches[0][$id], $char, $page_id);
       
  2522   }
       
  2523   
       
  2524   if ( $ns_fixed )
       
  2525   {
       
  2526     $page_id = "{$match[1]}$page_id";
  2505   }
  2527   }
  2506   
  2528   
  2507   return $page_id;
  2529   return $page_id;
  2508 }
  2530 }
  2509 
  2531