Index: trunk/extensions/MetavidWiki/includes/MV_MagicWords.php |
— | — | @@ -58,6 +58,9 @@ |
59 | 59 | case 'RECENTSTREAMS': |
60 | 60 | return $this->getRecentStreams(); |
61 | 61 | break; |
| 62 | + case 'RECENTSPEACHES': |
| 63 | + return $this->getRecentSpeaches(); |
| 64 | + break; |
62 | 65 | case 'PERSONSPEECHES': |
63 | 66 | return $this->getPersonOut(); |
64 | 67 | break; |
— | — | @@ -68,7 +71,7 @@ |
69 | 72 | return "error: unknown mvData function: <b>{$this->magicTypeKey}</b> <br>"; |
70 | 73 | break; |
71 | 74 | } |
72 | | - } |
| 75 | + } |
73 | 76 | function getBillOut() { |
74 | 77 | // return 'bill results'; |
75 | 78 | if ( $this->params['bill'] != '' ) { |
— | — | @@ -103,7 +106,7 @@ |
104 | 107 | return $ms->getUnifiedResultsHTML( $show_sidebar = false ); |
105 | 108 | } |
106 | 109 | function getStartTime() { |
107 | | - $start_time = 0; |
| 110 | + $start_time = 0; |
108 | 111 | // be sure to define 'mv_date_last_week' in messeges |
109 | 112 | switch( $this->params['time_range'] ) { |
110 | 113 | case 'last_week':$start_time = time() - ( 7 * 24 * 60 * 60 ); break; |
— | — | @@ -115,6 +118,29 @@ |
116 | 119 | } |
117 | 120 | return $start_time; |
118 | 121 | } |
| 122 | + function getRecentSpeaches(){ |
| 123 | + $dbr = & wfGetDB( DB_READ ); |
| 124 | + //do a query for speeches: |
| 125 | + $vars = array( 'query_key', 'stream_id', 'start_time', 'end_time'); |
| 126 | + $conds = array( 'view_date >=' . $dbr->addQuotes( $this->getStartTime() ) ); |
| 127 | + $options = array( 'GROUP BY' => 'stream_id', 'ORDER BY' => '`stream_id` DESC ', |
| 128 | + 'LIMIT' => intval( $this->params['num_results'] ) ); |
| 129 | + $result = $dbr->select( 'mv_clipview_digest', |
| 130 | + $vars, |
| 131 | + $conds, |
| 132 | + __METHOD__, |
| 133 | + $options |
| 134 | + ); |
| 135 | + if ( $dbr->numRows( $result ) == 0 ) { |
| 136 | + return ''; |
| 137 | + } else { |
| 138 | + $outItems = Array(); |
| 139 | + while ( $row = $dbr->fetchObject( $result ) ) { |
| 140 | + $outItems[]= $this->getItemOutput($row); |
| 141 | + } |
| 142 | + return $this->formatOutputItems($outItems); |
| 143 | + } |
| 144 | + } |
119 | 145 | // gets the top few clip ranges |
120 | 146 | function getTopClips() { |
121 | 147 | $dbr = & wfGetDB( DB_READ ); |
— | — | @@ -122,7 +148,7 @@ |
123 | 149 | $vars = array( 'query_key', 'stream_id', 'start_time', 'end_time', 'COUNT(1) as hit_count' ); |
124 | 150 | $conds = array( 'view_date >=' . $dbr->addQuotes( $this->getStartTime() ) ); |
125 | 151 | $options = array( 'GROUP BY' => 'query_key', 'ORDER BY' => '`hit_count` DESC ', |
126 | | - 'LIMIT' => ( $this->params['num_results'] ) ); |
| 152 | + 'LIMIT' => intval( $this->params['num_results'] ) ); |
127 | 153 | $result = $dbr->select( 'mv_clipview_digest', |
128 | 154 | $vars, |
129 | 155 | $conds, |
— | — | @@ -131,104 +157,135 @@ |
132 | 158 | ); |
133 | 159 | if ( $dbr->numRows( $result ) == 0 ) { |
134 | 160 | return ''; |
| 161 | + } else { |
| 162 | + $outItems = Array(); |
| 163 | + while ( $row = $dbr->fetchObject( $result ) ) { |
| 164 | + $outItems[]= $this->getItemOutput($row); |
| 165 | + } |
| 166 | + return $this->formatOutputItems($outItems); |
| 167 | + } |
| 168 | + |
| 169 | + } |
| 170 | + function getItemOutput( $row ){ |
| 171 | + global $wgUser; |
| 172 | + $sk = $wgUser->getSkin(); |
| 173 | + |
| 174 | + $person_ht = $bill_ht = $category_ht = $o= ''; |
| 175 | + // first make link and stream title: |
| 176 | + $mvStream = MV_Stream::newStreamByID( $row->stream_id ); |
| 177 | + $nt = $mvStream->getStreamName() . '/' . seconds2ntp( $row->start_time ) |
| 178 | + . '/' . seconds2ntp( $row->end_time ); |
| 179 | + $mvTitle = new MV_Title( $nt, MV_NS_STREAM ); |
| 180 | + |
| 181 | + $mvStreamTitle = Title :: MakeTitle( MV_NS_STREAM, $mvTitle->getNearStreamName( $extra_range = '0' ) ); |
| 182 | + |
| 183 | + |
| 184 | + // output the image: |
| 185 | + $o .= $sk->makeKnownLinkObj( $mvStreamTitle, |
| 186 | + '<img alt="image for ' . $mvTitle->getStreamNameText() . ' ' . |
| 187 | + $mvTitle->getTimeDesc() . '" src="' . $mvTitle->getStreamImageURL( 'small' ) . |
| 188 | + '"/>', |
| 189 | + 'tl=1' ); |
| 190 | + |
| 191 | + $title_span = ''; |
| 192 | + if ( isset( $mvStream->date_start_time ) ) { |
| 193 | + $parts = split( '_', $mvStream->getStreamName() ); |
| 194 | + if ( count( $parts ) >= 3 ) { |
| 195 | + $title_span = ucfirst( $parts[0] . ' ' ); |
| 196 | + } else { |
| 197 | + $title_span = $mvStream->getStreamName(); |
| 198 | + } |
| 199 | + $title_span .= date( 'F jS, Y', $mvStream->date_start_time ); |
135 | 200 | } else { |
136 | | - if ( $this->params['format'] == 'ul_list' ) { |
137 | | - $class_attr = ( $this->params['class'] != '' ) ? ' class="' . $this->params['class'] . '"':''; |
138 | | - $o .= '<ul' . $class_attr . '>'; |
| 201 | + $title_span = $mvTitle->getStreamNameText() . $mvTitle->getTimeDesc(); |
| 202 | + } |
| 203 | + $o .= '<span class="title">' . |
| 204 | + $sk->makeKnownLinkObj( $mvStreamTitle, |
| 205 | + $title_span, |
| 206 | + 'tl=1' ) . |
| 207 | + '</span>'; |
| 208 | + // try to get metadata from anno_en first. |
| 209 | + // @@todo maybe the following metadata grabbing could be abstracted to a single function in mv_index |
| 210 | + $mvd_rows = MV_Index::getMVDInRange( |
| 211 | + $row->stream_id, |
| 212 | + $row->start_time, |
| 213 | + $row->end_time, |
| 214 | + $mvd_type = 'anno_en', |
| 215 | + $getText = true, |
| 216 | + $smw_properties = array( 'Speech_by', 'Bill', 'category' ), |
| 217 | + $options = array( 'limit' => 1 ) |
| 218 | + ); |
| 219 | + if ( count( $mvd_rows ) != 0 ) { |
| 220 | + reset( $mvd_rows ); |
| 221 | + $mvd_row = current( $mvd_rows ); |
| 222 | + // print_r($mvd_rows); |
| 223 | + // print "type of: " . gettype($mvd_row); |
| 224 | + if ( isset( $mvd_row->Speech_by ) ) { |
| 225 | + if ( trim( $mvd_row->Speech_by ) != '' ) { |
| 226 | + $ptitle = Title::MakeTitle( NS_MAIN, $mvd_row->Speech_by ); |
| 227 | + $o .= '<span class="keywords">' . |
| 228 | + $sk->makeKnownLinkObj( $ptitle, $ptitle->getText() ) . |
| 229 | + '</span>'; |
| 230 | + } |
139 | 231 | } |
140 | | - global $wgUser; |
141 | | - $sk = $wgUser->getSkin(); |
142 | | - while ( $row = $dbr->fetchObject( $result ) ) { |
143 | | - $o .= '<li>'; |
144 | | - $person_ht = $bill_ht = $category_ht = ''; |
145 | | - // first make link and stream title: |
146 | | - $mvStream = MV_Stream::newStreamByID( $row->stream_id ); |
147 | | - $nt = $mvStream->getStreamName() . '/' . seconds2ntp( $row->start_time ) |
148 | | - . '/' . seconds2ntp( $row->end_time ); |
149 | | - $mvTitle = new MV_Title( $nt, MV_NS_STREAM ); |
150 | | - |
151 | | - $mvStreamTitle = Title :: MakeTitle( MV_NS_STREAM, $mvTitle->getNearStreamName( $extra_range = '0' ) ); |
152 | | - |
153 | | - |
154 | | - // output the image: |
155 | | - $o .= $sk->makeKnownLinkObj( $mvStreamTitle, |
156 | | - '<img alt="image for ' . $mvTitle->getStreamNameText() . ' ' . |
157 | | - $mvTitle->getTimeDesc() . '" src="' . $mvTitle->getStreamImageURL( 'small' ) . |
158 | | - '"/>', |
159 | | - 'tl=1' ); |
160 | | - $title_span = ''; |
161 | | - if ( isset( $mvStream->date_start_time ) ) { |
162 | | - $parts = split( '_', $mvStream->getStreamName() ); |
163 | | - if ( count( $parts ) >= 3 ) { |
164 | | - $title_span = ucfirst( $parts[0] . ' ' ); |
165 | | - } else { |
166 | | - $title_span = $mvStream->getStreamName(); |
167 | | - } |
168 | | - $title_span .= date( 'F jS, Y', $mvStream->date_start_time ); |
169 | | - } else { |
170 | | - $title_span = $mvTitle->getStreamNameText() . $mvTitle->getTimeDesc(); |
| 232 | + if ( isset( $mvd_row->Bill ) ) { |
| 233 | + if ( trim( $mvd_row->Bill ) != '' ) { |
| 234 | + $btitle = Title::MakeTitle( NS_MAIN, $mvd_row->Bill ); |
| 235 | + $o .= '<br><span class="keywords">Bill:' . |
| 236 | + $sk->makeKnownLinkObj( $btitle ) . ' |
| 237 | + </span>'; |
171 | 238 | } |
172 | | - $o .= '<span class="title">' . |
173 | | - $sk->makeKnownLinkObj( $mvStreamTitle, |
174 | | - $title_span, |
175 | | - 'tl=1' ) . |
176 | | - '</span>'; |
177 | | - // try to get metadata from anno_en first. |
178 | | - // @@todo maybe the following metadata grabbing could be abstracted to a single function in mv_index |
179 | | - $mvd_rows = MV_Index::getMVDInRange( |
180 | | - $row->stream_id, |
181 | | - $row->start_time, |
182 | | - $row->end_time, |
183 | | - $mvd_type = 'anno_en', |
184 | | - $getText = true, |
185 | | - $smw_properties = array( 'Speech_by', 'Bill', 'category' ), |
186 | | - $options = array( 'limit' => 1 ) |
187 | | - ); |
188 | | - if ( count( $mvd_rows ) != 0 ) { |
189 | | - reset( $mvd_rows ); |
190 | | - $mvd_row = current( $mvd_rows ); |
191 | | - // print_r($mvd_rows); |
192 | | - // print "type of: " . gettype($mvd_row); |
193 | | - if ( isset( $mvd_row->Speech_by ) ) { |
194 | | - if ( trim( $mvd_row->Speech_by ) != '' ) { |
195 | | - $ptitle = Title::MakeTitle( NS_MAIN, $mvd_row->Speech_by ); |
196 | | - $o .= '<span class="keywords">' . |
197 | | - $sk->makeKnownLinkObj( $ptitle, $ptitle->getText() ) . |
198 | | - '</span>'; |
199 | | - } |
200 | | - } |
201 | | - if ( isset( $mvd_row->Bill ) ) { |
202 | | - if ( trim( $mvd_row->Bill ) != '' ) { |
203 | | - $btitle = Title::MakeTitle( NS_MAIN, $mvd_row->Bill ); |
204 | | - $o .= '<span class="keywords">Bill:' . |
205 | | - $sk->makeKnownLinkObj( $btitle ) . ' |
206 | | - </span>'; |
207 | | - } |
208 | | - } |
209 | | - global $wgContLang; |
210 | | - /*$mvdNStxt = $wgContLang->getNsText(MV_NS_MVD); |
211 | | - //grab categories: |
212 | | - $cl_res = $dbr->select('categorylinks', 'cl_to', |
213 | | - array('cl_sortkey'=>$mvdNStxt.':'.str_replace('_',' ',$mvd_row->wiki_title)), |
214 | | - 'getTopClips::Categories', |
215 | | - 'LIMIT 0, 5'); |
216 | | - if($dbr->numRows($cl_res)!=0){ |
217 | | - $o.='<span class="keywords">Categories: '; |
218 | | - $coma=''; |
219 | | - while($cl_row= $dbr->fetchObject($cl_res) ){ |
220 | | - $cTitle = Title::MakeTitle(NS_CATEGORY, $cl_row->cl_to); |
221 | | - $o.=$coma.$sk->makeKnownLinkObj($cTitle, $cTitle->getText()); |
222 | | - $coma=', '; |
223 | | - } |
224 | | - $o.='</span>'; |
225 | | - } */ |
226 | | - } |
227 | | - $o .= '</li>'; |
228 | 239 | } |
229 | | - $o .= '</ul><div style="clear:both"></div>'; |
| 240 | + global $wgContLang; |
| 241 | + $mvdNStxt = $wgContLang->getNsText(MV_NS_MVD); |
| 242 | + //grab categories: |
| 243 | + /*$cl_res = $dbr->select('categorylinks', 'cl_to', |
| 244 | + array('cl_sortkey'=>$mvdNStxt.':'.str_replace('_',' ',$mvd_row->wiki_title)), |
| 245 | + 'getTopClips::Categories', |
| 246 | + 'LIMIT 0, 5'); |
| 247 | + if($dbr->numRows($cl_res)!=0){ |
| 248 | + $o.='<span class="keywords">Categories: '; |
| 249 | + $coma=''; |
| 250 | + while($cl_row= $dbr->fetchObject($cl_res) ){ |
| 251 | + $cTitle = Title::MakeTitle(NS_CATEGORY, $cl_row->cl_to); |
| 252 | + $o.=$coma.$sk->makeKnownLinkObj($cTitle, $cTitle->getText()); |
| 253 | + $coma=', '; |
| 254 | + } |
| 255 | + $o.='</span>'; |
| 256 | + }*/ |
230 | 257 | } |
231 | 258 | return $o; |
232 | 259 | } |
| 260 | + function formatOutputItems($outItems){ |
| 261 | + $class_attr = ( $this->params['class'] != '' ) ? ' class="' . htmlspecialchars($this->params['class']) . '"':''; |
| 262 | + if ( $this->params['format'] == 'ul_list' ) { |
| 263 | + $o .= '<ul' . $class_attr . '>'; |
| 264 | + foreach($outItems as $item){ |
| 265 | + $o.='<li>'.$item.'</li>'; |
| 266 | + } |
| 267 | + $o .= '</ul>'; |
| 268 | + } |
| 269 | + if( $this->params['format'] == 'table' ){ |
| 270 | + $width = (isset($this->params['width']))?$this->params['width']:800; |
| 271 | + $o .= '<table '.$class_attr .'>'; |
| 272 | + $col = (isset($this->params['columns']))?$this->params['columns']:4; |
| 273 | + $j=0; |
| 274 | + foreach($outItems as $item){ |
| 275 | + if( $j == 0 ) |
| 276 | + $o.='<tr>'; |
| 277 | + $o.='<td valign="top" style="text-align:center" width="'.intval( $width / $col ) . '">' . $item . '</td>'; |
| 278 | + if($j == $col-1){ |
| 279 | + $o.= '</tr>'; |
| 280 | + $j = 0; |
| 281 | + }else{ |
| 282 | + $j++; |
| 283 | + } |
| 284 | + } |
| 285 | + $o.='</table>'; |
| 286 | + } |
| 287 | + $o.='<div style="clear:both"></div>'; |
| 288 | + return $o; |
| 289 | + } |
233 | 290 | // get the top few search results this is a ~slow~ query ... |
234 | 291 | // @@todo we should only run it every 2 hours or something.. |
235 | 292 | function getTopSearches() { |