r23683 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23682‎ | r23683 | r23684 >
Date:20:31, 3 July 2007
Author:erik
Status:old
Tags:
Comment:
move DB functions to API
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/type.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1228,5 +1228,110 @@
12291229 return $meanings;
12301230 }
12311231
 1232+function definingExpressionRow($definedMeaningId) {
 1233+ $dc=wdGetDataSetContext();
 1234+ $dbr =& wfGetDB(DB_SLAVE);
 1235+ $queryResult = $dbr->query("SELECT {$dc}_expression_ns.expression_id, spelling, language_id " .
 1236+ " FROM {$dc}_defined_meaning, {$dc}_expression_ns " .
 1237+ " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
 1238+ " AND {$dc}_expression_ns.expression_id={$dc}_defined_meaning.expression_id".
 1239+ " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning").
 1240+ " AND " . getLatestTransactionRestriction("{$dc}_expression_ns"));
 1241+ $expression = $dbr->fetchObject($queryResult);
 1242+ return array($expression->expression_id, $expression->spelling, $expression->language_id);
 1243+}
12321244
 1245+function definingExpression($definedMeaningId) {
 1246+ $dc=wdGetDataSetContext();
 1247+ $dbr =& wfGetDB(DB_SLAVE);
 1248+ $queryResult = $dbr->query("SELECT spelling " .
 1249+ " FROM {$dc}_defined_meaning, {$dc}_expression_ns " .
 1250+ " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
 1251+ " AND {$dc}_expression_ns.expression_id={$dc}_defined_meaning.expression_id".
 1252+ " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning").
 1253+ " AND " . getLatestTransactionRestriction("{$dc}_expression_ns"));
 1254+ $expression = $dbr->fetchObject($queryResult);
 1255+ return $expression->spelling;
 1256+}
12331257
 1258+function definedMeaningExpressionForLanguage($definedMeaningId, $languageId) {
 1259+ $dc=wdGetDataSetContext();
 1260+ $dbr =& wfGetDB(DB_SLAVE);
 1261+ $queryResult = $dbr->query(
 1262+ "SELECT spelling" .
 1263+ " FROM {$dc}_syntrans, {$dc}_expression_ns " .
 1264+ " WHERE defined_meaning_id=$definedMeaningId" .
 1265+ " AND {$dc}_expression_ns.expression_id={$dc}_syntrans.expression_id" .
 1266+ " AND {$dc}_expression_ns.language_id=$languageId" .
 1267+ " AND {$dc}_syntrans.identical_meaning=1" .
 1268+ " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
 1269+ " AND " . getLatestTransactionRestriction("{$dc}_expression_ns") .
 1270+ " LIMIT 1"
 1271+ );
 1272+
 1273+ if ($expression = $dbr->fetchObject($queryResult))
 1274+ return $expression->spelling;
 1275+ else
 1276+ return "";
 1277+}
 1278+
 1279+function definedMeaningExpressionForAnyLanguage($definedMeaningId) {
 1280+ $dc=wdGetDataSetContext();
 1281+ $dbr =& wfGetDB(DB_SLAVE);
 1282+ $queryResult = $dbr->query(
 1283+ "SELECT spelling " .
 1284+ " FROM {$dc}_syntrans, {$dc}_expression_ns" .
 1285+ " WHERE defined_meaning_id=$definedMeaningId" .
 1286+ " AND {$dc}_expression_ns.expression_id={$dc}_syntrans.expression_id" .
 1287+ " AND {$dc}_syntrans.identical_meaning=1" .
 1288+ " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
 1289+ " AND " . getLatestTransactionRestriction("{$dc}_expression_ns") .
 1290+ " LIMIT 1");
 1291+
 1292+ if ($expression = $dbr->fetchObject($queryResult))
 1293+ return $expression->spelling;
 1294+ else
 1295+ return "";
 1296+}
 1297+
 1298+function definedMeaningExpression($definedMeaningId) {
 1299+ global
 1300+ $wgUser;
 1301+
 1302+ $userLanguage = getLanguageIdForCode($wgUser->getOption('language'));
 1303+
 1304+ list($definingExpressionId, $definingExpression, $definingExpressionLanguage) = definingExpressionRow($definedMeaningId);
 1305+
 1306+ if ($definingExpressionLanguage == $userLanguage && expressionIsBoundToDefinedMeaning($definingExpressionId, $definedMeaningId))
 1307+ return $definingExpression;
 1308+ else {
 1309+ if ($userLanguage > 0)
 1310+ $result = definedMeaningExpressionForLanguage($definedMeaningId, $userLanguage);
 1311+ else
 1312+ $result = "";
 1313+
 1314+ if ($result == "") {
 1315+ $result = definedMeaningExpressionForLanguage($definedMeaningId, 85);
 1316+
 1317+ if ($result == "") {
 1318+ $result = definedMeaningExpressionForAnyLanguage($definedMeaningId);
 1319+
 1320+ if ($result == "")
 1321+ $result = $definingExpression;
 1322+ }
 1323+ }
 1324+ }
 1325+
 1326+ return $result;
 1327+}
 1328+
 1329+function getTextValue($textId) {
 1330+ $dc=wdGetDataSetContext();
 1331+ $dbr =& wfGetDB(DB_SLAVE);
 1332+ $queryResult = $dbr->query("SELECT text_text from {$dc}_text where text_id=$textId");
 1333+
 1334+ return $dbr->fetchObject($queryResult)->text_text;
 1335+}
 1336+
 1337+
 1338+
