Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

When ?ns given, try to be clever by using namespace for unknown pages

darcs-hash:20090126155418-6e07b-02becf49566705930197f214683fbea3a558836d.gz
  • Loading branch information...
commit 6c9a275772077be72e081d9a36df97a3a190f24f 1 parent 2da0f9d
Andreas Gohr authored January 26, 2009

Showing 1 changed file with 35 additions and 4 deletions. Show diff stats Hide diff stats

  1. 39  syntax.php
39  syntax.php
@@ -52,7 +52,9 @@ function connectTo($mode) {
52 52
      * Handle the match
53 53
      */
54 54
     function handle($match, $state, $pos, &$handler){
55  
-        $id = cleanID(substr($match,7,-2));
  55
+        $id = substr($match,7,-2);
  56
+        list($id,$opt) = explode('?',$id,2);
  57
+        $id = cleanID($id);
56 58
 
57 59
         // fetch the instructions of the control page
58 60
         $instructions = p_cached_instructions(wikiFN($id),false,$id);
@@ -89,7 +91,7 @@ function handle($match, $state, $pos, &$handler){
89 91
             }
90 92
         }
91 93
 
92  
-        return array(wikiFN($id),$list);
  94
+        return array(wikiFN($id),$list,$opt);
93 95
     }
94 96
 
95 97
     /**
@@ -101,6 +103,7 @@ function render($format, &$R, $data) {
101 103
         global $INFO;
102 104
         global $ID;
103 105
         $fn   = $data[0];
  106
+        $opt  = $data[2];
104 107
         $data = $data[1];
105 108
 
106 109
         if($format == 'metadata'){
@@ -110,8 +113,36 @@ function render($format, &$R, $data) {
110 113
 
111 114
         $R->info['cache'] = false; // no cache please
112 115
 
113  
-        $parent = (array) $data[$INFO['id']]['parents']; // get the "path" of the page we're on currently
114  
-        array_push($parent,$INFO['id']);
  116
+        $parent = array();
  117
+        if(isset($data[$INFO['id']])){
  118
+            $parent = (array) $data[$INFO['id']]['parents']; // get the "path" of the page we're on currently
  119
+            array_push($parent,$INFO['id']);
  120
+        }elseif($opt == 'ns'){
  121
+            $ns   = $INFO['id'];
  122
+
  123
+            // traverse up for matching namespaces
  124
+            do {
  125
+                $ns = getNS($ns);
  126
+                $try = "$ns:";
  127
+                resolve_pageid('',$try,$foo);
  128
+                if(isset($data[$try])){
  129
+                    // got a start page
  130
+                    $parent = (array) $data[$try]['parents'];
  131
+                    array_push($parent,$try);
  132
+                    break;
  133
+                }else{
  134
+                    // search for the first page matching the namespace
  135
+                    foreach($data as $key => $junk){
  136
+                        if(getNS($key) == $ns){
  137
+                            $parent = (array) $data[$key]['parents'];
  138
+                            array_push($parent,$key);
  139
+                            break;
  140
+                        }
  141
+                    }
  142
+                }
  143
+
  144
+            }while($ns);
  145
+        }
115 146
 
116 147
         // we need the top ID for the renderer
117 148
         $oldid = $ID;

0 notes on commit 6c9a275

Please sign in to comment.
Something went wrong with that request. Please try again.