r22707 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22706‎ | r22707 | r22708 >
Date:16:05, 4 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for linking in result output.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinters.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -51,6 +51,7 @@
5252 $desc2->addPrintRequest($pr1);
5353 $pr2 = new SMWPrintrequest(SMW_PRINT_RELS, 'Borders', Title::newFromText('Relation:Borders'));
5454 $desc->addPrintRequest($pr2);
 55+ $desc2->addPrintRequest($pr2);
5556 $pr3 = new SMWPrintrequest(SMW_PRINT_ATTS, 'Population', Title::newFromText('Attribute:Population'));
5657 $desc->addPrintRequest($pr3);
5758 $desc2->addPrintRequest($pr3);
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php
@@ -150,19 +150,28 @@
151151
152152 /**
153153 * Return the main text representation of the next result object
154 - * (Title or SMWDataValue). Convenience method that would not be
155 - * required if Titles would be but special SMWDataValues.
 154+ * (Title or SMWDataValue) as HTML. Convenience method that would
 155+ * not be required if Titles would be but special SMWDataValues.
 156+ *
 157+ * The parameter $linker controls linking of title values and should
 158+ * be some Linker object (or NULL for no linking). At some stage its
 159+ * interpretation should be part of the generalised SMWDataValue.
156160 */
157 - public function getNextText() {
 161+ public function getNextHTMLText($linker = NULL) {
158162 $object = current($this->content);
159163 next($this->content);
160164 if ($object instanceof SMWDataValue) { //print data values
161 - return $object->getStringValue();
 165+ return htmlspecialchars($object->getStringValue()); ///TODO: escaping will be done in SMWDataValue
162166 } elseif ($object instanceof Title) { // print Title objects
163 - return $object->getPrefixedText(); ///TODO: support optional linking of titles
164 - /// As long as SMWDataValue is not re-implemented to support linking and optional HTML,
165 - /// all solutions here can only be hacks, returning complete HTML links based on some
166 - /// Boolean parameter.
 167+ if ($linker === NULL) {
 168+ return htmlspecialchars($object->getPrefixedText());
 169+ } else {
 170+ if ($this->printrequest->getMode() == SMW_PRINT_THIS) { // "this" results must exist
 171+ return $linker->makeKnownLinkObj($object);
 172+ } else {
 173+ return $linker->makeLinkObj($object);
 174+ }
 175+ }
167176 } else {
168177 return false;
169178 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinters.php
@@ -16,12 +16,13 @@
1717 protected $mFormat; // a string identifier describing a valid format
1818 protected $mIntro = ''; // text to print before the output in case it is *not* empty
1919 protected $mSearchlabel = NULL; // text to use for link to further results, or empty if link should not be shown
20 - protected $mLinkSubj; // should article names of the (unique) subjects be linked?
21 - protected $mLinkObj; // should article names of the objects be linked?
 20+ protected $mLinkFirst; // should article names of the first column be linked?
 21+ protected $mLinkOthers; // should article names of other columns (besides the first) be linked?
2222 protected $mDefault = ''; // default return value for empty queries
2323 protected $mShowHeaders = true; // should the headers (property names) be printed?
2424 protected $mMainLabel = NULL; // label used for displaying the subject, or NULL if none was given
2525 protected $mInline; // is this query result "inline" in some page (only then a link to unshown results is created, error handling may also be affected)
 26+ protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time.
2627
2728 /**
2829 * Constructor. The parameter $format is a format string
@@ -31,8 +32,9 @@
3233 global $smwgIQDefaultLinking;
3334 $this->mFormat = $format;
3435 $this->mInline = $inline;
35 - $this->mLinkSubj = ($smwgIQDefaultLinking != 'none');
36 - $this->mLinkObj = ($smwgIQDefaultLinking == 'all');
 36+ $this->mLinkFirst = ($smwgIQDefaultLinking != 'none');
 37+ $this->mLinkOthers = ($smwgIQDefaultLinking == 'all');
 38+ $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)?
3739 }
3840
3941 /**
@@ -62,16 +64,16 @@
6365 if (array_key_exists('link', $params)) {
6466 switch (strtolower($params['link'])) {
6567 case 'head': case 'subject':
66 - $this->mLinkSubj = true;
67 - $this->mLinkObj = false;
 68+ $this->mLinkFirst = true;
 69+ $this->mLinkOthers = false;
6870 break;
6971 case 'all':
70 - $this->mLinkSubj = true;
71 - $this->mLinkObj = true;
 72+ $this->mLinkFirst = true;
 73+ $this->mLinkOthers = true;
7274 break;
7375 case 'none':
74 - $this->mLinkSubj = false;
75 - $this->mLinkObj = false;
 76+ $this->mLinkFirst = false;
 77+ $this->mLinkOthers = false;
7678 break;
7779 }
7880 }
@@ -96,6 +98,20 @@
9799 */
98100 abstract protected function getHTML($res);
99101
 102+ /**
 103+ * Depending on current linking settings, returns a linker object
 104+ * for making hyperlinks or NULL if no links should be created.
 105+ *
 106+ * @param $firstrow True of this is the first result row (having special linkage settings).
 107+ */
 108+ protected function getLinker($firstcol = false) {
 109+ if ( ($firstcol && $this->mLinkFirst) || (!$firstcol && $this->mLinkOthers) ) {
 110+ return $this->mLinker;
 111+ } else {
 112+ return NULL;
 113+ }
 114+ }
 115+
100116 }
101117
102118 /**
@@ -127,7 +143,7 @@
128144 foreach ($row as $field) {
129145 $result .= "<td>";
130146 $first = true;
131 - while ( ($text = $field->getNextText()) !== false) {
 147+ while ( ($text = $field->getNextHTMLText($this->getLinker($firstcol))) !== false) {
132148 if ($first) $first = false; else $result .= '<br />';
133149 $result .= $text;
134150 }

Status & tagging log