r19891 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19890‎ | r19891 | r19892 >
Date:10:11, 12 February 2007
Author:proes
Status:old
Tags:
Comment:
Improved search page:
* Some parts of the page are configurable now through globals.
* 'Go' button now uses the following resolution scheme:
- Search for an expression, if only one found then go to DefinedMeaning page, if more than one found go to Expression page
- Otherwise, search for an external identifier, if found one, go to DefinedMeaning page
- Otherwise, go to Expression page and allow user to add a new expression.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Expression.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/type.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialDatasearch.php
@@ -32,6 +32,7 @@
3333 function SpecialDatasearch() {
3434 SpecialPage::SpecialPage('Datasearch');
3535
 36+ require_once("WikiDataGlobals.php");
3637 require_once("forms.php");
3738 require_once("type.php");
3839 require_once("Expression.php");
@@ -61,56 +62,96 @@
6263 $this->collectionMemberAttribute = new Attribute("collection-member", "Collection member", $definedMeaningReferenceType);
6364 }
6465
65 - function execute( $par ) {
 66+ function execute($parameter) {
6667 global
67 - $wgOut, $wgTitle, $wgRequest;
 68+ $wgOut, $wgTitle;
6869
69 - $spelling = ltrim($_GET['search-text']);
 70+ $searchText = ltrim($_GET['search-text']);
7071
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+ }
7477
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));
7689 }
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);
8392
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+ }
8699
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);
88119
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));
102138
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>');
112154
113 - $wgOut->addHTML($this->searchExternalIdentifiers($spelling, $collectionId));
114 - }
 155+ $wgOut->addHTML($this->searchExternalIdentifiers($searchText, $collectionId));
115156 }
116157 }
117158
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
@@ -1,5 +1,7 @@
22 <?php
33
 4+// Attribute names
 5+
46 global
57 $wgAlternativeDefinitionAttributeName,
68 $wgAlternativeDefinitionsAttributeName,
@@ -100,6 +102,8 @@
101103 $wgUrlAttributeAttributeName = "Property";
102104 $wgUrlAttributeValuesAttributeName = "URL properties";
103105
 106+// Attribute Ids
 107+
104108 global
105109 $wgAlternativeDefinitionsAttributeId,
106110 $wgClassAttributesAttributeId,
@@ -123,6 +127,8 @@
124128 $wgRelationsAttributeId = "relations";
125129 $wgSynonymsAndTranslationsAttributeId = "synonyms-translations";
126130
 131+// Defined meaning editor
 132+
127133 global
128134 $wgDefinedMeaningAttributesOrder;
129135
@@ -139,6 +145,8 @@
140146 $wgDefinedMeaningAttributesAttributeId
141147 );
142148
 149+// Go to source templates
 150+
143151 require_once("GotoSourceTemplate.php");
144152
145153 global
@@ -146,6 +154,8 @@
147155
148156 $wgGotoSourceTemplates = array(); // Map of collection id => GotoSourceTemplate
149157
 158+// Page titles
 159+
150160 global
151161 $wgDefinedMeaningPageTitlePrefix,
152162 $wgExpressionPageTitlePrefix;
@@ -153,6 +163,8 @@
154164 $wgDefinedMeaningPageTitlePrefix = "";
155165 $wgExpressionPageTitlePrefix = "Multiple meanings";
156166
 167+// Authoritative versioning
 168+
157169 global
158170 $wgShowAuthoritativeContributionPanelAtBottom,
159171 $wgShowAuthoritativeContributionPanelAtTop;
@@ -160,4 +172,17 @@
161173 $wgShowAuthoritativeContributionPanelAtBottom = false;
162174 $wgShowAuthoritativeContributionPanelAtTop = true;
163175
 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+
164189 ?>
\ No newline at end of file
Index: trunk/extensions/Wikidata/OmegaWiki/Expression.php
@@ -868,13 +868,53 @@
869869
870870 function getCollectionMemberId($collectionId, $sourceIdentifier) {
871871 $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+ );
874879
875880 if ($collectionEntry = $dbr->fetchObject($queryResult))
876881 return $collectionEntry->member_mid;
877882 else
878 - return null;
 883+ return 0;
879884 }
880885
 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+
881921 ?>
\ No newline at end of file
Index: trunk/extensions/Wikidata/OmegaWiki/type.php
@@ -21,24 +21,35 @@
2222 return '<input type="checkbox" disabled="disabled"/>';
2323 }
2424
25 -function spellingAsLink($value) {
 25+function pageAsURL($nameSpace, $title) {
2626 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);
3130 }
3231
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>';
3946 }
4047
 48+function spellingAsLink($spelling) {
 49+ return createLink(spellingAsURL($spelling), $spelling);
 50+}
 51+
4152 function definedMeaningReferenceAsLink($definedMeaningId, $definingExpression, $label) {
42 - return createLink("DefinedMeaning", "$definingExpression ($definedMeaningId)", $label);
 53+ return createLink(definedMeaningReferenceAsURL($definedMeaningId, $definingExpression), $label);
4354 }
4455
4556 function languageIdAsText($languageId) {
@@ -164,15 +175,8 @@
165176 }
166177
167178 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));
177181 else
178182 return "";
179183 }