r106677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106676‎ | r106677 | r106678 >
Date:19:51, 19 December 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
exception handling; documentation; formatting
Modified paths:
  • /trunk/extensions/SolrStore/SolrConnector.i18n.php (deleted) (history)
  • /trunk/extensions/SolrStore/SolrConnector.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrConnectorStore.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrDoc.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrSearch.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrSearchFieldSet.php (modified) (history)
  • /trunk/extensions/SolrStore/SolrStore.alias.php (added) (history)
  • /trunk/extensions/SolrStore/SolrStore.i18n.php (added) (history)
  • /trunk/extensions/SolrStore/SolrStore.php (added) (history)
  • /trunk/extensions/SolrStore/SolrTalker.php (modified) (history)
  • /trunk/extensions/SolrStore/SpecialSolrSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrConnector.i18n.php
@@ -1,26 +0,0 @@
2 -<?php
3 -/**
4 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
5 - *
6 - * @defgroup SolrStore
7 - * @author Simon Bachenberg
8 - */
9 -$messages = array();
10 -$specialPageAliases = array();
11 -
12 -$messages['en'] = array(
13 - 'solrsearch' => 'SolrSearch',
14 - 'searchFieldSets' => 'SolrSearch',
15 - 'searchFieldSets-select' => 'Please select a SearchSet',
16 - 'searchFieldSets-title' => 'SolrSearch: SearchSet Select',
17 -);
18 -$messages['de'] = array(
19 - 'solrsearch' => 'SolrSuche',
20 - 'searchFieldSets' => 'SolrSuche',
21 - 'searchFieldSets-select' => 'Bitte wählen Sie ein SearchSet aus',
22 - 'searchFieldSets-title' => 'SolrSearch: SearchSet Auswahl',
23 -);
24 -
25 -$specialPageAliases['en'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch'));
26 -$specialPageAliases['de'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch'));
27 -?>
Index: trunk/extensions/SolrStore/SolrConnector.php
@@ -1,96 +1,11 @@
22 <?php
3 -
43 /**
5 - * A terminology markup extension with a Semantic MediaWiki backend
6 - *
7 - * @defgroup SolrStore
8 - * @author Stephan Gambke, Simon Bachenberg
9 - * @version 0.5 Beta
10 - */
11 -
12 -/**
13 - * The main file of the SolrConnector extension
14 - *
15 - * @file
 4+ * Early versions of the extension had to include SolrConnector.php.
 5+ *
 6+ * This file keeps backward compatibility for a while.
 7+ *
168 * @ingroup SolrStore
 9+ * @file
1710 */
1811
19 -
20 -if ( !defined( 'MEDIAWIKI' ) ) {
21 - die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' );
22 -}
23 -
24 -if ( !defined( 'SMW_VERSION' ) ) {
25 - die( 'SolrConnector depends on the Semantic MediaWiki extension. You need to install Semantic MediaWiki first.' );
26 -}
27 -
28 -/**
29 - * The Solr Connector version
30 - */
31 -define( 'SC_VERSION', '0.5 Beta' );
32 -
33 -// register the extension
34 -//TODO: Add other authors here and in the file header
35 -$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array(
36 - 'path' => __FILE__,
37 - 'name' => 'SolrStore',
38 - 'author' => array( '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', '[http://www.mediawiki.org/wiki/User:SBachenberg Simon Bachenberg]', 'Sascha Schüller' ),
39 - 'url' => 'http://www.mediawiki.org/wiki/Extension:SolrStore',
40 - 'descriptionmsg' => 'solrconnector-desc',
41 - 'version' => SC_VERSION,
42 -);
43 -
44 -
45 -// server-local path to this file
46 -$dir = dirname( __FILE__ );
47 -
48 -// register message file
49 -$wgExtensionMessagesFiles['SolrConnector'] = $dir . '/SolrConnector.i18n.php';
50 -//$wgExtensionMessagesFiles['SolrConnectorAlias'] = $dir . '/SolrConnector.alias.php';
51 -
52 -// register class files with the Autoloader
53 -$wgAutoloadClasses['SolrConnectorStore'] = $dir . '/SolrConnectorStore.php';
54 -$wgAutoloadClasses['SolrDoc'] = $dir . '/SolrDoc.php';
55 -$wgAutoloadClasses['SolrTalker'] = $dir . '/SolrTalker.php';
56 -$wgAutoloadClasses['SolrSearch'] = $dir . '/SolrSearch.php';
57 -$wgAutoloadClasses['SolrResult'] = $dir . '/SolrSearch.php';
58 -$wgAutoloadClasses['SolrSearchSet'] = $dir . '/SolrSearch.php';
59 -$wgAutoloadClasses['SpecialSolrSearch'] = $dir . '/SpecialSolrSearch.php';
60 -$wgAutoloadClasses['SolrSearchFieldSet'] = $dir . '/SolrSearchFieldSet.php';
61 -
62 -
63 -// Specialpage
64 -$wgSpecialPages['SolrSearch'] = 'SpecialSolrSearch'; # Tell MediaWiki about the new special page and its class name
65 -$wgSpecialPageGroups['SolrSearch'] = 'smw_group';
66 -// register Special pages
67 -//$wgSpecialPages['SemanticGlossaryBrowser'] = 'SpecialSemanticGlossaryBrowser';
68 -//$wgSpecialPageGroups['SemanticGlossaryBrowser'] = 'other';
69 -
70 -// register hook handlers
71 -//$wgHooks['smwInitProperties'][] = 'SemanticGlossaryRegisterProperties';
72 -//$wgHooks['smwInitDatatypes'][] = 'SemanticGlossaryRegisterPropertyAliases';
73 -
74 -// register resource modules with the Resource Loader
75 -//$wgResourceModules['ext.SemanticGlossary.Browser'] = array(
76 -// 'localBasePath' => $dir,
77 -// 'styles' => 'skins/SemanticGlossaryBrowser.css',
78 -// 'remoteExtPath' => 'SemanticGlossary'
79 -//);
80 -
81 -// Create new permission 'editglossary' and assign it to usergroup 'user' by default
82 -$wgGroupPermissions['user']['editglossary'] = true;
83 -
84 -
85 -// original store
86 -$wgscBaseStore = $smwgDefaultStore;
87 -$smwgDefaultStore = "SolrConnectorStore";
88 -$smwgQuerySources["solr"] = "SolrConnectorStore";
89 -$wgSearchType = 'SolrSearch';
90 -
91 -// Solr Configuration
92 -$wgSolrTalker = new SolrTalker();
93 -if ( !isset( $wgSolrUrl ) ){
94 - //Url to the Solr Server
95 - $wgSolrUrl = 'http://svbosofixwiki:8180/solr';
96 -}
97 -
 12+include_once dirname( __FILE__ ) . '/SolrStore.php';
\ No newline at end of file
Index: trunk/extensions/SolrStore/SolrStore.i18n.php
@@ -0,0 +1,25 @@
 2+<?php
 3+/**
 4+ * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 5+ *
 6+ * @ingroup SolrStore
 7+ * @file
 8+ * @author Simon Bachenberg
 9+ */
 10+$messages = array();
 11+
 12+$messages['en'] = array(
 13+ 'solrconnector-desc' => 'Search semantic properties with the power of a fulltext search engine.',
 14+ 'solrsearch' => 'SolrSearch',
 15+ 'searchFieldSets' => 'SolrSearch',
 16+ 'searchFieldSets-select' => 'Please select a SearchSet',
 17+ 'searchFieldSets-title' => 'SolrSearch: SearchSet Select',
 18+);
 19+
 20+$messages['de'] = array(
 21+ 'solrsearch' => 'SolrSuche',
 22+ 'searchFieldSets' => 'SolrSuche',
 23+ 'searchFieldSets-select' => 'Bitte wählen Sie ein SearchSet aus',
 24+ 'searchFieldSets-title' => 'SolrSearch: SearchSet Auswahl',
 25+);
 26+
Property changes on: trunk/extensions/SolrStore/SolrStore.i18n.php
___________________________________________________________________
Added: svn:eol-style
127 + native
Index: trunk/extensions/SolrStore/SolrStore.php
@@ -0,0 +1,78 @@
 2+<?php
 3+/**
 4+ * The SolrStore Extension is a Semantic Mediawiki Search provider based on
 5+ * Apache Solr.
 6+ *
 7+ * @defgroup SolrStore
 8+ * @author Stephan Gambke, Simon Bachenberg
 9+ * @version 0.5 Beta
 10+ */
 11+
 12+/**
 13+ * The main file of the SolrConnector extension
 14+ *
 15+ * @file
 16+ * @ingroup SolrStore
 17+ */
 18+
 19+
 20+if ( !defined( 'MEDIAWIKI' ) ) {
 21+ die( 'This file is part of a MediaWiki extension, it is not a valid entry point.' );
 22+}
 23+
 24+if ( !defined( 'SMW_VERSION' ) ) {
 25+ die( 'SolrConnector depends on the Semantic MediaWiki extension. You need to install Semantic MediaWiki first.' );
 26+}
 27+
 28+/**
 29+ * The Solr Connector version
 30+ */
 31+define( 'SC_VERSION', '0.5 Beta' );
 32+
 33+// register the extension
 34+//TODO: Add other authors here and in the file header
 35+$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array(
 36+ 'path' => __FILE__,
 37+ 'name' => 'SolrStore',
 38+ 'author' => array( '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', '[http://www.mediawiki.org/wiki/User:SBachenberg Simon Bachenberg]', 'Sascha Schüller' ),
 39+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SolrStore',
 40+ 'descriptionmsg' => 'solrconnector-desc',
 41+ 'version' => SC_VERSION,
 42+);
 43+
 44+
 45+// server-local path to this file
 46+$dir = dirname( __FILE__ );
 47+
 48+// register message file
 49+$wgExtensionMessagesFiles['SolrStore'] = $dir . '/SolrStore.i18n.php';
 50+$wgExtensionMessagesFiles['SolrStoreAlias'] = $dir . '/SolrStore.alias.php';
 51+
 52+// register class files with the Autoloader
 53+$wgAutoloadClasses['SolrConnectorStore'] = $dir . '/SolrConnectorStore.php';
 54+$wgAutoloadClasses['SolrDoc'] = $dir . '/SolrDoc.php';
 55+$wgAutoloadClasses['SolrTalker'] = $dir . '/SolrTalker.php';
 56+$wgAutoloadClasses['SolrSearch'] = $dir . '/SolrSearch.php';
 57+$wgAutoloadClasses['SolrResult'] = $dir . '/SolrSearch.php';
 58+$wgAutoloadClasses['SolrSearchSet'] = $dir . '/SolrSearch.php';
 59+$wgAutoloadClasses['SpecialSolrSearch'] = $dir . '/SpecialSolrSearch.php';
 60+$wgAutoloadClasses['SolrSearchFieldSet'] = $dir . '/SolrSearchFieldSet.php';
 61+
 62+
 63+// Specialpage
 64+$wgSpecialPages['SolrSearch'] = 'SpecialSolrSearch'; # Tell MediaWiki about the new special page and its class name
 65+$wgSpecialPageGroups['SolrSearch'] = 'smw_group';
 66+
 67+
 68+// original store
 69+$wgscBaseStore = $smwgDefaultStore;
 70+$smwgDefaultStore = "SolrConnectorStore";
 71+$smwgQuerySources["solr"] = "SolrConnectorStore";
 72+$wgSearchType = 'SolrSearch';
 73+
 74+// Solr Configuration
 75+$wgSolrTalker = new SolrTalker();
 76+if ( !isset( $wgSolrUrl ) ){
 77+ //Url to the Solr Server
 78+ $wgSolrUrl = 'http://svbosofixwiki:8180/solr';
 79+}
Property changes on: trunk/extensions/SolrStore/SolrStore.php
___________________________________________________________________
Added: svn:eol-style
180 + native
Index: trunk/extensions/SolrStore/SolrTalker.php
@@ -1,13 +1,17 @@
22 <?php
3 -
43 /**
5 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 4+ * File holding the SolrTalker class
65 *
7 - * This class should do all the Work with SOlr.
8 - *
9 - * @defgroup SolrStore
 6+ * @ingroup SolrStore
 7+ * @file
108 * @author Simon Bachenberg
119 */
 10+
 11+/**
 12+ * This class should do all the talk to the Solr server.
 13+ *
 14+ * @ingroup SolrStore
 15+ */
1216 class SolrTalker {
1317
1418 private $header = array("Content-type:text/xml; charset=utf-8");
@@ -127,7 +131,7 @@
128132 $queryStr = '';
129133 foreach ($queryParts as $value) {
130134 if (strpos($value, ':') !== false) { //Value conatins a ":" ?
131 - $parts = split(':', $value); //Split the Query part in Key (Parts[0]) and Value (Parts[1])
 135+ $parts = explode(':', $value); //Split the Query part in Key (Parts[0]) and Value (Parts[1])
132136 $solrField = $this->findField($parts[0]); //Search for a Solr Field for the Key
133137 if ($solrField) {
134138 $queryStr = $queryStr . ' ' . $solrField . ':' . $parts[1];
@@ -205,29 +209,46 @@
206210
207211 curl_setopt($ch, CURLOPT_URL, $url);
208212 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
209 - curl_setopt($ch, CURLOPT_POST, 1);
210213 curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
211214 curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
212 -
 215+
213216 if ($xmlcontent) {
 217+ curl_setopt($ch, CURLOPT_POST, 1);
214218 curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
215219 curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlcontent);
216220 }
217221
218222 $data = curl_exec($ch);
 223+
 224+ if ( curl_errno( $ch ) != 0 ) {
 225+ throw new MWException( curl_error( $ch ) );
 226+ }
 227+
 228+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 229+
 230+ curl_close($ch);
219231
220 - if (curl_errno($ch)) {
 232+ // if the request was successful
 233+ if ( $httpCode == 200 ) {
 234+
 235+ try {
 236+ $xml = new SimpleXMLElement($data);
 237+ } catch (Exception $exc) {
 238+ throw new MWException( $exc->getMessage() );
 239+ }
 240+
 241+ } else { // some error occurred
 242+
 243+ // have to scrape the error message from the returned HTML
 244+ $xml = new DOMDocument;
 245+ $xml->loadHTML( $data );
 246+
 247+ $u = $xml->getElementsByTagName( 'u' );
 248+ $errmsg = $xml->saveXML( $u->item( $u->length - 1 )->firstChild );
221249
222 - } else {
223 - curl_close($ch);
224 - }
 250+ throw new MWException( $errmsg );
 251+ }
225252
226 - try {
227 - $xml = new SimpleXMLElement($data);
228 - } catch (Exception $exc) {
229 - return false;
230 - }
231 -
232253 return $xml;
233254 }
234255
@@ -404,5 +425,3 @@
405426 }
406427
407428 }
408 -
409 -?>
Index: trunk/extensions/SolrStore/SolrStore.alias.php
@@ -0,0 +1,14 @@
 2+<?php
 3+/**
 4+ * Aliases for special pages
 5+ *
 6+ * @ingroup SolrStore
 7+ * @file
 8+ * @author Simon Bachenberg
 9+ */
 10+
 11+$specialPageAliases = array();
 12+
 13+$specialPageAliases['en'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch'));
 14+$specialPageAliases['de'] = array('solrsearch' => array('SolrSearch', 'SpecialSolrSearch'));
 15+
Property changes on: trunk/extensions/SolrStore/SolrStore.alias.php
___________________________________________________________________
Added: svn:eol-style
116 + native
Index: trunk/extensions/SolrStore/SolrDoc.php
@@ -1,17 +1,16 @@
22 <?php
3 -
43 /**
5 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 4+ * File holding the SolrDoc class
65 *
7 - * @defgroup SolrStore
 6+ * @ingroup SolrStore
 7+ * @file
88 * @author Simon Bachenberg
99 */
1010
1111 /**
1212 * Class for saving Documents for sending to Solr
1313 *
14 - * @file
15 - * @ingroup SolrConnector
 14+ * @ingroup SolrStore
1615 */
1716 class SolrDoc {
1817 private $output;
@@ -64,5 +63,3 @@
6564 return $all;
6665 }
6766 }
68 -
69 -?>
Index: trunk/extensions/SolrStore/SolrSearch.php
@@ -1,11 +1,17 @@
22 <?php
3 -
43 /**
5 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 4+ * File holding the SolrSearch class
65 *
7 - * @defgroup SolrStore
 6+ * @ingroup SolrStore
 7+ * @file
88 * @author Simon Bachenberg
99 */
 10+
 11+/**
 12+ * TODO: Insert class description
 13+ *
 14+ * @ingroup SolrStore
 15+ */
1016 class SolrSearch extends SearchEngine {
1117
1218 var $limit = 10;
Index: trunk/extensions/SolrStore/SolrSearchFieldSet.php
@@ -1,17 +1,22 @@
22 <?php
 3+/**
 4+ * File holding the SolrSearchFieldSet class
 5+ *
 6+ * @ingroup SolrStore
 7+ * @file
 8+ * @author Simon Bachenberg
 9+ */
310
411 /**
5 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
6 - *
7 - * @example To create a SearchSet for your Wiki add the Following Lines to you LocalSettings.php
 12+ * TODO: Insert class description
 13+ *
 14+ * To create a SearchSet for your Wiki add the Following Lines to you LocalSettings.php
815 * $wgSolrFields = array(
916 * new SolrSearchFieldSet('<Name of the SearchSet>', '<Semicolon Seperated List of your Semantic Propertys>', ''<Semicolon Seperated List of the Lable for your Fields>', '<Extra Query Parameters>'),
1017 * new SolrSearchFieldSet('Institution', 'has_name; has_country', 'Name, Country', ' AND category:Event')
1118 * );
1219 *
13 - *
14 - * @defgroup SolrStore
15 - * @author Simon Bachenberg
 20+ * @ingroup SolrStore
1621 */
1722 class SolrSearchFieldSet {
1823
@@ -60,5 +65,3 @@
6166 }
6267
6368 }
64 -
65 -?>
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php
@@ -1,12 +1,19 @@
22 <?php
33 /**
4 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 4+ * File holding the SpecialSolrSearch class
55 *
66 * This is the SpecialPage, displaying the SearchSets and Results
77 *
8 - * @defgroup SolrStore
 8+ * @ingroup SolrStore
 9+ * @file
910 * @author Simon Bachenberg
1011 */
 12+
 13+/**
 14+ * TODO: Insert class description
 15+ *
 16+ * @ingroup SolrStore
 17+ */
1118 class SpecialSolrSearch extends SpecialPage {
1219
1320 /**
@@ -539,5 +546,3 @@
540547 }
541548
542549 }
543 -
544 -?>
\ No newline at end of file
Index: trunk/extensions/SolrStore/SolrConnectorStore.php
@@ -1,12 +1,17 @@
22 <?php
3 -
4 -
53 /**
6 - * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 4+ * File holding the SolrConnectorStore class
75 *
8 - * @defgroup SolrStore
 6+ * @ingroup SolrStore
 7+ * @file
98 * @author Simon Bachenberg, Stephan Gambke
109 */
 10+
 11+/**
 12+ * TODO: Insert class description
 13+ *
 14+ * @ingroup SolrStore
 15+ */
1116 class SolrConnectorStore extends SMWStore {
1217
1318 static protected $smBaseStore;
@@ -392,4 +397,3 @@
393398 }
394399
395400 }
396 -

Status & tagging log