r22987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22986‎ | r22987 | r22988 >
Date:16:41, 14 June 2007
Author:kim
Status:old
Tags:
Comment:
Now actually really readable __tostring s with nifty indentation :-P
(kinda sucks that we only need it a couple of times)

(DefinedMeaning supports this with ?view_as=raw)
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/RecordSet.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/RecordSet.php
@@ -10,6 +10,7 @@
1111 public function getKey();
1212 public function getRecordCount();
1313 public function getRecord($index);
 14+ # public function save(); # <- we first need to implement, then uncomment
1415 }
1516
1617 class ArrayRecordSet implements RecordSet {
@@ -53,8 +54,30 @@
5455 * @return carriage return separated list of values
5556 */
5657 public function __tostring() {
57 - return implode("\n",$this->records);
 58+ return $this->tostring_indent();
5859 }
 60+
 61+ public function tostring_indent($depth=0,$key="") {
 62+ $rv="\n".str_pad("",$depth*8);
 63+ $rv.="$key:ArrayRecordSet {";
 64+ $rv2=$rv;
 65+ foreach ($this->records as $value) {
 66+ $rv=$rv2;
 67+ $methods=get_class_methods(get_class($value));
 68+ if (!is_null($methods)) {
 69+ if (in_array("tostring_indent",$methods)) {
 70+ $value=$value->tostring_indent($depth+1);
 71+ }
 72+ }
 73+ $rv.="$value";
 74+
 75+ $rv2=$rv;
 76+ $rv2.=", ";
 77+ }
 78+ $rv.="}";
 79+
 80+ return $rv;
 81+ }
5982 }
6083
6184 class ConvertingRecordSet implements RecordSet {
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -7,6 +7,7 @@
88 require_once('Transaction.php');
99 require_once('WikiDataTables.php');
1010 require_once('RecordSetQueries.php');
 11+require_once('DefinedMeaningModel.php');
1112
1213 function getSynonymSQLForLanguage($languageId, &$definedMeaningIds) {
1314
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -59,8 +59,33 @@
6060 * @return comma-separated values
6161 */
6262 public function __tostring() {
63 - return implode(",",$this->values);
 63+ return $this->tostring_indent();
6464 }
 65+
 66+ public function tostring_indent($depth=0,$key="") {
 67+ $rv="\n".str_pad("",$depth*8);
 68+ $rv.="$key:Record {";
 69+ $rv2=$rv;
 70+ foreach ($this->values as $key=>$value) {
 71+ $rv=$rv2;
 72+ $methods=get_class_methods(get_class($value));
 73+ $repr="$key:$value";
 74+ if (!is_null($methods)) {
 75+ if (in_array("tostring_indent",$methods)) {
 76+ $repr=$value->tostring_indent($depth+1,$key);
 77+
 78+
 79+ }
 80+ }
 81+ $rv.=$repr;
 82+
 83+ $rv2=$rv;
 84+ $rv2.=", ";
 85+ }
 86+ $rv.="}";
 87+ return $rv;
 88+ }
 89+
6590 }
6691
6792 function project($record, $structure) {

Status & tagging log