Index: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php |
— | — | @@ -1,9 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Print query results in interactive timelines. |
| 5 | + * |
| 6 | + * @file SRF_Timeline.php |
| 7 | + * @ingroup SemanticResultFormats |
| 8 | + * |
5 | 9 | * @author Markus Krötzsch |
6 | | - * @file |
7 | | - * @ingroup SemanticResultFormats |
8 | 10 | */ |
9 | 11 | |
10 | 12 | /** |
— | — | @@ -27,6 +29,7 @@ |
28 | 30 | if ( array_key_exists( 'timelineend', $params ) ) { |
29 | 31 | $this->m_tlend = smwfNormalTitleDBKey( $params['timelineend'] ); |
30 | 32 | } |
| 33 | + |
31 | 34 | if ( array_key_exists( 'timelinesize', $params ) ) { |
32 | 35 | $this->m_tlsize = htmlspecialchars( str_replace( ';', ' ', strtolower( trim( $params['timelinesize'] ) ) ) ); |
33 | 36 | // str_replace makes sure this is only one value, not mutliple CSS fields (prevent CSS attacks) |
— | — | @@ -34,12 +37,14 @@ |
35 | 38 | } else { |
36 | 39 | $this->m_tlsize = '300px'; |
37 | 40 | } |
| 41 | + |
38 | 42 | if ( array_key_exists( 'timelinebands', $params ) ) { |
39 | 43 | // check for band parameter, should look like "DAY,MONTH,YEAR" |
40 | 44 | $this->m_tlbands = preg_split( '/[,][\s]*/u', trim( $params['timelinebands'] ) ); |
41 | 45 | } else { |
42 | 46 | $this->m_tlbands = array( 'MONTH', 'YEAR' ); // / TODO: check what default the JavaScript uses |
43 | 47 | } |
| 48 | + |
44 | 49 | if ( array_key_exists( 'timelineposition', $params ) ) { |
45 | 50 | $this->m_tlpos = strtolower( trim( $params['timelineposition'] ) ); |
46 | 51 | } else { |
— | — | @@ -48,12 +53,12 @@ |
49 | 54 | } |
50 | 55 | |
51 | 56 | public function getName() { |
52 | | - wfLoadExtensionMessages( 'SemanticResultFormats' ); |
53 | 57 | return wfMsg( 'srf_printername_' . $this->mFormat ); |
54 | 58 | } |
55 | 59 | |
56 | 60 | protected function getResultText( $res, $outputmode ) { |
57 | 61 | global $smwgIQRunningNumber, $wgScriptPath; |
| 62 | + |
58 | 63 | SMWOutputs::requireHeadItem( SMW_HEADER_STYLE ); |
59 | 64 | SMWOutputs::requireHeadItem( 'smw_tlhelper', '<script type="text/javascript" src="' . $wgScriptPath . '/extensions/SemanticResultFormats/Timeline/SRF_timeline.js"></script>' ); |
60 | 65 | SMWOutputs::requireHeadItem( 'smw_tl', '<script type="text/javascript" src="' . $wgScriptPath . '/extensions/SemanticResultFormats/Timeline/SimileTimeline/timeline-api.js"></script>' ); |
— | — | @@ -68,6 +73,7 @@ |
69 | 74 | } else { |
70 | 75 | $date_value = $pr->getData()->getXSDValue(); |
71 | 76 | } |
| 77 | + |
72 | 78 | if ( ( $this->m_tlend == '' ) && ( $this->m_tlstart != '' ) && |
73 | 79 | ( $this->m_tlstart != $date_value ) ) { |
74 | 80 | $this->m_tlend = $date_value; |
— | — | @@ -78,7 +84,6 @@ |
79 | 85 | } |
80 | 86 | } |
81 | 87 | |
82 | | - wfLoadExtensionMessages( 'SemanticMediaWiki' ); |
83 | 88 | // print header |
84 | 89 | $link = $res->getQueryLink( wfMsgForContent( 'smw_iq_altresults' ) ); |
85 | 90 | $result = "<div class=\"smwtimeline\" id=\"smwtimeline$smwgIQRunningNumber\" style=\"height: $this->m_tlsize\">"; |
— | — | @@ -92,9 +97,11 @@ |
93 | 98 | // print all result rows |
94 | 99 | $positions = array(); // possible positions, collected to select one for centering |
95 | 100 | $curcolor = 0; // color cycling is used for eventline |
| 101 | + |
96 | 102 | if ( ( $this->m_tlstart != '' ) || $eventline ) { |
97 | 103 | $output = false; // true if output for the popup was given on current line |
98 | 104 | if ( $eventline ) $events = array(); // array of events that are to be printed |
| 105 | + |
99 | 106 | while ( $row = $res->getNext() ) { |
100 | 107 | $hastime = false; // true as soon as some startdate value was found |
101 | 108 | $hastitle = false; // true as soon as some label for the event was found |
— | — | @@ -102,9 +109,11 @@ |
103 | 110 | $curmeta = ''; // current event meta data |
104 | 111 | $curarticle = ''; // label of current article, if it was found; needed only for eventline labeling |
105 | 112 | $first_col = true; |
| 113 | + |
106 | 114 | foreach ( $row as $field ) { |
107 | 115 | $first_value = true; |
108 | 116 | $pr = $field->getPrintRequest(); |
| 117 | + |
109 | 118 | if ( $pr->getData() == '' ) { |
110 | 119 | $date_value = null; |
111 | 120 | } elseif ( method_exists ( $pr->getData(), 'getValueKey' ) ) { |
— | — | @@ -112,23 +121,29 @@ |
113 | 122 | } else { |
114 | 123 | $date_value = $pr->getData()->getXSDValue(); |
115 | 124 | } |
| 125 | + |
116 | 126 | while ( ( $object = $field->getNextObject() ) !== false ) { |
117 | 127 | $l = $this->getLinker( $first_col ); |
| 128 | + |
118 | 129 | if ( !$hastitle && $object->getTypeID() != '_wpg' ) { // "linking" non-pages in title positions confuses timeline scripts, don't try this |
119 | 130 | $l = null; |
120 | 131 | } |
| 132 | + |
121 | 133 | if ( $object->getTypeID() == '_wpg' ) { // use shorter "LongText" for wikipage |
122 | 134 | $objectlabel = $object->getLongText( $outputmode, $l ); |
123 | 135 | } else { |
124 | 136 | $objectlabel = $object->getShortText( $outputmode, $l ); |
125 | 137 | } |
| 138 | + |
126 | 139 | $urlobject = ( $l !== null ); |
127 | 140 | $header = ''; |
| 141 | + |
128 | 142 | if ( $first_value ) { |
129 | 143 | // find header for current value: |
130 | 144 | if ( $this->mShowHeaders && ( '' != $pr->getLabel() ) ) { |
131 | 145 | $header = $pr->getText( $outputmode, $this->mLinker ) . ': '; |
132 | 146 | } |
| 147 | + |
133 | 148 | // is this a start date? |
134 | 149 | if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && |
135 | 150 | ( $date_value == $this->m_tlstart ) ) { |
— | — | @@ -139,30 +154,40 @@ |
140 | 155 | $positions[$object->getHash()] = $object->getXMLSchemaDate(); |
141 | 156 | $hastime = true; |
142 | 157 | } |
| 158 | + |
143 | 159 | // is this the end date? |
144 | 160 | if ( ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && |
145 | 161 | ( $date_value == $this->m_tlend ) ) { |
146 | 162 | // NOTE: We can assume $object to be an SMWDataValue in this case. |
147 | 163 | $curmeta .= '<span class="smwtlend">' . $object->getXMLSchemaDate( false ) . '</span>'; |
148 | 164 | } |
| 165 | + |
149 | 166 | // find title for displaying event |
150 | 167 | if ( !$hastitle ) { |
151 | | - if ( $urlobject ) { |
152 | | - $curmeta .= '<span class="smwtlurl">' . $objectlabel . '</span>'; |
153 | | - } else { |
154 | | - $curmeta .= '<span class="smwtltitle">' . $objectlabel . '</span>'; |
155 | | - } |
| 168 | + $curmeta .= Html::element( |
| 169 | + 'span', |
| 170 | + array( |
| 171 | + 'class' => $urlobject ? 'smwtlurl' : 'smwtltitle' |
| 172 | + ), |
| 173 | + $objectlabel |
| 174 | + ); |
| 175 | + |
156 | 176 | if ( ( $pr->getMode() == SMWPrintRequest::PRINT_THIS ) ) { |
157 | 177 | // NOTE: type Title of $object implied |
158 | 178 | $curarticle = $object->getLongWikiText(); |
159 | 179 | } |
160 | 180 | $hastitle = true; |
161 | 181 | } |
162 | | - } 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 |
| 182 | + } elseif ( $output ) { |
| 183 | + // 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 |
| 184 | + $curdata .= ', '; |
| 185 | + } |
| 186 | + |
163 | 187 | if ( !$first_col || !$first_value || $eventline ) { |
164 | 188 | $curdata .= $header . $objectlabel; |
165 | 189 | $output = true; |
166 | 190 | } |
| 191 | + |
167 | 192 | if ( $eventline && ( $pr->getMode() == SMWPrintRequest::PRINT_PROP ) && ( $pr->getTypeID() == '_dat' ) && ( '' != $pr->getLabel() ) && ( $date_value != $this->m_tlstart ) && ( $date_value != $this->m_tlend ) ) { |
168 | 193 | if ( method_exists( $object, 'getValueKey' ) ) { |
169 | 194 | $events[] = array( $object->getXMLSchemaDate(), $pr->getLabel(), $object->getValueKey() ); |
— | — | @@ -173,6 +198,7 @@ |
174 | 199 | } |
175 | 200 | $first_value = false; |
176 | 201 | } |
| 202 | + |
177 | 203 | if ( $output ) $curdata .= "<br />"; |
178 | 204 | $output = false; |
179 | 205 | $first_col = false; |
— | — | @@ -181,6 +207,7 @@ |
182 | 208 | if ( $hastime ) { |
183 | 209 | $result .= '<span class="smwtlevent">' . $curmeta . '<span class="smwtlcoloricon">' . $curcolor . '</span>' . $curdata . '</span>'; |
184 | 210 | } |
| 211 | + |
185 | 212 | if ( $eventline ) { |
186 | 213 | foreach ( $events as $event ) { |
187 | 214 | $result .= '<span class="smwtlevent"><span class="smwtlstart">' . $event[0] . '</span><span class="smwtlurl">' . $event[1] . '</span><span class="smwtlcoloricon">' . $curcolor . '</span>'; |
— | — | @@ -192,9 +219,11 @@ |
193 | 220 | $curcolor = ( $curcolor + 1 ) % 10; |
194 | 221 | } |
195 | 222 | } |
| 223 | + |
196 | 224 | if ( count( $positions ) > 0 ) { |
197 | 225 | ksort( $positions ); |
198 | 226 | $positions = array_values( $positions ); |
| 227 | + |
199 | 228 | switch ( $this->m_tlpos ) { |
200 | 229 | case 'start': |
201 | 230 | $result .= '<span class="smwtlposition">' . $positions[0] . '</span>'; |
— | — | @@ -217,7 +246,7 @@ |
218 | 247 | return $result; |
219 | 248 | } |
220 | 249 | |
221 | | - function getParameters() { |
| 250 | + public function getParameters() { |
222 | 251 | $params = parent::getParameters(); |
223 | 252 | $params[] = array( 'name' => 'timelinebands', 'type' => 'enum-list', 'description' => wfMsg( 'srf_paramdesc_timelinebands' ), 'values' => array( 'DECADE', 'YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE' ) ); |
224 | 253 | $params[] = array( 'name' => 'timelineposition', 'type' => 'enumeration', 'description' => wfMsg( 'srf_paramdesc_timelineposition' ), 'values' => array( 'start', 'middle', 'end' ) ); |
— | — | @@ -226,4 +255,5 @@ |
227 | 256 | $params[] = array( 'name' => 'timelinesize', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_timelinesize' ) ); |
228 | 257 | return $params; |
229 | 258 | } |
| 259 | + |
230 | 260 | } |