Index: trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | function SpecialDatasearch() { |
34 | 34 | SpecialPage::SpecialPage('Datasearch'); |
35 | 35 | |
| 36 | + require_once("WikiDataGlobals.php"); |
36 | 37 | require_once("forms.php"); |
37 | 38 | require_once("type.php"); |
38 | 39 | require_once("Expression.php"); |
— | — | @@ -61,56 +62,96 @@ |
62 | 63 | $this->collectionMemberAttribute = new Attribute("collection-member", "Collection member", $definedMeaningReferenceType); |
63 | 64 | } |
64 | 65 | |
65 | | - function execute( $par ) { |
| 66 | + function execute($parameter) { |
66 | 67 | global |
67 | | - $wgOut, $wgTitle, $wgRequest; |
| 68 | + $wgOut, $wgTitle; |
68 | 69 | |
69 | | - $spelling = ltrim($_GET['search-text']); |
| 70 | + $searchText = ltrim($_GET['search-text']); |
70 | 71 | |
71 | | - if (isset($_GET['go'])) { |
72 | | - global |
73 | | - $wgScript; |
| 72 | + if (isset($_GET['go'])) |
| 73 | + $this->go($searchText); |
| 74 | + else |
| 75 | + $this->search($searchText); |
| 76 | + } |
74 | 77 | |
75 | | - $wgOut->redirect($wgScript . '/OmegaWiki:' . $spelling); |
| 78 | + function go($searchText) { |
| 79 | + global |
| 80 | + $wgScript, $wgOut; |
| 81 | + |
| 82 | + $expressionMeaningIds = getExpressionMeaningIds($searchText); |
| 83 | + |
| 84 | + if (count($expressionMeaningIds) > 0) { |
| 85 | + if (count($expressionMeaningIds) == 1) |
| 86 | + $wgOut->redirect(definedMeaningIdAsURL($expressionMeaningIds[0])); |
| 87 | + else |
| 88 | + $wgOut->redirect(spellingAsURL($searchText)); |
76 | 89 | } |
77 | | - else { |
78 | | - $fulltext = $_GET['fulltext']; |
79 | | - $collectionId = $wgRequest->getInt("collection"); |
80 | | - $languageId = $wgRequest->getInt("language"); |
81 | | - $withinWords = $wgRequest->getBool('within-words'); |
82 | | - $withinExternalIdentifiers = $wgRequest->getBool('within-external-identifiers'); |
| 90 | + else { |
| 91 | + $collectionMemberId = getAnyDefinedMeaningWithSourceIdentifier($searchText); |
83 | 92 | |
84 | | - if (!$withinWords && !$withinExternalIdentifiers) |
85 | | - $withinWords = true; |
| 93 | + if ($collectionMemberId != 0) |
| 94 | + $wgOut->redirect(definedMeaningIdAsURL($collectionMemberId)); |
| 95 | + else |
| 96 | + $wgOut->redirect(spellingAsURL($searchText)); |
| 97 | + } |
| 98 | + } |
86 | 99 | |
87 | | - $languageName = languageIdAsText($languageId); |
| 100 | + function search($searchText) { |
| 101 | + global |
| 102 | + $wgOut, $wgRequest, $wgFilterLanguageId, |
| 103 | + $wgSearchWithinWordsDefaultValue, $wgSearchWithinExternalIdentifiersDefaultValue, |
| 104 | + $wgShowSearchWithinExternalIdentifiersOption, $wgShowSearchWithinWordsOption; |
| 105 | + |
| 106 | + $collectionId = $wgRequest->getInt("collection"); |
| 107 | + $languageId = $wgRequest->getInt("language"); |
| 108 | + $withinWords = $wgRequest->getBool("within-words"); |
| 109 | + $withinExternalIdentifiers = $wgRequest->getBool("within-external-identifiers"); |
| 110 | + |
| 111 | + if (!$withinWords && !$withinExternalIdentifiers) { |
| 112 | + $withinWords = $wgSearchWithinWordsDefaultValue; |
| 113 | + $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
| 114 | + } |
| 115 | + |
| 116 | + $languageName = languageIdAsText($languageId); |
| 117 | + $options = array(); |
| 118 | + $options['Search text'] = getTextBox('search-text', $searchText); |
88 | 119 | |
89 | | - $wgOut->addHTML(getOptionPanel(array( |
90 | | - 'Search text' => getTextBox('search-text', $_GET['search-text']), |
91 | | - 'Language' => getSuggest('language', "language", array(), $languageId, $languageName), |
92 | | - 'Collection' => getSuggest('collection', 'collection', array(), $collectionId, collectionIdAsText($collectionId)), |
93 | | - 'Within words' => getCheckBox('within-words', $withinWords), |
94 | | - 'Within external identifiers' => getCheckBox('within-external-identifiers', $withinExternalIdentifiers) |
95 | | - ))); |
96 | | - |
97 | | - if ($withinWords) { |
98 | | - if ($languageId != 0) |
99 | | - $languageText = " in <i>" . $languageName . "</i> "; |
100 | | - else |
101 | | - $languageText = " "; |
| 120 | + if ($wgFilterLanguageId == 0) |
| 121 | + $options['Language'] = getSuggest('language', "language", array(), $languageId, $languageName); |
| 122 | + else |
| 123 | + $languageId = $wgFilterLanguageId; |
| 124 | + |
| 125 | + $options['Collection'] = getSuggest('collection', 'collection', array(), $collectionId, collectionIdAsText($collectionId)); |
| 126 | + |
| 127 | + if ($wgShowSearchWithinWordsOption) |
| 128 | + $options['Within words'] = getCheckBox('within-words', $withinWords); |
| 129 | + else |
| 130 | + $withinWords = $wgSearchWithinWordsDefaultValue; |
| 131 | + |
| 132 | + if ($wgShowSearchWithinExternalIdentifiersOption) |
| 133 | + $options['Within external identifiers'] = getCheckBox('within-external-identifiers', $withinExternalIdentifiers); |
| 134 | + else |
| 135 | + $withinExternalIdentifiers = $wgSearchWithinExternalIdentifiersDefaultValue; |
| 136 | + |
| 137 | + $wgOut->addHTML(getOptionPanel($options)); |
102 | 138 | |
103 | | - $wgOut->addHTML('<h1>Words' . $languageText . 'matching <i>'. $spelling . '</i> and associated meanings</h1>'); |
104 | | - $wgOut->addHTML('<p>Showing only a maximum of 100 matches.</p>'); |
105 | | - |
106 | | - $wgOut->addHTML($this->searchWords($spelling, $collectionId, $languageId)); |
107 | | - } |
108 | | - |
109 | | - if ($withinExternalIdentifiers) { |
110 | | - $wgOut->addHTML('<h1>External identifiers matching <i>'. $spelling . '</i></h1>'); |
111 | | - $wgOut->addHTML('<p>Showing only a maximum of 100 matches.</p>'); |
| 139 | + if ($withinWords) { |
| 140 | + if ($languageId != 0 && $languageName != "") |
| 141 | + $languageText = " in <i>" . $languageName . "</i> "; |
| 142 | + else |
| 143 | + $languageText = " "; |
| 144 | + |
| 145 | + $wgOut->addHTML('<h1>Words' . $languageText . 'matching <i>'. $searchText . '</i> and associated meanings</h1>'); |
| 146 | + $wgOut->addHTML('<p>Showing only a maximum of 100 matches.</p>'); |
| 147 | + |
| 148 | + $wgOut->addHTML($this->searchWords($searchText, $collectionId, $languageId)); |
| 149 | + } |
| 150 | + |
| 151 | + if ($withinExternalIdentifiers) { |
| 152 | + $wgOut->addHTML('<h1>External identifiers matching <i>'. $searchText . '</i></h1>'); |
| 153 | + $wgOut->addHTML('<p>Showing only a maximum of 100 matches.</p>'); |
112 | 154 | |
113 | | - $wgOut->addHTML($this->searchExternalIdentifiers($spelling, $collectionId)); |
114 | | - } |
| 155 | + $wgOut->addHTML($this->searchExternalIdentifiers($searchText, $collectionId)); |
115 | 156 | } |
116 | 157 | } |
117 | 158 | |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +// Attribute names |
| 5 | + |
4 | 6 | global |
5 | 7 | $wgAlternativeDefinitionAttributeName, |
6 | 8 | $wgAlternativeDefinitionsAttributeName, |
— | — | @@ -100,6 +102,8 @@ |
101 | 103 | $wgUrlAttributeAttributeName = "Property"; |
102 | 104 | $wgUrlAttributeValuesAttributeName = "URL properties"; |
103 | 105 | |
| 106 | +// Attribute Ids |
| 107 | + |
104 | 108 | global |
105 | 109 | $wgAlternativeDefinitionsAttributeId, |
106 | 110 | $wgClassAttributesAttributeId, |
— | — | @@ -123,6 +127,8 @@ |
124 | 128 | $wgRelationsAttributeId = "relations"; |
125 | 129 | $wgSynonymsAndTranslationsAttributeId = "synonyms-translations"; |
126 | 130 | |
| 131 | +// Defined meaning editor |
| 132 | + |
127 | 133 | global |
128 | 134 | $wgDefinedMeaningAttributesOrder; |
129 | 135 | |
— | — | @@ -139,6 +145,8 @@ |
140 | 146 | $wgDefinedMeaningAttributesAttributeId |
141 | 147 | ); |
142 | 148 | |
| 149 | +// Go to source templates |
| 150 | + |
143 | 151 | require_once("GotoSourceTemplate.php"); |
144 | 152 | |
145 | 153 | global |
— | — | @@ -146,6 +154,8 @@ |
147 | 155 | |
148 | 156 | $wgGotoSourceTemplates = array(); // Map of collection id => GotoSourceTemplate |
149 | 157 | |
| 158 | +// Page titles |
| 159 | + |
150 | 160 | global |
151 | 161 | $wgDefinedMeaningPageTitlePrefix, |
152 | 162 | $wgExpressionPageTitlePrefix; |
— | — | @@ -153,6 +163,8 @@ |
154 | 164 | $wgDefinedMeaningPageTitlePrefix = ""; |
155 | 165 | $wgExpressionPageTitlePrefix = "Multiple meanings"; |
156 | 166 | |
| 167 | +// Authoritative versioning |
| 168 | + |
157 | 169 | global |
158 | 170 | $wgShowAuthoritativeContributionPanelAtBottom, |
159 | 171 | $wgShowAuthoritativeContributionPanelAtTop; |
— | — | @@ -160,4 +172,17 @@ |
161 | 173 | $wgShowAuthoritativeContributionPanelAtBottom = false; |
162 | 174 | $wgShowAuthoritativeContributionPanelAtTop = true; |
163 | 175 | |
| 176 | +// Search page |
| 177 | + |
| 178 | +global |
| 179 | + $wgSearchWithinExternalIdentifiersDefaultValue, |
| 180 | + $wgSearchWithinWordsDefaultValue, |
| 181 | + $wgShowSearchWithinExternalIdentifiersOption, |
| 182 | + $wgShowSearchWithinWordsOption; |
| 183 | + |
| 184 | +$wgSearchWithinExternalIdentifiersDefaultValue = true; |
| 185 | +$wgSearchWithinWordsDefaultValue = true; |
| 186 | +$wgShowSearchWithinExternalIdentifiersOption = true; |
| 187 | +$wgShowSearchWithinWordsOption = true; |
| 188 | + |
164 | 189 | ?> |
\ No newline at end of file |
Index: trunk/extensions/Wikidata/OmegaWiki/Expression.php |
— | — | @@ -868,13 +868,53 @@ |
869 | 869 | |
870 | 870 | function getCollectionMemberId($collectionId, $sourceIdentifier) { |
871 | 871 | $dbr = & wfGetDB(DB_SLAVE); |
872 | | - $queryResult = $dbr->query("SELECT member_mid from uw_collection_contents " . |
873 | | - "WHERE collection_id=$collectionId AND internal_member_id=". $dbr->addQuotes($sourceIdentifier)); |
| 872 | + $queryResult = $dbr->query( |
| 873 | + "SELECT member_mid" . |
| 874 | + " FROM uw_collection_contents " . |
| 875 | + " WHERE collection_id=$collectionId" . |
| 876 | + " AND internal_member_id=". $dbr->addQuotes($sourceIdentifier) . |
| 877 | + " AND " . getLatestTransactionRestriction('uw_collection_contents') |
| 878 | + ); |
874 | 879 | |
875 | 880 | if ($collectionEntry = $dbr->fetchObject($queryResult)) |
876 | 881 | return $collectionEntry->member_mid; |
877 | 882 | else |
878 | | - return null; |
| 883 | + return 0; |
879 | 884 | } |
880 | 885 | |
| 886 | +function getAnyDefinedMeaningWithSourceIdentifier($sourceIdentifier) { |
| 887 | + $dbr = & wfGetDB(DB_SLAVE); |
| 888 | + $queryResult = $dbr->query( |
| 889 | + "SELECT member_mid" . |
| 890 | + " FROM uw_collection_contents " . |
| 891 | + " WHERE internal_member_id=". $dbr->addQuotes($sourceIdentifier) . |
| 892 | + " AND " . getLatestTransactionRestriction('uw_collection_contents') . |
| 893 | + " LIMIT 1" |
| 894 | + ); |
| 895 | + |
| 896 | + if ($collectionEntry = $dbr->fetchObject($queryResult)) |
| 897 | + return $collectionEntry->member_mid; |
| 898 | + else |
| 899 | + return 0; |
| 900 | +} |
| 901 | + |
| 902 | +function getExpressionMeaningIds($spelling) { |
| 903 | + $dbr = & wfGetDB(DB_SLAVE); |
| 904 | + $queryResult = $dbr->query( |
| 905 | + "SELECT defined_meaning_id" . |
| 906 | + " FROM uw_expression_ns, uw_syntrans " . |
| 907 | + " WHERE spelling=". $dbr->addQuotes($spelling) . |
| 908 | + " AND uw_expression_ns.expression_id=uw_syntrans.expression_id" . |
| 909 | + " AND " . getLatestTransactionRestriction('uw_syntrans') . |
| 910 | + " AND " . getLatestTransactionRestriction('uw_expression_ns') |
| 911 | + ); |
| 912 | + |
| 913 | + $result = array(); |
| 914 | + |
| 915 | + while ($synonymRecord = $dbr->fetchObject($queryResult)) |
| 916 | + $result[] = $synonymRecord->defined_meaning_id; |
| 917 | + |
| 918 | + return $result; |
| 919 | +} |
| 920 | + |
881 | 921 | ?> |
\ No newline at end of file |
Index: trunk/extensions/Wikidata/OmegaWiki/type.php |
— | — | @@ -21,24 +21,35 @@ |
22 | 22 | return '<input type="checkbox" disabled="disabled"/>'; |
23 | 23 | } |
24 | 24 | |
25 | | -function spellingAsLink($value) { |
| 25 | +function pageAsURL($nameSpace, $title) { |
26 | 26 | global |
27 | | - $wgUser; |
28 | | - |
29 | | -// return $wgUser->getSkin()->makeLink("OmegaWiki:$value", htmlspecialchars($value)); |
30 | | - return createLink("Expression", $value, $value); |
| 27 | + $wgScript; |
| 28 | + |
| 29 | + return $wgScript. '/' . $nameSpace . ':' . htmlspecialchars($title); |
31 | 30 | } |
32 | 31 | |
33 | | -function createLink($nameSpace, $title, $text) { |
34 | | - global |
35 | | - $wgUser, $wgScript; |
36 | | - |
37 | | - return '<a href="'. $wgScript. '/' . $nameSpace . ':' . htmlspecialchars($title) . '">' . htmlspecialchars($text) . '</a>'; |
38 | | -// return $wgUser->getSkin()->makeLink("$nameSpace:$tag", htmlspecialchars($text)); |
| 32 | +function spellingAsURL($spelling) { |
| 33 | + return pageAsURL("Expression", $spelling); |
| 34 | +} |
| 35 | + |
| 36 | +function definedMeaningReferenceAsURL($definedMeaningId, $definingExpression) { |
| 37 | + return pageAsURL("DefinedMeaning", "$definingExpression ($definedMeaningId)"); |
| 38 | +} |
| 39 | + |
| 40 | +function definedMeaningIdAsURL($definedMeaningId) { |
| 41 | + return definedMeaningReferenceAsURL($definedMeaningId, definingExpression($definedMeaningId)); |
| 42 | +} |
| 43 | + |
| 44 | +function createLink($url, $text) { |
| 45 | + return '<a href="'. $url . '">' . htmlspecialchars($text) . '</a>'; |
39 | 46 | } |
40 | 47 | |
| 48 | +function spellingAsLink($spelling) { |
| 49 | + return createLink(spellingAsURL($spelling), $spelling); |
| 50 | +} |
| 51 | + |
41 | 52 | function definedMeaningReferenceAsLink($definedMeaningId, $definingExpression, $label) { |
42 | | - return createLink("DefinedMeaning", "$definingExpression ($definedMeaningId)", $label); |
| 53 | + return createLink(definedMeaningReferenceAsURL($definedMeaningId, $definingExpression), $label); |
43 | 54 | } |
44 | 55 | |
45 | 56 | function languageIdAsText($languageId) { |
— | — | @@ -164,15 +175,8 @@ |
165 | 176 | } |
166 | 177 | |
167 | 178 | function definedMeaningAsLink($definedMeaningId) { |
168 | | - global |
169 | | - $wgUser; |
170 | | - |
171 | | - if ($definedMeaningId > 0) { |
172 | | - $definedMeaningExpression = definedMeaningExpression($definedMeaningId); |
173 | | - $definingExpression = definingExpression($definedMeaningId); |
174 | | - |
175 | | - return createLink("DefinedMeaning", "$definingExpression ($definedMeaningId)", $definedMeaningExpression); |
176 | | - } |
| 179 | + if ($definedMeaningId > 0) |
| 180 | + return createLink(definedMeaningIdAsURL($definedMeaningId), definedMeaningExpression($definedMeaningId)); |
177 | 181 | else |
178 | 182 | return ""; |
179 | 183 | } |