r104375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104374‎ | r104375 | r104376 >
Date:23:21, 27 November 2011
Author:bkaempgen
Status:deferred (Comments)
Tags:
Comment:
== SWB - 2011-11-27 ==
* Incoming links work now
* beautifications
* language
* ...
Modified paths:
  • /trunk/extensions/SemanticWebBrowser/CHANGELOG (modified) (history)
  • /trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.alias.php (added) (history)
  • /trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.i18n.php (added) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/SWB_ControlProperties.php (deleted) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/SWB_CreatePage.php (deleted) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/SWB_Infolink.php (modified) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/SWB_SemanticSearchByLabel.php (deleted) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/SWB_Setup.php (deleted) (history)
  • /trunk/extensions/SemanticWebBrowser/includes/datavalues/SWBResolvableUriValue.php (modified) (history)
  • /trunk/extensions/SemanticWebBrowser/lib/Graphite.php (modified) (history)
  • /trunk/extensions/SemanticWebBrowser/specials/SearchTriple/SWB_SpecialBrowseWiki.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.alias.php
@@ -0,0 +1,15 @@
 2+<?php
 3+/**
 4+ * Aliases for special pages
 5+ *
 6+ * @author Anna Kantorovitch and Benedikt K�mpgen
 7+ * @ingroup Extensions
 8+ * @ingroup SWBLanguage
 9+ */
 10+
 11+
 12+/** English (English) */
 13+
 14+$specialPageAliases['en'] = array(
 15+ 'BrowseWiki' => array( 'BrowseWiki' ),
 16+);
\ No newline at end of file
Property changes on: trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.alias.php
___________________________________________________________________
Added: svn:eol-style
117 + native
Added: svn:keywords
218 + LastChangedDate LastChangedRevision LastChangedBy Id
Index: trunk/extensions/SemanticWebBrowser/specials/SearchTriple/SWB_SpecialBrowseWiki.php
@@ -6,30 +6,22 @@
77 *
88 * A factbox like view on an article, implemented by a special page.
99 *
10 - * @author Anna Kantorovitch
 10+ *
1111 */
1212
1313 /**
1414 * A factbox view on one specific article, showing all the Semantic data about it
15 - *
16 - * @ingroup SMWSpecialPage
 15+ *@author Anna Kantorovitch
 16+ *@author Benedikt Kämpgen
 17+ *
1718 * @ingroup SpecialPage
1819 */
 20+
1921 global $swbgIP;
20 -// require_once "$swbgIP/EasyRDF/lib/EasyRdf.php";
21 -// require_once "$swbgIP/EasyRDF/examples/html_tag_helpers.php";
22 -// set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
23 -// require_once ($swbgIP.'EasyRDF/examples/html_tag_helpers.php');
24 -// require_once "EasyRdf.php";
25 -// require_once "html_tag_helpers.php";
26 -set_include_path($swbgIP.'lib/');
27 -/**
28 - * Here, we need EasyRDF.
29 - */
30 -require_once ($swbgIP.'lib/EasyRdf.php');
3122
 23+set_include_path($swbgIP . 'lib/');
 24+require_once ($swbgIP . 'lib/EasyRdf.php');
3225
33 -//require_once( "$swbgIP/Graphite.php" );
3426
3527 class SWBSpecialBrowseWiki extends SpecialPage {
3628 /// int How many incoming values should be asked for
@@ -48,6 +40,8 @@
4941 private $offset = 0;
5042 ///if searchwindow is created or not
5143 private $windowCreated=false;
 44+
 45+ private $title;
5246
5347 /**
5448 * Constructor
@@ -68,30 +62,18 @@
6963 * @param[in] $query string Given by MediaWiki
7064 */
7165 public function execute( $query ) {
72 - global $wgRequest, $wgOut, $smwgBrowseShowAll,$wgContLang;
73 -
 66+ global $wgRequest, $wgOut, $smwgBrowseShowAll, $wgContLang;
7467 $this->setHeaders();
7568
7669 // get the GET parameters
7770 $this->articletext = $wgRequest->getVal( 'article' );
78 -
 71+ $this->title = $wgOut->getTitle();
7972 // no GET parameters? Then try the URL
8073 if ( $this->articletext == '' ) {
8174 $params = SMWInfolink::decodeParameters( $query, false );
8275 reset( $params );
8376 $this->articletext = current( $params );
8477 }
85 -
86 - // if page existing in the wiki, I want that one instead
87 - $uriPageName = $this->getInternalMapping( $this->articletext );
88 -
89 - if (!isset($uriPageName) && $uriPageName == null ) {
90 - // get subject
91 - $this->subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $this->articletext );
92 - } else {
93 - $this->subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $uriPageName );
94 - }
95 -
9678 $offsettext = $wgRequest->getVal( 'offset' );
9779 $this->offset = ( $offsettext == '' ) ? 0:intval( $offsettext );
9880 $dir = $wgRequest->getVal( 'dir' );
@@ -104,136 +86,14 @@
10587 if ( $dir == 'in' ) $this->showoutgoing = false;
10688 if ( $dir == 'out' ) $this->showincoming = false;
10789
108 - // Why do we need different variants? Removed...
109 -
110 - // Why do we need to input query form? Removed...
111 -
112 - // print OutputPage
 90+ // print OutputPage
 91+
11392 $wgOut->addHTML( $this->displayBrowse() );
11493 SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
11594
11695 }
11796
118 - //new function for search swb actually not used
119 - function wfSpecialSearch( $par = '' ) {
120 - global $wgRequest, $wgUser, $wgOut;
121 - $wgOut->allowClickjacking();
12297
123 - // Strip underscores from title parameter; most of the time we'll want
124 - // text form here. But don't strip underscores from actual text params!
125 - $titleParam = str_replace( '_', ' ', $par );
126 - //echo "par='".$par."'";
127 - // Fetch the search term
128 - $search = str_replace( "\n", " ", $wgRequest->getText( 'search', $titleParam ) );
129 - //echo "search='".$search."'";
130 - $searchPage = new SpecialSearch( $wgRequest, $wgUser );
131 - if( $wgRequest->getVal( 'fulltext' )
132 - || !is_null( $wgRequest->getVal( 'offset' ))
133 - || !is_null( $wgRequest->getVal( 'searchx' )) )
134 - {
135 - $searchPage->showResults( $search );
136 - } else {
137 - $searchPage->goResult( $search );
138 - }
139 - }
140 - /** New function for browsing SWB
141 - * actually not used
142 - * based on lodpuller.php
143 - * Function getPagesByAlias doesn't work
144 - *
145 - * @param unknown_type $label
146 - * @param unknown_type $lang
147 - */
148 - private function checkSearch($label, $lang){
149 - global $wgOut, $wgScriptPath;
150 - $pages = SWBCreatePage::getPagesByAlias( $label, $lang );
151 -
152 - if (count($pages) === 0) {
153 - // Do nothing
154 - } elseif (count($pages) === 1) {
155 - // Go to that page directly
156 - $wgOut->redirect( "$wgScriptPath/topic/$lang/$pages[0]" );
157 - return;
158 - } else {
159 - global $wgSitename;
160 - $wgOut->setHTMLTitle( wfMsg('swb-disambiguation') . ':' . $label . ' - ' . $wgSitename );
161 - $wgOut->setPageTitle( $label );
162 - $wgOut->addWikiText( wfMsg('swb-disambiguationpage', $label) );
163 - foreach ($pages as $page) {
164 - $plabel = SWBCreatePage::getLabel($page, $lang);
165 - $pdescription = SWBCreatePage::getDescription($page, $lang);
166 - $wgOut->addWikiText( "* '''[[$page|$plabel]]''': $pdescription" );
167 - }
168 - $wgOut->addWikiText( "\n\n" );
169 - }
170 -
171 - //list($wphits, $wpsuggest, $wpresults) = SWBSemanticSearchByLabel::getWikipediaSearch( $label, $lang );
172 - list($wphits, $wpsuggest, $wpresults) = SWBSpecialBrowseWiki::getWikiSearch( $label, $lang );
173 - $exactmatch = false;
174 - if (count($wpresults)) {
175 - $wgOut->addWikiText( wfMsg('swb-wpsearchresults' ) );
176 - $wgOut->addHTML('<ul>');
177 - foreach($wpresults as $title => $snippet) {
178 - if ($title == $label) $exactmatch = true;
179 - $target = str_replace(' ', '_', $title);
180 - $wgOut->addHTML("<li><a href=\"$wgServer$wgScriptPath/wikipedia/$lang/$target\">$title</a><br> <em>$snippet</em></li>");
181 - }
182 - $wgOut->addHTML('</ul>');
183 - $wgOut->addWikiText( "\n\n" );
184 - }
185 -
186 - if ($wpsuggest) {
187 - $wgOut->addWikiText( wfMsg('swb-didyoumean') );
188 - $target = str_replace(' ', '_', $wpsuggest);
189 - $wgOut->addHTML("<ul><li><a href=\"$wgServer$wgScriptPath/$lang/$target\">$wpsuggest</a></li></ul>");
190 - $wgOut->addWikiText( "\n\n" );
191 - }
192 -
193 - // If nothing was found
194 - if ((count($pages)===0) && (!$exactmatch)) {
195 - $title = Title::newFromText( $label );
196 - if ($title->exists()) {
197 - // If the page exists (but not with the title)
198 - $wgOut->addWikiText( wfMsg('swb-pagenameexists' ));
199 - $langlabel = SWBCreatePage::getLabel( $label, $lang );
200 - $displaylabel = $langlabel ? $langlabel : $label;
201 - $target = str_replace(' ', '_', $label);
202 - $wgOut->addHtml("<ul><li><a href=\"$wgServer$wgScriptPath/topic/$lang/$target\">$displaylabel</a></li></ul>");
203 - } else {
204 - // If such a page does not exist at all, enable its creation
205 - $wgOut->addWikiText( wfMsg('swb-createpage' ));
206 - $target = str_replace(' ', '_', $label);
207 - $wgOut->addHtml("<ul><li><a href=\"$wgServer$wgScriptPath/topic/$lang/$target\">$label</a></li></ul>");
208 - }
209 - }
210 - }
211 -
212 - private function getWikiSearch($term, $lang){
213 - $term = urlencode($term);
214 - $ch = curl_init();
215 - curl_setopt($ch, CURLOPT_URL, "http://$lang.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=$term");
216 - curl_setopt($ch, CURLOPT_USERAGENT, "swbspecialbrowsewiki");
217 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
218 - $output = curl_exec($ch);
219 - curl_close($ch);
220 -
221 - $answer = json_decode($output);
222 - $hits = $answer->query->searchinfo->totalhits;
223 - $results = array();
224 - $suggestion = '';
225 - if ($hits === 0) {
226 - if (property_exists($answer->query->searchinfo, 'suggestion'))
227 - $suggestion = $answer->query->searchinfo->suggestion;
228 - } else {
229 - foreach( $answer->query->search as $hit ) {
230 - $results[$hit->title] = $hit->snippet;
231 - }
232 - }
233 - return array($hits, $suggestion, $results);
234 -
235 -
236 - }
237 - ########################END of checkSearch########################
23898 /**
23999 * Create and output HTML including the complete factbox, based on the extracted
240100 * parameters in the execute comment.
@@ -244,12 +104,11 @@
245105 global $wgContLang, $wgOut;
246106 $html = "\n";
247107 $leftside = !( $wgContLang->isRTL() ); // For right to left languages, all is mirrored
248 -
249 - // TODO: What does valid mean, here?
 108+ //get subject type SMWWikiPage
 109+ $this->subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $this->articletext );
250110 if ( $this->subject->isValid() ) {
251111
252 - // Here, we can distinguish
253 - /*
 112+ /** Here, we can distinguish
254113 * 1. We have an existing page + any number of equivalent URIs
255114 * 2. We have a non-existing page, which is a URI
256115 */
@@ -257,9 +116,9 @@
258117 $wgOut->addStyle( '../extensions/SemanticMediaWiki/skins/SMW_custom.css' );
259118
260119 $html .= $this->displayHead();
 120+ // $data is of type SMWSemanticData
 121+ $data = smwfGetStore()->getSemanticData( $this->subject->getDataItem() );
261122 if ( $this->showoutgoing ) {
262 - // $data is of type SMWSemanticData
263 - $data = smwfGetStore()->getSemanticData( $this->subject->getDataItem() );
264123 $html .= $this->displayData( $data, $leftside );
265124 $html .= $this->displayCenter();
266125 }
@@ -275,145 +134,203 @@
276135
277136 // Now, we can display data from the Semantic Web
278137
279 - // Two possibilities: 1. Existing page with equivalent uris 2. Non-existing page with URL
280 -
281 - //$equivalentURI = SMWPropertyValue::makeUserProperty( "equivalent URI" );
282 - //$equivalentURI = SMWPropertyValue::makeProperty( "__spu" );
283 - $equivalentURI = new SMWDIProperty("_URI");
 138+ /** Two possibilities:
 139+ * 1. Existing page with equivalent uris
 140+ * 2. Non-existing page with URL
 141+ */
 142+ $equivalentURI = new SMWDIProperty( "_URI" );
284143 $arr_equi_values = $data->getPropertyValues($equivalentURI);
285144
286145 // If no equivalentURIs, then maybe the article itself
287146 if (empty($arr_equi_values)) {
288 - // http://harth.org/andreas/foaf#ah
 147+
289148 $info = parse_url($this->articletext);
290 - (!isset($info['scheme'])) ? $scheme = "" : $scheme = $info['scheme'];
291 - (!isset($info['host'])) ? $host = "" : $host = "//".$info['host'];
292 - (!isset($info['path'])) ? $path = "" : $path = $info['path'];
293 - (!isset($info['query'])) ? $query = "" : $query = $info['query'];
294 - (!isset($info['fragment'])) ? $fragment = "" : $fragment = $info['fragment'];
295 - $arr_equi_values[] = new SMWDIUri($scheme, $host.$path, $query, $fragment);
 149+ (!isset( $info['scheme']) ) ? $scheme = "" : $scheme = $info['scheme'];
 150+ (!isset( $info['host']) ) ? $host = "" : $host = "//".$info['host'];
 151+ (!isset( $info['path']) ) ? $path = "" : $path = $info['path'];
 152+ (!isset( $info['query']) ) ? $query = "" : $query = $info['query'];
 153+ (!isset( $info['fragment'])) ? $fragment = "" : $fragment = $info['fragment'];
 154+
 155+ if($scheme=="" || $host.$path==""){
 156+ // in this case SMWDIUri becomes Exception
 157+ }else{
 158+ $arr_equi_values[] = new SMWDIUri($scheme, $host.$path, $query, $fragment); }
296159 }
297 -
298160 foreach ($arr_equi_values as $uri) {
299161 // Two possibilities: 1. No URL 2. URL
300 -
301 - // Build the graph
302 - $graph = new EasyRdf_Graph($uri->getURI());
303 - $graph->load();
304 -
305 - // Now, we resolve this URI and store the rdf
306 -
307 - $html .= $this->displaySemanticHead($uri->getURI());
308 - if ( $this->showoutgoing ) {
309 - // should be: $data is of type SMWSemanticData
310 - $swdata = $this->getSemanticWebData($graph, $uri->getURI() );
311 - $html .= $this->displaySemanticWebData( $swdata, $leftside );
312 - $html .= $this->displayCenter();
313 - }
314 - if ( $this->showincoming ) {
315 - // TODO: Make work
316 - list( $indata, $more ) = $this->getSemanticWebInData($graph, $uri->getURI() );
317 - global $smwgBrowseShowInverse;
318 - if ( !$smwgBrowseShowInverse ) $leftside = !$leftside;
319 - $html .= $this->displaySemanticWebData( $indata, $leftside, true );
320 - $html .= $this->displayBottom( $more );
321 - // We need to switch browse inverse, again
322 - $leftside = !$leftside;
323 - }
 162+ if( $uri === null ){
 163+ }else{
 164+ // Build the graph
 165+ $uriprint = $uri->getURI();
 166+ if( !isset($uriprint) ){
 167+ }else{
 168+ //create object for graph
 169+ $graph = new EasyRdf_Graph($uri->getURI());
 170+ $html .= $this->displayGraph($graph, $uri, $leftside);
 171+ }
 172+ }
324173 }
325174
326 - // Apparently, it is here that the hash # gets removed, therefore removed.
327 - //$this->articletext = $this->subject->getWikiValue();
328 -
329175 // Add a bit space between the factbox and the query form
330176 if ( !$this->including() ) $html .= "<p> &#160; </p>\n";
331177 }
332178 if ( !$this->including() ) $html .= $this->queryForm();
333179 $wgOut->addHTML( $html );
334180 }
335 -
 181+
 182+ /**
 183+ * Create and output HTML including the complete factbox, based on the extracted
 184+ * parameters in the execute comment.
 185+ * for one Graph object
 186+ * @return string A HTML string with the factbox
 187+ * @return leftside in parameter
 188+ */
 189+ public function displayGraph($graph, $uri, &$leftside){
 190+ $graph->load();
 191+ $html = "";
 192+ // Now, we resolve this URI and store the rdf
 193+ $html .= $this->displaySemanticHead( $uri->getURI() );
 194+ if ( $this->showoutgoing ) {
 195+ // should be: $data is of type SMWSemanticData
 196+ $swdata = $this->getSemanticWebData( $graph, $uri->getURI() );
 197+ $html .= $this->displaySemanticWebData( $swdata, $leftside );
 198+ $html .= $this->displayCenter();
 199+ }
 200+ if ( $this->showincoming ) {
 201+ list( $indata, $more ) = $this->getSemanticWebInData( $graph, $uri->getURI() );
 202+ global $smwgBrowseShowInverse;
 203+ if ( !$smwgBrowseShowInverse ) $leftside = !$leftside;
 204+ $html .= $this->displaySemanticWebData( $indata, $leftside, true );
 205+ $html .= $this->displayBottom( $more );
 206+ // We need to switch browse inverse, again
 207+ $leftside = !$leftside;
 208+ }
 209+ return $html;
 210+ }
 211+
 212+
