Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
— | — | @@ -0,0 +1,134 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Abstract base class for printing qurey results. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Abstract base class for SMW's novel query printing mechanism. It implements |
| 10 | + * part of the former functionality of SMWInlineQuery (everything related to |
| 11 | + * output formatting and the correspoding parameters) and is subclassed by concrete |
| 12 | + * printers that provide the main formatting functionality. |
| 13 | + */ |
| 14 | +abstract class SMWResultPrinter { |
| 15 | + |
| 16 | + // parameters: |
| 17 | + protected $mFormat; // a string identifier describing a valid format |
| 18 | + protected $mIntro = ''; // text to print before the output in case it is *not* empty |
| 19 | + protected $mSearchlabel = NULL; // text to use for link to further results, or empty if link should not be shown |
| 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? |
| 22 | + protected $mDefault = ''; // default return value for empty queries |
| 23 | + protected $mShowHeaders = true; // should the headers (property names) be printed? |
| 24 | + 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) |
| 25 | + protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time. |
| 26 | + |
| 27 | + /** |
| 28 | + * Constructor. The parameter $format is a format string |
| 29 | + * that may influence the processing details. |
| 30 | + */ |
| 31 | + public function SMWResultPrinter($format, $inline) { |
| 32 | + global $smwgQDefaultLinking; |
| 33 | + $this->mFormat = $format; |
| 34 | + $this->mInline = $inline; |
| 35 | + $this->mLinkFirst = ($smwgQDefaultLinking != 'none'); |
| 36 | + $this->mLinkOthers = ($smwgQDefaultLinking == 'all'); |
| 37 | + $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)? |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Main entry point: takes an SMWQueryResult and parameters |
| 42 | + * given as key-value-pairs in an array and returns the |
| 43 | + * serialised version of the results, formatted as inline HTML |
| 44 | + * or (for special printers) as RDF or XML or whatever. Normally |
| 45 | + * not overwritten by subclasses. |
| 46 | + */ |
| 47 | + public function getResultHTML($results, $params) { |
| 48 | + $this->readParameters($params); |
| 49 | + if ($results->getCount() == 0) { |
| 50 | + if (!$results->hasFurtherResults()) { |
| 51 | + return htmlspecialchars($this->mDefault); |
| 52 | + } elseif ($this->mInline) { |
| 53 | + $label = $this->mSearchlabel; |
| 54 | + if ($label === NULL) { //apply defaults |
| 55 | + $result = '<a href="' . $results->getQueryURL() . '">' . wfMsgForContent('smw_iq_moreresults') . '</a>'; |
| 56 | + } else { |
| 57 | + $result = '<a href="' . $results->getQueryURL() . '">' . $label . '</a>'; |
| 58 | + } |
| 59 | + $result .= $this->getErrorString($results); // just append error messages |
| 60 | + return $result; |
| 61 | + } |
| 62 | + } |
| 63 | + return $this->getHTML($results); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Read an array of parameter values given as key-value-pairs and |
| 68 | + * initialise internal member fields accordingly. Possibly overwritten |
| 69 | + * (extended) by subclasses. |
| 70 | + */ |
| 71 | + protected function readParameters($params) { |
| 72 | + if (array_key_exists('intro', $params)) { |
| 73 | + $this->mIntro = htmlspecialchars(str_replace('_', ' ', $params['intro'])); |
| 74 | + } |
| 75 | + if (array_key_exists('searchlabel', $params)) { |
| 76 | + $this->mSearchlabel = htmlspecialchars($params['searchlabel']); |
| 77 | + } |
| 78 | + if (array_key_exists('link', $params)) { |
| 79 | + switch (strtolower($params['link'])) { |
| 80 | + case 'head': case 'subject': |
| 81 | + $this->mLinkFirst = true; |
| 82 | + $this->mLinkOthers = false; |
| 83 | + break; |
| 84 | + case 'all': |
| 85 | + $this->mLinkFirst = true; |
| 86 | + $this->mLinkOthers = true; |
| 87 | + break; |
| 88 | + case 'none': |
| 89 | + $this->mLinkFirst = false; |
| 90 | + $this->mLinkOthers = false; |
| 91 | + break; |
| 92 | + } |
| 93 | + } |
| 94 | + if (array_key_exists('default', $params)) { |
| 95 | + $this->mDefault = htmlspecialchars(str_replace('_', ' ', $params['default'])); |
| 96 | + } |
| 97 | + if (array_key_exists('headers', $params)) { |
| 98 | + if ( 'hide' == strtolower($params['headers'])) { |
| 99 | + $this->mShowHeaders = false; |
| 100 | + } else { |
| 101 | + $this->mShowHeaders = true; |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Return HTML version of serialised results. |
| 108 | + * Implemented by subclasses. |
| 109 | + */ |
| 110 | + abstract protected function getHTML($res); |
| 111 | + |
| 112 | + /** |
| 113 | + * Depending on current linking settings, returns a linker object |
| 114 | + * for making hyperlinks or NULL if no links should be created. |
| 115 | + * |
| 116 | + * @param $firstrow True of this is the first result row (having special linkage settings). |
| 117 | + */ |
| 118 | + protected function getLinker($firstcol = false) { |
| 119 | + if ( ($firstcol && $this->mLinkFirst) || (!$firstcol && $this->mLinkOthers) ) { |
| 120 | + return $this->mLinker; |
| 121 | + } else { |
| 122 | + return NULL; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Provides a simple formatted string of all the error messages that occurred. |
| 128 | + * Can be used if not specific error formatting is desired. Compatible with HTML |
| 129 | + * and Wiki. |
| 130 | + */ |
| 131 | + protected function getErrorString($res) { |
| 132 | + return smwfEncodeMessages($res->getErrors()); |
| 133 | + } |
| 134 | + |
| 135 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 136 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php |
— | — | @@ -0,0 +1,143 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results in lists. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * New implementation of SMW's printer for results in lists. |
| 10 | + * |
| 11 | + * Somewhat confusing code, since one has to iterate through lists, inserting texts |
| 12 | + * in between their elements depending on whether the element is the first that is |
| 13 | + * printed, the first that is printed in parentheses, or the last that will be printed. |
| 14 | + * Maybe one could further simplify this. |
| 15 | + */ |
| 16 | +class SMWListResultPrinter extends SMWResultPrinter { |
| 17 | + |
| 18 | + protected $mSep = ''; |
| 19 | + protected $mTemplate = ''; |
| 20 | + |
| 21 | + protected function readParameters($params) { |
| 22 | + SMWResultPrinter::readParameters($params); |
| 23 | + |
| 24 | + if (array_key_exists('sep', $params)) { |
| 25 | + $this->mSep = htmlspecialchars(str_replace('_',' ',$params['sep'])); |
| 26 | + } |
| 27 | + if (array_key_exists('template', $params)) { |
| 28 | + $this->mTemplate = $params['template']; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + protected function getHTML($res) { |
| 33 | + global $wgTitle,$smwgStoreActive; |
| 34 | + // print header |
| 35 | + $result = $this->mIntro; |
| 36 | + if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) { |
| 37 | + $result .= '<' . $this->mFormat . '>'; |
| 38 | + $footer = '</' . $this->mFormat . '>'; |
| 39 | + $rowstart = "\n\t<li>"; |
| 40 | + $rowend = '</li>'; |
| 41 | + $plainlist = false; |
| 42 | + } else { |
| 43 | + if ($this->mSep != '') { |
| 44 | + $listsep = $this->mSep; |
| 45 | + $finallistsep = $listsep; |
| 46 | + } else { // default list ", , , and, " |
| 47 | + $listsep = ', '; |
| 48 | + $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' '; |
| 49 | + } |
| 50 | + $footer = ''; |
| 51 | + $rowstart = ''; |
| 52 | + $rowend = ''; |
| 53 | + $plainlist = true; |
| 54 | + } |
| 55 | + |
| 56 | + if ($this->mTemplate != '') { |
| 57 | + $parser_options = new ParserOptions(); |
| 58 | + $parser_options->setEditSection(false); // embedded sections should not have edit links |
| 59 | + $parser = new Parser(); |
| 60 | + $usetemplate = true; |
| 61 | + } else { |
| 62 | + $usetemplate = false; |
| 63 | + } |
| 64 | + |
| 65 | + // print all result rows |
| 66 | + $first_row = true; |
| 67 | + $row = $res->getNext(); |
| 68 | + while ( $row !== false ) { |
| 69 | + $nextrow = $res->getNext(); // look ahead |
| 70 | + if ( !$first_row && $plainlist ) { |
| 71 | + if ($nextrow !== false) $result .= $listsep; // the comma between "rows" other than the last one |
| 72 | + else $result .= $finallistsep; |
| 73 | + } else $result .= $rowstart; |
| 74 | + |
| 75 | + $first_col = true; |
| 76 | + if ($usetemplate) { // build template code |
| 77 | + $wikitext = ''; |
| 78 | + foreach ($row as $field) { |
| 79 | + $wikitext .= "|"; |
| 80 | + $first_value = true; |
| 81 | + while ( ($text = $field->getNextWikiText($this->getLinker($first_col))) !== false ) { |
| 82 | + if ($first_value) $first_value = false; else $wikitext .= ', '; |
| 83 | + $wikitext .= $text; |
| 84 | + } |
| 85 | + $first_col = false; |
| 86 | + } |
| 87 | + $result .= '{{' . $this->mTemplate . str_replace(array('=','|'), array('=', '|'), $wikitext) . '}}'; // encode '=' and '|' for use in templates (templates fail otherwise) |
| 88 | + } else { // build simple list |
| 89 | + $first_col = true; |
| 90 | + $found_values = false; // has anything but the first column been printed? |
| 91 | + foreach ($row as $field) { |
| 92 | + $first_value = true; |
| 93 | + while ( ($text = $field->getNextHTMLText($this->getLinker($first_col))) !== false ) { |
| 94 | + if (!$first_col && !$found_values) { // first values after first column |
| 95 | + $result .= ' ('; |
| 96 | + $found_values = true; |
| 97 | + } elseif ($found_values || !$first_value) { |
| 98 | + // any value after '(' or non-first values on first column |
| 99 | + $result .= ', '; |
| 100 | + } |
| 101 | + if ($first_value) { // first value in any column, print header |
| 102 | + $first_value = false; |
| 103 | + if ( $this->mShowHeaders && ('' != $field->getPrintRequest()->getLabel()) ) { |
| 104 | + $result .= $field->getPrintRequest()->getHTMLText($this->mLinker) . ' '; |
| 105 | + } |
| 106 | + } |
| 107 | + $result .= $text; // actual output value |
| 108 | + } |
| 109 | + $first_col = false; |
| 110 | + } |
| 111 | + if ($found_values) $result .= ')'; |
| 112 | + } |
| 113 | + $result .= $rowend; |
| 114 | + $first_row = false; |
| 115 | + $row = $nextrow; |
| 116 | + } |
| 117 | + |
| 118 | + if ($usetemplate) { |
| 119 | + $old_smwgStoreActive = $smwgStoreActive; |
| 120 | + $smwgStoreActive = false; // no annotations stored, no factbox printed |
| 121 | + $parserOutput = $parser->parse($result, $wgTitle, $parser_options); |
| 122 | + $result = $parserOutput->getText(); |
| 123 | + $smwgStoreActive = $old_smwgStoreActive; |
| 124 | + } |
| 125 | + |
| 126 | + if ($this->mInline && $res->hasFurtherResults()) { |
| 127 | + $label = $this->mSearchlabel; |
| 128 | + if ($label === NULL) { //apply defaults |
| 129 | + if ('ol' == $this->mFormat) $label = ''; |
| 130 | + else $label = wfMsgForContent('smw_iq_moreresults'); |
| 131 | + } |
| 132 | + if (!$first_row) $result .= ' '; // relevant for list, unproblematic for ul/ol |
| 133 | + if ($label != '') { |
| 134 | + $result .= $rowstart . '<a href="' . $res->getQueryURL() . '">' . $label . '</a>' . $rowend; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + // print footer |
| 139 | + $result .= $footer; |
| 140 | + $result .= $this->getErrorString($res); // just append error messages |
| 141 | + |
| 142 | + return $result; |
| 143 | + } |
| 144 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_List.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 145 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results in tables. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * New implementation of SMW's printer for result tables. |
| 10 | + */ |
| 11 | +class SMWTableResultPrinter extends SMWResultPrinter { |
| 12 | + |
| 13 | + protected function getHTML($res) { |
| 14 | + global $smwgIQRunningNumber; |
| 15 | + |
| 16 | + // print header |
| 17 | + if ('broadtable' == $this->mFormat) |
| 18 | + $widthpara = ' width="100%"'; |
| 19 | + else $widthpara = ''; |
| 20 | + $result = $this->mIntro . |
| 21 | + "<table class=\"smwtable\"$widthpara id=\"querytable" . $smwgIQRunningNumber . "\">\n"; |
| 22 | + if ($this->mShowHeaders) { // building headers |
| 23 | + $result .= "\n\t\t<tr>"; |
| 24 | + foreach ($res->getPrintRequests() as $pr) { |
| 25 | + $result .= "\t\t\t<th>" . $pr->getHTMLText($this->mLinker) . "</th>\n"; |
| 26 | + } |
| 27 | + $result .= "\n\t\t</tr>"; |
| 28 | + } |
| 29 | + |
| 30 | + // print all result rows |
| 31 | + while ( $row = $res->getNext() ) { |
| 32 | + $result .= "\t\t<tr>\n"; |
| 33 | + $firstcol = true; |
| 34 | + foreach ($row as $field) { |
| 35 | + $result .= "<td>"; |
| 36 | + $first = true; |
| 37 | + while ( ($text = $field->getNextHTMLText($this->getLinker($firstcol))) !== false ) { |
| 38 | + if ($first) $first = false; else $result .= '<br />'; |
| 39 | + $result .= $text; |
| 40 | + } |
| 41 | + $result .= "</td>"; |
| 42 | + $firstcol = false; |
| 43 | + } |
| 44 | + $result .= "\n\t\t</tr>\n"; |
| 45 | + } |
| 46 | + |
| 47 | + // print further results footer |
| 48 | + if ($this->mInline && $res->hasFurtherResults()) { |
| 49 | + $label = $this->mSearchlabel; |
| 50 | + if ($label === NULL) { //apply default |
| 51 | + $label = wfMsgForContent('smw_iq_moreresults'); |
| 52 | + } |
| 53 | + if ($label != '') { |
| 54 | + $result .= "\n\t\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> <a href="' . $res->getQueryURL() . '">' . $label . '</a></td></tr>'; |
| 55 | + } |
| 56 | + } |
| 57 | + $result .= "\t</table>"; // print footer |
| 58 | + $result .= $this->getErrorString($res); // just append error messages |
| 59 | + return $result; |
| 60 | + } |
| 61 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Embedded.php |
— | — | @@ -0,0 +1,108 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results in tables. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Printer for embedded data. |
| 10 | + * Embeds in the page output the contents of the pages in the query result set. |
| 11 | + * Only the first column of the query is considered. If it is a page reference then that page's contents is embedded. |
| 12 | + * The optional "titlestyle" formatting parameter can be used to apply a format to the headings for the page titles. |
| 13 | + * If "titlestyle" is not specified, a <h1> tag is used. |
| 14 | + * @author Fernando Correia |
| 15 | + * @author Markus Krötzsch |
| 16 | + */ |
| 17 | +class SMWEmbeddedResultPrinter extends SMWResultPrinter { |
| 18 | + |
| 19 | + protected $m_showhead; |
| 20 | + protected $m_embedformat; |
| 21 | + |
| 22 | + protected function readParameters($params) { |
| 23 | + SMWResultPrinter::readParameters($params); |
| 24 | + |
| 25 | + if (array_key_exists('embedonly', $params)) { |
| 26 | + $this->m_showhead = false; |
| 27 | + } else { |
| 28 | + $this->m_showhead = true; |
| 29 | + } |
| 30 | + if (array_key_exists('embedformat', $params)) { |
| 31 | + $this->m_embedformat = $params['embedformat']; |
| 32 | + } else { |
| 33 | + $this->m_embedformat = 'h1'; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public function getHTML($res) { |
| 38 | + // handle factbox |
| 39 | + global $smwgStoreActive, $wgTitle; |
| 40 | + $old_smwgStoreActive = $smwgStoreActive; |
| 41 | + $smwgStoreActive = false; // no annotations stored, no factbox printed |
| 42 | + |
| 43 | + // print header |
| 44 | + $result = $this->mIntro; |
| 45 | + |
| 46 | + switch ($this->m_embedformat) { |
| 47 | + case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6': |
| 48 | + $footer = ''; |
| 49 | + $embstart = ''; |
| 50 | + $headstart = '<' . $this->m_embedformat . '>'; |
| 51 | + $headend = '</' . $this->m_embedformat . ">\n"; |
| 52 | + $embend = ''; |
| 53 | + break; |
| 54 | + case 'ul': case 'ol': |
| 55 | + $result .= '<' . $this->m_embedformat . '>'; |
| 56 | + $footer = '</' . $this->m_embedformat . '>'; |
| 57 | + $embstart = '<li>'; |
| 58 | + $headstart = ''; |
| 59 | + $headend = "<br />\n"; |
| 60 | + $embend = "</li>\n"; |
| 61 | + break; |
| 62 | + } |
| 63 | + |
| 64 | + // print all result rows |
| 65 | + $parser_options = new ParserOptions(); |
| 66 | + $parser_options->setEditSection(false); // embedded sections should not have edit links |
| 67 | + $parser = new Parser(); |
| 68 | + |
| 69 | + while ( $row = $res->getNext() ) { |
| 70 | + $first_col = true; |
| 71 | + foreach ($row as $field) { |
| 72 | + if ( $field->getPrintRequest()->getTypeID() == '_wpg' ) { // ensure that we deal with title-likes |
| 73 | + while ( ($object = $field->getNextObject()) !== false ) { |
| 74 | + $result .= $embstart; |
| 75 | + $text= $object->getLongHTMLText($this->getLinker(true)); |
| 76 | + if ($this->m_showhead) { |
| 77 | + $result .= $headstart . $text . $headend; |
| 78 | + } |
| 79 | + if ($object->getNamespace() == NS_MAIN) { |
| 80 | + $articlename = ':' . $object->getText(); |
| 81 | + } else { |
| 82 | + $articlename = $object->getPrefixedText(); |
| 83 | + } |
| 84 | + $parserOutput = $parser->parse('{{' . $articlename . '}}', $wgTitle, $parser_options); |
| 85 | + $result .= $parserOutput->getText(); |
| 86 | + $result .= $embend; |
| 87 | + } |
| 88 | + } |
| 89 | + break; // only use first column for now |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + // show link to more results |
| 94 | + if ($this->mInline && $res->hasFurtherResults()) { |
| 95 | + $label = $this->mSearchlabel; |
| 96 | + if ($label === NULL) { //apply defaults |
| 97 | + $label = wfMsgForContent('smw_iq_moreresults'); |
| 98 | + } |
| 99 | + if ($label != '') { |
| 100 | + $result .= $embstart . '<a href="' . $res->getQueryURL() . '">' . $label . '</a>' . $embend ; |
| 101 | + } |
| 102 | + } |
| 103 | + $result .= $footer; |
| 104 | + $result .= $this->getErrorString($res); // just append error messages |
| 105 | + |
| 106 | + $smwgStoreActive = $old_smwgStoreActive; |
| 107 | + return $result; |
| 108 | + } |
| 109 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Embedded.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 110 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -8,9 +8,7 @@ |
9 | 9 | |
10 | 10 | global $smwgIP; |
11 | 11 | require_once($smwgIP . '/includes/storage/SMW_Store.php'); |
12 | | -require_once($smwgIP . '/includes/SMW_QueryPrinters.php'); |
13 | 12 | |
14 | | - |
15 | 13 | /** |
16 | 14 | * Static class for accessing functions to generate and execute semantic queries |
17 | 15 | * and to serialise their results. |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php |
— | — | @@ -0,0 +1,182 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results in interactive timelines. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * New implementation of SMW's printer for timeline data. |
| 11 | + */ |
| 12 | +class SMWTimelineResultPrinter extends SMWResultPrinter { |
| 13 | + |
| 14 | + protected $m_tlstart = ''; // name of the start-date property if any |
| 15 | + protected $m_tlend = ''; // name of the end-date property if any |
| 16 | + protected $m_tlsize = ''; // CSS-compatible size (such as 400px) |
| 17 | + protected $m_tlbands = ''; // array of band IDs (MONTH, YEAR, ...) |
| 18 | + protected $m_tlpos = ''; // position identifier (start, end, today, middle) |
| 19 | + |
| 20 | + protected function readParameters($params) { |
| 21 | + SMWResultPrinter::readParameters($params); |
| 22 | + |
| 23 | + if (array_key_exists('timelinestart', $params)) { |
| 24 | + $this->m_tlstart = smwfNormalTitleDBKey($params['timelinestart']); |
| 25 | + } |
| 26 | + if (array_key_exists('timelineend', $params)) { |
| 27 | + $this->m_tlend = smwfNormalTitleDBKey($params['timelineend']); |
| 28 | + } |
| 29 | + if (array_key_exists('timelinesize', $params)) { |
| 30 | + $this->m_tlsize = htmlspecialchars(str_replace(';', ' ', strtolower($params['timelinesize']))); |
| 31 | + // str_replace makes sure this is only one value, not mutliple CSS fields (prevent CSS attacks) |
| 32 | + } else { |
| 33 | + $this->m_tlsize = '300px'; |
| 34 | + } |
| 35 | + if (array_key_exists('timelinebands', $params)) { |
| 36 | + //check for band parameter, should look like "DAY,MONTH,YEAR" |
| 37 | + $this->m_tlbands = preg_split('/[,][\s]*/',$params['timelinebands']); |
| 38 | + } else { |
| 39 | + $this->m_tlbands = array('MONTH','YEAR'); // TODO: check what default the JavaScript uses |
| 40 | + } |
| 41 | + if (array_key_exists('timelineposition', $params)) { |
| 42 | + $this->m_tlpos = strtolower($params['timelineposition']); |
| 43 | + } else { |
| 44 | + $this->m_tlpos = 'middle'; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + public function getHTML($res) { |
| 49 | + global $smwgIQRunningNumber; |
| 50 | + |
| 51 | + $eventline = ('eventline' == $this->mFormat); |
| 52 | + |
| 53 | + if ( !$eventline && ($this->m_tlstart == '') ) { // seek defaults |
| 54 | + foreach ($res->getPrintRequests() as $pr) { |
| 55 | + if ( ($pr->getMode() == SMW_PRINT_PROP) && ($pr->getTypeID() == '_dat') ) { |
| 56 | + if ( ($this->m_tlend == '') && ($this->m_tlstart != '') && |
| 57 | + ($this->m_tlstart != $pr->getTitle()->getDBKey()) ) { |
| 58 | + $this->m_tlend = $pr->getTitle()->getDBKey(); |
| 59 | + } elseif ( ($this->m_tlstart == '') && ($this->m_tlend != $pr->getTitle()->getDBKey()) ) { |
| 60 | + $this->m_tlstart = $pr->getTitle()->getDBKey(); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + // print header |
| 67 | + $result = "<div class=\"smwtimeline\" id=\"smwtimeline$smwgIQRunningNumber\" style=\"height: $this->m_tlsize\">"; |
| 68 | + $result .= '<span class="smwtlcomment">' . wfMsgForContent('smw_iq_nojs',$res->getQueryURL()) . '</span>'; // note for people without JavaScript |
| 69 | + |
| 70 | + foreach ($this->m_tlbands as $band) { |
| 71 | + $result .= '<span class="smwtlband">' . htmlspecialchars($band) . '</span>'; |
| 72 | + //just print any "band" given, the JavaScript will figure out what to make of it |
| 73 | + } |
| 74 | + |
| 75 | + // print all result rows |
| 76 | + $positions = array(); // possible positions, collected to select one for centering |
| 77 | + $curcolor = 0; // color cycling is used for eventline |
| 78 | + if ( ($this->m_tlstart != '') || $eventline ) { |
| 79 | + $output = false; // true if output for the popup was given on current line |
| 80 | + if ($eventline) $events = array(); // array of events that are to be printed |
| 81 | + while ( $row = $res->getNext() ) { |
| 82 | + $hastime = false; // true as soon as some startdate value was found |
| 83 | + $hastitle = false; // true as soon as some label for the event was found |
| 84 | + $curdata = ''; // current *inner* print data (within some event span) |
| 85 | + $curmeta = ''; // current event meta data |
| 86 | + $curarticle = ''; // label of current article, if it was found; needed only for eventline labeling |
| 87 | + $first_col = true; |
| 88 | + foreach ($row as $field) { |
| 89 | + $first_value = true; |
| 90 | + $pr = $field->getPrintRequest(); |
| 91 | + while ( ($object = $field->getNextObject()) !== false ) { |
| 92 | + $l = $this->getLinker($first_col); |
| 93 | + $objectlabel = $object->getShortHTMLText($l); |
| 94 | + $urlobject = ($l !== NULL); |
| 95 | + $header = ''; |
| 96 | + if ($first_value) { |
| 97 | + // find header for current value: |
| 98 | + if ( $this->mShowHeaders && ('' != $pr->getLabel()) ) { |
| 99 | + $header = $pr->getHTMLText($this->mLinker) . ' '; |
| 100 | + } |
| 101 | + // is this a start date? |
| 102 | + if ( ($pr->getMode() == SMW_PRINT_PROP) && |
| 103 | + ($pr->getTitle()->getDBKey() == $this->m_tlstart) ) { |
| 104 | + //FIXME: Timeline scripts should support XSD format explicitly. They |
| 105 | + //currently seem to implement iso8601 which deviates from XSD in cases. |
| 106 | + //NOTE: We can assume $object to be an SMWDataValue in this case. |
| 107 | + $curmeta .= '<span class="smwtlstart">' . $object->getXSDValue() . '</span>'; |
| 108 | + $positions[$object->getNumericValue()] = $object->getXSDValue(); |
| 109 | + $hastime = true; |
| 110 | + } |
| 111 | + // is this the end date? |
| 112 | + if ( ($pr->getMode() == SMW_PRINT_PROP) && |
| 113 | + ($pr->getTitle()->getDBKey() == $this->m_tlend) ) { |
| 114 | + //NOTE: We can assume $object to be an SMWDataValue in this case. |
| 115 | + $curmeta .= '<span class="smwtlend">' . $object->getXSDValue() . '</span>'; |
| 116 | + } |
| 117 | + // find title for displaying event |
| 118 | + if ( !$hastitle ) { |
| 119 | + if ($urlobject) { |
| 120 | + $curmeta .= '<span class="smwtlurl">' . $objectlabel . '</span>'; |
| 121 | + } else { |
| 122 | + $curmeta .= '<span class="smwtltitle">' . $objectlabel . '</span>'; |
| 123 | + } |
| 124 | + if ( ($pr->getMode() == SMW_PRINT_THIS) ) { |
| 125 | + // NOTE: type Title of $object implied |
| 126 | + $curarticle = $object->getText(); |
| 127 | + } |
| 128 | + $hastitle = true; |
| 129 | + } |
| 130 | + } elseif ($output) $curdata .= ', '; //it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row |
| 131 | + if (!$first_col || !$first_value || $eventline) { |
| 132 | + $curdata .= $header . $objectlabel; |
| 133 | + $output = true; |
| 134 | + } |
| 135 | + if ($eventline && ($pr->getMode() == SMW_PRINT_PROP) && ($pr->getTypeID() == '_dat') && ('' != $pr->getLabel()) && ($pr->getTitle()->getText() != $this->m_tlstart) && ($pr->getTitle()->getText() != $this->m_tlend) ) { |
| 136 | + $events[] = array($object->getXSDValue(), $pr->getLabel(), $object->getNumericValue()); |
| 137 | + } |
| 138 | + $first_value = false; |
| 139 | + } |
| 140 | + if ($output) $curdata .= "<br />"; |
| 141 | + $output = false; |
| 142 | + $first_col = false; |
| 143 | + } |
| 144 | + |
| 145 | + if ( $hastime ) { |
| 146 | + $result .= '<span class="smwtlevent">' . $curmeta . '<span class="smwtlcoloricon">' . $curcolor . '</span>' . $curdata . '</span>'; |
| 147 | + } |
| 148 | + if ( $eventline ) { |
| 149 | + foreach ($events as $event) { |
| 150 | + $result .= '<span class="smwtlevent"><span class="smwtlstart">' . $event[0] . '</span><span class="smwtlurl">' . $event[1] . '</span><span class="smwtlcoloricon">' . $curcolor . '</span>'; |
| 151 | + if ( $curarticle != '' ) $result .= '<span class="smwtlprefix">' . $curarticle . ' </span>'; |
| 152 | + $result .= $curdata . '</span>'; |
| 153 | + $positions[$event[2]] = $event[0]; |
| 154 | + } |
| 155 | + $events = array(); |
| 156 | + $curcolor = ($curcolor + 1) % 10; |
| 157 | + } |
| 158 | + } |
| 159 | + if (count($positions) > 0) { |
| 160 | + ksort($positions); |
| 161 | + $positions = array_values($positions); |
| 162 | + switch ($this->m_tlpos) { |
| 163 | + case 'start': |
| 164 | + $result .= '<span class="smwtlposition">' . $positions[0] . '</span>'; |
| 165 | + break; |
| 166 | + case 'end': |
| 167 | + $result .= '<span class="smwtlposition">' . $positions[count($positions)-1] . '</span>'; |
| 168 | + break; |
| 169 | + case 'today': break; // default |
| 170 | + case 'middle': default: |
| 171 | + $result .= '<span class="smwtlposition">' . $positions[ceil(count($positions)/2)-1] . '</span>'; |
| 172 | + break; |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + //no further results displayed ... |
| 177 | + |
| 178 | + // print footer |
| 179 | + $result .= "</div>"; |
| 180 | + $result .= $this->getErrorString($res); // just append error messages |
| 181 | + return $result; |
| 182 | + } |
| 183 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 184 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php |
— | — | @@ -0,0 +1,77 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Print query results using templates. |
| 5 | + * @author Markus Krötzsch |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Printer for template data. Passes a result row as anonymous parameters to |
| 10 | + * a given template (which might ignore them or not) and prints the result. |
| 11 | + */ |
| 12 | +class SMWTemplateResultPrinter extends SMWResultPrinter { |
| 13 | + |
| 14 | + protected $m_template; |
| 15 | + |
| 16 | + protected function readParameters($params) { |
| 17 | + SMWResultPrinter::readParameters($params); |
| 18 | + |
| 19 | + if (array_key_exists('template', $params)) { |
| 20 | + $this->m_template = $params['template']; |
| 21 | + } else { |
| 22 | + $this->m_template = false; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public function getHTML($res) { |
| 27 | + // handle factbox |
| 28 | + global $smwgStoreActive, $wgTitle; |
| 29 | + |
| 30 | + // print all result rows |
| 31 | + if ($this->m_template == false) { |
| 32 | + return 'Please provide parameter "template" for query to work.'; // TODO: internationalise, beautify |
| 33 | + } |
| 34 | + |
| 35 | + $old_smwgStoreActive = $smwgStoreActive; |
| 36 | + $smwgStoreActive = false; // no annotations stored, no factbox printed |
| 37 | + |
| 38 | + $parserinput = $this->mIntro; |
| 39 | + |
| 40 | + $parser_options = new ParserOptions(); |
| 41 | + $parser_options->setEditSection(false); // embedded sections should not have edit links |
| 42 | + $parser = new Parser(); |
| 43 | + while ( $row = $res->getNext() ) { |
| 44 | + $wikitext = ''; |
| 45 | + $firstcol = true; |
| 46 | + foreach ($row as $field) { |
| 47 | + $wikitext .= "|"; |
| 48 | + $first = true; |
| 49 | + while ( ($text = $field->getNextWikiText($this->getLinker($firstcol))) !== false ) { |
| 50 | + if ($first) { |
| 51 | + $first = false; |
| 52 | + } else { |
| 53 | + $wikitext .= ', '; |
| 54 | + } |
| 55 | + $wikitext .= $text; |
| 56 | + } |
| 57 | + $firstcol = false; |
| 58 | + } |
| 59 | + $parserinput .= '{{' . $this->m_template . str_replace(array('=','|'), array('=', '|'), $wikitext) . '}}'; // encode '=' and '|' for use in templates (templates fail otherwise) |
| 60 | + } |
| 61 | + $parserOutput = $parser->parse($parserinput, $wgTitle, $parser_options); |
| 62 | + $result = $parserOutput->getText(); |
| 63 | + // show link to more results |
| 64 | + if ($this->mInline && $res->hasFurtherResults()) { |
| 65 | + $label = $this->mSearchlabel; |
| 66 | + if ($label === NULL) { //apply defaults |
| 67 | + $label = wfMsgForContent('smw_iq_moreresults'); |
| 68 | + } |
| 69 | + if ($label != '') { |
| 70 | + $result .= '<a href="' . $res->getQueryURL() . '">' . $label . '</a>'; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + $smwgStoreActive = $old_smwgStoreActive; |
| 75 | + $result .= $this->getErrorString($res); // just append error messages |
| 76 | + return $result; |
| 77 | + } |
| 78 | +} |
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Template.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 79 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -69,6 +69,14 @@ |
70 | 70 | |
71 | 71 | $smwgMasterStore = NULL; |
72 | 72 | smwfInitContentMessages(); |
| 73 | + |
| 74 | + ///// setup some autoloading ///// |
| 75 | + $wgAutoloadClasses[SMWResultPrinter] = $smwgIP . '/includes/SMW_QueryPrinter.php'; |
| 76 | + $wgAutoloadClasses[SMWTableResultPrinter] = $smwgIP . '/includes/SMW_QP_Table.php'; |
| 77 | + $wgAutoloadClasses[SMWListResultPrinter] = $smwgIP . '/includes/SMW_QP_List.php'; |
| 78 | + $wgAutoloadClasses[SMWTimelineResultPrinter] = $smwgIP . '/includes/SMW_QP_Timeline.php'; |
| 79 | + $wgAutoloadClasses[SMWEmbeddedResultPrinter] = $smwgIP . '/includes/SMW_QP_Embedded.php'; |
| 80 | + $wgAutoloadClasses[SMWTemplateResultPrinter] = $smwgIP . '/includes/SMW_QP_Template.php'; |
73 | 81 | |
74 | 82 | ///// register specials ///// |
75 | 83 | $wgAutoloadClasses['SMWAskPage'] = $smwgIP . '/specials/AskSpecial/SMW_SpecialAsk.php'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinters.php |
— | — | @@ -1,684 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * This file provides various classes that print query results. |
5 | | - * @author Markus Kr�tzsch |
6 | | - */ |
7 | | - |
8 | | -/** |
9 | | - * Abstract base class for SMW's novel query printing mechanism. It implements |
10 | | - * part of the former functionality of SMWInlineQuery (everything related to |
11 | | - * output formatting and the correspoding parameters) and is subclassed by concrete |
12 | | - * printers that provide the main formatting functionality. |
13 | | - */ |
14 | | -abstract class SMWResultPrinter { |
15 | | - |
16 | | - // parameters: |
17 | | - protected $mFormat; // a string identifier describing a valid format |
18 | | - protected $mIntro = ''; // text to print before the output in case it is *not* empty |
19 | | - protected $mSearchlabel = NULL; // text to use for link to further results, or empty if link should not be shown |
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? |
22 | | - protected $mDefault = ''; // default return value for empty queries |
23 | | - protected $mShowHeaders = true; // should the headers (property names) be printed? |
24 | | - 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) |
25 | | - protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time. |
26 | | - |
27 | | - /** |
28 | | - * Constructor. The parameter $format is a format string |
29 | | - * that may influence the processing details. |
30 | | - */ |
31 | | - public function SMWResultPrinter($format, $inline) { |
32 | | - global $smwgQDefaultLinking; |
33 | | - $this->mFormat = $format; |
34 | | - $this->mInline = $inline; |
35 | | - $this->mLinkFirst = ($smwgQDefaultLinking != 'none'); |
36 | | - $this->mLinkOthers = ($smwgQDefaultLinking == 'all'); |
37 | | - $this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)? |
38 | | - } |
39 | | - |
40 | | - /** |
41 | | - * Main entry point: takes an SMWQueryResult and parameters |
42 | | - * given as key-value-pairs in an array and returns the |
43 | | - * serialised version of the results, formatted as inline HTML |
44 | | - * or (for special printers) as RDF or XML or whatever. Normally |
45 | | - * not overwritten by subclasses. |
46 | | - */ |
47 | | - public function getResultHTML($results, $params) { |
48 | | - $this->readParameters($params); |
49 | | - if ($results->getCount() == 0) { |
50 | | - if (!$results->hasFurtherResults()) { |
51 | | - return htmlspecialchars($this->mDefault); |
52 | | - } elseif ($this->mInline) { |
53 | | - $label = $this->mSearchlabel; |
54 | | - if ($label === NULL) { //apply defaults |
55 | | - $result = '<a href="' . $results->getQueryURL() . '">' . wfMsgForContent('smw_iq_moreresults') . '</a>'; |
56 | | - } else { |
57 | | - $result = '<a href="' . $results->getQueryURL() . '">' . $label . '</a>'; |
58 | | - } |
59 | | - $result .= $this->getErrorString($results); // just append error messages |
60 | | - return $result; |
61 | | - } |
62 | | - } |
63 | | - return $this->getHTML($results); |
64 | | - } |
65 | | - |
66 | | - /** |
67 | | - * Read an array of parameter values given as key-value-pairs and |
68 | | - * initialise internal member fields accordingly. Possibly overwritten |
69 | | - * (extended) by subclasses. |
70 | | - */ |
71 | | - protected function readParameters($params) { |
72 | | - if (array_key_exists('intro', $params)) { |
73 | | - $this->mIntro = htmlspecialchars(str_replace('_', ' ', $params['intro'])); |
74 | | - } |
75 | | - if (array_key_exists('searchlabel', $params)) { |
76 | | - $this->mSearchlabel = htmlspecialchars($params['searchlabel']); |
77 | | - } |
78 | | - if (array_key_exists('link', $params)) { |
79 | | - switch (strtolower($params['link'])) { |
80 | | - case 'head': case 'subject': |
81 | | - $this->mLinkFirst = true; |
82 | | - $this->mLinkOthers = false; |
83 | | - break; |
84 | | - case 'all': |
85 | | - $this->mLinkFirst = true; |
86 | | - $this->mLinkOthers = true; |
87 | | - break; |
88 | | - case 'none': |
89 | | - $this->mLinkFirst = false; |
90 | | - $this->mLinkOthers = false; |
91 | | - break; |
92 | | - } |
93 | | - } |
94 | | - if (array_key_exists('default', $params)) { |
95 | | - $this->mDefault = htmlspecialchars(str_replace('_', ' ', $params['default'])); |
96 | | - } |
97 | | - if (array_key_exists('headers', $params)) { |
98 | | - if ( 'hide' == strtolower($params['headers'])) { |
99 | | - $this->mShowHeaders = false; |
100 | | - } else { |
101 | | - $this->mShowHeaders = true; |
102 | | - } |
103 | | - } |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Return HTML version of serialised results. |
108 | | - * Implemented by subclasses. |
109 | | - */ |
110 | | - abstract protected function getHTML($res); |
111 | | - |
112 | | - /** |
113 | | - * Depending on current linking settings, returns a linker object |
114 | | - * for making hyperlinks or NULL if no links should be created. |
115 | | - * |
116 | | - * @param $firstrow True of this is the first result row (having special linkage settings). |
117 | | - */ |
118 | | - protected function getLinker($firstcol = false) { |
119 | | - if ( ($firstcol && $this->mLinkFirst) || (!$firstcol && $this->mLinkOthers) ) { |
120 | | - return $this->mLinker; |
121 | | - } else { |
122 | | - return NULL; |
123 | | - } |
124 | | - } |
125 | | - |
126 | | - /** |
127 | | - * Provides a simple formatted string of all the error messages that occurred. |
128 | | - * Can be used if not specific error formatting is desired. Compatible with HTML |
129 | | - * and Wiki. |
130 | | - */ |
131 | | - protected function getErrorString($res) { |
132 | | - return smwfEncodeMessages($res->getErrors()); |
133 | | - } |
134 | | - |
135 | | - |
136 | | -} |
137 | | - |
138 | | -/** |
139 | | - * New implementation of SMW's printer for result tables. |
140 | | - */ |
141 | | -class SMWTableResultPrinter extends SMWResultPrinter { |
142 | | - |
143 | | - protected function getHTML($res) { |
144 | | - global $smwgIQRunningNumber; |
145 | | - |
146 | | - |
147 | | - |
148 | | - // print header |
149 | | - if ('broadtable' == $this->mFormat) |
150 | | - $widthpara = ' width="100%"'; |
151 | | - else $widthpara = ''; |
152 | | - $result = $this->mIntro . |
153 | | - "<table class=\"smwtable\"$widthpara id=\"querytable" . $smwgIQRunningNumber . "\">\n"; |
154 | | - if ($this->mShowHeaders) { // building headers |
155 | | - $result .= "\n\t\t<tr>"; |
156 | | - foreach ($res->getPrintRequests() as $pr) { |
157 | | - $result .= "\t\t\t<th>" . $pr->getHTMLText($this->mLinker) . "</th>\n"; |
158 | | - } |
159 | | - $result .= "\n\t\t</tr>"; |
160 | | - } |
161 | | - |
162 | | - // print all result rows |
163 | | - while ( $row = $res->getNext() ) { |
164 | | - $result .= "\t\t<tr>\n"; |
165 | | - $firstcol = true; |
166 | | - foreach ($row as $field) { |
167 | | - $result .= "<td>"; |
168 | | - $first = true; |
169 | | - while ( ($text = $field->getNextHTMLText($this->getLinker($firstcol))) !== false ) { |
170 | | - if ($first) $first = false; else $result .= '<br />'; |
171 | | - $result .= $text; |
172 | | - } |
173 | | - $result .= "</td>"; |
174 | | - $firstcol = false; |
175 | | - } |
176 | | - $result .= "\n\t\t</tr>\n"; |
177 | | - } |
178 | | - |
179 | | - // print further results footer |
180 | | - if ($this->mInline && $res->hasFurtherResults()) { |
181 | | - $label = $this->mSearchlabel; |
182 | | - if ($label === NULL) { //apply default |
183 | | - $label = wfMsgForContent('smw_iq_moreresults'); |
184 | | - } |
185 | | - if ($label != '') { |
186 | | - $result .= "\n\t\t<tr class=\"smwfooter\"><td class=\"sortbottom\" colspan=\"" . $res->getColumnCount() . '"> <a href="' . $res->getQueryURL() . '">' . $label . '</a></td></tr>'; |
187 | | - } |
188 | | - } |
189 | | - $result .= "\t</table>"; // print footer |
190 | | - $result .= $this->getErrorString($res); // just append error messages |
191 | | - return $result; |
192 | | - } |
193 | | -} |
194 | | - |
195 | | -/** |
196 | | - * New implementation of SMW's printer for results in lists. |
197 | | - * |
198 | | - * Somewhat confusing code, since one has to iterate through lists, inserting texts |
199 | | - * in between their elements depending on whether the element is the first that is |
200 | | - * printed, the first that is printed in parentheses, or the last that will be printed. |
201 | | - * Maybe one could further simplify this. |
202 | | - */ |
203 | | -class SMWListResultPrinter extends SMWResultPrinter { |
204 | | - |
205 | | - protected $mSep = ''; |
206 | | - protected $mTemplate = ''; |
207 | | - |
208 | | - protected function readParameters($params) { |
209 | | - SMWResultPrinter::readParameters($params); |
210 | | - |
211 | | - if (array_key_exists('sep', $params)) { |
212 | | - $this->mSep = htmlspecialchars(str_replace('_',' ',$params['sep'])); |
213 | | - } |
214 | | - if (array_key_exists('template', $params)) { |
215 | | - $this->mTemplate = $params['template']; |
216 | | - } |
217 | | - } |
218 | | - |
219 | | - protected function getHTML($res) { |
220 | | - global $wgTitle,$smwgStoreActive; |
221 | | - // print header |
222 | | - $result = $this->mIntro; |
223 | | - if ( ('ul' == $this->mFormat) || ('ol' == $this->mFormat) ) { |
224 | | - $result .= '<' . $this->mFormat . '>'; |
225 | | - $footer = '</' . $this->mFormat . '>'; |
226 | | - $rowstart = "\n\t<li>"; |
227 | | - $rowend = '</li>'; |
228 | | - $plainlist = false; |
229 | | - } else { |
230 | | - if ($this->mSep != '') { |
231 | | - $listsep = $this->mSep; |
232 | | - $finallistsep = $listsep; |
233 | | - } else { // default list ", , , and, " |
234 | | - $listsep = ', '; |
235 | | - $finallistsep = wfMsgForContent('smw_finallistconjunct') . ' '; |
236 | | - } |
237 | | - $footer = ''; |
238 | | - $rowstart = ''; |
239 | | - $rowend = ''; |
240 | | - $plainlist = true; |
241 | | - } |
242 | | - |
243 | | - if ($this->mTemplate != '') { |
244 | | - $parser_options = new ParserOptions(); |
245 | | - $parser_options->setEditSection(false); // embedded sections should not have edit links |
246 | | - $parser = new Parser(); |
247 | | - $usetemplate = true; |
248 | | - } else { |
249 | | - $usetemplate = false; |
250 | | - } |
251 | | - |
252 | | - // print all result rows |
253 | | - $first_row = true; |
254 | | - $row = $res->getNext(); |
255 | | - while ( $row !== false ) { |
256 | | - $nextrow = $res->getNext(); // look ahead |
257 | | - if ( !$first_row && $plainlist ) { |
258 | | - if ($nextrow !== false) $result .= $listsep; // the comma between "rows" other than the last one |
259 | | - else $result .= $finallistsep; |
260 | | - } else $result .= $rowstart; |
261 | | - |
262 | | - $first_col = true; |
263 | | - if ($usetemplate) { // build template code |
264 | | - $wikitext = ''; |
265 | | - foreach ($row as $field) { |
266 | | - $wikitext .= "|"; |
267 | | - $first_value = true; |
268 | | - while ( ($text = $field->getNextWikiText($this->getLinker($first_col))) !== false ) { |
269 | | - if ($first_value) $first_value = false; else $wikitext .= ', '; |
270 | | - $wikitext .= $text; |
271 | | - } |
272 | | - $first_col = false; |
273 | | - } |
274 | | - $result .= '{{' . $this->mTemplate . str_replace(array('=','|'), array('=', '|'), $wikitext) . '}}'; // encode '=' and '|' for use in templates (templates fail otherwise) |
275 | | - } else { // build simple list |
276 | | - $first_col = true; |
277 | | - $found_values = false; // has anything but the first column been printed? |
278 | | - foreach ($row as $field) { |
279 | | - $first_value = true; |
280 | | - while ( ($text = $field->getNextHTMLText($this->getLinker($first_col))) !== false ) { |
281 | | - if (!$first_col && !$found_values) { // first values after first column |
282 | | - $result .= ' ('; |
283 | | - $found_values = true; |
284 | | - } elseif ($found_values || !$first_value) { |
285 | | - // any value after '(' or non-first values on first column |
286 | | - $result .= ', '; |
287 | | - } |
288 | | - if ($first_value) { // first value in any column, print header |
289 | | - $first_value = false; |
290 | | - if ( $this->mShowHeaders && ('' != $field->getPrintRequest()->getLabel()) ) { |
291 | | - $result .= $field->getPrintRequest()->getHTMLText($this->mLinker) . ' '; |
292 | | - } |
293 | | - } |
294 | | - $result .= $text; // actual output value |
295 | | - } |
296 | | - $first_col = false; |
297 | | - } |
298 | | - if ($found_values) $result .= ')'; |
299 | | - } |
300 | | - $result .= $rowend; |
301 | | - $first_row = false; |
302 | | - $row = $nextrow; |
303 | | - } |
304 | | - |
305 | | - if ($usetemplate) { |
306 | | - $old_smwgStoreActive = $smwgStoreActive; |
307 | | - $smwgStoreActive = false; // no annotations stored, no factbox printed |
308 | | - $parserOutput = $parser->parse($result, $wgTitle, $parser_options); |
309 | | - $result = $parserOutput->getText(); |
310 | | - $smwgStoreActive = $old_smwgStoreActive; |
311 | | - } |
312 | | - |
313 | | - if ($this->mInline && $res->hasFurtherResults()) { |
314 | | - $label = $this->mSearchlabel; |
315 | | - if ($label === NULL) { //apply defaults |
316 | | - if ('ol' == $this->mFormat) $label = ''; |
317 | | - else $label = wfMsgForContent('smw_iq_moreresults'); |
318 | | - } |
319 | | - if (!$first_row) $result .= ' '; // relevant for list, unproblematic for ul/ol |
320 | | - if ($label != '') { |
321 | | - $result .= $rowstart . '<a href="' . $res->getQueryURL() . '">' . $label . '</a>' . $rowend; |
322 | | - } |
323 | | - } |
324 | | - |
325 | | - // print footer |
326 | | - $result .= $footer; |
327 | | - $result .= $this->getErrorString($res); // just append error messages |
328 | | - |
329 | | - return $result; |
330 | | - } |
331 | | -} |
332 | | - |
333 | | - |
334 | | -/** |
335 | | - * New implementation of SMW's printer for timeline data. |
336 | | - */ |
337 | | -class SMWTimelineResultPrinter extends SMWResultPrinter { |
338 | | - |
339 | | - protected $m_tlstart = ''; // name of the start-date property if any |
340 | | - protected $m_tlend = ''; // name of the end-date property if any |
341 | | - protected $m_tlsize = ''; // CSS-compatible size (such as 400px) |
342 | | - protected $m_tlbands = ''; // array of band IDs (MONTH, YEAR, ...) |
343 | | - protected $m_tlpos = ''; // position identifier (start, end, today, middle) |
344 | | - |
345 | | - protected function readParameters($params) { |
346 | | - SMWResultPrinter::readParameters($params); |
347 | | - |
348 | | - if (array_key_exists('timelinestart', $params)) { |
349 | | - $this->m_tlstart = smwfNormalTitleDBKey($params['timelinestart']); |
350 | | - } |
351 | | - if (array_key_exists('timelineend', $params)) { |
352 | | - $this->m_tlend = smwfNormalTitleDBKey($params['timelineend']); |
353 | | - } |
354 | | - if (array_key_exists('timelinesize', $params)) { |
355 | | - $this->m_tlsize = htmlspecialchars(str_replace(';', ' ', strtolower($params['timelinesize']))); |
356 | | - // str_replace makes sure this is only one value, not mutliple CSS fields (prevent CSS attacks) |
357 | | - } else { |
358 | | - $this->m_tlsize = '300px'; |
359 | | - } |
360 | | - if (array_key_exists('timelinebands', $params)) { |
361 | | - //check for band parameter, should look like "DAY,MONTH,YEAR" |
362 | | - $this->m_tlbands = preg_split('/[,][\s]*/',$params['timelinebands']); |
363 | | - } else { |
364 | | - $this->m_tlbands = array('MONTH','YEAR'); // TODO: check what default the JavaScript uses |
365 | | - } |
366 | | - if (array_key_exists('timelineposition', $params)) { |
367 | | - $this->m_tlpos = strtolower($params['timelineposition']); |
368 | | - } else { |
369 | | - $this->m_tlpos = 'middle'; |
370 | | - } |
371 | | - } |
372 | | - |
373 | | - public function getHTML($res) { |
374 | | - global $smwgIQRunningNumber; |
375 | | - |
376 | | - $eventline = ('eventline' == $this->mFormat); |
377 | | - |
378 | | - if ( !$eventline && ($this->m_tlstart == '') ) { // seek defaults |
379 | | - foreach ($res->getPrintRequests() as $pr) { |
380 | | - if ( ($pr->getMode() == SMW_PRINT_PROP) && ($pr->getTypeID() == '_dat') ) { |
381 | | - if ( ($this->m_tlend == '') && ($this->m_tlstart != '') && |
382 | | - ($this->m_tlstart != $pr->getTitle()->getDBKey()) ) { |
383 | | - $this->m_tlend = $pr->getTitle()->getDBKey(); |
384 | | - } elseif ( ($this->m_tlstart == '') && ($this->m_tlend != $pr->getTitle()->getDBKey()) ) { |
385 | | - $this->m_tlstart = $pr->getTitle()->getDBKey(); |
386 | | - } |
387 | | - } |
388 | | - } |
389 | | - } |
390 | | - |
391 | | - // print header |
392 | | - $result = "<div class=\"smwtimeline\" id=\"smwtimeline$smwgIQRunningNumber\" style=\"height: $this->m_tlsize\">"; |
393 | | - $result .= '<span class="smwtlcomment">' . wfMsgForContent('smw_iq_nojs',$res->getQueryURL()) . '</span>'; // note for people without JavaScript |
394 | | - |
395 | | - foreach ($this->m_tlbands as $band) { |
396 | | - $result .= '<span class="smwtlband">' . htmlspecialchars($band) . '</span>'; |
397 | | - //just print any "band" given, the JavaScript will figure out what to make of it |
398 | | - } |
399 | | - |
400 | | - // print all result rows |
401 | | - $positions = array(); // possible positions, collected to select one for centering |
402 | | - $curcolor = 0; // color cycling is used for eventline |
403 | | - if ( ($this->m_tlstart != '') || $eventline ) { |
404 | | - $output = false; // true if output for the popup was given on current line |
405 | | - if ($eventline) $events = array(); // array of events that are to be printed |
406 | | - while ( $row = $res->getNext() ) { |
407 | | - $hastime = false; // true as soon as some startdate value was found |
408 | | - $hastitle = false; // true as soon as some label for the event was found |
409 | | - $curdata = ''; // current *inner* print data (within some event span) |
410 | | - $curmeta = ''; // current event meta data |
411 | | - $curarticle = ''; // label of current article, if it was found; needed only for eventline labeling |
412 | | - $first_col = true; |
413 | | - foreach ($row as $field) { |
414 | | - $first_value = true; |
415 | | - $pr = $field->getPrintRequest(); |
416 | | - while ( ($object = $field->getNextObject()) !== false ) { |
417 | | - $l = $this->getLinker($first_col); |
418 | | - $objectlabel = $object->getShortHTMLText($l); |
419 | | - $urlobject = ($l !== NULL); |
420 | | - $header = ''; |
421 | | - if ($first_value) { |
422 | | - // find header for current value: |
423 | | - if ( $this->mShowHeaders && ('' != $pr->getLabel()) ) { |
424 | | - $header = $pr->getHTMLText($this->mLinker) . ' '; |
425 | | - } |
426 | | - // is this a start date? |
427 | | - if ( ($pr->getMode() == SMW_PRINT_PROP) && |
428 | | - ($pr->getTitle()->getDBKey() == $this->m_tlstart) ) { |
429 | | - //FIXME: Timeline scripts should support XSD format explicitly. They |
430 | | - //currently seem to implement iso8601 which deviates from XSD in cases. |
431 | | - //NOTE: We can assume $object to be an SMWDataValue in this case. |
432 | | - $curmeta .= '<span class="smwtlstart">' . $object->getXSDValue() . '</span>'; |
433 | | - $positions[$object->getNumericValue()] = $object->getXSDValue(); |
434 | | - $hastime = true; |
435 | | - } |
436 | | - // is this the end date? |
437 | | - if ( ($pr->getMode() == SMW_PRINT_PROP) && |
438 | | - ($pr->getTitle()->getDBKey() == $this->m_tlend) ) { |
439 | | - //NOTE: We can assume $object to be an SMWDataValue in this case. |
440 | | - $curmeta .= '<span class="smwtlend">' . $object->getXSDValue() . '</span>'; |
441 | | - } |
442 | | - // find title for displaying event |
443 | | - if ( !$hastitle ) { |
444 | | - if ($urlobject) { |
445 | | - $curmeta .= '<span class="smwtlurl">' . $objectlabel . '</span>'; |
446 | | - } else { |
447 | | - $curmeta .= '<span class="smwtltitle">' . $objectlabel . '</span>'; |
448 | | - } |
449 | | - if ( ($pr->getMode() == SMW_PRINT_THIS) ) { |
450 | | - // NOTE: type Title of $object implied |
451 | | - $curarticle = $object->getText(); |
452 | | - } |
453 | | - $hastitle = true; |
454 | | - } |
455 | | - } elseif ($output) $curdata .= ', '; //it *can* happen that output is false here, if the subject was not printed (fixed subject query) and mutliple items appear in the first row |
456 | | - if (!$first_col || !$first_value || $eventline) { |
457 | | - $curdata .= $header . $objectlabel; |
458 | | - $output = true; |
459 | | - } |
460 | | - if ($eventline && ($pr->getMode() == SMW_PRINT_PROP) && ($pr->getTypeID() == '_dat') && ('' != $pr->getLabel()) && ($pr->getTitle()->getText() != $this->m_tlstart) && ($pr->getTitle()->getText() != $this->m_tlend) ) { |
461 | | - $events[] = array($object->getXSDValue(), $pr->getLabel(), $object->getNumericValue()); |
462 | | - } |
463 | | - $first_value = false; |
464 | | - } |
465 | | - if ($output) $curdata .= "<br />"; |
466 | | - $output = false; |
467 | | - $first_col = false; |
468 | | - } |
469 | | - |
470 | | - if ( $hastime ) { |
471 | | - $result .= '<span class="smwtlevent">' . $curmeta . '<span class="smwtlcoloricon">' . $curcolor . '</span>' . $curdata . '</span>'; |
472 | | - } |
473 | | - if ( $eventline ) { |
474 | | - foreach ($events as $event) { |
475 | | - $result .= '<span class="smwtlevent"><span class="smwtlstart">' . $event[0] . '</span><span class="smwtlurl">' . $event[1] . '</span><span class="smwtlcoloricon">' . $curcolor . '</span>'; |
476 | | - if ( $curarticle != '' ) $result .= '<span class="smwtlprefix">' . $curarticle . ' </span>'; |
477 | | - $result .= $curdata . '</span>'; |
478 | | - $positions[$event[2]] = $event[0]; |
479 | | - } |
480 | | - $events = array(); |
481 | | - $curcolor = ($curcolor + 1) % 10; |
482 | | - } |
483 | | - } |
484 | | - if (count($positions) > 0) { |
485 | | - ksort($positions); |
486 | | - $positions = array_values($positions); |
487 | | - switch ($this->m_tlpos) { |
488 | | - case 'start': |
489 | | - $result .= '<span class="smwtlposition">' . $positions[0] . '</span>'; |
490 | | - break; |
491 | | - case 'end': |
492 | | - $result .= '<span class="smwtlposition">' . $positions[count($positions)-1] . '</span>'; |
493 | | - break; |
494 | | - case 'today': break; // default |
495 | | - case 'middle': default: |
496 | | - $result .= '<span class="smwtlposition">' . $positions[ceil(count($positions)/2)-1] . '</span>'; |
497 | | - break; |
498 | | - } |
499 | | - } |
500 | | - } |
501 | | - //no further results displayed ... |
502 | | - |
503 | | - // print footer |
504 | | - $result .= "</div>"; |
505 | | - $result .= $this->getErrorString($res); // just append error messages |
506 | | - return $result; |
507 | | - } |
508 | | -} |
509 | | - |
510 | | - |
511 | | -/** |
512 | | - * Printer for template data. Passes a result row as anonymous parameters to |
513 | | - * a given template (which might ignore them or not) and prints the result. |
514 | | - */ |
515 | | -class SMWTemplateResultPrinter extends SMWResultPrinter { |
516 | | - |
517 | | - protected $m_template; |
518 | | - |
519 | | - protected function readParameters($params) { |
520 | | - SMWResultPrinter::readParameters($params); |
521 | | - |
522 | | - if (array_key_exists('template', $params)) { |
523 | | - $this->m_template = $params['template']; |
524 | | - } else { |
525 | | - $this->m_template = false; |
526 | | - } |
527 | | - } |
528 | | - |
529 | | - public function getHTML($res) { |
530 | | - // handle factbox |
531 | | - global $smwgStoreActive, $wgTitle; |
532 | | - |
533 | | - // print all result rows |
534 | | - if ($this->m_template == false) { |
535 | | - return 'Please provide parameter "template" for query to work.'; // TODO: internationalise, beautify |
536 | | - } |
537 | | - |
538 | | - $old_smwgStoreActive = $smwgStoreActive; |
539 | | - $smwgStoreActive = false; // no annotations stored, no factbox printed |
540 | | - |
541 | | - $parserinput = $this->mIntro; |
542 | | - |
543 | | - $parser_options = new ParserOptions(); |
544 | | - $parser_options->setEditSection(false); // embedded sections should not have edit links |
545 | | - $parser = new Parser(); |
546 | | - while ( $row = $res->getNext() ) { |
547 | | - $wikitext = ''; |
548 | | - $firstcol = true; |
549 | | - foreach ($row as $field) { |
550 | | - $wikitext .= "|"; |
551 | | - $first = true; |
552 | | - while ( ($text = $field->getNextWikiText($this->getLinker($firstcol))) !== false ) { |
553 | | - if ($first) { |
554 | | - $first = false; |
555 | | - } else { |
556 | | - $wikitext .= ', '; |
557 | | - } |
558 | | - $wikitext .= $text; |
559 | | - } |
560 | | - $firstcol = false; |
561 | | - } |
562 | | - $parserinput .= '{{' . $this->m_template . str_replace(array('=','|'), array('=', '|'), $wikitext) . '}}'; // encode '=' and '|' for use in templates (templates fail otherwise) |
563 | | - } |
564 | | - $parserOutput = $parser->parse($parserinput, $wgTitle, $parser_options); |
565 | | - $result = $parserOutput->getText(); |
566 | | - // show link to more results |
567 | | - if ($this->mInline && $res->hasFurtherResults()) { |
568 | | - $label = $this->mSearchlabel; |
569 | | - if ($label === NULL) { //apply defaults |
570 | | - $label = wfMsgForContent('smw_iq_moreresults'); |
571 | | - } |
572 | | - if ($label != '') { |
573 | | - $result .= '<a href="' . $res->getQueryURL() . '">' . $label . '</a>'; |
574 | | - } |
575 | | - } |
576 | | - |
577 | | - $smwgStoreActive = $old_smwgStoreActive; |
578 | | - $result .= $this->getErrorString($res); // just append error messages |
579 | | - return $result; |
580 | | - } |
581 | | -} |
582 | | - |
583 | | - |
584 | | -/** |
585 | | - * Printer for embedded data. |
586 | | - * Embeds in the page output the contents of the pages in the query result set. |
587 | | - * Only the first column of the query is considered. If it is a page reference then that page's contents is embedded. |
588 | | - * The optional "titlestyle" formatting parameter can be used to apply a format to the headings for the page titles. |
589 | | - * If "titlestyle" is not specified, a <h1> tag is used. |
590 | | - * @author Fernando Correia |
591 | | - * @author Markus Kr�tzsch |
592 | | - */ |
593 | | -class SMWEmbeddedResultPrinter extends SMWResultPrinter { |
594 | | - |
595 | | - protected $m_showhead; |
596 | | - protected $m_embedformat; |
597 | | - |
598 | | - protected function readParameters($params) { |
599 | | - SMWResultPrinter::readParameters($params); |
600 | | - |
601 | | - if (array_key_exists('embedonly', $params)) { |
602 | | - $this->m_showhead = false; |
603 | | - } else { |
604 | | - $this->m_showhead = true; |
605 | | - } |
606 | | - if (array_key_exists('embedformat', $params)) { |
607 | | - $this->m_embedformat = $params['embedformat']; |
608 | | - } else { |
609 | | - $this->m_embedformat = 'h1'; |
610 | | - } |
611 | | - } |
612 | | - |
613 | | - public function getHTML($res) { |
614 | | - // handle factbox |
615 | | - global $smwgStoreActive, $wgTitle; |
616 | | - $old_smwgStoreActive = $smwgStoreActive; |
617 | | - $smwgStoreActive = false; // no annotations stored, no factbox printed |
618 | | - |
619 | | - // print header |
620 | | - $result = $this->mIntro; |
621 | | - |
622 | | - switch ($this->m_embedformat) { |
623 | | - case 'h1': case 'h2': case 'h3': case 'h4': case 'h5': case 'h6': |
624 | | - $footer = ''; |
625 | | - $embstart = ''; |
626 | | - $headstart = '<' . $this->m_embedformat . '>'; |
627 | | - $headend = '</' . $this->m_embedformat . ">\n"; |
628 | | - $embend = ''; |
629 | | - break; |
630 | | - case 'ul': case 'ol': |
631 | | - $result .= '<' . $this->m_embedformat . '>'; |
632 | | - $footer = '</' . $this->m_embedformat . '>'; |
633 | | - $embstart = '<li>'; |
634 | | - $headstart = ''; |
635 | | - $headend = "<br />\n"; |
636 | | - $embend = "</li>\n"; |
637 | | - break; |
638 | | - } |
639 | | - |
640 | | - // print all result rows |
641 | | - $parser_options = new ParserOptions(); |
642 | | - $parser_options->setEditSection(false); // embedded sections should not have edit links |
643 | | - $parser = new Parser(); |
644 | | - |
645 | | - while ( $row = $res->getNext() ) { |
646 | | - $first_col = true; |
647 | | - foreach ($row as $field) { |
648 | | - if ( $field->getPrintRequest()->getTypeID() == '_wpg' ) { // ensure that we deal with title-likes |
649 | | - while ( ($object = $field->getNextObject()) !== false ) { |
650 | | - $result .= $embstart; |
651 | | - $text= $object->getLongHTMLText($this->getLinker(true)); |
652 | | - if ($this->m_showhead) { |
653 | | - $result .= $headstart . $text . $headend; |
654 | | - } |
655 | | - if ($object->getNamespace() == NS_MAIN) { |
656 | | - $articlename = ':' . $object->getText(); |
657 | | - } else { |
658 | | - $articlename = $object->getPrefixedText(); |
659 | | - } |
660 | | - $parserOutput = $parser->parse('{{' . $articlename . '}}', $wgTitle, $parser_options); |
661 | | - $result .= $parserOutput->getText(); |
662 | | - $result .= $embend; |
663 | | - } |
664 | | - } |
665 | | - break; // only use first column for now |
666 | | - } |
667 | | - } |
668 | | - |
669 | | - // show link to more results |
670 | | - if ($this->mInline && $res->hasFurtherResults()) { |
671 | | - $label = $this->mSearchlabel; |
672 | | - if ($label === NULL) { //apply defaults |
673 | | - $label = wfMsgForContent('smw_iq_moreresults'); |
674 | | - } |
675 | | - if ($label != '') { |
676 | | - $result .= $embstart . '<a href="' . $res->getQueryURL() . '">' . $label . '</a>' . $embend ; |
677 | | - } |
678 | | - } |
679 | | - $result .= $footer; |
680 | | - $result .= $this->getErrorString($res); // just append error messages |
681 | | - |
682 | | - $smwgStoreActive = $old_smwgStoreActive; |
683 | | - return $result; |
684 | | - } |
685 | | -} |