r25852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25851‎ | r25852 | r25853 >
Date:12:53, 14 September 2007
Author:erik
Status:old
Tags:
Comment:
first (still incomplete and hackish) stab at new expression UI
to activate, change namespace handler for Expression namespace from
'OmegaWiki' to 'ExpressionPage'.
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/ExpressionPage.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -82,8 +82,7 @@
8383
8484 function initializeWikidata() {
8585 global
86 - $wgMessageCache, $wgExtensionPreferences, $wdSiteContext;
87 -;
 86+ $wgMessageCache, $wgExtensionPreferences, $wdSiteContext, $wgPropertyToColumnFilters;
8887
8988 $dbr =& wfGetDB(DB_MASTER);
9089 $dbr->query("SET NAMES utf8");
@@ -168,7 +167,9 @@
169168 "LinkAttribute" => "Property",
170169 "LinkAttributeValues" => "Links",
171170 "Property" => "Property",
172 - "Value" => "Value"
 171+ "Value" => "Value",
 172+ "meaningsoftitle"=>"Meanings of \"$1\"",
 173+ "meaningsofsubtitle"=>"<em>Wiki link:</em> [[$1]]",
173174 );
174175
175176 $prefixedmsgarray=array();
@@ -190,7 +191,10 @@
191192 'size' => 10,
192193 'options' => $datasetarray
193194 );
194 -
 195+ $wgPropertyToColumnFilters = array(
 196+ new PropertyToColumnFilter("partOfSpeech", "Part of speech", array(358760))
 197+ );
 198+
195199 global
196200 $messageCacheOK;
197201
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
1153 + native
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -8,11 +8,18 @@
99 public $spelling;
1010 public $languageId;
1111 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) {
1416 $this->id = $id;
1517 $this->spelling = $spelling;
1618 $this->languageId = $languageId;
 19+ if(is_null($dc)) {
 20+ $this->dataset=wdGetDataSetContext();
 21+ } else {
 22+ $this->dataset=$dc;
 23+ }
1724 }
1825
1926 function createNewInDatabase() {
@@ -38,8 +45,19 @@
3946 if (!$this->isBoundToDefinedMeaning($definedMeaningId))
4047 $this->bindToDefinedMeaning($definedMeaningId, $identicalMeaning);
4148 }
 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+
4261 }
43 -
4462 function getExpression($expressionId, $dc=null) {
4563 if(is_null($dc)) {
4664 $dc=wdGetDataSetContext();
@@ -902,8 +920,11 @@
903921 $dbr->query($sql);
904922 }
905923
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+ }
908929 $dbr =& wfGetDB(DB_SLAVE);
909930 $queryResult = $dbr->query("SELECT text_text FROM {$dc}_defined_meaning as dm, {$dc}_translated_content as tc, {$dc}_text as t ".
910931 "WHERE dm.defined_meaning_id=$definedMeaningId " .
@@ -1080,8 +1101,10 @@
10811102 return 0;
10821103 }
10831104
1084 -function getExpressionMeaningIds($spelling) {
1085 - $dc=wdGetDataSetContext();
 1105+function getExpressionMeaningIds($spelling, $dc=null) {
 1106+ if(is_null($dc)) {
 1107+ $dc=wdGetDataSetContext();
 1108+ }
10861109 $dbr = & wfGetDB(DB_SLAVE);
10871110 $queryResult = $dbr->query(
10881111 "SELECT defined_meaning_id" .
@@ -1285,8 +1308,10 @@
12861309 return $meanings;
12871310 }
12881311
1289 -function definingExpressionRow($definedMeaningId) {
1290 - $dc=wdGetDataSetContext();
 1312+function definingExpressionRow($definedMeaningId, $dc=null) {
 1313+ if(is_null($dc)) {
 1314+ $dc=wdGetDataSetContext();
 1315+ }
12911316 $dbr =& wfGetDB(DB_SLAVE);
12921317 $queryResult = $dbr->query("SELECT {$dc}_expression_ns.expression_id, spelling, language_id " .
12931318 " FROM {$dc}_defined_meaning, {$dc}_expression_ns " .
@@ -1396,6 +1421,23 @@
13971422 return $dbr->fetchObject($queryResult)->text_text;
13981423 }
13991424
 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+
14001442 class ClassAttribute {
14011443 public $attributeId;
14021444 public $levelName;
@@ -1468,4 +1510,6 @@
14691511
14701512 return $result;
14711513 }
1472 -}
 1514+
 1515+
 1516+}
\ No newline at end of file

Status & tagging log