Index: trunk/extensions/Wikidata/OmegaWiki/type.php
@@ -80,111 +80,6 @@
8181 substr($timestamp, 8, 2) . ':' . substr($timestamp, 10, 2) . ':' . substr($timestamp, 12, 2);
8282 }
8383
84 -function definingExpressionRow($definedMeaningId) {
85 - $dc=wdGetDataSetContext();
86 - $dbr =& wfGetDB(DB_SLAVE);
87 - $queryResult = $dbr->query("SELECT {$dc}_expression_ns.expression_id, spelling, language_id " .
88 - " FROM {$dc}_defined_meaning, {$dc}_expression_ns " .
89 - " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
90 - " AND {$dc}_expression_ns.expression_id={$dc}_defined_meaning.expression_id".
91 - " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning").
92 - " AND " . getLatestTransactionRestriction("{$dc}_expression_ns"));
93 - $expression = $dbr->fetchObject($queryResult);
94 - return array($expression->expression_id, $expression->spelling, $expression->language_id);
95 -}
96 -
97 -function definingExpression($definedMeaningId) {
98 - $dc=wdGetDataSetContext();
99 - $dbr =& wfGetDB(DB_SLAVE);
100 - $queryResult = $dbr->query("SELECT spelling " .
101 - " FROM {$dc}_defined_meaning, {$dc}_expression_ns " .
102 - " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
103 - " AND {$dc}_expression_ns.expression_id={$dc}_defined_meaning.expression_id".
104 - " AND " . getLatestTransactionRestriction("{$dc}_defined_meaning").
105 - " AND " . getLatestTransactionRestriction("{$dc}_expression_ns"));
106 - $expression = $dbr->fetchObject($queryResult);
107 - return $expression->spelling;
108 -}
109 -
110 -function definedMeaningExpressionForLanguage($definedMeaningId, $languageId) {
111 - $dc=wdGetDataSetContext();
112 - $dbr =& wfGetDB(DB_SLAVE);
113 - $queryResult = $dbr->query(
114 - "SELECT spelling" .
115 - " FROM {$dc}_syntrans, {$dc}_expression_ns " .
116 - " WHERE defined_meaning_id=$definedMeaningId" .
117 - " AND {$dc}_expression_ns.expression_id={$dc}_syntrans.expression_id" .
118 - " AND {$dc}_expression_ns.language_id=$languageId" .
119 - " AND {$dc}_syntrans.identical_meaning=1" .
120 - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
121 - " AND " . getLatestTransactionRestriction("{$dc}_expression_ns") .
122 - " LIMIT 1"
123 - );
124 -
125 - if ($expression = $dbr->fetchObject($queryResult))
126 - return $expression->spelling;
127 - else
128 - return "";
129 -}
130 -
131 -function definedMeaningExpressionForAnyLanguage($definedMeaningId) {
132 - $dc=wdGetDataSetContext();
133 - $dbr =& wfGetDB(DB_SLAVE);
134 - $queryResult = $dbr->query(
135 - "SELECT spelling " .
136 - " FROM {$dc}_syntrans, {$dc}_expression_ns" .
137 - " WHERE defined_meaning_id=$definedMeaningId" .
138 - " AND {$dc}_expression_ns.expression_id={$dc}_syntrans.expression_id" .
139 - " AND {$dc}_syntrans.identical_meaning=1" .
140 - " AND " . getLatestTransactionRestriction("{$dc}_syntrans") .
141 - " AND " . getLatestTransactionRestriction("{$dc}_expression_ns") .
142 - " LIMIT 1");
143 -
144 - if ($expression = $dbr->fetchObject($queryResult))
145 - return $expression->spelling;
146 - else
147 - return "";
148 -}
149 -
150 -function definedMeaningExpression($definedMeaningId) {
151 - global
152 - $wgUser;
153 -
154 - $userLanguage = getLanguageIdForCode($wgUser->getOption('language'));
155 -
156 - list($definingExpressionId, $definingExpression, $definingExpressionLanguage) = definingExpressionRow($definedMeaningId);
157 -
158 - if ($definingExpressionLanguage == $userLanguage && expressionIsBoundToDefinedMeaning($definingExpressionId, $definedMeaningId))
159 - return $definingExpression;
160 - else {
161 - if ($userLanguage > 0)
162 - $result = definedMeaningExpressionForLanguage($definedMeaningId, $userLanguage);
163 - else
164 - $result = "";
165 -
166 - if ($result == "") {
167 - $result = definedMeaningExpressionForLanguage($definedMeaningId, 85);
168 -
169 - if ($result == "") {
170 - $result = definedMeaningExpressionForAnyLanguage($definedMeaningId);
171 -
172 - if ($result == "")
173 - $result = $definingExpression;
174 - }
175 - }
176 - }
177 -
178 - return $result;
179 -}
180 -
181 -function getTextValue($textId) {
182 - $dc=wdGetDataSetContext();
183 - $dbr =& wfGetDB(DB_SLAVE);
184 - $queryResult = $dbr->query("SELECT text_text from {$dc}_text where text_id=$textId");
185 -
186 - return $dbr->fetchObject($queryResult)->text_text;
187 -}
188 -
18984 function definingExpressionAsLink($definedMeaningId) {
19085 return spellingAsLink(definingExpression($definedMeaningId));
19186 }

Status & tagging log