336213 /**
337214 *
338215 * Similar to getInData(), but in this case regarding the Semantic Web.
339216 */
340 - private function getSemanticWebInData($graph, $uri) {
341 -
 217+ private function getSemanticWebInData( $graph, $uri ) {
342218 $indata = new SMWSemanticData( $this->subject->getDataItem() );
343 -
344219 $options = new SMWRequestOptions();
345220 $options->sort = true;
346221 $options->limit = SWBSpecialBrowseWiki::$incomingpropertiescount;
347222 if ( $this->offset > 0 ) $options->offset = $this->offset;
348223
349 - // I need all incoming properties
350 - //$inproperties = $this->getSemanticInProperties($graph, $this->subject->getDataItem(), $options );
351 - $inproperties = $this->getSemanticInProperties($graph, $uri, $options );
352 -
353 - if ( count( $inproperties ) == SWBSpecialBrowseWiki::$incomingpropertiescount ) {
 224+ $triples = $this->getSemanticInfos( $graph, null, null, $uri );
 225+ if ( count( $triples ) >= SWBSpecialBrowseWiki::$incomingpropertiescount ) {
354226 $more = true;
355 - array_pop( $inproperties ); // drop the last one
 227+ array_pop( $triples ); // drop the last one
356228 } else {
357229 $more = false;
358230 }
359 -
360 - $valoptions = new SMWRequestOptions();
361 - $valoptions->sort = true;
362 - $valoptions->limit = SWBSpecialBrowseWiki::$incomingvaluescount;
363 -
364 - // For each incoming property, I run getArraySubjects.
365 - foreach ( $inproperties as $property ) {
366 -
367 - // $values = smwfGetStore()->getPropertySubjects( $property, $this->subject->getDataItem(), $valoptions );
368 - $values = $this->getSemanticPropertySubjects($graph, $property, $this->subject->getDataItem(), $valoptions );
369 - foreach ( $values as $value ) {
370 - $indata->addPropertyObjectValue( $property, $value );
 231+
 232+ //get each triple with subject, property, object . All are strings
 233+ foreach ( $triples as $triple ) {
 234+ list( $subject, $property, $object ) = $triple;
 235+ $propertyPageName = $this->getInternalMapping( $property );
 236+ $dataProperty = null;
 237+ if( !isset($propertyPageName) || $propertyPageName == null){
 238+ $dataProperty = SMWDIProperty::newFromUserLabel( $property );
 239+ //$dataProperty=new SMWDIProperty( $property, false);
 240+ }else{
 241+ $dataProperty = SMWDIProperty::newFromUserLabel( $propertyPageName );
371242 }
 243+
 244+ $subjectPageName = $this->getInternalMapping( $subject );
 245+ $wikipage = null;
 246+ if( !isset( $subjectPageName ) || $subjectPageName == null){
 247+ $wikipage = new SMWDIWikiPage( $subject, NS_MAIN, '');
 248+ }else{
 249+ $wikipage = new SMWDIWikiPage( $subjectPageName, NS_MAIN, '');
 250+ }
 251+
 252+ $indata->addPropertyObjectValue( $dataProperty, $wikipage );
372253 }
373 -
374254 return array( $indata, $more );
375255 }
376 -
 256+
 257+
377258 /**
378259 * Get an array of all properties for which there is some subject that
379 - * relates to the given value. The result is an array of SMWDIWikiPage
 260+ * relates to the given value. The result is an array of SMWDIProperty
380261 * objects.
381262 */
382 - private function getSemanticInProperties($graph, $uri, $requestoptions = null) {
383 -
384 - // Why not properties?
385 - $arr_wpgs = array();
386 -
387 -
 263+
 264+ private function getSemanticInProperties( $graph, $uri, $requestoptions = null ) {
 265+ $arr_objs = array();
 266+ $arr_props = array();
388267 // Now, ask for all incoming uris
389 - //anna
390 - //$theIncomingProperties = $graph->reversePropertyUris($object);
391 - $theIncomingProperties = $graph->reversePropertyUris($uri);
392 - foreach ($theIncomingProperties as $inProp) {
393 - //$inPropResult = $this->getArraySubjects($graph, $inProp, $theResource);
394 - $inPropResult = $this->getArraySubjects($graph, $inProp, $uri);
395 - // TODO create $data
 268+ $theIncomingProperties = $graph->reversePropertyUris( $uri );
 269+ foreach ( $theIncomingProperties as $inProp ) {
 270+
 271+ //getArraySubject :: get all subjects (from RDF) which have the needed property and
 272+ //its uri is a reference to given object
 273+ $inPropResult = $this->getArraySubjects( $graph, $inProp, $uri );
 274+ foreach( $inPropResult as $inPropSubject ){
 275+ $uriPageName = $this->getInternalMapping( $inProp );
 276+ $label = $inPropSubject['value'];
 277+ $dataProperty = SMWDIProperty::newFromUserLabel( $label );
 278+ $arr_objs[] = $dataProperty;
 279+ $arr_props[] = $inProp;
 280+ }
396281 }
397 -
398 - return $arr_wpgs;
 282+ return array ( $arr_objs, $arr_props );
399283 }
400284
 285+
 286+ /**
 287+ * Finds all subjects, properties and objects which are equal to needed subject, property and object
 288+ * The result is an array each element has subject, property, object (all string)
 289+ *
 290+ *
 291+ */
 292+ private function getSemanticInfos( $graph,$sSubject, $sProperty, $sObject,$requestoptions = null ) {
 293+ $arr_triples = array();
 294+ $subjects = $graph->toArray();
 295+
 296+ foreach ( $subjects as $subject=>$properties ){
 297+ if( $sSubject == null || $subject == $sSubject ){
 298+ foreach( $properties as $property => $values ){
 299+ if( $sProperty == null || $sProperty == $property ){
 300+ foreach( $values as $object ){
 301+ if( $this->isURI( $object['value'] ) ){
 302+ if( $sObject==null || $object['value'] == $sObject ){
 303+ $arr_triples[] = array( $subject, $property, $object['value'] );
 304+ }
 305+ }
 306+ }
 307+
 308+ }
 309+ }
 310+ }
 311+ }
 312+ return $arr_triples;
 313+ }
401314 /**
402 - * Get an array of all subjects that have the given value for the given
403 - * property. The result is an array of SMWDIWikiPage objects. If null
404 - * is given as a value, all subjects having that property are returned.
 315+ * Check uri, uri as http://...
 316+ * @param string $uri
 317+ * return true if uri in normal format, else in other cases
405318 */
406 - private function getSemanticPropertySubjects($graph, SMWDIProperty $property, $value, $requestoptions = null ) {
407 - $arr_wpgs = array();
408 -
409 - return $arr_wpgs;
 319+ public static function isURI( $uri ){
 320+ $info = parse_url( $uri );
 321+ ( !isset( $info['scheme'] ) ) ? $scheme = "" : $scheme = $info['scheme'];
 322+ ( !isset( $info['host'] ) ) ? $host = "" : $host = "//".$info['host'];
 323+ ( !isset( $info['path'] ) ) ? $path = "" : $path = $info['path'];
 324+ ( !isset( $info['query'] ) ) ? $query = "" : $query = $info['query'];
 325+ ( !isset($info['fragment']) ) ? $fragment = "" : $fragment = $info['fragment'];
 326+ if( $scheme == "" || $host.$path == "" )return false;
 327+ else return true;
410328 }
411 -
412329 /**
413330 *
414331 * Similar to getSemanticData(), but in this case regarding the Semantic Web.
415332 * @param String $uri
416333 */
417 - private function getSemanticWebData($graph, $uri) {
 334+ private function getSemanticWebData( $graph, $uri ) {
418335 // Several possibilities: URI with redirect to RDF, URL with RDFa (but talking about what?),...
419336
420337 // $data is of type SMWSemanticData
@@ -422,38 +339,29 @@
423340 // I want to show all incoming and outcoming links
424341 // ...ideally in the same style
425342 // Get the representation of the URI
426 - $theResource = $graph->resource($uri);
427 -
 343+ $theResource = $graph->resource( $uri );
428344 // Outgoing
429 - $theOutgoingProperties = $graph->propertyUris($theResource);
430 -
 345+ $theOutgoingProperties = $graph->propertyUris( $theResource );
431346 // for each, ask for the objects
432 - foreach ($theOutgoingProperties as $outProp) {
433 -
434 - $outPropResult = $this->getArrayObjects($graph, $theResource, $outProp);
435 -
 347+ foreach ( $theOutgoingProperties as $outProp ) {
 348+ $outPropResult = $this->getArrayObjects( $graph, $theResource, $outProp );
436349 // now, we have the subject, the property, the object (uri/literal)
437 - foreach ($outPropResult as $outPropObject) {
 350+ foreach ( $outPropResult as $outPropObject ) {
438351
439352 /*
440353 * The question now is, what kind of propert.
441 - *
442354 * If there is a page in the wiki, we simply use it as property.
443 - *
444355 * Otherwise, we need to invent a new page with the URI as name
445 - *
446356 */
447357 $uriPageName = $this->getInternalMapping( $outProp );
448 -
449358 $dataProperty = null;
450 - if (!isset($uriPageName) || $uriPageName == null) {
 359+ if ( !isset( $uriPageName ) || $uriPageName == null) {
451360 // There is no, we create a new property page
452361 /*
453362 * TODO: maybe register new property type that can display the property more
454363 * conveniently, e.g., with browse further: smwInitProperties
455364 */
456 - $dataProperty = SMWDIProperty::newFromUserLabel( $outProp );;
457 -
 365+ $dataProperty = SMWDIProperty::newFromUserLabel( $outProp );
458366 } else {
459367 $dataProperty = SMWDIProperty::newFromUserLabel( $uriPageName );
460368 }
@@ -462,7 +370,7 @@
463371 // TODO: Maybe distinguish more, later, e.g., language
464372 $dataValue = null;
465373
466 - if ($outPropObject["type"] == "uri") {
 374+ if ( $outPropObject["type"] == "uri" ) {
467375
468376 /*
469377 * If there is a page in the wiki with the value as equivalent URI, we
@@ -470,34 +378,25 @@
471379 */
472380 $uriPageName = $this->getInternalMapping( $outPropObject["value"] );
473381
474 - if (!isset($uriPageName) && $uriPageName == null ) {
475 -
476 - // We could create a link that would lead to SemanticWebBrowser
477 - // $info = parse_url($outPropObject["value"]);
478 - //(!isset($info['scheme'])) ? $scheme = "" : $scheme = $info['scheme'];
479 - //(!isset($info['host'])) ? $host = "" : $host = "//".$info['host'];
480 - //(!isset($info['path'])) ? $path = "" : $path = $info['path'];
481 - //(!isset($info['query'])) ? $query = "" : $query = $info['query'];
482 - //(!isset($info['fragment'])) ? $fragment = "" : $fragment = $info['fragment'];
483 - //$dataItem = new SMWDIUri($scheme, $host.$path, $query, $fragment);
484 - //$dataItem = SMWDataValueFactory::newTypeIDValue( '_wpg', $outPropObject["value"] );
485 -
 382+ if ( !isset( $uriPageName ) && $uriPageName == null ) {
486383 // URI value
487 - // TODO: Make custom value type work, it is not used, yet.
488 - //$dataValue = SMWDataValueFactory::newTypeIDValue( '_rur', $outPropObject["value"], $property = $dataProperty );
489 - $dataValue = SMWDataValueFactory::newTypeIDValue( '_uri', $outPropObject["value"], $property = $dataProperty );
 384+ $dataValue = SMWDataValueFactory::newTypeIDValue( '_rur', $outPropObject["value"], $property = $dataProperty );
490385 } else {
491 -
492386 $dataValue = SMWDataValueFactory::newTypeIDValue( '_wpg', $uriPageName, $property = $dataProperty );
493 - //$dataItem = SMWDIWikiPage::newFromTitle(Title::newFromText($uriPageName));
494387 }
495388
496389 } else {
497390 // literal
 391+ $this->debug($outPropObject["value"],"vis:");
498392 $dataValue = SMWDataValueFactory::newTypeIDValue( '_txt', $outPropObject["value"], $property = $dataProperty );
499393 //$dataItem = new SMWDIString($outPropObject["value"]);
500394 }
501 - $semanticDataResult->addPropertyObjectValue( $dataProperty, $dataValue->getDataItem() );
 395+ // some objects have invalid type and print warning triangle instead of object info
 396+ //in this case object has class SMWDIError
 397+ // in this case this object wouldn't be printed
 398+ if( !( get_class( $dataValue->getDataItem() ) == "SMWDIError" ) ){
 399+ $semanticDataResult->addPropertyObjectValue( $dataProperty, $dataValue->getDataItem() );
 400+ }
502401 }
503402 }
504403 return $semanticDataResult;
@@ -512,49 +411,47 @@
513412 */
514413 public static function getInternalMapping( $uri ) {
515414
516 - // Watch out correct spelling: [[equivalent URI::X]]
517 - $equivalentURI = new SMWDIProperty("_URI");
 415+ // Watch out correct spelling: [[equivalent URI::XXX]]
 416+ $equivalentURI = new SMWDIProperty( "_URI" );
518417 $urivalue = SMWDataValueFactory::newPropertyObjectValue( $equivalentURI, $uri );
519418
520419 // $values = smwfGetStore()->getPropertySubjects( $property, $this->subject->getDataItem(), $valoptions );
521420 $results = smwfGetStore()->getPropertySubjects( $equivalentURI, $urivalue->getDataItem() );
522421
523422 $mappings = array();
524 - foreach($results as $result) {
 423+ foreach( $results as $result ) {
525424 //$mappings[] = $result->getWikiValue();
526425 $mappings[] = $result->getTitle()->getText();
527426 }
528 - if (count($mappings) === 0) return null;
 427+ if ( count( $mappings ) === 0) return null;
529428 return $mappings[0]; // TODO Only returns one. There never should be more than one.
530429 }
531430
532 - private function getArrayObjects($graph, $subject, $property) {
 431+ private function getArrayObjects( $graph, $subject, $property ) {
533432
534433 $arr_objects = array();
535434
536435 // TODO: ignore bnodes, language tags, for now.
537436
538 - $theOutgoingProperties = $graph->propertyUris($subject);
 437+ $theOutgoingProperties = $graph->propertyUris( $subject );
539438
540439 // For each outgoing uri, get the resources/literals
541440
542 - $theOutgoingUriValues = $graph->allResources($subject, $property);
543 - foreach ($theOutgoingUriValues as $uri) {
 441+ $theOutgoingUriValues = $graph->allResources( $subject, $property );
 442+ foreach ( $theOutgoingUriValues as $uri ) {
544443 // only non-bnodes
545 - if (!$uri->isBnode()) {
546 - $res = array("type" => "uri", "value" => $uri->getUri());
 444+ if ( !$uri->isBnode() ) {
 445+ $res = array( "type" => "uri", "value" => $uri->getUri() );
547446 $arr_objects[] = $res;
548447 }
549448 }
550449
551 - $theOutgoingLiteralValues = $graph->allLiterals($subject, $property );
552 - foreach ($theOutgoingLiteralValues as $literal) {
553 -
554 - // TODO: Display more nicely.
555 - if ($literal instanceof EasyRdf_Literal_Date || $literal instanceof EasyRdf_Literal_DateTime) {
556 - $res = array("type" => "literal", "value" => $literal->dumpValue(false));
 450+ $theOutgoingLiteralValues = $graph->allLiterals( $subject, $property );
 451+ foreach ( $theOutgoingLiteralValues as $literal ) {
 452+ if ( $literal instanceof EasyRdf_Literal_Date || $literal instanceof EasyRdf_Literal_DateTime ) {
 453+ $res = array( "type" => "literal", "value" => $literal->dumpValue( false ) );
557454 } else {
558 - $res = array("type" => "literal", "value" => $literal->getValue());
 455+ $res = array( "type" => "literal", "value" => $literal->getValue() );
559456 }
560457
561458 $arr_objects[] = $res;
@@ -562,9 +459,16 @@
563460
564461 return $arr_objects;
565462 }
 463+/**
 464+ *
 465+ * get all subjects (from RDF) which have the needed $property and its uri is a reference to needed object
 466+ *
 467+ * @param unknown_type $graph
 468+ * @param unknown_type $property
 469+ * @param unknown_type $object
 470+ */
 471+ private function getArraySubjects( $graph, $property, $object ) {
566472
567 - private function getArraySubjects($graph, $property, $object) {
568 -
569473 $arr_subjects = array();
570474
571475 // For each incoming uri, get the resources (
@@ -576,16 +480,14 @@
577481 $allResources = $graph->resources();
578482
579483 // for each resource, get the values for each of the incoming properties
580 - foreach ($allResources as $aResource) {
581 - $allSpecResources = $graph->allResources($aResource, $property);
 484+ foreach ( $allResources as $aResource ) {
 485+ $allSpecResources = $graph->allResources( $aResource, $property );
582486
583487 // For each resource, check if our $object
584 -
585 - foreach ($allSpecResources as $aSpecResource) {
586 - if (!$aSpecResource->isBnode()) {
587 - if ($aSpecResource->getUri() == $object) {
588 -
589 - $res = array("type" => "uri", "value" => $aSpecResource->getUri());
 488+ foreach ( $allSpecResources as $aSpecResource ) {
 489+ if ( !$aSpecResource->isBnode() ) {
 490+ if ( $aSpecResource->getUri() == $object ) {
 491+ $res = array( "type" => "uri", "value" => $aSpecResource->getUri() );
590492 $arr_subjects[] = $res;
591493 }
592494 }
@@ -595,120 +497,8 @@
596498 return $arr_subjects;
597499 }
598500
 501+
599502 /**
600 - * Creates the HTML table displaying the data of one subject.
601 - *based on displayData
602 - * @param[in] $data SMWSemanticData The data to be displayed
603 - * @param[in] $left bool Should properties be displayed on the left side?
604 - * @param[in] $incoming bool Is this an incoming? Or an outgoing?
605 - *
606 - * @return A string containing the HTML with the factbox
607 - *
608 - * @deprecated Replaced by displaySemanticWebData
609 - */
610 - private function getProperty( SMWSemanticData $data,$propertyName, $left = true, $incoming = false ) {
611 - // Some of the CSS classes are different for the left or the right side.
612 - // In this case, there is an "i" after the "smwb-". This is set here.
613 - $ccsPrefix = $left ? 'smwb-' : 'smwb-i';
614 - $returnvalues=array();
615 - $html = "<table class=\"{$ccsPrefix}factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
616 -
617 - $diProperties = $data->getProperties();
618 - $noresult = true;
619 - foreach ( $diProperties as $diProperty ) {
620 - $label='';
621 - $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null );
622 - echo "================================================================\n ";
623 - if ( $dvProperty->isVisible() ) {
624 - $label=$this->getPropertyLabel( $dvProperty, $incoming );
625 - //echo "Label='".$label."'\n";
626 - //echo "PropertyNamel='".$propertyName."'\n";
627 - $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) );
628 - $proptext = $dvProperty->getShortHTMLText( smwfGetLinker() ) . "\n";
629 - echo "Proptext1='".$proptext."'\n";
630 - } elseif ( $diProperty->getKey() == '_INST' ) {
631 - $proptext = smwfGetLinker()->specialLink( 'Categories' );
632 - echo "Proptext2='".$proptext."'";
633 - } elseif ( $diProperty->getKey() == '_REDI' ) {
634 - $proptext = smwfGetLinker()->specialLink( 'Listredirects', 'isredirect' );
635 - echo "Proptext3='".$proptext."'";
636 - } else {
637 - continue; // skip this line
638 - }
639 -
640 -
641 - $head = "<th>" . $proptext . "</th>\n";
642 -
643 - $body = "<td>\n";
644 -
645 - $values = $data->getPropertyValues( $diProperty );
646 -
647 - //Check on needed property name and safe its values
648 -
649 -
650 - if ( $incoming && ( count( $values ) >= SWBSpecialBrowseWiki::$incomingvaluescount ) ) {
651 - $moreIncoming = true;
652 - array_pop( $values );
653 - } else {
654 - $moreIncoming = false;
655 - }
656 -
657 - $first = true;
658 - foreach ( $values as $di ) {
659 - if ( $first ) {
660 - $first = false;
661 - } else {
662 - $body .= ', ';
663 - }
664 -
665 - if ( $incoming ) {
666 - $dv = SMWDataValueFactory::newDataItemValue( $di, null );
667 - } else {
668 - $dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
669 - }
670 - $value=$this->displayValue( $dvProperty, $dv, $incoming );
671 - //$text=$value->getValue();
672 - echo " GetProperty.Value='".$value."'";
673 - if(strpos($label,$propertyName)>0){
674 - echo "index ok";
675 - array_push($returnvalues,$value);
676 - }
677 - // echo "Text='".$text."'";
678 - $body .= "<span class=\"{$ccsPrefix}value\">" .
679 - $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>\n";
680 - }
681 -
682 - if ( $moreIncoming ) { // link to the remaining incoming pages:
683 - $body .= Html::element(
684 - 'a',
685 - array(
686 - 'href' => SpecialPage::getSafeTitleFor( 'SearchByProperty' )->getLocalURL( array(
687 - 'property' => $dvProperty->getWikiValue(),
688 - 'value' => $this->subject->getWikiValue()
689 - ) )
690 - ),
691 - wfMsg( "smw_browse_more" )
692 - );
693 -
694 - }
695 -
696 - $body .= "</td>\n";
697 -
698 - // display row
699 - $html .= "<tr class=\"{$ccsPrefix}propvalue\">\n" .
700 - ( $left ? ( $head . $body ):( $body . $head ) ) . "</tr>\n";
701 - $noresult = false;
702 - } // end foreach properties
703 -
704 - if ( $noresult ) {
705 - $html .= "<tr class=\"smwb-propvalue\"><th> &#160; </th><td><em>" .
706 - wfMsg( $incoming ? 'swb_browse_no_incoming':'swb_browse_no_outgoing' ) . "</em></td></tr>\n";
707 - }
708 - $html .= "</table>\n";
709 - return $returnvalues;
710 - }
711 -
712 - /**
713503 * Creates the HTML table displaying the Semantic Web data of one uri
714504 *
715505 * @param SMWSemanticData $data
@@ -717,11 +507,11 @@
718508 *
719509 * @return A string containing the HTML with the factbox
720510 */
721 - private function displaySemanticWebData (SMWSemanticData $data, $left = true, $incoming = false ) {
 511+ private function displaySemanticWebData ( SMWSemanticData $data, $left = true, $incoming = false ) {
722512 // Some of the CSS classes are different for the left or the right side.
723513 // In this case, there is an "i" after the "smwb-". This is set here.
724514 $ccsPrefix = $left ? 'smwb-' : 'smwb-i';
725 -
 515+
726516 $html = "<table class=\"{$ccsPrefix}factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
727517
728518 $diProperties = $data->getProperties();
@@ -737,7 +527,7 @@
738528
739529 // Typically, we have a URI. Provide link to further browse the SW.
740530 // Always type 11 for prop: echo "dipropType:".$diProperty->getDIType();
741 -
 531+
742532 } elseif ( $diProperty->getKey() == '_INST' ) {
743533 $proptext = smwfGetLinker()->specialLink( 'Categories' );
744534 } elseif ( $diProperty->getKey() == '_REDI' ) {
@@ -769,14 +559,12 @@
770560 if ( $incoming ) {
771561 $dv = SMWDataValueFactory::newDataItemValue( $di, null );
772562 } else {
773 - //$dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
774563 // We do have values of different types, therefore not specific property.
775564 // TODO: Later, we could look into property, whether specific type to override.
776565 $dv = SMWDataValueFactory::newDataItemValue( $di, null );
777566 }
778567
779568 $body .= "<span class=\"{$ccsPrefix}value\">" .
780 - //$this->displayValue( $dvProperty, $dv, $incoming ) . "</span>\n";
781569 $this->displaySemanticValue( $dvProperty, $dv, $incoming ) . "</span>\n";
782570 }
783571
@@ -785,11 +573,11 @@
786574 'a',
787575 array(
788576 'href' => SpecialPage::getSafeTitleFor( 'SearchByProperty' )->getLocalURL( array(
789 - 'property' => $dvProperty->getWikiValue(),
 577+ 'property' => $dvProperty->getWikiValue(),
790578 'value' => $this->subject->getWikiValue()
791579 ) )
792580 ),
793 - wfMsg( "smw_browse_more" )
 581+ wfMsg( "swb_browse_more" )
794582 );
795583
796584 }
@@ -800,13 +588,14 @@
801589 $html .= "<tr class=\"{$ccsPrefix}propvalue\">\n" .
802590 ( $left ? ( $head . $body ):( $body . $head ) ) . "</tr>\n";
803591 $noresult = false;
804 - } // end foreach properties
 592+ }
805593
806594 if ( $noresult ) {
807595 $html .= "<tr class=\"smwb-propvalue\"><th> &#160; </th><td><em>" .
808596 wfMsg( $incoming ? 'swb_browse_no_incoming':'swb_browse_no_outgoing' ) . "</em></td></tr>\n";
809597 }
810598 $html .= "</table>\n";
 599+
811600 return $html;
812601 }
813602
@@ -822,15 +611,15 @@
823612 private function displayData( SMWSemanticData $data, $left = true, $incoming = false ) {
824613 // Some of the CSS classes are different for the left or the right side.
825614 // In this case, there is an "i" after the "smwb-". This is set here.
 615+ $arr_uris = array();
826616 $ccsPrefix = $left ? 'smwb-' : 'smwb-i';
827617
828618 $html = "<table class=\"{$ccsPrefix}factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
829 -
 619+
830620 $diProperties = $data->getProperties();
831621 $noresult = true;
832622 foreach ( $diProperties as $diProperty ) {
833623 $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null );
834 -
835624 if ( $dvProperty->isVisible() ) {
836625 $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) );
837626 $proptext = $dvProperty->getShortHTMLText( smwfGetLinker() ) . "\n";
@@ -856,6 +645,16 @@
857646
858647 $first = true;
859648 foreach ( $values as $di ) {
 649+ if( get_class( $di ) == "SMWDIWikiPage" ){
 650+ $this->debug( "[WIKIPage]" );
 651+
 652+ }elseif( get_class ( $di ) == "SMWDITime" ){
 653+ $this->debug ( "[SMWTime]" );
 654+ }elseif( get_class ( $di ) == "SMWDIUri" ){
 655+ $this->debug ( "[DiURI]" );
 656+ }else{
 657+ $this->debug( "[nothing]" );
 658+ }
860659 if ( $first ) {
861660 $first = false;
862661 } else {
@@ -876,11 +675,11 @@
877676 'a',
878677 array(
879678 'href' => SpecialPage::getSafeTitleFor( 'SearchByProperty' )->getLocalURL( array(
880 - 'property' => $dvProperty->getWikiValue(),
 679+ 'property' => $dvProperty->getWikiValue(),
881680 'value' => $this->subject->getWikiValue()
882681 ) )
883682 ),
884 - wfMsg( "smw_browse_more" )
 683+ wfMsg( "swb_browse_more" )
885684 );
886685
887686 }
@@ -912,10 +711,8 @@
913712 */
914713 private function displaySemanticValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) {
915714 $linker = smwfGetLinker();
916 -
917715 $html = $dataValue->getLongHTMLText( $linker );
918716
919 - // TODO: How to I trigger autoload if extends?
920717 SMWInfolink::decodeParameters();
921718 if ( $dataValue->getTypeID() == '_wpg' ) {
922719 $html .= "&#160;" . SWBInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker );
@@ -928,8 +725,6 @@
929726 // Provide link for browsing
930727 $html .= "&#160;" . SWBInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $linker );
931728 }
932 -
933 - // TODO: Literal possibly visualized different also
934729 }
935730
936731 return $html;
@@ -969,11 +764,21 @@
970765 */
971766 private function displayHead() {
972767 global $wgOut;
973 -
 768+
 769+ /**
 770+ * if subject(that is currently browsed to) contains a "_" so
 771+ * this symbols are replaced in this subject by SMWDataValueFactory with a blank.
 772+ * for solve this problem we replace string $this->subject->getTitle() to
 773+ * the original title($this->articletext)
 774+ */
 775+ $getTitle = smwfGetLinker()->makeLinkObj( $this->subject->getTitle() );
 776+ $replaceTitle = str_replace( $this->subject->getTitle(), $this->articletext, $getTitle );
 777+
974778 $wgOut->setHTMLTitle( $this->subject->getTitle() );
975779 $html = "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
976780 $html .= "<tr class=\"smwb-title\"><td colspan=\"2\">\n";
977 - $html .= smwfGetLinker()->makeLinkObj( $this->subject->getTitle() ) . "\n"; // @todo Replace makeLinkObj with link as soon as we drop MW1.12 compatibility
 781+ //$html .= smwfGetLinker()->makeLinkObj( $this->subject->getTitle() ) . "\n"; // @todo Replace makeLinkObj with link as soon as we drop MW1.12 compatibility
 782+ $html .= $replaceTitle . "\n"; // @todo Replace makeLinkObj with link as soon as we drop MW1.12 compatibility
978783 $html .= "</td></tr>\n";
979784 $html .= "</table>\n";
980785
@@ -991,7 +796,7 @@
992797 $wgOut->setHTMLTitle( $this->subject->getTitle() );
993798 $html = "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
994799 $html .= "<tr class=\"smwb-title\"><td colspan=\"2\">\n";
995 - // No link but full URI should be shown
 800+ // TODO: No link but full URI should be shown
996801 $html .= $uri. "\n"; // @todo Replace makeLinkObj with link as soon as we drop MW1.12 compatibility
997802 $html .= "</td></tr>\n";
998803 $html .= "</table>\n";
@@ -1009,8 +814,8 @@
1010815 "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n" .
1011816 "<tr class=\"smwb-center\"><td colspan=\"2\">\n" .
1012817 ( $this->showincoming ?
1013 - $this->linkHere( wfMsg( 'smw_browse_hide_incoming' ), true, false, 0 ):
1014 - $this->linkHere( wfMsg( 'smw_browse_show_incoming' ), true, true, $this->offset ) ) .
 818+ $this->linkHere( wfMsg( 'swb_browse_hide_incoming' ), true, false, 0 ):
 819+ $this->linkHere( wfMsg( 'swb_browse_show_incoming' ), true, true, $this->offset ) ) .
1015820 "&#160;\n" . "</td></tr>\n" . "</table>\n";
1016821 }
1017822
@@ -1031,7 +836,7 @@
1032837 $this->linkHere( wfMsg( 'smw_result_prev' ), $this->showoutgoing, true, $offset );
1033838 $offset = $this->offset + SWBSpecialBrowseWiki::$incomingpropertiescount - 1;
1034839 $html .= " &#160;&#160;&#160; <strong>" . wfMsg( 'smw_result_results' ) . " " . ( $this->offset + 1 ) .
1035 - " – " . ( $offset ) . "</strong> &#160;&#160;&#160; ";
 840+ " – " . ( $offset ) . "</strong> &#160;&#160;&#160; ";
1036841 $html .= $more ? $this->linkHere( wfMsg( 'smw_result_next' ), $this->showoutgoing, true, $offset ):wfMsg( 'smw_result_next' );
1037842 }
1038843 }
@@ -1115,10 +920,10 @@
1116921 global $smwgBrowseShowInverse;
1117922
1118923 if ( $incoming && $smwgBrowseShowInverse ) {
1119 - $oppositeprop = SMWPropertyValue::makeUserProperty( wfMsg( 'smw_inverse_label_property' ) );
 924+ $oppositeprop = SMWPropertyValue::makeUserProperty( wfMsg( 'swb_inverse_label_property' ) );
1120925 $labelarray = &smwfGetStore()->getPropertyValues( $property->getDataItem()->getDiWikiPage(), $oppositeprop->getDataItem() );
1121926 $rv = ( count( $labelarray ) > 0 ) ? $labelarray[0]->getLongWikiText():
1122 - wfMsg( 'smw_inverse_label_default', $property->getWikiValue() );
 927+ wfMsg( 'swb_inverse_label_default', $property->getWikiValue() );
1123928 } else {
1124929 $rv = $property->getWikiValue();
1125930 }
@@ -1131,17 +936,18 @@
1132937 *
1133938 * @return A string containing the HTML for the form
1134939 */
 940+
1135941 private function queryForm() {
1136942 self::addAutoComplete();
1137943 $title = SpecialPage::getTitleFor( 'BrowseWiki' );
1138944 return ' <form name="smwbrowse" action="' . $title->escapeLocalURL() . '" method="get">' . "\n" .
1139945 ' <input type="hidden" name="title" value="' . $title->getPrefixedText() . '"/>' .
1140 - wfMsg( 'smw_browse_article' ) . "<br />\n" .
 946+ wfMsg( 'swb_browse_article' ) . "<br />\n" .
1141947 ' <input type="text" name="article" id="page_input_box" value="' . htmlspecialchars( $this->articletext ) . '" />' . "\n" .
1142 - ' <input type="submit" value="' . wfMsg( 'smw_browse_go' ) . "\"/>\n" .
 948+ ' <input type="submit" value="' . wfMsg( 'swb_browse_go' ) . "\"/>\n" .
1143949 " </form>\n";
1144950 }
1145 -
 951+
1146952 /**
1147953 * Creates the JS needed for adding auto-completion to queryForm(). Uses the
1148954 * MW API to fetch suggestions.
@@ -1167,7 +973,31 @@
1168974
1169975 SMWOutputs::requireScript( 'smwAutocompleteSpecialBrowse', $javascript_autocomplete_text );
1170976 }
 977+
 978+
 979+ /**
 980+ * Creates the JS needed for
 981+ */
 982+ private static function setStartMenu(){
 983+ SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
1171984
 985+ $javascript_autocomplete_text = <<<END
 986+<script type="text/javascript">
 987+jQuery(document).ready(function(){
 988+ var xxx="hallo";
 989+ echo "xxx=".xxx;
 990+ druck = window.open ('', 'fenster', xxx);
 991+ druck.print();
 992+
 993+});
 994+</script>
 995+
 996+END;
 997+
 998+ SMWOutputs::requireScript( 'smwAutocompleteSpecialBrowse', $javascript_autocomplete_text );
 999+ }
 1000+
 1001+
11721002 /**
11731003 * Replace the last two space characters with unbreakable spaces for beautification.
11741004 *
@@ -1180,77 +1010,17 @@
11811011 return $count > 2 ? preg_replace( '/($nonBreakingSpace)/u', ' ', $text, max( 0, $count - 2 ) ):$text;
11821012 }
11831013
 1014+
 1015+/* can be used for testing
 1016+ * 1.parameter is the text to display
 1017+ * 2.parameter is the name of the text
 1018+ */
11841019
1185 - //Add Test Foaf-Info
 1020+public static function debug( $displaytext,$name=""){
 1021+ //echo $name;
 1022+ //echo $name."='".$displaytext."' "."<br />";
 1023+ }
11861024
1187 - /**
1188 - *
1189 - * create object EaysRDF Graph based on uri
1190 - * load graph
1191 - * load information about person
1192 - * get information about person
1193 - * safe information together and return this information
1194 - * @param unknown_type $uri
1195 - * @param unknown_type $html
1196 - */
1197 -
1198 - private function foafInfo($uri){
1199 - global $wgOut;
1200 - $html="\n";
1201 - if (isset($uri)) {
1202 - if ( $uri != '' ) {
1203 - $graph = new EasyRdf_Graph($uri);
1204 - $graph->load();
1205 - if ($graph->type() == 'foaf:PersonalProfileDocument') {
1206 - $person = $graph->primaryTopic();
1207 - }elseif ($graph->type() == 'foaf:Person') {
1208 - $person = $graph->resource();
1209 - }
1210 - }
1211 - }
1212 - $html.=$this->displayHead();
1213 - if (isset($person)) {
1214 - $Name=$person->get('foaf:name');
1215 - $Homepage=link_to( $person->get('foaf:homepage') );
1216 - $Description=$person->get(array('dc:description','dc11:description'));
1217 - $html.="Name:".$Name."<br />";
1218 - $html.="Homepage:".$Homepage."<br />";
1219 - $html.="Description:".$Description."<br />";
1220 -
1221 - $wgOut->addHTML("Name:".$Name);
1222 - $wgOut->addHTML("Homepage:".$Homepage);
1223 - $wgOut->addHTML("Description:".$Description);
1224 -
1225 - //echo "<h2>Known Persons</h2>\n";
1226 - //echo "<ul>\n";
1227 - $html.="<h2>Known Persons</h2>\n";
1228 - $html.="<ul>\n";
1229 - foreach ($person->all('foaf:knows') as $friend) {
1230 - $label = $friend->label();
1231 - if (!$label) {
1232 - $label = $friend->getUri();
1233 - }
1234 -
1235 - if ($friend->isBnode()) {
1236 - //echo "<li>$label</li>";
1237 - $html.="<li>$label</li>";
1238 - } else {
1239 - $html.="<li>".link_to_self( $label, 'uri='.urlencode($friend) )."</li>";
1240 - // echo "<li>".link_to_self( $label, 'uri='.urlencode($friend) )."</li>";
1241 - }
1242 - }
1243 - // echo "</ul>\n";
1244 - $html.="</ul>\n";
1245 - }
1246 -
1247 - if (isset($graph)) {
1248 - //echo "<br />";
1249 - // echo $graph->dump();
1250 - $html.="<br />";
1251 - $html.=$graph->dump();
1252 - }
1253 - return $html;
1254 - }
1255 -
 1025+
12561026 }
12571027
Index: trunk/extensions/SemanticWebBrowser/includes/SWB_CreatePage.php
@@ -1,529 +0,0 @@
2 -<?php
3 -/**
4 - * Class implementing extension for pulling in LOD data
5 - * based on LODPuller
6 - * @ingroup SWB
7 - * @author Anna Kantorovitch
8 - */
9 -
10 -class SWBCreatePage {
11 - static function render( &$out, &$sk ) {
12 - $new = new SWBCreatePage();
13 - return $new->getPage( $out, $sk );
14 - }
15 -
16 - private $title = null;
17 - private $pagename = '';
18 - private $sames = array();
19 - private $localurl = '';
20 -
21 - function getPage( &$out, &$sk ) {
22 - $this->title = $out->getTitle();
23 - $this->pagename = $this->title->getPrefixedText();
24 - if (!(($this->title->getNamespace() === NS_MAIN) || ($this->title->getNamespace() === SMW_NS_PROPERTY) || ($this->title->getNamespace() === SMW_NS_TYPE))) return true;
25 - $this->localurl = $this->title->getPrefixedURL();
26 - if ($this->localurl === 'Main_Page') return true;
27 - global $wgRequest;
28 - if (!(($wgRequest->getText( 'action' ) === 'view') || ($wgRequest->getText( 'action' ) === 'purge') || ($wgRequest->getText( 'action' ) == ''))) return true;
29 -
30 - $out->includeJQuery();
31 - global $swbgIP;
32 - $lodpullerScriptPath=$swbgIP;
33 - $out->addScriptFile( $lodpullerScriptPath . 'js/jquery.jeditable.js' );
34 - $out->addScriptFile( $lodpullerScriptPath . 'js/jquery.loadmask.min.js' );
35 - $out->addScriptFile( $lodpullerScriptPath . 'js/jquery.autocomplete.js' );
36 - $out->addScriptFile( $lodpullerScriptPath . 'js/jquery.translate-NCT,core,NCT-adapter,ui,progress.min.js' );
37 - $out->addScriptFile( $lodpullerScriptPath . 'js/jqModal.js' );
38 -
39 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODPullerAPI.js' );
40 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODUtil.js' );
41 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODSame.js' );
42 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODContent.js' );
43 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODLinks.js' );
44 - $out->addScriptFile( $lodpullerScriptPath . 'js/WikiFacts.js' );
45 - $out->addScriptFile( $lodpullerScriptPath . 'js/Wikipedia.js' );
46 - $out->addScriptFile( $lodpullerScriptPath . 'js/WikiLabels.js' );
47 - $out->addScriptFile( $lodpullerScriptPath . 'js/WikiFacts.js' );
48 - $out->addScriptFile( $lodpullerScriptPath . 'js/LODPuller.js' );
49 - $out->addScriptFile( $lodpullerScriptPath . 'js/main.js' );
50 -
51 - $out->addExtensionStyle( $lodpullerScriptPath . 'css/jquery.autocomplete.css' );
52 - $out->addExtensionStyle( $lodpullerScriptPath . 'css/jquery.loadmask.css' );
53 - $out->addExtensionStyle( $lodpullerScriptPath . 'css/lodpuller.css' );
54 -
55 - global $wgParser;
56 - if (isset($wgParser->lodpuller)) {
57 - global $wgLang;
58 - $label = $wgParser->lodpuller->getLabel($this->title->getPrefixedText(), $wgLang->getCode());
59 - if ($label) {
60 - global $wgSitename;
61 - $out->setHTMLTitle($label . " - " . $wgSitename);
62 - $out->setPageTitle($label);
63 - }
64 - }
65 -
66 -
67 - // Page gets created completely new
68 - $old = $out->getHTML();
69 - $out->clearHTML();
70 -
71 - //$out->addHTML( "<div id=\"lod-main\">\n" );
72 - $this->renderMain( $old, $out );
73 - //$out->addHTML( "</div>\n" ); // lod-main;
74 -
75 - //$out->addHTML( "<div id=\"lod-side\">\n" );
76 - $this->renderSidebar( $out );
77 - //$out->addHTML( "</div>" ); // lod-side
78 -
79 - return true;
80 - }
81 -
82 - /**
83 - * Create the main part of the page, with the text and the
84 - * and Wikipedia page.
85 - *
86 - * @param OutputPage $out Coming from the page renderer
87 - * @return null
88 - */
89 - private function renderMain( &$old, &$out ) {
90 - $out->addHTML( $old );
91 - // TODO simply renders the current page, should render the descriptive blurb
92 -
93 - if (($this->title->getNamespace() === SMW_NS_PROPERTY) || ($this->title->getNamespace() === SMW_NS_TYPE)) return;
94 -
95 - $out->addHTML( '<h2>' . wfMsg('swb-facts') . '</h2>' );
96 - $out->addWikiText( '<div id="main-facts"></div>' );
97 -
98 - $out->addHTML( '<h2>' . wfMsg('swb-webofdata') . '</h2>' );
99 - $out->addHTML( '<div id="lod-content"></div>' );
100 -
101 -// $out->addHTML( '<h2>' . wfMsg('lodpuller-wikipedia') . '</h2>' );
102 -
103 -// $out->addHTML( "<div id=\"wikipedia-content\"></div>\n" );
104 - $out->addHTML( '<h2>' . wfMsg('swb-links') . '</h2>' );
105 - //$this->getFaviki( $out );
106 - $out->addHTML( "<div id=\"swb-links\"></div>\n" );
107 -
108 - }
109 -
110 - private function getFaviki( &$out ) {
111 - $ch = curl_init();
112 -
113 - // TODO change. this should actually take the local part of the dbpedia
114 - // link, not just the name of the page!
115 -
116 - $termenc = urlencode( $this->pagename );
117 -// $url = "http://www.faviki.com/api/get/";
118 - //$out->addWikiText( $url );
119 - curl_setopt($ch, CURLOPT_URL, $url);
120 - curl_setopt($ch, CURLOPT_HEADER, 0);
121 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122 - curl_setopt($ch, CURLOPT_POST, true);
123 - //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST' );
124 - curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_key' => '562a065ae6317a8100bc40e2e895bfb4', 'tag' => $this->pagename));
125 - //curl_setopt($ch, CURLOPT_HTTPHEADER, array ( "Accept: application/json" ));
126 - $xmlanswer = curl_exec($ch);
127 - curl_close($ch);
128 -
129 - $xmlanswer = preg_replace('/&[^; ]{0,6}.?/e', "((substr('\\0',-1) == ';') ? '\\0' : '&amp;'.substr('\\0',1))", $xmlanswer);
130 - //$out->addWikiText( " " . $xmlanswer );
131 -
132 - libxml_use_internal_errors(true);
133 - $xml = simplexml_load_string( $xmlanswer );
134 - $error = false;
135 - foreach(libxml_get_errors() as $error) {
136 - $out->addWikiText( $error->message );
137 - $error = true;
138 - }
139 - if ($error) return;
140 - //$out->addWikiText($xml['status']);
141 - //$out->addWikiText(print_r($xml, true));
142 -
143 - if ($xml->webpages) {
144 - // TODO Change. Make prettier, i.e. add a faviki icon or something
145 - $out->addHTML('<h4>From <a href="http://www.faviki.com">faviki</a> &mdash; tags that make sense</h4>');
146 - $out->addHTML('<ul>');
147 - $i = 0;
148 - foreach($xml->webpages->webpage as $webpage) {
149 - $i = $i + 1;
150 - if ($i > 6) break;
151 - $out->addHTML( "<li><a href=\"$webpage->url\">$webpage->title</a></li>");
152 - }
153 - $out->addHTML("<li><a href=\"http://www.faviki.com/tag/$this->pagename\">More on faviki</a></li>");
154 - $out->addHTML('</ul>');
155 - $out->addHTML('<h4>Links saved in Shortipedia</h4>');
156 - }
157 -
158 - return;
159 - }
160 -
161 - /**
162 - * Checks if the URI is known and an equivalent URI to any of the already
163 - * existing pages. If so, it returns the name of the page, otherwise null.
164 - *
165 - * @param string $uri Identifier for an entity
166 - * @return string The name of the page describing the entity, otherwise null
167 - */
168 - public static function getInternalMapping( $uri ) {
169 - $equivalentURI = SMWPropertyValue::makeUserProperty( "equivalent URI" );
170 - $urivalue = SMWDataValueFactory::newPropertyObjectValue( $equivalentURI, $uri );
171 -
172 - $results = &smwfGetStore()->getPropertySubjects( $equivalentURI, $urivalue );
173 -
174 - $mappings = array();
175 - foreach($results as $result) {
176 - $mappings[] = $result->getWikiValue();
177 - }
178 - if (count($mappings) === 0) return "";
179 - return $mappings[0]; // TODO Only returns one. There never should be more than one.
180 - }
181 -
182 -
183 - /**
184 - * Returns an array of strings with all URIs the given page is equivalent
185 - * to.
186 - *
187 - * @param $pagename Name of the page
188 - * @return array_of_string List of URIs of the entity described by the page
189 - */
190 - public static function getExternalMappings( $pagename ) {
191 - $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename );
192 - $pagename = $subject->isValid() ? $subject->getText():'';
193 - if ($pagename === '') return array();
194 - $equivalentURI = SMWPropertyValue::makeUserProperty( "equivalent URI" );
195 -
196 - $results = &smwfGetStore()->getPropertyValues( $subject, $equivalentURI );
197 -
198 - $mappings = array();
199 - foreach($results as $result) {
200 - $mappings[] = $result->getWikiValue();
201 - }
202 - return $mappings;
203 - }
204 -
205 - public static function getDifferents( $pagename ) {
206 - $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename );
207 - $pagename = $subject->isValid() ? $subject->getText():'';
208 - if ($pagename === '') return array();
209 - $differentFrom = SMWPropertyValue::makeUserProperty( "Different from" );
210 -
211 - $results = &smwfGetStore()->getPropertyValues( $subject, $differentFrom );
212 -
213 - $differents = array();
214 - foreach($results as $result) {
215 - $differents[] = $result->getWikiValue();
216 - }
217 - return $differents;
218 - }
219 -
220 - /**
221 - * Returns an array of pagenames that have the given label in the given
222 - * language.
223 - *
224 - * @param $label Name of the page
225 - * @param $lang Language. Assumes user language if none is given.
226 - * @return array_of_string List of pagenames
227 - */
228 - public static function getPagesByLabel( $label, $lang = '' ) {
229 - if ($lang === '') {
230 - global $wgLang;
231 - $lang = $wgLang->getCode();
232 - }
233 - if ($label === '') return array();
234 - $labelprop = SMWPropertyValue::makeUserProperty( 'label' );
235 - $labelvalue = SMWDataValueFactory::newPropertyObjectValue( $labelprop, "$label;$lang" );
236 -
237 - $results = &smwfGetStore()->getPropertySubjects( $labelprop, $labelvalue );
238 -
239 - $pages = array();
240 - foreach($results as $result) {
241 - $pages[] = $result->getWikiValue();
242 - }
243 - return $pages;
244 - }
245 -
246 - /**
247 - * Returns an array of pagenames that have the given alias in the given
248 - * language.
249 - *
250 - * @param $label Alias of the page
251 - * @param $lang Language. Assumes user language if none is given.
252 - * @return array_of_string List of pagenames
253 - */
254 - public static function getPagesByAlias( $label, $lang = '' ) {
255 - if ($lang === '') {
256 - global $wgLang;
257 - $lang = $wgLang->getCode();
258 - }
259 - if ($label === '') return array();
260 - //$propertyDv = SMWPropertyValue::makeUserProperty( $propertyName );
261 - //$propertyDi = $propertyDv->getDataItem();
262 - //$result = SMWDataValueFactory::newPropertyObjectValue( $propertyDi, $value, $caption );
263 -
264 - $propertyDv = SMWPropertyValue::makeUserProperty( 'alias' );
265 - $propertyDi = $propertyDv->getDataItem();
266 - $labelvalue = SMWDataValueFactory::newPropertyObjectValue( $propertyDi, "$label;$lang" );
267 -
268 - $results = &smwfGetStore()->getPropertySubjects( $propertyDi, $labelvalue );
269 -
270 - $pages = array();
271 - foreach($results as $result) {
272 - $pages[] = $result->getWikiValue();
273 - }
274 - return $pages;
275 - }
276 -
277 - /**
278 - * Returns the page that is linked to the given Wikipedia article
279 - *
280 - * @param $articlename Name of the article
281 - * @param $lang Language. Assumes user language if none is given.
282 - * @return string Resulting page
283 - */
284 - public static function getPageByWikipediaLink( $articlename, $lang = '' ) {
285 - if ($lang === '') {
286 - global $wgLang;
287 - $lang = $wgLang->getCode();
288 - }
289 - if ($articlename === '') return array();
290 - $labelprop = SMWPropertyValue::makeUserProperty( 'Wikipedia' );
291 - $labelvalue = SMWDataValueFactory::newPropertyObjectValue( $labelprop, "$articlename;$lang" );
292 -
293 - $results = &smwfGetStore()->getPropertySubjects( $labelprop, $labelvalue );
294 -
295 - $pages = array();
296 - foreach($results as $result) {
297 - return $result->getWikiValue();
298 - }
299 - return '';
300 - }
301 -
302 - /**
303 - * Returns the label of a page in the given language. If no language is
304 - * given, the user language is assumed.
305 - *
306 - * @param $pagename Name of the page
307 - * @param $lang Language (as the usual Wikipedia codes)
308 - * @return string Label, or empty string if none is set
309 - */
310 - public static function getLabel( $pagename, $lang = '' ) {
311 - return SWBCreatePage::getI18nData( 'Label', $pagename, $lang );
312 - }
313 -
314 - /**
315 - * Returns the description of a page in the given language. If no language is
316 - * given, the user language is assumed.
317 - *
318 - * @param $pagename Name of the page
319 - * @param $lang Language (as the usual Wikipedia codes)
320 - * @return string Description, or empty string if none is set
321 - */
322 - public static function getDescription( $pagename, $lang = '' ) {
323 - return SWBCreatePage::getI18nData( 'Description', $pagename, $lang );
324 - }
325 -
326 - /**
327 - * Returns the wikipedia link of a page in the given language. If no
328 - * language is given, the user language is assumed.
329 - *
330 - * @param $pagename Name of the page
331 - * @param $lang Language (as the usual Wikipedia codes)
332 - * @return string Label, or empty string if none is set
333 - */
334 - public static function getWikipediaLink( $pagename, $lang = '' ) {
335 - return SWBCreatePage::getI18nData( 'Wikipedia', $pagename, $lang );
336 - }
337 -
338 - /**
339 - * Implementation for the getLabel and getWikipediaLink methods.
340 - *
341 - * @param string $type One of 'label' or 'wikipedia'
342 - * @param string $pagename Target page name
343 - * @param string $lang Language to use
344 - * @return string Result from database, dependent on type
345 - */
346 - private static function getI18nData( $type, $pagename, $lang ) {
347 - $alllangs = ($lang==='all');
348 - if ($lang === '') {
349 - global $wgLang;
350 - $lang = $wgLang->getCode();
351 - }
352 - $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename );
353 - $pagename = $subject->isValid() ? $subject->getText():'';
354 - if ($pagename === '') return $alllangs ? array() : '';
355 - $prop = SMWPropertyValue::makeUserProperty( $type );
356 -
357 - $results = &smwfGetStore()->getPropertyValues( $subject, $prop );
358 -
359 - // We get back an array of SMWRecordValues, where the first value is
360 - // the label and the second the language. As soon as we find the
361 - // correct language, return the label
362 - $content = array();
363 - foreach($results as $result) {
364 - $dvs = $result->getDVs();
365 - if (count($dvs) != 2) continue;
366 - if ($alllangs) {
367 - $content[$dvs[1]->getWikiValue()] = $dvs[0]->getWikiValue();
368 - } else {
369 - if ($lang === $dvs[1]->getWikiValue())
370 - return $dvs[0]->getWikiValue();
371 - }
372 - }
373 - return $alllangs ? $content : '';
374 - }
375 -
376 - static public function getWikipediaLinks( $pagename ) {
377 - return SWBCreatePage::getI18nData( 'Wikipedia', $pagename, 'all' );
378 - }
379 -
380 - static public function getType( $pagename ) {
381 - $property = SMWPropertyValue::makeUserProperty( $pagename );
382 - if ($property == null) return '';
383 - return $property->getTypesValue()->getWikiValue();
384 - }
385 -
386 - /**
387 - * Checks if a the given language is one of the languages known to the
388 - * system.
389 - *
390 - * @param string $lang Language code to be checked
391 - * @return bool true if a known language, else false
392 - */
393 - static public function validLanguage( $lang ) {
394 - global $lodpullerAllLanguages;
395 - return (array_key_exists($lang, $lodpullerAllLanguages));
396 - }
397 -
398 - /**
399 - * Create the sidebar with the facts from the system, the possible matches,
400 - * and the external facts.
401 - *
402 - * @param OutputPage $out Coming from the page renderer
403 - * @return null
404 - */
405 - private function renderSidebar( &$out ) {
406 - global $wgLang;
407 -
408 - if ($this->title->getNamespace() === SMW_NS_PROPERTY) {
409 - $currenttype = 'Type:' . SWBCreatePage::getType( $this->pagename );
410 - $out->addHTML( '<h3>' . wfMsg('lodpuller-propertytype') . '</h3>' );
411 - $out->addHTML( '<form id="propertytypeform"><select id="propertytype" value="' . $currenttype .'">' );
412 - $types = $this->getTypes( $wgLang->getCode() );
413 - foreach($types as $type => $label) {
414 - $selected = ($type == $currenttype)? ' selected="selected"' : '';
415 - $out->addHTML( "<option value=\"$type\"$selected>$label</option>" );
416 - }
417 - $out->addHTML( '</select></form>' );
418 - }
419 -
420 - $out->addHTML( '<h2>' . wfMsg('lodpuller-labels') . '</h2>' );
421 - $out->addHTML( '<div id="sidebar-labels"></div>' );
422 -
423 - return;
424 - }
425 -
426 - static private function getTypes( $lang ) {
427 - // Create the query
428 - $parser = new SMWQueryParser();
429 - $description = $parser->getQueryDescription( '[[Type:+]]' );
430 - $labelprop = SMWPropertyValue::makeUserProperty( 'Label' );
431 - $labelpr = new SMWPrintRequest( SMWPrintRequest::PRINT_PROP, 'Label', $labelprop );
432 - $description->addPrintRequest( $labelpr );
433 - $query = new SMWQuery( $description );
434 -
435 - $results = &smwfGetStore()->getQueryResult( $query );
436 -
437 - $types = array();
438 - while($result = $results->getNext()) {
439 - $title = $result[0]->getResultSubject()->getWikiValue();
440 - if (in_array($title, array('Type:Record', 'Type:Annotation URI', 'Type:Code', 'Type:Text'))) continue;
441 -
442 - $label = '';
443 - while($labelrecord = $result[0]->getNextObject()) {
444 - $dvs = $labelrecord->getDVs();
445 - if ($dvs[1]->getWikiValue() === $lang)
446 - $label = $dvs[0]->getWikiValue();
447 - }
448 - $types[$title] = $label ? $label : $title;
449 - }
450 -
451 - return $types;
452 - }
453 -
454 - static public function preferences( $user, &$preferences ) {
455 -
456 - $preferences['lodpuller-lang'] = array(
457 - 'type' => 'toggle',
458 - 'label-message' => 'lodpuller-usecustomlang',
459 - 'section' => 'personal/i18n'
460 - );
461 -
462 - global $lodpullerAllLanguages;
463 - foreach ( $lodpullerAllLanguages as $code => $name ) {
464 - $preferences['lodpuller-lang-' . $code] = array(
465 - 'type' => 'toggle',
466 - 'label' => $code . ' - ' . $name,
467 - 'section' => 'language'
468 - );
469 - }
470 -
471 - // TODO Change the yourlanguage label in preferences info/i18n to "User Interface Language"
472 - return true;
473 - }
474 -
475 - /**
476 - * Function hooked to MakeGlobalVariablesScript. Add all the variables that
477 - * are needed for the JavaScript.
478 - * See http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
479 - *
480 - * @param array $vars variable (or multiple variables) to be added into the output of Skin::makeVariablesScript
481 - * @return bool true if everything went OK
482 - */
483 - static public function addJSVariables( &$vars ) {
484 - global $wgParser;
485 - $vars['lodpullerfacts'] = isset($wgParser->lodpuller) ? $wgParser->lodpuller->getResultObject() : array();
486 -
487 - // List of all messages that need to be made available to the JS
488 - $lodpullerJSMessages = array(
489 - 'loadingwikipedia', 'loadingwebofdata',
490 - 'browse', 'go', 'cancel', 'hide', 'show', 'load', 'saving', 'close',
491 - 'showalllanguages', 'hidesomelanguages',
492 - 'addfact', 'removefact', 'addingfact', 'removingfact',
493 - 'source', 'sources', 'addsource', 'removesource', 'addingsource', 'removingsource',
494 - 'map', 'unmap', 'maping', 'unmapping', 'addmapping',
495 - 'morefrom', 'nodata', 'loadinglinkeddata', 'addlabel', 'adddescription', 'addlink',
496 - 'addinglabel', 'addingdescription', 'addfacts', 'removefacts',
497 - 'mapwikipedia', 'mapotherwikipedia', 'unmapwikipedia', 'addwikipedia',
498 - 'alias', 'aliases', 'addalias', 'removealias', 'addingalias', 'removingalias',
499 - 'removelod', 'hideproperty',
500 - 'help-title', 'help-add-fact'
501 - );
502 - foreach($lodpullerJSMessages as $key) {
503 - $lodpullermessages[$key] = wfMsg('lodpuller-' . $key);
504 - }
505 - $vars['lpMsgs'] = $lodpullermessages;
506 - $vars['lpLanguages'] = SWBCreatePage::getLanguageLabels();
507 - return true;
508 - }
509 -
510 - static public function getLanguageLabels() {
511 - global $wgParser, $lodpullerDefaultLanguages, $lodpullerAllLanguages, $wgUser, $wgLang;
512 - $languages = array();
513 - foreach ( $lodpullerAllLanguages as $code => $name ) {
514 - $label = $description = '';
515 - if ($wgUser->getBoolOption( 'lodpuller-lang' ))
516 - $show = $wgUser->getBoolOption( 'lodpuller-lang-' . $code);
517 - else
518 - $show = in_array($code, $lodpullerDefaultLanguages);
519 - if ($code === $wgLang->getCode()) $show = true;
520 - if (isset($wgParser->lodpuller))
521 - $label = $wgParser->lodpuller->getLabel($wgParser->getTitle()->getPrefixedText(), $code );
522 - if (isset($wgParser->lodpuller))
523 - $description = $wgParser->lodpuller->getDescription($wgParser->getTitle()->getPrefixedText(), $code );
524 - $lang = array("lang"=>array($code, $name, $show), "label"=>$label, "desc"=>$description);
525 - array_push($languages, $lang);
526 - }
527 - return $languages;
528 - }
529 -}
530 -
Index: trunk/extensions/SemanticWebBrowser/includes/SWB_Setup.php
@@ -1,62 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Global functions used for setting up the Semantic WebBrowser extension.
6 - * @author Benedikt K�mpgen and Anna Kantorovitch
7 - * @file SWB_Setup.php
8 - * @ingroup SWB
9 - */
10 -//include for toolbox
11 -global $swbgToolboxBrowseSemWeb;
12 -
13 -$wgExtensionMessagesFiles['SemanticWebBrowser'] = $swbgIP . 'languages/SWB_Messages.php'; // register messages (requires MW=>1.11)
14 -
15 -// Register special pages aliases file
16 -$wgExtensionAliasesFiles['SemanticWebBrowser'] = $swbgIP . 'languages/SWB_Aliases.php';
17 -
18 -/**
19 - * create Special Page for Browse Wiki
20 - */
21 -$wgAutoloadClasses['SWBSpecialBrowseWiki'] = $swbgIP . 'specials/SearchTriple/SWB_SpecialBrowseWiki.php';
22 -$wgSpecialPages['BrowseWiki'] = 'SWBSpecialBrowseWiki';
23 -$wgSpecialPageGroups['BrowseWiki'] = 'smw_group';
24 -
25 -// InfoLink
26 -$wgAutoloadClasses['SWBInfolink'] = $swbgIP . 'includes/SWB_Infolink.php';
27 -
28 -// Data values
29 -$wgAutoloadClasses['SWBResolvableUriValue'] = $swbgIP . 'includes/datavalues/SWBResolvableUriValue.php';
30 -
31 -$wgHooks['smwInitProperties'][] = 'registerPropertyTypes';
32 -
33 -
34 -function registerPropertyTypes() {
35 - // 5 means uri
36 - SMWDataValueFactory::registerDatatype( "_rur", "SWBResolvableUriValue", SMWDataItem::TYPE_URI, $label = false );
37 -
38 - return true;
39 -}
40 -
41 -//include in toolbox direcly link to Browsing Semantic Web
42 -
43 -if ( $swbgToolboxBrowseSemWeb ) {
44 - $wgHooks['SkinTemplateToolboxEnd'][] = 'swbfShowBrowseSemWeb';
45 -}
46 -
47 -/**
48 - * Add a link to the toolbox to view the properties of the current page in
49 - * Special:Browse. The links has the CSS id "t-swbbrowsesemweb" so that it can be
50 - * skinned or hidden with all standard mechanisms (also by individual users
51 - * with custom CSS).
52 - */
53 -function swbfShowBrowseSemWeb( $skintemplate ) {
54 - if ( $skintemplate->data['isarticle'] ) {
55 - smwfLoadExtensionMessages( 'SemanticWebBrowser' );
56 -
57 - $browsesemweb = SWBInfolink::newBrowsingSemWeb( wfMsg( 'swb_browse_semantic_web' ),
58 - $skintemplate->data['titleprefixeddbkey'], false );
59 - echo '<li id="t-swbbrowsesemweb">' . $browsesemweb->getHTML() . '</li>';
60 - }
61 - return true;
62 -}
63 -
Index: trunk/extensions/SemanticWebBrowser/includes/SWB_SemanticSearchByLabel.php
@@ -1,129 +0,0 @@
2 -<?php
3 -/**
4 - * based on LODPullerByLabel
5 - * @group SWB
6 - * @author Anna
7 - *
8 - */
9 -class SWBSemanticSearchByLabel extends SpecialPage {
10 - function __construct() {
11 - parent::__construct( 'SWBSemanticSearchByLabel' );
12 - }
13 -
14 - function execute( $par ) {
15 - global $wgRequest, $wgOut, $wgScriptPath, $wgServer;
16 -
17 - $this->setHeaders(); // check if really needed, i.e. for a redirect
18 -
19 - # Get request data: $lang and $label
20 - // TODO if no lang or label is given, maybe a form should appear to ask for both
21 - $lang = $wgRequest->getText('uselang');
22 - if ($lang) {
23 - if (!SWBCreatePage::validLanguage($lang)) {
24 - $wgOut->addWikiText("Specified language unknown to the system.");
25 - // No I18n since we would not know in which language, obviously
26 - return;
27 - }
28 - } else {
29 - global $wgLang;
30 - $lang = $wgLang->getCode();
31 - }
32 -
33 - $label = $par;
34 - if (!$par) {
35 - $label = $wgRequest->getText('label');
36 - if (!$label) {
37 - $wgOut->addWikiText( wfMsg('swb-nolabelgiven') );
38 - return;
39 - }
40 - }
41 -
42 - $pages = SWBCreatePage::getPagesByAlias( $label, $lang );
43 -
44 - if (count($pages) === 0) {
45 - // Do nothing
46 - } elseif (count($pages) === 1) {
47 - // Go to that page directly
48 - $wgOut->redirect( "$wgScriptPath/topic/$lang/$pages[0]" );
49 - return;
50 - } else {
51 - global $wgSitename;
52 - $wgOut->setHTMLTitle( wfMsg('swb-disambiguation') . ':' . $label . ' - ' . $wgSitename );
53 - $wgOut->setPageTitle( $label );
54 - $wgOut->addWikiText( wfMsg('swb-disambiguationpage', $label) );
55 - foreach ($pages as $page) {
56 - $plabel = SWBCreatePage::getLabel($page, $lang);
57 - $pdescription = SWBCreatePage::getDescription($page, $lang);
58 - $wgOut->addWikiText( "* '''[[$page|$plabel]]''': $pdescription" );
59 - }
60 - $wgOut->addWikiText( "\n\n" );
61 - }
62 -
63 - list($wphits, $wpsuggest, $wpresults) = SWBSemanticSearchByLabel::getWikipediaSearch( $label, $lang );
64 -
65 - $exactmatch = false;
66 - if (count($wpresults)) {
67 - $wgOut->addWikiText( wfMsg('swb-wpsearchresults' ) );
68 - $wgOut->addHTML('<ul>');
69 - foreach($wpresults as $title => $snippet) {
70 - if ($title == $label) $exactmatch = true;
71 - $target = str_replace(' ', '_', $title);
72 - $wgOut->addHTML("<li><a href=\"$wgServer$wgScriptPath/wikipedia/$lang/$target\">$title</a><br> <em>$snippet</em></li>");
73 - }
74 - $wgOut->addHTML('</ul>');
75 - $wgOut->addWikiText( "\n\n" );
76 - }
77 -
78 - if ($wpsuggest) {
79 - $wgOut->addWikiText( wfMsg('swb-didyoumean') );
80 - $target = str_replace(' ', '_', $wpsuggest);
81 - $wgOut->addHTML("<ul><li><a href=\"$wgServer$wgScriptPath/$lang/$target\">$wpsuggest</a></li></ul>");
82 - $wgOut->addWikiText( "\n\n" );
83 - }
84 -
85 -
86 - // If nothing was found
87 - if ((count($pages)===0) && (!$exactmatch)) {
88 - $title = Title::newFromText( $label );
89 - if ($title->exists()) {
90 - // If the page exists (but not with the title)
91 - $wgOut->addWikiText( wfMsg('swb-pagenameexists' ));
92 - $langlabel = SWBCreatePage::getLabel( $label, $lang );
93 - $displaylabel = $langlabel ? $langlabel : $label;
94 - $target = str_replace(' ', '_', $label);
95 - $wgOut->addHtml("<ul><li><a href=\"$wgServer$wgScriptPath/topic/$lang/$target\">$displaylabel</a></li></ul>");
96 - } else {
97 - // If such a page does not exist at all, enable its creation
98 - $wgOut->addWikiText( wfMsg('swb-createpage' ));
99 - $target = str_replace(' ', '_', $label);
100 - $wgOut->addHtml("<ul><li><a href=\"$wgServer$wgScriptPath/topic/$lang/$target\">$label</a></li></ul>");
101 - }
102 - }
103 - }
104 -
105 - // TODO See also LODPullerSuggestAPI::getWikipediaSearch
106 - private static function getWikipediaSearch( $term, $lang ) {
107 - $term = urlencode($term);
108 - $ch = curl_init();
109 - curl_setopt($ch, CURLOPT_URL, "http://$lang.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=$term");
110 - curl_setopt($ch, CURLOPT_USERAGENT, "lodpuller");
111 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
112 - $output = curl_exec($ch);
113 - curl_close($ch);
114 -
115 - $answer = json_decode($output);
116 - $hits = $answer->query->searchinfo->totalhits;
117 - $results = array();
118 - $suggestion = '';
119 - if ($hits === 0) {
120 - if (property_exists($answer->query->searchinfo, 'suggestion'))
121 - $suggestion = $answer->query->searchinfo->suggestion;
122 - } else {
123 - foreach( $answer->query->search as $hit ) {
124 - $results[$hit->title] = $hit->snippet;
125 - }
126 - }
127 - return array($hits, $suggestion, $results);
128 - }
129 -
130 -}
Index: trunk/extensions/SemanticWebBrowser/includes/SWB_ControlProperties.php
@@ -1,535 +0,0 @@
2 -<?php /**
3 - * Helper class to save some data in the parser. Will be added to the parser
4 - * when called.
5 - * based on LODParseHelper
6 - * @ingroup SWB
7 - * @author Anna
8 - */
9 -class SWBControlProperties {
10 - public $lastproperty = "";
11 - public $lastvalue = "";
12 - public $title = "";
13 - public $deflang = "";
14 -
15 - public $facts = array();
16 - public $mappings = array();
17 - public $different = array();
18 - public $labels = array();
19 - public $aliases = array();
20 - public $descriptions = array();
21 - public $wikipedias = array();
22 - public $links = array();
23 - public $type = '';
24 -
25 - public function __construct( &$parser ) {
26 - $this->title = $parser->getTitle()->getPrefixedText();
27 - global $wgLang;
28 - $this->deflang = $wgLang->getCode();
29 - $this->labelize($this->title, $this->deflang);
30 - }
31 -
32 - public function addPropertyValue($property, $value, $lang="") {
33 - $property = ucfirst($property);
34 - if (strpos($property, 'Property:')!==0) $property = 'Property:' . $property;
35 - if (SWBControlProperties::forbiddenProperty($property)) return;
36 - if (!array_key_exists($property, $this->facts))
37 - $this->facts[$property] = array();
38 - if (!array_key_exists($value, $this->facts[$property]))
39 - $this->facts[$property][$value] = array();
40 -
41 - $this->labelize($property, $lang);
42 - $this->labelize($value, $lang);
43 - }
44 -
45 - public static function forbiddenProperty($property) {
46 - $forbidden = array('Property:Label', 'Property:Alias',
47 - 'Property:Wikipedia', 'Property:Has type', 'Property:Description',
48 - 'Property:Equivalent URI', 'Property:Modification date',
49 - 'Property:Different from');
50 - $property = ucfirst($property);
51 - if (strpos($property, 'Property:')!==0) $property = 'Property:' . $property;
52 - return in_array($property, $forbidden);
53 - }
54 -
55 - public function removePropertyValue($property, $value, $lang="") {
56 - $property = ucfirst($property);
57 - if (strpos($property, 'Property:')!==0) $property = 'Property:' . $property;
58 - if (!array_key_exists($property, $this->facts))
59 - return;
60 - if (!array_key_exists($value, $this->facts[$property]))
61 - return;
62 - unset($this->facts[$property][$value]);
63 - if (count($this->facts[$property]) === 0) {
64 - unset($this->facts[$property]);
65 - return;
66 - }
67 - }
68 -
69 - public function addSource($property, $value, $source, $lang="") {
70 - $property = ucfirst($property);
71 - if (strpos($property, 'Property:')!==0) $property = 'Property:' . $property;
72 - if (SWBControlProperties::forbiddenProperty($property)) return;
73 - if (!array_key_exists($property, $this->facts))
74 - $this->facts[$property] = array();
75 - if (!array_key_exists($value, $this->facts[$property]))
76 - $this->facts[$property][$value] = array();
77 - if (!in_array($source, $this->facts[$property][$value]))
78 - $this->facts[$property][$value][] = $source;
79 -
80 - $this->labelize($property, $lang);
81 - $this->labelize($value, $lang);
82 - }
83 -
84 - public function removeSource($property, $value, $source, $lang="") {
85 - $property = ucfirst($property);
86 - if (strpos($property, 'Property:')!==0) $property = 'Property:' . $property;
87 - if (!array_key_exists($property, $this->facts))
88 - return;
89 - if (!array_key_exists($value, $this->facts[$property]))
90 - return;
91 - $key = array_search($source, $this->facts[$property][$value]);
92 - if ($key === false) return;
93 - unset($this->facts[$property][$value][$key]);
94 - $this->facts[$property][$value] = array_values($this->facts[$property][$value]);
95 - }
96 -
97 - public function addMapping($uri, $title = '', $lang="") {
98 - if ($title === '') $title = $this->title;
99 - $this->mappings[$uri] = $title;
100 -
101 - $this->labelize($title, $lang);
102 - }
103 -
104 - public function removeMapping($uri, $title = '', $lang="") {
105 - if (array_key_exists($uri, $this->mappings))
106 - unset($this->mappings[$uri]);
107 - }
108 -
109 - public function addDifferent($uri, $title = '', $lang = '') {
110 - if ($title === '') $title = $this->title;
111 - if (in_array($uri, $this->different))
112 - return;
113 - $this->different[] = $uri;
114 - }
115 -
116 - public function removeDifferent($uri, $title = '', $lang = '') {
117 - $key = array_search($uri, $this->different);
118 - if ($key === false)
119 - return;
120 - unset($this->different[$key]);
121 - }
122 -
123 - public function addLabel($entity, $label, $lang) {
124 - if (!SWBCreatePage::validLanguage($lang))
125 - return;
126 - if (!array_key_exists($lang, $this->labels))
127 - $this->labels[$lang] = array();
128 - $this->labels[$lang][$entity] = $label;
129 - }
130 -
131 - public function removeLabel($entity, $label, $lang) {
132 - if (!array_key_exists($lang, $this->labels))
133 - return;
134 - unset($this->labels[$lang][$entity]);
135 - }
136 -
137 - public function getLabel($entity, $lang) {
138 - if (!array_key_exists($lang, $this->labels))
139 - return "";
140 - if (!array_key_exists($entity, $this->labels[$lang]))
141 - return "";
142 - return $this->labels[$lang][$entity];
143 - }
144 -
145 - public function addAlias($entity, $alias, $lang) {
146 - if (!SWBCreatePage::validLanguage($lang))
147 - return;
148 - if (!array_key_exists($lang, $this->aliases))
149 - $this->aliases[$lang] = array();
150 - if (!in_array($alias, $this->aliases[$lang]))
151 - $this->aliases[$lang][] = $alias;
152 - }
153 -
154 - public function removeAlias($entity, $alias, $lang) {
155 - if (!array_key_exists($lang, $this->aliases))
156 - return;
157 - $key = array_search($alias, $this->aliases[$lang]);
158 - if ($key === false)
159 - return;
160 - unset($this->aliases[$lang][$key]);
161 - }
162 -
163 - public function addDescription($entity, $description, $lang) {
164 - if (!SWBCreatePage::validLanguage($lang))
165 - return;
166 - if (!array_key_exists($lang, $this->descriptions))
167 - $this->descriptions[$lang] = array();
168 - $this->descriptions[$lang][$entity] = $description;
169 -
170 - $this->labelize($entity, $lang);
171 - }
172 -
173 - public function removeDescription($entity, $description, $lang) {
174 - if (!array_key_exists($lang, $this->descriptions))
175 - return;
176 - unset($this->descriptions[$lang][$entity]);
177 - }
178 -
179 - public function getDescription($entity, $lang) {
180 - if (!array_key_exists($lang, $this->descriptions))
181 - return "";
182 - if (!array_key_exists($entity, $this->descriptions[$lang]))
183 - return "";
184 - return $this->descriptions[$lang][$entity];
185 - }
186 -
187 - public function addWikipedia($entity, $wikipedia, $lang) {
188 - if (!SWBCreatePage::validLanguage($lang))
189 - return;
190 - $this->wikipedias[$lang] = $wikipedia;
191 - }
192 -
193 - public function removeWikipedia($entity, $wikipedia, $lang) {
194 - if (!array_key_exists($lang, $this->wikipedias))
195 - return;
196 - unset($this->wikipedias[$lang]);
197 - }
198 -
199 - public function getWikipedia($entity, $lang) {
200 - if (!array_key_exists($lang, $this->wikipedias))
201 - return "";
202 - return $this->wikipedias[$lang];
203 - }
204 -
205 - public function addLink( $link ) {
206 - if (in_array($link, $this->links))
207 - return;
208 - $linkvalue = SMWDataValueFactory::newTypeIDValue( '_uri', $link );
209 - if ($linkvalue->isValid())
210 - $this->links[] = $link;
211 - }
212 -
213 - public function removeLink( $link ) {
214 - $key = array_search($link, $this->links);
215 - if ($key === false) return;
216 - unset($this->links[$key]);
217 - }
218 -
219 - public function addType( $type ) {
220 - $this->type = $type;
221 - }
222 -
223 - private function labelize($name, $lang) {
224 - $lang = ($lang==='')? $this->deflang: $lang;
225 - if (!array_key_exists($lang, $this->labels))
226 - $this->labels[$lang] = array();
227 -
228 - if (array_key_exists($name, $this->labels[$lang])) return;
229 - $this->labels[$lang][$name] = SWBCreatePage::getLabel($name, $lang);
230 - }
231 -
232 - function isKnown($property, $object, $objecttype, $source) {
233 - if (!array_key_exists($property, $this->mappings)) return false;
234 - if (!array_key_exists($this->mappings[$property], $this->facts)) return false;
235 - $literal = ($objecttype === 'literal');
236 - if ($literal) {
237 - if (!array_key_exists($object, $this->facts[$this->mappings[$property]])) return false;
238 - $sources = $this->facts[$this->mappings[$property]][$object];
239 - } else {
240 - if (!array_key_exists($object, $this->mappings)) return false;
241 - if (!array_key_exists($this->mappings[$object], $this->facts[$this->mappings[$property]])) return false;
242 - $sources = $this->facts[$this->mappings[$property]][$this->mappings[$object]];
243 - }
244 - return in_array($source, $sources);
245 - }
246 -
247 - /**
248 - * Deals with the #property parser function, i.e. by creating the text for
249 - * the factbox (within the Parser object) and by adding the annotation
250 - * link to the text. Will be called by the parser.
251 - *
252 - * @param $parser
253 - * @return replacement text for the parserfunction
254 - */
255 - static public function doProperty( &$parser ) {
256 - $params = func_get_args();
257 - $prop = $params[1];
258 -
259 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
260 -
261 - $parser->lodpuller->lastproperty = $prop;
262 - $parser->lodpuller->lastvalue = '';
263 -
264 - return '';
265 - }
266 -
267 - /**
268 - * Deals with the #value parser function, i.e. by creating the text for
269 - * the factbox (within the Parser object) and by adding the annotation
270 - * link to the text. Will be called by the parser.
271 - *
272 - * @param $parser
273 - * @return replacement text for the parserfunction
274 - */
275 - static public function doValue( &$parser ) {
276 - $params = func_get_args();
277 - $val = $params[1];
278 -
279 - if (!isset($parser->lodpuller)) return '';
280 - if ($parser->lodpuller->lastproperty === '') return '';
281 -
282 - $prop = $parser->lodpuller->lastproperty;
283 - $parser->lodpuller->lastvalue = $val;
284 -
285 - $parser->lodpuller->addPropertyValue( $prop, $val );
286 -
287 - if (SWBControlProperties::forbiddenProperty($prop)) return '';
288 -
289 - $text = "[[$prop::$val| ]]";
290 - return $text;
291 - }
292 -
293 - /**
294 - * Deals with the #source parser function. Currently nothing happens to the
295 - * source, but it is at least saved. Eventually, the source should be
296 - * exported. // TODO implement saving and exporting the source. somehow :P
297 - *
298 - * @param $parser
299 - * @return replacement text for the parserfunction
300 - */
301 - static public function doSource( &$parser ) {
302 - $params = func_get_args();
303 - $source = $params[1];
304 -
305 - if (!isset($parser->lodpuller)) return "";
306 - if ($parser->lodpuller->lastproperty === "") return "";
307 - if ($parser->lodpuller->lastvalue === "") return "";
308 -
309 - $parser->lodpuller->addSource( $parser->lodpuller->lastproperty, $parser->lodpuller->lastvalue, $source );
310 -
311 - return "";
312 - }
313 -
314 - static public function doMapping( &$parser ) {
315 - $params = func_get_args();
316 - $uri = $params[1];
317 -
318 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
319 -
320 - $parser->lodpuller->addMapping( $uri );
321 -
322 - $text = "[[Equivalent URI::$uri| ]]";
323 - return $text;
324 - }
325 -
326 - static public function doDifferent( &$parser ) {
327 - $params = func_get_args();
328 - $uri = $params[1];
329 -
330 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
331 -
332 - $parser->lodpuller->addDifferent( $uri );
333 -
334 - $text = "[[Different from::$uri| ]]";
335 - return $text;
336 - }
337 -
338 - static public function doLabel ( &$parser ) {
339 - $params = func_get_args();
340 - $lang = $params[1];
341 - $content = $params[2];
342 -
343 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
344 -
345 - $parser->lodpuller->addLabel( $parser->getTitle()->getPrefixedText(), $content, $lang );
346 -
347 - $text = "[[Label::$content;$lang| ]][[Alias::$content;$lang| ]]";
348 - return $text;
349 - }
350 -
351 - static public function doAlias ( &$parser ) {
352 - $params = func_get_args();
353 - $lang = $params[1];
354 - $content = $params[2];
355 -
356 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
357 -
358 - $parser->lodpuller->addAlias( $parser->getTitle()->getPrefixedText(), $content, $lang );
359 -
360 - $text = "[[Alias::$content;$lang| ]]";
361 - return $text;
362 - }
363 -
364 - static public function doDescription ( &$parser ) {
365 - $params = func_get_args();
366 - $lang = $params[1];
367 - $content = $params[2];
368 -
369 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
370 -
371 - $parser->lodpuller->addDescription( $parser->getTitle()->getPrefixedText(), $content, $lang );
372 -
373 - $text = "[[Description::$content;$lang| ]]";
374 - return $text;
375 - }
376 -
377 - static public function doWikipedia ( &$parser ) {
378 - $params = func_get_args();
379 - $lang = $params[1];
380 - $content = $params[2];
381 -
382 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
383 -
384 - $parser->lodpuller->addWikipedia( $parser->getTitle()->getPrefixedText(), $content, $lang );
385 -
386 - $text = "[[Wikipedia::$content;$lang| ]]";
387 - return $text;
388 - }
389 -
390 - static public function doType( &$parser ) {
391 - $params = func_get_args();
392 - $content = $params[1];
393 -
394 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
395 -
396 - $parser->lodpuller->addType( $content );
397 -
398 - $text = "[[Has type::$content| ]]";
399 - return $text;
400 - }
401 -
402 - static public function doLink( &$parser ) {
403 - $params = func_get_args();
404 - $content = $params[1];
405 -
406 - if (!isset($parser->lodpuller)) $parser->lodpuller = new SWBControlProperties( $parser );
407 -
408 - $parser->lodpuller->addLink( $content );
409 -
410 - $text = "[[Link::$content| ]]";
411 - return $text;
412 - }
413 -
414 - public function getWikiText() {
415 - $retval = '';
416 - $labels = $this->removeEmpty($this->labels);
417 - foreach($this->labels as $lang => $labels) {
418 - if (array_key_exists($this->title, $labels)) {
419 - $label = $labels[$this->title];
420 - if ($label)
421 - $retval .= "{{#label:$lang|$label}}";
422 - }
423 - }
424 - foreach($this->aliases as $lang => $aliases) {
425 - foreach($aliases as $alias) {
426 - $retval .= "{{#alias:$lang|$alias}}";
427 - }
428 - }
429 - foreach($this->descriptions as $lang => $descriptions) {
430 - if (array_key_exists($this->title, $descriptions)) {
431 - $description = $descriptions[$this->title];
432 - if ($description)
433 - $retval .= "{{#description:$lang|$description}}";
434 - }
435 - }
436 - foreach($this->wikipedias as $lang => $wikipedia) {
437 - if ($wikipedia)
438 - $retval .= "{{#wikipedia:$lang|$wikipedia}}";
439 - }
440 - foreach($this->mappings as $uri => $mapping) {
441 - $retval .= "{{#mapping:$uri}}";
442 - }
443 - foreach($this->different as $uri) {
444 - $retval .= "{{#different:$uri}}";
445 - }
446 - foreach($this->facts as $property => $values) {
447 - $retval .= "{{#property:$property}}";
448 - foreach($values as $value => $sources) {
449 - $retval .="{{#value:$value}}";
450 - foreach ($sources as $source) {
451 - $retval .= "{{#source:$source}}";
452 - }
453 - }
454 - }
455 - if ($this->type) {
456 - $retval .= "{{#type:$this->type}}";
457 - }
458 - foreach($this->links as $link) {
459 - $retval .= "{{#link:$link}}";
460 - }
461 - return $retval;
462 - }
463 -
464 - private function removeEmpty($arr) {
465 - $result = array();
466 - foreach($arr as $index => $value)
467 - if ($value !== null) $result[$index] = $value;
468 - return $result;
469 - }
470 -
471 - public function getResultObject( $lang = '' ) {
472 - if ($lang === '') {
473 - global $wgLang;
474 - $lang = $wgLang->getCode();
475 - }
476 - $stuff = array();
477 - //$stuff['facts'] = $this->facts;
478 - $facts = array();
479 - global $wgUser, $wgScriptPath, $wgServer;
480 - $skin = $wgUser->getSkin();
481 -
482 - foreach ($this->facts as $property => $valsource) {
483 - foreach ($valsource as $value => $sources) {
484 - $fact = array();
485 - $fact['property'] = $property;
486 - $propertyObj = SMWPropertyValue::makeUserProperty( $property );
487 - $typesvalue = $propertyObj->getTypesValue();
488 - $literal = ($typesvalue->getWikiValue() !== 'Page');
489 - $fact['propertytype'] = $typesvalue->getWikiValue();
490 - $propertylabel = SWBCreatePage::getLabel($property, $lang);
491 - $fact['propertylabel'] = $propertylabel ? $propertylabel : $property;
492 - $fact['value'] = $value;
493 - $fact['valuetype'] = $literal ? 'literal' : 'entity';
494 - if ($literal) {
495 - $valuelabel = $value;
496 - } else {
497 - $valuelabel = SWBCreatePage::getLabel($value, $lang);
498 - if ($valuelabel == '') $valuelabel = 'Topic:' . $value;
499 - }
500 - $fact['valuelabel'] = $valuelabel;
501 - $valueObj = SMWDataValueFactory::newPropertyObjectValue( $propertyObj, $value, $valuelabel );
502 - $long = $valueObj->getShortHTMLText( $skin );
503 - $short = $valueObj->getLongHTMLText( $skin );
504 - if ($literal) {
505 - $valueliteral = (($typesvalue->getWikiValue() == 'Number') && (is_string($short))) ? $short : $long;
506 - } else {
507 - $valueliteral = ( "<a href=\"$wgServer$wgScriptPath/topic/$lang/$value\" class=\"lodlink\">$valuelabel</a>" );
508 - }
509 -
510 - $fact['valueliteral'] = $valueliteral;
511 - //$fact['valueliterallong'] = $long;
512 - //$fact['valueliteralshort'] = $short;
513 - $fact['sources'] = $sources;
514 - $facts[] = $fact;
515 - }
516 - }
517 - $stuff['facts'] = $facts;
518 - $stuff['mappings'] = $this->mappings;
519 - if ($lang == '') $lang = $this->deflang;
520 -
521 - // get the label for all entities in the requested language
522 - $stuff['labels'] = array_key_exists($lang, $this->labels) ? $this->removeEmpty($this->labels[$lang]) : null;
523 - $stuff['aliases'] = $this->aliases;
524 - $stuff['links'] = $this->links;
525 - $stuff['thistype'] = $this->type;
526 -
527 - // get the label for the main entity in all languages
528 - $stuff['thislabel'] = array();
529 - foreach($this->labels as $l => $a)
530 - if (array_key_exists($this->title, $a))
531 - $stuff['thislabel'][$l] = $a[$this->title];
532 -
533 - $stuff['descriptions'] = array_key_exists($lang, $this->descriptions) ? $this->descriptions[$lang] : null;
534 - return $stuff;
535 - }
536 -}
Index: trunk/extensions/SemanticWebBrowser/includes/datavalues/SWBResolvableUriValue.php
@@ -8,10 +8,8 @@
99 * This datavalue implements URL/URI/ANNURI/PHONE/EMAIL datavalues suitable for
1010 * defining the respective types of properties.
1111 *
12 - * @author Nikolas Iwan
13 - * @author Markus Krötzsch
14 - * @ingroup SMWDataValues
15 - * @bug Correctly create safe HTML and Wiki text.
 12+ * @author Anna Kantorovitch
 13+ * @author Benedikt Kämpgen
1614 */
1715 class SWBResolvableUriValue extends SMWDataValue {
1816
@@ -28,7 +26,8 @@
2927 private $m_mode;
3028
3129 protected function parseUserValue( $value ) {
32 -
 30+ // echo "parseUserValue";
 31+
3332 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3433 $value = trim( $value );
3534 $this->m_wikitext = $value;
@@ -85,7 +84,8 @@
8685
8786 // Now create the URI data item:
8887 try {
89 - $this->m_dataitem = new SMWDIUri( $scheme, $hierpart, $query, $fragment, $this->m_typeid);
 88+ SWBSpecialBrowseWiki:: debug( $this->m_typeid, "typeid" );
 89+ $this->m_dataitem = new SMWDIUri( $scheme, $hierpart, $query, $fragment, $this->m_typeid );
9090 } catch ( SMWDataItemException $e ) {
9191 $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) );
9292 $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
@@ -108,7 +108,7 @@
109109 * @return boolean
110110 */
111111 protected function loadDataItem( SMWDataItem $dataItem ) {
112 - echo "loadItem";
 112+ SWBSpecialBrowseWiki:: debug( "loadItem" );
113113 if ( $dataItem->getDIType() == SMWDataItem::TYPE_URI ) {
114114 $this->m_dataitem = $dataItem;
115115 if ( $this->m_mode == SMW_URI_MODE_EMAIL ) {
@@ -126,7 +126,7 @@
127127 }
128128
129129 public function getShortWikiText( $linked = null ) {
130 - echo "shortWiki";
 130+ SWBSpecialBrowseWiki:: debug( "shortWiki" );
131131 $url = $this->getURL();
132132 if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) {
133133 return $this->m_caption;
@@ -136,7 +136,7 @@
137137 }
138138
139139 public function getShortHTMLText( $linker = null ) {
140 - echo "shortHTML";
 140+ SWBSpecialBrowseWiki:: debug( "shortHTML" );
141141 $url = $this->getURL();
142142 if ( ( $linker === null ) || ( !$this->isValid() ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) {
143143 return $this->m_caption;
@@ -146,7 +146,7 @@
147147 }
148148
149149 public function getLongWikiText( $linked = null ) {
150 - echo "longWiki";
 150+ SWBSpecialBrowseWiki:: debug( "longWiki" );
151151 if ( !$this->isValid() ) {
152152 return $this->getErrorText();
153153 }
@@ -159,7 +159,7 @@
160160 }
161161
162162 public function getLongHTMLText( $linker = null ) {
163 - echo "longHTML";
 163+ SWBSpecialBrowseWiki:: debug( "longHTML" );
164164 if ( !$this->isValid() ) {
165165 return $this->getErrorText();
166166 }
@@ -176,7 +176,7 @@
177177 }
178178
179179 public function getURI() {
180 - echo "uri";
 180+ SWBSpecialBrowseWiki:: debug( "uri" );
181181 return $this->m_dataitem->getURI();
182182 }
183183
@@ -193,7 +193,7 @@
194194 * @return string
195195 */
196196 public function getURL() {
197 - echo "getURL";
 197+ SWBSpecialBrowseWiki:: debug( "getURL" );
198198 global $wgUrlProtocols;
199199 foreach ( $wgUrlProtocols as $prot ) {
200200 if ( ( $prot == $this->m_dataitem->getScheme() . ':' ) || ( $prot == $this->m_dataitem->getScheme() . '://' ) ) {
Index: trunk/extensions/SemanticWebBrowser/includes/SWB_Infolink.php
@@ -1,30 +1,22 @@
22 <?php
33
44 /**
5 - *
 5+ *
66 * @file SWB_Infolink
77 * @ingroup SWB
88 * @author Anna Kantorovitch and Benedikt Kämpgen
99 *
1010 */
1111 class SWBInfolink extends SMWInfolink {
12 -
 12+
1313 public function __construct( $internal, $caption, $target, $style = false, array $params = array() ) {
14 - parent::__construct($internal, $caption, $target, $style, $params);
 14+ parent::__construct( $internal, $caption, $target, $style, $params );
1515 }
16 -
17 - /**
18 - * Static function to construct links to the browsing special.
19 - *
20 - * @param string $caption The label for the link.
21 - * @param string $titleText
22 - * @param mixed $style CSS class of a span to embedd the link into, or false if no extra style is required.
23 - *
24 - * @return SMWInfolink
25 - */
 16+
2617 public static function newBrowsingLink( $caption, $titleText, $style = 'smwbrowse' ) {
2718 global $wgContLang;
28 - return new SMWInfolink(
 19+
 20+ return new SWBInfolink(
2921 true,
3022 $caption,
3123 $wgContLang->getNsText( NS_SPECIAL ) . ':BrowseWiki',
@@ -32,25 +24,8 @@
3325 array( $titleText )
3426 );
3527 }
36 -
37 - /**
38 - *
39 - * Link for toolbox
40 - * @param unknown_type $caption
41 - * @param unknown_type $titleText
42 - * @param unknown_type $style
43 - */
44 - public static function newBrowsingSemWeb( $caption, $titleText, $style = 'swbbrowse' ) {
45 - global $wgContLang;
46 - return new SMWInfolink(
47 - true,
48 - $caption,
49 - $wgContLang->getNsText( NS_SPECIAL ) . ':BrowseWiki',
50 - $style,
51 - array( $titleText )
52 - );
53 - }
54 -}
5528
5629
 30+}
5731
 32+
Index: trunk/extensions/SemanticWebBrowser/lib/Graphite.php
@@ -13,7 +13,7 @@
1414 # SimpleGraph - http://code.google.com/p/moriarty/wiki/SimpleGraph
1515 #
1616 # I've used function calls in common with EasyRDF, where it makes sense
17 -# to do so. Easy RDF now uses our dump() style. We're one big happy linked
 17+# to do so. Easy RDF now uses our dump() style. We're one big happy linked
1818 # data community!
1919
2020 # todo:
@@ -27,8 +27,8 @@
2828 {
2929 public function __construct( $namespaces = array(), $uri = null )
3030 {
31 - $this->t = array( "sp" => array(), "op"=>array() );
32 - foreach( $namespaces as $short=>$long )
 31+ $this->t = array( "sp" => array(), "op" => array() );
 32+ foreach ( $namespaces as $short => $long )
3333 {
3434 $this->ns( $short, $long );
3535 }
@@ -48,20 +48,20 @@
4949 $this->debug = false;
5050
5151 $this->firstGraphURI = null;
52 - if( $uri )
53 - {
 52+ if ( $uri )
 53+ {
5454 $this->forceString( $uri );
55 - $this->load( $uri );
 55+ $this->load( $uri );
5656 }
5757 }
5858
59 - public function cacheDir( $dir, $age = 86400 ) # default age is 24 hours
 59+ public function cacheDir( $dir, $age = 86400 ) # default age is 24 hours
6060 {
6161 $error = "";
62 - if( !file_exists( $dir ) ) { $error = "No such directory: $dir"; }
63 - elseif( !is_dir( $dir ) ) { $error = "Not a directory: $dir"; }
64 - elseif( !is_writable( $dir ) ) { $error = "Not writable: $dir"; }
65 - if( $error ) {
 62+ if ( !file_exists( $dir ) ) { $error = "No such directory: $dir"; }
 63+ elseif ( !is_dir( $dir ) ) { $error = "Not a directory: $dir"; }
 64+ elseif ( !is_writable( $dir ) ) { $error = "Not writable: $dir"; }
 65+ if ( $error ) {
6666 print "<ul><li>Graphite cacheDir error: $error</li></ul>";
6767 }
6868 else
@@ -78,86 +78,86 @@
7979 $this->forceString( $uri );
8080 $uri = $this->expandURI( $uri );
8181
82 - if( substr( $uri,0,5 ) == "data:" )
 82+ if ( substr( $uri, 0, 5 ) == "data:" )
8383 {
84 - $data = urldecode( preg_replace( "/^data:[^,]*,/","", $uri ) );
 84+ $data = urldecode( preg_replace( "/^data:[^,]*,/", "", $uri ) );
8585 $parser = ARC2::getTurtleParser();
8686 $parser->parse( $uri, $data );
8787 }
8888 else
8989 {
90 - if( isset($this->loaded[$uri]) ) { return $this->loaded[$uri]; }
91 - if( isset($this->cacheDir) )
 90+ if ( isset( $this->loaded[$uri] ) ) { return $this->loaded[$uri]; }
 91+ if ( isset( $this->cacheDir ) )
9292 {
93 - $filename = $this->cacheDir."/".md5($uri);
 93+ $filename = $this->cacheDir . "/" . md5( $uri );
9494
95 - if( !file_exists( $filename ) || filemtime($filename)+$this->cacheAge < time() )
 95+ if ( !file_exists( $filename ) || filemtime( $filename ) + $this->cacheAge < time() )
9696 {
9797 # decache if out of date, even if we fail to re cache.
98 - if( file_exists( $filename ) ) { unlink( $filename ); }
 98+ if ( file_exists( $filename ) ) { unlink( $filename ); }
9999 $url = $uri;
100100 $ttl = 16;
101101 $mime = "";
102 - $old_user_agent = ini_get('user_agent');
103 - ini_set('user_agent', "PHP\r\nAccept: application/rdf+xml");
104 - while( $ttl > 0 )
 102+ $old_user_agent = ini_get( 'user_agent' );
 103+ ini_set( 'user_agent', "PHP\r\nAccept: application/rdf+xml" );
 104+ while ( $ttl > 0 )
105105 {
106106 # dirty hack to set the accept header without using curl
107 - if( !$rdf_fp = fopen($url, 'r') ) { break; }
108 - $meta_data = stream_get_meta_data($rdf_fp);
 107+ if ( !$rdf_fp = fopen( $url, 'r' ) ) { break; }
 108+ $meta_data = stream_get_meta_data( $rdf_fp );
109109 $redir = 0;
110 - foreach($meta_data['wrapper_data'] as $response)
 110+ foreach ( $meta_data['wrapper_data'] as $response )
111111 {
112 - if (substr(strtolower($response), 0, 10) == 'location: ')
 112+ if ( substr( strtolower( $response ), 0, 10 ) == 'location: ' )
113113 {
114 - $newurl = substr($response, 10);
115 - if( substr( $newurl, 0, 1 ) == "/" )
116 - {
117 - $parts = preg_split( "/\//",$url );
118 - $newurl = $parts[0]."//".$parts[2].$newurl;
 114+ $newurl = substr( $response, 10 );
 115+ if ( substr( $newurl, 0, 1 ) == "/" )
 116+ {
 117+ $parts = preg_split( "/\//", $url );
 118+ $newurl = $parts[0] . "//" . $parts[2] . $newurl;
119119 }
120120 $url = $newurl;
121121 $redir = 1;
122122 }
123 - if (substr(strtolower($response), 0, 14) == 'content-type: ')
 123+ if ( substr( strtolower( $response ), 0, 14 ) == 'content-type: ' )
124124 {
125 - $mime = preg_replace( "/\s*;.*$/","", substr($response, 14));
 125+ $mime = preg_replace( "/\s*;.*$/", "", substr( $response, 14 ) );
126126 }
127127 }
128 - if( !$redir ) { break; }
 128+ if ( !$redir ) { break; }
129129 $ttl--;
130 - fclose($rdf_fp);
 130+ fclose( $rdf_fp );
131131 }
132 - ini_set('user_agent', $old_user_agent);
133 - if( $ttl > 0 && $mime == "application/rdf+xml" && $rdf_fp )
 132+ ini_set( 'user_agent', $old_user_agent );
 133+ if ( $ttl > 0 && $mime == "application/rdf+xml" && $rdf_fp )
134134 {
135135 # candidate for caching!
136 - if (!$cache_fp = fopen($filename, 'w'))
 136+ if ( !$cache_fp = fopen( $filename, 'w' ) )
137137 {
138138 echo "Cannot write file ($filename)";
139139 exit;
140140 }
141 -
142 - while (!feof($rdf_fp)) {
143 - fwrite( $cache_fp, fread($rdf_fp, 8192) );
 141+
 142+ while ( !feof( $rdf_fp ) ) {
 143+ fwrite( $cache_fp, fread( $rdf_fp, 8192 ) );
144144 }
145 - fclose($cache_fp);
 145+ fclose( $cache_fp );
146146 }
147 - fclose($rdf_fp);
 147+ fclose( $rdf_fp );
148148 }
149 -
 149+
150150 }
151 - if( isset( $filename ) && file_exists( $filename ) )
 151+ if ( isset( $filename ) && file_exists( $filename ) )
152152 {
153153 $parser = ARC2::getRDFXMLParser();
154154 $parser->parse( $filename );
155155 }
156156 else
157 - {
 157+ {
158158 $parser = ARC2::getRDFParser();
159159 # Don't try to load the same URI twice!
160 -
161 - if( !isset( $this->firstGraphURI ) )
 160+
 161+ if ( !isset( $this->firstGraphURI ) )
162162 {
163163 $this->firstGraphURI = $uri;
164164 }
@@ -167,12 +167,12 @@
168168
169169 $errors = $parser->getErrors();
170170 $parser->resetErrors();
171 - if( sizeof($errors) )
 171+ if ( sizeof( $errors ) )
172172 {
173 - if( $this->debug )
 173+ if ( $this->debug )
174174 {
175175 print "<h3>Error loading: $uri</h3>";
176 - print "<ul><li>".join( "</li><li>",$errors)."</li></ul>";
 176+ print "<ul><li>" . join( "</li><li>", $errors ) . "</li></ul>";
177177 }
178178 return 0;
179179 }
@@ -186,12 +186,12 @@
187187 $parser->parse( $base, $data );
188188 $errors = $parser->getErrors();
189189 $parser->resetErrors();
190 - if( sizeof($errors) )
 190+ if ( sizeof( $errors ) )
191191 {
192 - if( $this->debug )
 192+ if ( $this->debug )
193193 {
194194 print "<h3>Error loading: $uri</h3>";
195 - print "<ul><li>".join( "</li><li>",$errors)."</li></ul>";
 195+ print "<ul><li>" . join( "</li><li>", $errors ) . "</li></ul>";
196196 }
197197 return 0;
198198 }
@@ -203,12 +203,12 @@
204204 $parser->parse( $base, $data );
205205 $errors = $parser->getErrors();
206206 $parser->resetErrors();
207 - if( sizeof($errors) )
 207+ if ( sizeof( $errors ) )
208208 {
209 - if( $this->debug )
 209+ if ( $this->debug )
210210 {
211211 print "<h3>Error loading: $uri</h3>";
212 - print "<ul><li>".join( "</li><li>",$errors)."</li></ul>";
 212+ print "<ul><li>" . join( "</li><li>", $errors ) . "</li></ul>";
213213 }
214214 return 0;
215215 }
@@ -217,36 +217,36 @@
218218
219219 function addTriples( $triples )
220220 {
221 -if( @$_GET["X"] )
 221+if ( @$_GET["X"] )
222222 {
223223 print "<pre>";
224224 print_r( $triples );
225225 print "</pre>";
226226 }
227 - foreach( $triples as $t )
 227+ foreach ( $triples as $t )
228228 {
229 - $t["s"] = $this->cleanURI($t["s"]);
230 - if( !isset($map[$t["s"]]) ) { continue; }
231 - $t["p"] = $this->cleanURI($t["p"]);
232 - if( $t["p"] != "http://www.w3.org/2002/07/owl#sameAs" ) { continue; }
 229+ $t["s"] = $this->cleanURI( $t["s"] );
 230+ if ( !isset( $map[$t["s"]] ) ) { continue; }
 231+ $t["p"] = $this->cleanURI( $t["p"] );
 232+ if ( $t["p"] != "http://www.w3.org/2002/07/owl#sameAs" ) { continue; }
233233 $aliases[$t["o"]] = $t["s"];
234234 }
235 - foreach( $triples as $t )
 235+ foreach ( $triples as $t )
236236 {
237 - $t["s"] = $this->cleanURI($t["s"]);
238 - $t["p"] = $this->cleanURI($t["p"]);
 237+ $t["s"] = $this->cleanURI( $t["s"] );
 238+ $t["p"] = $this->cleanURI( $t["p"] );
239239 $mod = 0;
240 - if( isset($aliases[$t["s"]]) ) { $t["s"]=$aliases[$t["s"]]; }
241 - if( isset($aliases[$t["p"]]) ) { $t["p"]=$aliases[$t["p"]]; }
242 - if( isset($aliases[$t["o"]]) ) { $t["o"]=$aliases[$t["o"]]; }
 240+ if ( isset( $aliases[$t["s"]] ) ) { $t["s"] = $aliases[$t["s"]]; }
 241+ if ( isset( $aliases[$t["p"]] ) ) { $t["p"] = $aliases[$t["p"]]; }
 242+ if ( isset( $aliases[$t["o"]] ) ) { $t["o"] = $aliases[$t["o"]]; }
243243 // if( $mod )
244244 // {
245 - if( $t["o_type"]=="literal" )
 245+ if ( $t["o_type"] == "literal" )
246246 {
247247 $this->t["sp"][$t["s"]][$t["p"]][] = array(
248 - "v"=>$t["o"],
249 - "d"=>$t["o_datatype"],
250 - "l"=>$t["o_lang"] );
 248+ "v" => $t["o"],
 249+ "d" => $t["o_datatype"],
 250+ "l" => $t["o_lang"] );
251251 }
252252 else
253253 {
@@ -261,16 +261,16 @@
262262 }
263263
264264
265 - public function cleanURI( $uri )
 265+ public function cleanURI( $uri )
266266 {
267 - if( !$uri ) { return; }
268 - return preg_replace( '/^(https?:\/\/[^:\/]+):80\//','$1/', $uri );
 267+ if ( !$uri ) { return; }
 268+ return preg_replace( '/^(https?:\/\/[^:\/]+):80\//', '$1/', $uri );
269269 }
270270
271271 public function primaryTopic( $uri = null )
272272 {
273 - if( !$uri ) { $uri = $this->firstGraphURI; }
274 - if( !$uri ) { return new Graphite_Null($this->g); }
 273+ if ( !$uri ) { $uri = $this->firstGraphURI; }
 274+ if ( !$uri ) { return new Graphite_Null( $this->g ); }
275275 $this->forceString( $uri );
276276
277277 return $this->resource( $uri )->get( "foaf:primaryTopic", "-foaf:isPrimaryTopicOf" );
@@ -278,7 +278,7 @@
279279
280280 public function ns( $short, $long )
281281 {
282 - if( preg_match( '/^(urn|doi|http|https|ftp|mailto|xmlns|file|data)$/', $short ) )
 282+ if ( preg_match( '/^(urn|doi|http|https|ftp|mailto|xmlns|file|data)$/', $short ) )
283283 {
284284 print "<ul><li>Setting a namespace called '$short' is just asking for trouble. Abort.</li></ul>";
285285 exit;
@@ -295,18 +295,18 @@
296296
297297 public function allOfType( $uri )
298298 {
299 - return $this->resource( $uri )->all("-rdf:type");
 299+ return $this->resource( $uri )->all( "-rdf:type" );
300300 }
301301
302302 public function shrinkURI( $uri )
303303 {
304304 $this->forceString( $uri );
305 - if( $uri == "" ) { return "* This Document *"; }
306 - foreach( $this->ns as $short=>$long )
 305+ if ( $uri == "" ) { return "* This Document *"; }
 306+ foreach ( $this->ns as $short => $long )
307307 {
308 - if( substr( $uri, 0, strlen($long) ) == $long )
 308+ if ( substr( $uri, 0, strlen( $long ) ) == $long )
309309 {
310 - return $short.":".substr( $uri, strlen($long ));
 310+ return $short . ":" . substr( $uri, strlen( $long ) );
311311 }
312312 }
313313 return $uri;
@@ -315,12 +315,12 @@
316316 public function expandURI( $uri )
317317 {
318318 $this->forceString( $uri );
319 - if( preg_match( '/:/', $uri ) )
 319+ if ( preg_match( '/:/', $uri ) )
320320 {
321321 list( $ns, $tag ) = preg_split( "/:/", $uri, 2 );
322 - if( isset($this->ns[$ns]) )
 322+ if ( isset( $this->ns[$ns] ) )
323323 {
324 - return $this->ns[$ns].$tag;
 324+ return $this->ns[$ns] . $tag;
325325 }
326326 }
327327 return $uri;
@@ -330,7 +330,7 @@
331331 public function allSubjects()
332332 {
333333 $r = new Graphite_ResourceList( $this );
334 - foreach( $this->t["sp"] as $subject_uri=>$foo )
 334+ foreach ( $this->t["sp"] as $subject_uri => $foo )
335335 {
336336 $r[] = new Graphite_Resource( $this, $subject_uri );
337337 }
@@ -340,27 +340,27 @@
341341 public function allObjects()
342342 {
343343 $r = new Graphite_ResourceList( $this );
344 - foreach( $this->t["op"] as $object_uri=>$foo )
 344+ foreach ( $this->t["op"] as $object_uri => $foo )
345345 {
346346 $r[] = new Graphite_Resource( $this, $object_uri );
347347 }
348348 return $r;
349349 }
350 -
351 - public function dump($options=array())
 350+
 351+ public function dump( $options = array() )
352352 {
353353 $r = array();
354 - foreach( $this->t["sp"] as $subject_uri=>$foo )
 354+ foreach ( $this->t["sp"] as $subject_uri => $foo )
355355 {
356356 $subject = new Graphite_Resource( $this, $subject_uri );
357 - $r []= $subject->dump($options);
 357+ $r [] = $subject->dump( $options );
358358 }
359 - return join("",$r );
 359+ return join( "", $r );
360360 }
361361
362362 public function forceString( &$uri )
363363 {
364 - if( is_object( $uri ) ) { $uri = $uri->toString(); }
 364+ if ( is_object( $uri ) ) { $uri = $uri->toString(); }
365365 return $uri;
366366 }
367367 }
@@ -372,18 +372,18 @@
373373 $this->g = $g;
374374 }
375375 function has() { return false; }
376 - function get() { return new Graphite_Null($this->g); }
377 - function type() { return new Graphite_Null($this->g); }
 376+ function get() { return new Graphite_Null( $this->g ); }
 377+ function type() { return new Graphite_Null( $this->g ); }
378378 function label() { return "[UNKNOWN]"; }
379379 function hasLabel() { return false; }
380 - function all() { return new Graphite_ResourceList($this->g, array()); }
 380+ function all() { return new Graphite_ResourceList( $this->g, array() ); }
381381 function types() { return $this->all(); }
382382 function relations() { return $this->all(); }
383383 function load() { return 0; }
384384 function loadSameAs() { return 0; }
385 - function loadSameAsOrg($prefix) { return 0; }
 385+ function loadSameAsOrg( $prefix ) { return 0; }
386386 function loadDataGovUKBackLinks() { return 0; }
387 -
 387+
388388 function dumpText() { return "Non existant Node"; }
389389 function dump() { return "<div style='padding:0.5em; background-color:lightgrey;border:dashed 1px grey;'>Non-existant Node</div>"; }
390390 function nodeType() { return "#node"; }
@@ -392,9 +392,9 @@
393393
394394 protected function parsePropertyArg( $arg )
395395 {
396 - if( is_a( $arg, "Graphite_Resource" ) )
 396+ if ( is_a( $arg, "Graphite_Resource" ) )
397397 {
398 - if( is_a( $arg, "Graphite_InverseRelation" ) )
 398+ if ( is_a( $arg, "Graphite_InverseRelation" ) )
399399 {
400400 $this->g->forceString( $arg );
401401 return array( "op", "$arg" );
@@ -404,10 +404,10 @@
405405 }
406406
407407 $set = "sp";
408 - if( substr( $arg,0,1) == "-" )
 408+ if ( substr( $arg, 0, 1 ) == "-" )
409409 {
410410 $set = "op";
411 - $arg = substr($arg,1);
 411+ $arg = substr( $arg, 1 );
412412 }
413413 return array( $set, $this->g->expandURI( "$arg" ) );
414414 }
@@ -427,53 +427,53 @@
428428
429429 function __toString() { return $this->triple["v"]; }
430430
431 - function dumpValueText()
 431+ function dumpValueText()
432432 {
433 - $r = '"'.$v.'"';
434 - if( isset($this->triple["l"]) && $this->triple["l"])
435 - {
436 - $r.="@".$this->triple["l"];
 433+ $r = '"' . $v . '"';
 434+ if ( isset( $this->triple["l"] ) && $this->triple["l"] )
 435+ {
 436+ $r .= "@" . $this->triple["l"];
437437 }
438 - if( isset($this->triple["t"]) )
439 - {
440 - $r.="^^".$this->g->shrinkURI($this->triple["t"]);
 438+ if ( isset( $this->triple["t"] ) )
 439+ {
 440+ $r .= "^^" . $this->g->shrinkURI( $this->triple["t"] );
441441 }
442442 return $r;
443443 }
444444
445 - function dumpValueHTML()
 445+ function dumpValueHTML()
446446 {
447 - $v = htmlspecialchars( $this->triple["v"],ENT_COMPAT,"UTF-8" );
448 -
 447+ $v = htmlspecialchars( $this->triple["v"], ENT_COMPAT, "UTF-8" );
 448+
449449 $v = preg_replace( "/\t/", "<span class='special_char' style='font-size:70%'>[tab]</span>", $v );
450450 $v = preg_replace( "/\n/", "<span class='special_char' style='font-size:70%'>[nl]</span><br />", $v );
451451 $v = preg_replace( "/\r/", "<span class='special_char' style='font-size:70%'>[cr]</span>", $v );
452452 $v = preg_replace( "/ +/e", "\"<span class='special_char' style='font-size:70%'>\".str_repeat(\"␣\",strlen(\"$0\")).\"</span>\"", $v );
453 - $r = '"'.$v.'"';
454 -
455 - if( isset($this->triple["l"]) && $this->triple["l"])
456 - {
457 - $r.="@".$this->triple["l"];
 453+ $r = '"' . $v . '"';
 454+
 455+ if ( isset( $this->triple["l"] ) && $this->triple["l"] )
 456+ {
 457+ $r .= "@" . $this->triple["l"];
458458 }
459 - if( isset($this->triple["t"]) )
460 - {
461 - $r.="^^".$this->g->shrinkURI($this->triple["t"]);
 459+ if ( isset( $this->triple["t"] ) )
 460+ {
 461+ $r .= "^^" . $this->g->shrinkURI( $this->triple["t"] );
462462 }
463463 return $r;
464464 }
465465
466 - function nodeType()
467 - {
468 - if( isset($this->triple["d"]) )
469 - {
 466+ function nodeType()
 467+ {
 468+ if ( isset( $this->triple["d"] ) )
 469+ {
470470 return $this->triple["d"];
471 - }
 471+ }
472472 return "#literal";
473473 }
474474
475 - function dumpValue()
 475+ function dumpValue()
476476 {
477 - return "<span style='color:blue'>".$this->dumpValueHTML()."</span>";
 477+ return "<span style='color:blue'>" . $this->dumpValueHTML() . "</span>";
478478 }
479479 }
480480
@@ -489,36 +489,36 @@
490490 public function get( /* List */ )
491491 {
492492 $args = func_get_args();
493 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
494 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 493+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 494+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
495495
496496 $l = $this->all( $args );
497 - if( sizeof( $l ) == 0 ) { return new Graphite_Null($this->g); }
 497+ if ( sizeof( $l ) == 0 ) { return new Graphite_Null( $this->g ); }
498498 return $l[0];
499499 }
500500
501501 public function getString( /* List */ )
502502 {
503503 $args = func_get_args();
504 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
505 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 504+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 505+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
506506
507507 $l = $this->all( $args );
508 - if( sizeof( $l ) == 0 ) { return; }
 508+ if ( sizeof( $l ) == 0 ) { return; }
509509 return $l[0]->toString();
510510 }
511511
512512 public function has( /* List */ )
513513 {
514514 $args = func_get_args();
515 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
516 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 515+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 516+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
517517
518 - foreach( $args as $arg )
 518+ foreach ( $args as $arg )
519519 {
520520 list( $set, $relation_uri ) = $this->parsePropertyArg( $arg );
521 - if( isset($this->g->t[$set][$this->uri])
522 - && isset($this->g->t[$set][$this->uri][$relation_uri]) )
 521+ if ( isset( $this->g->t[$set][$this->uri] )
 522+ && isset( $this->g->t[$set][$this->uri][$relation_uri] ) )
523523 {
524524 return true;
525525 }
@@ -529,54 +529,54 @@
530530 public function all( /* List */ )
531531 {
532532 $args = func_get_args();
533 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
534 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 533+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 534+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
535535 $l = array();
536536 $done = array();
537 - foreach( $args as $arg )
 537+ foreach ( $args as $arg )
538538 {
539539 list( $set, $relation_uri ) = $this->parsePropertyArg( $arg );
540 - if( !isset($this->g->t[$set][$this->uri])
541 - || !isset($this->g->t[$set][$this->uri][$relation_uri]) )
 540+ if ( !isset( $this->g->t[$set][$this->uri] )
 541+ || !isset( $this->g->t[$set][$this->uri][$relation_uri] ) )
542542 {
543543 continue;
544544 }
545545
546 - foreach( $this->g->t[$set][$this->uri][$relation_uri] as $v )
 546+ foreach ( $this->g->t[$set][$this->uri][$relation_uri] as $v )
547547 {
548 - if( is_array( $v ) )
 548+ if ( is_array( $v ) )
549549 {
550 - $l []= new Graphite_Literal( $this->g, $v );
551 - }
552 - else if( !isset($done[$v]) )
 550+ $l [] = new Graphite_Literal( $this->g, $v );
 551+ }
 552+ else if ( !isset( $done[$v] ) )
553553 {
554 - $l []= new Graphite_Resource( $this->g, $v );
 554+ $l [] = new Graphite_Resource( $this->g, $v );
555555 $done[$v] = 1;
556556 }
557557 }
558558 }
559 - return new Graphite_ResourceList($this->g,$l);
 559+ return new Graphite_ResourceList( $this->g, $l );
560560 }
561561
562562 public function relations()
563563 {
564564 $r = array();
565 - if( isset( $this->g->t["sp"][$this->uri] ) )
 565+ if ( isset( $this->g->t["sp"][$this->uri] ) )
566566 {
567 - foreach( array_keys( $this->g->t["sp"][$this->uri] ) as $pred )
 567+ foreach ( array_keys( $this->g->t["sp"][$this->uri] ) as $pred )
568568 {
569 - $r []= new Graphite_Relation( $this->g, $pred );
 569+ $r [] = new Graphite_Relation( $this->g, $pred );
570570 }
571571 }
572 - if( isset( $this->g->t["op"][$this->uri] ) )
 572+ if ( isset( $this->g->t["op"][$this->uri] ) )
573573 {
574 - foreach( array_keys( $this->g->t["op"][$this->uri] ) as $pred )
 574+ foreach ( array_keys( $this->g->t["op"][$this->uri] ) as $pred )
575575 {
576 - $r []= new Graphite_InverseRelation( $this->g, $pred );
 576+ $r [] = new Graphite_InverseRelation( $this->g, $pred );
577577 }
578578 }
579579
580 - return new Graphite_ResourceList($this->g,$r);
 580+ return new Graphite_ResourceList( $this->g, $r );
581581 }
582582
583583 public function load()
@@ -586,30 +586,30 @@
587587
588588 public function loadSameAsOrg( $prefix )
589589 {
590 - $sameasorg_uri = "http://sameas.org/rdf?uri=".urlencode( $this->uri );
 590+ $sameasorg_uri = "http://sameas.org/rdf?uri=" . urlencode( $this->uri );
591591 $n = $this->g->load( $sameasorg_uri );
592 - $n+= $this->loadSameAs( $prefix );
 592+ $n += $this->loadSameAs( $prefix );
593593 return $n;
594594 }
595595
596 - function loadDataGovUKBackLinks()
 596+ function loadDataGovUKBackLinks()
597597 {
598 - $backurl = "http://backlinks.psi.enakting.org/resource/rdf/".$this->uri;
599 - return $this->g->load( $backurl, array(), array( $this->uri=>1 ) );
 598+ $backurl = "http://backlinks.psi.enakting.org/resource/rdf/" . $this->uri;
 599+ return $this->g->load( $backurl, array(), array( $this->uri => 1 ) );
600600 }
601 -
602 - public function loadSameAs( $prefix=null )
 601+
 602+ public function loadSameAs( $prefix = null )
603603 {
604604 $cnt = 0;
605 - foreach( $this->all( "owl:sameAs" ) as $sameas )
 605+ foreach ( $this->all( "owl:sameAs" ) as $sameas )
606606 {
607607 $this->g->forceString( $sameas );
608 - if( $prefix && substr( $sameas, 0, strlen($prefix )) != $prefix )
 608+ if ( $prefix && substr( $sameas, 0, strlen( $prefix ) ) != $prefix )
609609 {
610610 continue;
611611 }
612 -
613 - $cnt += $this->g->load( $sameas, array( $sameas=>$this->uri ) );
 612+
 613+ $cnt += $this->g->load( $sameas, array( $sameas => $this->uri ) );
614614 }
615615 return $cnt;
616616 }
@@ -635,38 +635,38 @@
636636
637637 public function link()
638638 {
639 - return "<a title='".$this->uri."' href='".$this->uri."'>".$this->uri."</a>";
 639+ return "<a title='" . $this->uri . "' href='" . $this->uri . "'>" . $this->uri . "</a>";
640640 }
641641
642642 public function dumpText()
643643 {
644644 $r = "";
645645 $plist = array();
646 - foreach( $this->relations() as $prop )
 646+ foreach ( $this->relations() as $prop )
647647 {
648648 $olist = array();
649 - foreach( $this->all( $prop ) as $obj )
 649+ foreach ( $this->all( $prop ) as $obj )
650650 {
651 - $olist []= $obj->dumpValueText();
 651+ $olist [] = $obj->dumpValueText();
652652 }
653 - $plist []= $this->g->shrinkURI($prop)." ".join( ", ",$olist );
 653+ $plist [] = $this->g->shrinkURI( $prop ) . " " . join( ", ", $olist );
654654 }
655 - return $this->g->shrinkURI($this->uri)."\n ".join( ";\n ", $plist )." .\n";
 655+ return $this->g->shrinkURI( $this->uri ) . "\n " . join( ";\n ", $plist ) . " .\n";
656656 }
657657
658658 public function dump( $options = array() )
659659 {
660660 $r = "";
661661 $plist = array();
662 - foreach( $this->relations() as $prop )
 662+ foreach ( $this->relations() as $prop )
663663 {
664664 $olist = array();
665665 $all = $this->all( $prop );
666 - foreach( $all as $obj )
 666+ foreach ( $all as $obj )
667667 {
668 - $olist []= $obj->dumpValue($options);
 668+ $olist [] = $obj->dumpValue( $options );
669669 }
670 - if( is_a( $prop, "Graphite_InverseRelation" ) )
 670+ if ( is_a( $prop, "Graphite_InverseRelation" ) )
671671 {
672672 $pattern = "<span style='font-size:130%%'>&larr;</span> is <a title='%s' href='%s' style='text-decoration:none;color: green'>%s</a> of <span style='font-size:130%%'>&larr;</span> %s";
673673 }
@@ -675,43 +675,43 @@
676676 $pattern = "<span style='font-size:130%%'>&rarr;</span> <a title='%s' href='%s' style='text-decoration:none;color: green'>%s</a> <span style='font-size:130%%'>&rarr;</span> %s";
677677 }
678678 $this->g->forceString( $prop );
679 - $plist []= sprintf( $pattern, $prop, $prop, $this->g->shrinkURI($prop), join( ", ",$olist ));
 679+ $plist [] = sprintf( $pattern, $prop, $prop, $this->g->shrinkURI( $prop ), join( ", ", $olist ) );
680680 }
681 - $r.= "\n<a name='".htmlentities($this->uri)."'></a><div style='font-family: arial;padding:0.5em; background-color:lightgrey;border:dashed 1px grey;margin-bottom:2px;'>\n";
682 - if( isset($options["label"] ) )
 681+ $r .= "\n<a name='" . htmlentities( $this->uri ) . "'></a><div style='font-family: arial;padding:0.5em; background-color:lightgrey;border:dashed 1px grey;margin-bottom:2px;'>\n";
 682+ if ( isset( $options["label"] ) )
683683 {
684684 $label = $this->label();
685 - if( $label == "[NULL]" ) { $label = ""; } else { $label = "<strong>$label</strong>"; }
686 - if( $this->has( "rdf:type" ) )
 685+ if ( $label == "[NULL]" ) { $label = ""; } else { $label = "<strong>$label</strong>"; }
 686+ if ( $this->has( "rdf:type" ) )
687687 {
688 - if( $this->get( "rdf:type" )->hasLabel() )
 688+ if ( $this->get( "rdf:type" )->hasLabel() )
689689 {
690690 $typename = $this->get( "rdf:type" )->label();
691691 }
692 - else
 692+ else
693693 {
694694 $bits = preg_split( "/[\/#]/", $this->get( "rdf:type" )->uri );
695695 $typename = array_pop( $bits );
696 - $typename = preg_replace( "/([a-z])([A-Z])/","$1 $2",$typename );
 696+ $typename = preg_replace( "/([a-z])([A-Z])/", "$1 $2", $typename );
697697 }
698698 $r .= preg_replace( "/>a ([AEIOU])/i", ">an $1", "<div style='float:right'>a $typename</div>" );
699699 }
700 - if( $label != "" ) { $r.="<div>$label</div>"; }
 700+ if ( $label != "" ) { $r .= "<div>$label</div>"; }
701701 }
702 - $r.= " <!-- DUMP:".$this->uri." -->\n <div><a title='".$this->uri."' href='".$this->uri."' style='text-decoration:none'>".$this->g->shrinkURI($this->uri)."</a></div>\n";
703 - $r.=" <div style='padding-left: 3em'>\n <div>".join( "</div>\n <div>", $plist )."</div></div><div style='clear:both;height:1px; overflow:hidden'>&nbsp;</div></div>";
 702+ $r .= " <!-- DUMP:" . $this->uri . " -->\n <div><a title='" . $this->uri . "' href='" . $this->uri . "' style='text-decoration:none'>" . $this->g->shrinkURI( $this->uri ) . "</a></div>\n";
 703+ $r .= " <div style='padding-left: 3em'>\n <div>" . join( "</div>\n <div>", $plist ) . "</div></div><div style='clear:both;height:1px; overflow:hidden'>&nbsp;</div></div>";
704704 return $r;
705705 }
706706
707707 function __toString() { return $this->uri; }
708 - function dumpValue($options=array())
709 - {
 708+ function dumpValue( $options = array() )
 709+ {
710710 $label = $this->dumpValueText();
711 - if( $this->hasLabel() && @$options["labeluris"] )
 711+ if ( $this->hasLabel() && @$options["labeluris"] )
712712 {
713713 $label = $this->label();
714714 }
715 - return "<a href='".$this->uri."' title='".$this->uri."' style='text-decoration:none;color:red'>".$label."</a>";
 715+ return "<a href='" . $this->uri . "' title='" . $this->uri . "' style='text-decoration:none;color:red'>" . $label . "</a>";
716716 }
717717 function dumpValueText() { return $this->g->shrinkURI( $this->uri ); }
718718 function nodeType() { return "#resource"; }
@@ -728,10 +728,10 @@
729729 }
730730 class Graphite_ResourceList extends ArrayIterator
731731 {
732 - function __construct( $g, $a=array() )
 732+ function __construct( $g, $a = array() )
733733 {
734734 $this->g = $g;
735 - if( $a instanceof Graphite_ResourceList )
 735+ if ( $a instanceof Graphite_ResourceList )
736736 {
737737 print "<li>Graphite warning: passing a Graphite_ResourceList as the array passed to new Graphite_ResourceList will make weird stuff happen.</li>";
738738 }
@@ -742,11 +742,11 @@
743743 {
744744 $first = 1;
745745 $l = array();
746 - foreach( $this as $resource )
 746+ foreach ( $this as $resource )
747747 {
748 - if( !$first ) { $l []= $str; }
 748+ if ( !$first ) { $l [] = $str; }
749749 $this->g->forceString( $resource );
750 - $l []= $resource;
 750+ $l [] = $resource;
751751 $first = 0;
752752 }
753753 return join( "", $l );
@@ -755,108 +755,108 @@
756756 function dump()
757757 {
758758 $l = array();
759 - foreach( $this as $resource )
 759+ foreach ( $this as $resource )
760760 {
761 - $l [] = $resource->dump();
 761+ $l [] = $resource->dump();
762762 }
763763 return join( "", $l );
764764 }
765 -
 765+
766766 public function duplicate()
767767 {
768768 $l = array();
769 - foreach( $this as $resource ) { $l []= $resource; }
770 - return new Graphite_ResourceList($this->g,$l);
 769+ foreach ( $this as $resource ) { $l [] = $resource; }
 770+ return new Graphite_ResourceList( $this->g, $l );
771771 }
772772
773773 public function sort( /* List */ )
774774 {
775775 $args = func_get_args();
776 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
777 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 776+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 777+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
778778
779779 global $graphite_sort_args;
780780 $graphite_sort_args = array();
781 - foreach( $args as $arg )
 781+ foreach ( $args as $arg )
782782 {
783 - if( $arg instanceof Graphite_Resource ) { $arg = $arg->toString(); }
 783+ if ( $arg instanceof Graphite_Resource ) { $arg = $arg->toString(); }
784784 $graphite_sort_args [] = $arg;
785785 }
786786
787787 $new_list = $this->duplicate();
788 - usort($new_list, "graphite_sort_list_cmp" );
 788+ usort( $new_list, "graphite_sort_list_cmp" );
789789
790790 return $new_list;
791791 }
792792
793793 public function uasort( $cmp )
794794 {
795 - usort($this, $cmp );
 795+ usort( $this, $cmp );
796796 }
797797
798798 public function get( /* List */ )
799799 {
800800 $args = func_get_args();
801 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
802 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 801+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 802+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
803803 $l = array();
804 - foreach( $this as $resource )
 804+ foreach ( $this as $resource )
805805 {
806806 $l [] = $resource->get( $args );
807807 }
808 - return new Graphite_ResourceList($this->g,$l);
 808+ return new Graphite_ResourceList( $this->g, $l );
809809 }
810810
811 - public function label()
 811+ public function label()
812812 {
813813 $l = array();
814 - foreach( $this as $resource )
 814+ foreach ( $this as $resource )
815815 {
816816 $l [] = $resource->label();
817817 }
818 - return new Graphite_ResourceList($this->g,$l);
 818+ return new Graphite_ResourceList( $this->g, $l );
819819 }
820 -
821 - public function load()
 820+
 821+ public function load()
822822 {
823823 $n = 0;
824 - foreach( $this as $resource )
 824+ foreach ( $this as $resource )
825825 {
826826 $n += $resource->load();
827827 }
828828 return $n;
829829 }
830 -
 830+
831831 public function all( /* List */ )
832832 {
833833 $args = func_get_args();
834 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
835 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 834+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 835+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
836836 $l = array();
837837 $done = array();
838 - foreach( $this as $resource )
 838+ foreach ( $this as $resource )
839839 {
840840 $all = $resource->all( $args );
841 - foreach( $all as $to_add )
 841+ foreach ( $all as $to_add )
842842 {
843 - if( isset($done[$to_add->toString()]) ) { continue; }
844 - $l []= $to_add;
 843+ if ( isset( $done[$to_add->toString()] ) ) { continue; }
 844+ $l [] = $to_add;
845845 $done[$to_add->toString()] = 1;
846846 }
847847 }
848 - return new Graphite_ResourceList($this->g,$l);
 848+ return new Graphite_ResourceList( $this->g, $l );
849849 }
850850
851851 function append( $x /* List */ )
852852 {
853853 $args = func_get_args();
854 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
855 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 854+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 855+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
856856
857857 $list = $this->duplicate();
858 - foreach( $args as $arg )
 858+ foreach ( $args as $arg )
859859 {
860 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 860+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
861861 $list [] = $arg;
862862 }
863863 return $list;
@@ -864,37 +864,37 @@
865865
866866 function distinct()
867867 {
868 - $l= array();
 868+ $l = array();
869869 $done = array();
870 - foreach( $this as $resource )
 870+ foreach ( $this as $resource )
871871 {
872 - if( isset( $done[$resource->toString()] ) ) { continue; }
 872+ if ( isset( $done[$resource->toString()] ) ) { continue; }
873873 $l [] = $resource;
874 - $done[$resource->toString()]=1;
 874+ $done[$resource->toString()] = 1;
875875 }
876 - return new Graphite_ResourceList($this->g,$l);
 876+ return new Graphite_ResourceList( $this->g, $l );
877877 }
878878
879879 function union( /* List */ )
880880 {
881881 $args = func_get_args();
882 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
883 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 882+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 883+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
884884
885 - $list = new Graphite_ResourceList($this->g);
 885+ $list = new Graphite_ResourceList( $this->g );
886886 $done = array();
887 - foreach( $this as $resource )
 887+ foreach ( $this as $resource )
888888 {
889 - if( isset( $done[$resource->toString()] ) ) { continue; }
 889+ if ( isset( $done[$resource->toString()] ) ) { continue; }
890890 $list [] = $resource;
891 - $done[$resource->toString()]=1;
 891+ $done[$resource->toString()] = 1;
892892 }
893 - foreach( $args as $arg )
 893+ foreach ( $args as $arg )
894894 {
895 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
896 - if( isset( $done[$arg->toString()] ) ) { continue; }
 895+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 896+ if ( isset( $done[$arg->toString()] ) ) { continue; }
897897 $list [] = $arg;
898 - $done[$arg->toString()]=1;
 898+ $done[$arg->toString()] = 1;
899899 }
900900 return $list;
901901 }
@@ -902,20 +902,20 @@
903903 function intersection( /* List */ )
904904 {
905905 $args = func_get_args();
906 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
907 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 906+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 907+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
908908
909 - $list = new Graphite_ResourceList($this->g,array());
 909+ $list = new Graphite_ResourceList( $this->g, array() );
910910 $seen = array();
911 - foreach( $this as $arg )
 911+ foreach ( $this as $arg )
912912 {
913 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
914 - $seen[$arg->toString()]=1;
 913+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 914+ $seen[$arg->toString()] = 1;
915915 }
916 - foreach( $args as $arg )
 916+ foreach ( $args as $arg )
917917 {
918 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
919 - if( ! isset($seen[$arg->toString()]) ) { continue; }
 918+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 919+ if ( ! isset( $seen[$arg->toString()] ) ) { continue; }
920920 $list [] = $arg;
921921 }
922922 return $list;
@@ -924,20 +924,20 @@
925925 function except( /* List */ )
926926 {
927927 $args = func_get_args();
928 - if( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
929 - if( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
 928+ if ( $args[0] instanceof Graphite_ResourceList ) { $args = $args[0]; }
 929+ if ( is_array( $args[0] ) ) { $args = func_get_arg( 0 ); }
930930
931 - $list = new Graphite_ResourceList($this->g,array());
 931+ $list = new Graphite_ResourceList( $this->g, array() );
932932 $exclude = array();
933 - foreach( $args as $arg )
 933+ foreach ( $args as $arg )
934934 {
935 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
936 - $exclude[$arg->toString()]=1;
 935+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 936+ $exclude[$arg->toString()] = 1;
937937 }
938 - foreach( $this as $arg )
 938+ foreach ( $this as $arg )
939939 {
940 - if( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
941 - if( isset($exclude[$arg->toString()]) ) { continue; }
 940+ if ( ! $arg instanceof Graphite_Resource ) { $arg = $this->g->resource( $arg ); }
 941+ if ( isset( $exclude[$arg->toString()] ) ) { continue; }
942942 $list [] = $arg;
943943 }
944944 return $list;
@@ -947,13 +947,13 @@
948948 function graphite_sort_list_cmp( $a, $b )
949949 {
950950 global $graphite_sort_args;
951 -
952 - foreach( $graphite_sort_args as $arg )
 951+
 952+ foreach ( $graphite_sort_args as $arg )
953953 {
954954 $va = $a->get( $arg );
955955 $vb = $b->get( $arg );
956 - if($va < $vb) return -1;
957 - if($va > $vb) return 1;
 956+ if ( $va < $vb ) return -1;
 957+ if ( $va > $vb ) return 1;
958958 }
959959 return 0;
960960 }
Index: trunk/extensions/SemanticWebBrowser/CHANGELOG
@@ -3,4 +3,8 @@
44 * Release-notes added
55
66 == SWB - commit before 2011-09-19 ==
7 -* Basis functionality of browsing implemented
\ No newline at end of file
 7+* Basis functionality of browsing implemented based on browse wiki
 8+*property of wikipage for search SWB is shown
 9+
 10+== SWB - 2011-11-27 ==
 11+* Incoming links work now
Index: trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.i18n.php
@@ -0,0 +1,28 @@
 2+<?php
 3+/**
 4+ * Internationalization file for Semantic WebBrowser
 5+ *@author Anna Kantorovitch and Benedikt K�mpgen
 6+ * @ingroup Language
 7+ * @ingroup SWBLanguage
 8+ */
 9+
 10+
 11+/** English
 12+ *
 13+ */
 14+$messages['en'] = array(
 15+
 16+ // Messages for the browsing semantic Web special
 17+
 18+ 'browsewiki' => 'Browse Wiki & Semantic Web', #title of the SWB page
 19+ 'swb_browse_semantic_web' => 'Browse Wiki & Semantic Web', #title for browsing
 20+ 'swb_browse_article' => 'Enter the name of the page to start semantic browsing from.',#text above "go"window
 21+ 'swb_browse_go' => 'Go', #title of button "go"
 22+ 'swb_browse_show_incoming' => 'show incoming properties that link here', #title of properties
 23+ 'swb_browse_hide_incoming' => 'hide incoming properties that link here', #title of properties
 24+ 'swb_browse_no_outgoing' => 'This page has no properties.', #text: page has no properties
 25+ 'swb_browse_no_incoming' => 'No properties link to this page.', #text:page has no incoming properties
 26+ 'swb_inverse_label_property' => 'Inverse property label', # this is the name of a special property
 27+ 'swb_inverse_label_default' => '$1 of', #text : inverse label dafault,$1 is place marker, have not to be translated
 28+ 'swb_browse_more' => '…', #text: browse more details
 29+);
\ No newline at end of file
Property changes on: trunk/extensions/SemanticWebBrowser/SemanticWebBrowser.i18n.php
___________________________________________________________________
Added: svn:eol-style
130 + native
Added: svn:keywords
231 + LastChangedDate LastChangedRevision LastChangedBy Id

Follow-up revisions

RevisionCommit summaryAuthorDate
r105167r104375: Consistency tweaks in preparation for adding extension to translatew...raymond12:21, 5 December 2011
r105168r104375: Adding extension to translatewiki.netraymond12:21, 5 December 2011
r110085Some sort of fix to r104375. I'm not entirely sure what the appropriate fix i...demon21:15, 26 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   08:46, 29 November 2011
  1. Encoding issues in new files.
  2. Message documentation should be under qqq.
  3. Typo: dafault
#Comment by Raymond (talk | contribs)   08:48, 29 November 2011

Working on it already. Commit will follow soon.

#Comment by Jeroen De Dauw (talk | contribs)   03:09, 6 December 2011

So the fixme should be removed now?

#Comment by Raymond (talk | contribs)   06:15, 6 December 2011

Thanks for the reminder. Done.

#Comment by Nikerabbit (talk | contribs)   09:29, 6 December 2011
-						 " – " . ( $offset ) . "</strong>      ";
+						 " – " . ( $offset ) . "</strong>      ";

Status & tagging log