Index: trunk/extensions/Wikidata/App.php |
— | — | @@ -82,8 +82,7 @@ |
83 | 83 | |
84 | 84 | function initializeWikidata() { |
85 | 85 | global |
86 | | - $wgMessageCache, $wgExtensionPreferences, $wdSiteContext; |
87 | | -; |
| 86 | + $wgMessageCache, $wgExtensionPreferences, $wdSiteContext, $wgPropertyToColumnFilters; |
88 | 87 | |
89 | 88 | $dbr =& wfGetDB(DB_MASTER); |
90 | 89 | $dbr->query("SET NAMES utf8"); |
— | — | @@ -168,7 +167,9 @@ |
169 | 168 | "LinkAttribute" => "Property", |
170 | 169 | "LinkAttributeValues" => "Links", |
171 | 170 | "Property" => "Property", |
172 | | - "Value" => "Value" |
| 171 | + "Value" => "Value", |
| 172 | + "meaningsoftitle"=>"Meanings of \"$1\"", |
| 173 | + "meaningsofsubtitle"=>"<em>Wiki link:</em> [[$1]]", |
173 | 174 | ); |
174 | 175 | |
175 | 176 | $prefixedmsgarray=array(); |
— | — | @@ -190,7 +191,10 @@ |
191 | 192 | 'size' => 10, |
192 | 193 | 'options' => $datasetarray |
193 | 194 | ); |
194 | | - |
| 195 | + $wgPropertyToColumnFilters = array( |
| 196 | + new PropertyToColumnFilter("partOfSpeech", "Part of speech", array(358760)) |
| 197 | + ); |
| 198 | + |
195 | 199 | global |
196 | 200 | $messageCacheOK; |
197 | 201 | |
Index: trunk/extensions/Wikidata/OmegaWiki/ExpressionPage.php |
— | — | @@ -0,0 +1,151 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once('Wikidata.php'); |
| 5 | +require_once('Transaction.php'); |
| 6 | +require_once('WikiDataAPI.php'); |
| 7 | +require_once('forms.php'); |
| 8 | +require_once('Attribute.php'); |
| 9 | +require_once('type.php'); |
| 10 | +require_once('languages.php'); |
| 11 | +require_once('HTMLtable.php'); |
| 12 | +require_once('OmegaWikiRecordSets.php'); |
| 13 | +require_once('OmegaWikiEditors.php'); |
| 14 | +require_once('ViewInformation.php'); |
| 15 | +require_once('WikiDataGlobals.php'); |
| 16 | + |
| 17 | +/** |
| 18 | + * The ExpressionPage class renders pages in the Expression: namespace of a Wikidata application. |
| 19 | + * It is essentially a disambiguation page which can be customized using MediaWiki templates. |
| 20 | +*/ |
| 21 | +class ExpressionPage extends DefaultWikidataApplication { |
| 22 | + public function view() { |
| 23 | + global |
| 24 | + $wgOut, $wgTitle; |
| 25 | + |
| 26 | + parent::view(); |
| 27 | + $expressionAsPageTitle = $wgTitle->getText(); |
| 28 | + $wgOut->setPageTitle(wfMsgSc("meaningsoftitle",$expressionAsPageTitle)); |
| 29 | + $wgOut->setSubtitle(wfMsgSc("meaningsofsubtitle",$wgTitle->getPrefixedText())); |
| 30 | + $sets=wdGetDataSets(); |
| 31 | + $html=''; |
| 32 | + foreach($sets as $set) { |
| 33 | + $html.=$this->getMeaningBox($expressionAsPageTitle, $set); |
| 34 | + } |
| 35 | + $wgOut->addHTML($html); |
| 36 | + } |
| 37 | + |
| 38 | + protected function getMeaningBox($expression, $dataset) { |
| 39 | + global $wgOut, $wgUser; |
| 40 | + $name=$dataset->fetchName(); |
| 41 | + $exp=getExpressions($expression, $dataset); |
| 42 | + $wikiMagic=''; |
| 43 | + if(!empty($exp)) { |
| 44 | + foreach($exp as $foundExpression) { |
| 45 | + $foundExpression->fetchMeaningIds(); |
| 46 | + $languageNames=getOwLanguageNames(); |
| 47 | + $lang=$languageNames[$foundExpression->languageId]; |
| 48 | + $spell=$foundExpression->spelling; |
| 49 | + $wikiMagic.="{{Expression|language=$lang|spelling=$spell}}\n"; |
| 50 | + $defs=array(); |
| 51 | + foreach($foundExpression->meaningIds as $mid) { |
| 52 | + $def=getDefinedMeaningDefinitionForLanguage($mid,getLanguageIdForCode($wgUser->getOption('language')), $dataset); |
| 53 | + $defexrow=definingExpressionRow($mid); |
| 54 | + $defex=$defexrow[1]; |
| 55 | + $wikiMagic.="{{Meaning|definition=$def|dmid=$mid|defined_by=$defex}}\n"; |
| 56 | + } |
| 57 | + $wikiMagic.="\n"; |
| 58 | + |
| 59 | + } |
| 60 | + } else { |
| 61 | + $meaningList="No meanings found."; |
| 62 | + } |
| 63 | + $templatesAsHTML=$wgOut->parse($wikiMagic); |
| 64 | + |
| 65 | + $boxhtml=<<<HTML |
| 66 | +<P> |
| 67 | +<div style="border-style:solid;border-width:1px;border-color:#666666;padding:5px;"> |
| 68 | +<div style="float:right;"><span style="background:#eeeeee;border-style:solid;order-color:black;padding:3px;border-width:1px;"><B>$name</B></span> |
| 69 | +</div> |
| 70 | +$templatesAsHTML |
| 71 | +<br/> |
| 72 | +<B>Add new meaning:</B> |
| 73 | +<form> |
| 74 | +Language: <select><option name="English">English</option></select><br/> |
| 75 | +Definition:<br/><textarea></textarea> |
| 76 | +<input type="submit" value="Add meaning"> |
| 77 | + |
| 78 | +</form> |
| 79 | +</div> |
| 80 | +</P> |
| 81 | +HTML; |
| 82 | + return $boxhtml; |
| 83 | + } |
| 84 | + |
| 85 | + public function history() { |
| 86 | + global |
| 87 | + $wgOut, $wgTitle; |
| 88 | + |
| 89 | + parent::history(); |
| 90 | + |
| 91 | + $spelling = $wgTitle->getText(); |
| 92 | + |
| 93 | + $wgOut->addHTML( |
| 94 | + getExpressionsEditor($spelling, $this->viewInformation)->view( |
| 95 | + $this->getIdStack(), |
| 96 | + getExpressionsRecordSet($spelling, $this->viewInformation) |
| 97 | + ) |
| 98 | + ); |
| 99 | + |
| 100 | + $wgOut->addHTML(DefaultEditor::getExpansionCss()); |
| 101 | + $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>"); |
| 102 | + } |
| 103 | + |
| 104 | + protected function save($referenceQueryTransactionInformation) { |
| 105 | + global |
| 106 | + $wgTitle; |
| 107 | + |
| 108 | + parent::save($referenceQueryTransactionInformation); |
| 109 | + |
| 110 | + $spelling = $wgTitle->getText(); |
| 111 | + |
| 112 | + getExpressionsEditor($spelling, $this->viewInformation)->save( |
| 113 | + $this->getIdStack(), |
| 114 | + getExpressionsRecordSet($spelling, $this->viewInformation) |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + public function edit() { |
| 119 | + global |
| 120 | + $wgOut, $wgTitle, $wgUser; |
| 121 | + |
| 122 | + if(!parent::edit()) return false; |
| 123 | + $this->outputEditHeader(); |
| 124 | + |
| 125 | + $spelling = $wgTitle->getText(); |
| 126 | + |
| 127 | + $wgOut->addHTML( |
| 128 | + getExpressionsEditor($spelling, $this->viewInformation)->edit( |
| 129 | + $this->getIdStack(), |
| 130 | + getExpressionsRecordSet($spelling, $this->viewInformation) |
| 131 | + ) |
| 132 | + ); |
| 133 | + |
| 134 | + $this->outputEditFooter(); |
| 135 | + } |
| 136 | + |
| 137 | + public function getTitle() { |
| 138 | + global |
| 139 | + $wgTitle, $wgExpressionPageTitlePrefix; |
| 140 | + |
| 141 | + if ($wgExpressionPageTitlePrefix != "") |
| 142 | + $prefix = $wgExpressionPageTitlePrefix . ": "; |
| 143 | + else |
| 144 | + $prefix = ""; |
| 145 | + |
| 146 | + return $prefix . $wgTitle->getText(); |
| 147 | + } |
| 148 | + |
| 149 | + protected function getIdStack() { |
| 150 | + return new IdStack("expression"); |
| 151 | + } |
| 152 | +} |
Property changes on: trunk/extensions/Wikidata/OmegaWiki/ExpressionPage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 153 | + native |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -8,11 +8,18 @@ |
9 | 9 | public $spelling; |
10 | 10 | public $languageId; |
11 | 11 | public $pageId; |
12 | | - |
13 | | - function __construct($id, $spelling, $languageId) { |
| 12 | + public $meaningIds=array(); |
| 13 | + public $dataset; |
| 14 | + |
| 15 | + function __construct($id, $spelling, $languageId, $dc=null) { |
14 | 16 | $this->id = $id; |
15 | 17 | $this->spelling = $spelling; |
16 | 18 | $this->languageId = $languageId; |
| 19 | + if(is_null($dc)) { |
| 20 | + $this->dataset=wdGetDataSetContext(); |
| 21 | + } else { |
| 22 | + $this->dataset=$dc; |
| 23 | + } |
17 | 24 | } |
18 | 25 | |
19 | 26 | function createNewInDatabase() { |
— | — | @@ -38,8 +45,19 @@ |
39 | 46 | if (!$this->isBoundToDefinedMeaning($definedMeaningId)) |
40 | 47 | $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning); |
41 | 48 | } |
| 49 | + |
| 50 | + function fetchMeaningIds() { |
| 51 | + |
| 52 | + $dbr =& wfGetDB(DB_SLAVE); |
| 53 | + $dc=$this->dataset; |
| 54 | + $id=$this->id; |
| 55 | + $queryResult = $dbr->query("SELECT * FROM {$dc}_syntrans where expression_id=$id AND ".getLatestTransactionRestriction("{$dc}_syntrans")); |
| 56 | + while($syntransRecord=$dbr->fetchObject($queryResult)) { |
| 57 | + $this->meaningIds[]=$syntransRecord->defined_meaning_id; |
| 58 | + } |
| 59 | + } |
| 60 | + |
42 | 61 | } |
43 | | - |
44 | 62 | function getExpression($expressionId, $dc=null) { |
45 | 63 | if(is_null($dc)) { |
46 | 64 | $dc=wdGetDataSetContext(); |
— | — | @@ -902,8 +920,11 @@ |
903 | 921 | $dbr->query($sql); |
904 | 922 | } |
905 | 923 | |
906 | | -function getDefinedMeaningDefinitionForLanguage($definedMeaningId, $languageId) { |
907 | | - $dc=wdGetDataSetContext(); |
| 924 | +function getDefinedMeaningDefinitionForLanguage($definedMeaningId, $languageId, $dc=null) { |
| 925 | + if(is_null($dc)) { |
| 926 | + $dc=wdGetDataSetContext(); |
| 927 | + |
| 928 | + } |
908 | 929 | $dbr =& wfGetDB(DB_SLAVE); |
909 | 930 | $queryResult = $dbr->query("SELECT text_text FROM {$dc}_defined_meaning as dm, {$dc}_translated_content as tc, {$dc}_text as t ". |
910 | 931 | "WHERE dm.defined_meaning_id=$definedMeaningId " . |
— | — | @@ -1080,8 +1101,10 @@ |
1081 | 1102 | return 0; |
1082 | 1103 | } |
1083 | 1104 | |
1084 | | -function getExpressionMeaningIds($spelling) { |
1085 | | - $dc=wdGetDataSetContext(); |
| 1105 | +function getExpressionMeaningIds($spelling, $dc=null) { |
| 1106 | + if(is_null($dc)) { |
| 1107 | + $dc=wdGetDataSetContext(); |
| 1108 | + } |
1086 | 1109 | $dbr = & wfGetDB(DB_SLAVE); |
1087 | 1110 | $queryResult = $dbr->query( |
1088 | 1111 | "SELECT defined_meaning_id" . |
— | — | @@ -1285,8 +1308,10 @@ |
1286 | 1309 | return $meanings; |
1287 | 1310 | } |
1288 | 1311 | |
1289 | | -function definingExpressionRow($definedMeaningId) { |
1290 | | - $dc=wdGetDataSetContext(); |
| 1312 | +function definingExpressionRow($definedMeaningId, $dc=null) { |
| 1313 | + if(is_null($dc)) { |
| 1314 | + $dc=wdGetDataSetContext(); |
| 1315 | + } |
1291 | 1316 | $dbr =& wfGetDB(DB_SLAVE); |
1292 | 1317 | $queryResult = $dbr->query("SELECT {$dc}_expression_ns.expression_id, spelling, language_id " . |
1293 | 1318 | " FROM {$dc}_defined_meaning, {$dc}_expression_ns " . |
— | — | @@ -1396,6 +1421,23 @@ |
1397 | 1422 | return $dbr->fetchObject($queryResult)->text_text; |
1398 | 1423 | } |
1399 | 1424 | |
| 1425 | +function getExpressions($spelling, $dc=null) { |
| 1426 | + if(is_null($dc)) { |
| 1427 | + $dc=wdGetDataSetContext(); |
| 1428 | + } |
| 1429 | + $dbr =& wfGetDB(DB_SLAVE); |
| 1430 | + |
| 1431 | + $spelling=$dbr->addQuotes($spelling); |
| 1432 | + $queryResult = $dbr->query("SELECT * FROM {$dc}_expression_ns WHERE {$dc}_expression_ns.spelling=$spelling AND " . getLatestTransactionRestriction("{$dc}_expression_ns")); |
| 1433 | + |
| 1434 | + $rv=array(); |
| 1435 | + while($expressionRecord = $dbr->fetchObject($queryResult)) { |
| 1436 | + $rv[]=new Expression($expressionRecord->expression_id, $expressionRecord->spelling, $expressionRecord->language_id); |
| 1437 | + } |
| 1438 | + return $rv; |
| 1439 | + |
| 1440 | +} |
| 1441 | + |
1400 | 1442 | class ClassAttribute { |
1401 | 1443 | public $attributeId; |
1402 | 1444 | public $levelName; |
— | — | @@ -1468,4 +1510,6 @@ |
1469 | 1511 | |
1470 | 1512 | return $result; |
1471 | 1513 | } |
1472 | | -} |
| 1514 | + |
| 1515 | + |
| 1516 | +} |
\ No newline at end of file |