@@ -133,15 +133,15 @@ function gather_data($namespaces,$depth=0,$incmedia='ns'){
133133 );
134134 }
135135 }
136- // clean up duplicates
137- $ media = array_unique ($ media );
138136
139137 // now get links and media
140138 foreach ($ pages as $ pid => $ item ){
141139 // get instructions
142140 $ ins = p_cached_instructions (wikiFN ($ pid ),false ,$ pid );
143141 // find links and media usage
144142 foreach ($ ins as $ i ){
143+ $ mid = null ;
144+
145145 if ($ i [0 ] == 'internallink ' ){
146146 $ id = $ i [1 ][0 ];
147147 $ exists = true ;
@@ -151,21 +151,31 @@ function gather_data($namespaces,$depth=0,$incmedia='ns'){
151151 if ($ exists && isset ($ pages [$ id ])){
152152 $ pages [$ pid ]['links ' ][] = $ id ;
153153 }
154- //FIXME handle images in links here
155- }elseif ($ i [0 ] == 'internalmedia ' ){
156- if ($ incmedia == 'none ' ) continue ; // no media wanted
154+ if (is_array ($ i [1 ][1 ]) && $ i [1 ][1 ]['type ' ] == 'internalmedia ' ){
155+ $ mid = $ i [1 ][1 ]['src ' ]; // image link
156+ }else {
157+ continue ; // we're done here
158+ }
159+ }
157160
158- $ id = $ i [1 ][0 ];
159- $ exists = true ;
160- resolve_mediaid ($ item ['ns ' ],$ id ,$ exists );
161- list ($ id ) = explode ('# ' ,$ id ,2 );
162- if ($ exists ){
163- if ($ incmedia == 'all ' ){
164- $ media [] = $ id ; // add node
165- $ pages [$ pid ]['media ' ][] = $ id ;
166- }elseif (in_array ($ id ,$ media )){
167- $ pages [$ pid ]['media ' ][] = $ id ;
168- }
161+ if ($ i [0 ] == 'internalmedia ' ){
162+ $ mid = $ i [1 ][0 ];
163+ }
164+
165+ if (is_null ($ mid )) continue ;
166+ if ($ incmedia == 'none ' ) continue ; // no media wanted
167+
168+ $ exists = true ;
169+ resolve_mediaid ($ item ['ns ' ],$ mid ,$ exists );
170+ list ($ mid ) = explode ('# ' ,$ mid ,2 );
171+ $ mid = cleanID ($ mid );
172+
173+ if ($ exists ){
174+ if ($ incmedia == 'all ' ){
175+ $ media [] = $ mid ; // add node
176+ $ pages [$ pid ]['media ' ][] = $ mid ;
177+ }elseif (in_array ($ mid ,$ media )){
178+ $ pages [$ pid ]['media ' ][] = $ mid ;
169179 }
170180 }
171181 }
@@ -174,6 +184,8 @@ function gather_data($namespaces,$depth=0,$incmedia='ns'){
174184 $ pages [$ pid ]['links ' ] = array_unique ($ pages [$ pid ]['links ' ]);
175185 $ pages [$ pid ]['media ' ] = array_unique ($ pages [$ pid ]['media ' ]);
176186 }
187+ // clean up duplicates
188+ $ media = array_unique ($ media );
177189
178190 return array ('pages ' =>$ pages , 'media ' =>$ media );
179191}
0 commit comments