Index: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php |
— | — | @@ -103,18 +103,15 @@ |
104 | 104 | $wgSitename |
105 | 105 | ); |
106 | 106 | |
107 | | - $feed->outHeader(); |
108 | | - |
109 | | - $dbr = wfGetDB( DB_SLAVE ); |
110 | | - $sql = $this->dpl_buildSQL(); |
| 107 | + $res = $this->doQuery(); |
111 | 108 | // Debug line |
112 | 109 | // echo "\n<p>$sql</p>\n"; |
113 | | - $res = $dbr->query ( $sql ); |
114 | 110 | |
115 | 111 | // FIXME: figure out how to fail with no results gracefully |
116 | | - if ( $dbr->numRows( $res ) == 0 ) { |
| 112 | + if ( $res->numRows( $res ) == 0 ) { |
117 | 113 | $feed->outFooter(); |
118 | 114 | if ( false == $this->params['suppressErrors'] ) { |
| 115 | + $wgOut->disable(); |
119 | 116 | echo htmlspecialchars( wfMsg( 'googlenewssitemap_noresults' ) ); |
120 | 117 | return; |
121 | 118 | } else { |
— | — | @@ -122,7 +119,8 @@ |
123 | 120 | } |
124 | 121 | } |
125 | 122 | |
126 | | - foreach ( $res as $row ) { |
| 123 | + $feed->outHeader(); |
| 124 | + while ( $row = $res->fetchObject( $res ) ) { |
127 | 125 | $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
128 | 126 | |
129 | 127 | if ( !$title ) { |
— | — | @@ -130,7 +128,7 @@ |
131 | 129 | return; |
132 | 130 | } |
133 | 131 | |
134 | | - //$titleText = ( $this->params['nameSpace'] ) ? $title->getPrefixedText() : $title->getText(); |
| 132 | + $titleText = ( true == $this->params['nameSpace'] ) ? $title->getPrefixedText() : $title->getText(); |
135 | 133 | |
136 | 134 | if ( 'sitemap' == $this->params['feed'] ) { |
137 | 135 | |
— | — | @@ -171,64 +169,71 @@ |
172 | 170 | /** |
173 | 171 | * Build sql |
174 | 172 | **/ |
175 | | - public function dpl_buildSQL() { |
| 173 | + public function doQuery() { |
176 | 174 | |
177 | | - $sqlSelectFrom = 'SELECT page_namespace, page_title, page_id, c1.cl_timestamp FROM ' . $this->params['dbr']->tableName( 'page' ); |
| 175 | + $dbr = wfGetDB( DB_SLAVE ); |
178 | 176 | |
| 177 | + $tables[]=$dbr->tableName( 'page' ); |
| 178 | + |
| 179 | + //this is a little hacky, c1 is dynamically defined as the first category |
| 180 | + //so this can't ever work with uncategorized articles |
| 181 | + $fields = array('page_namespace', 'page_title', 'page_id', 'c1.cl_timestamp'); |
| 182 | + |
179 | 183 | if ( $this->params['nameSpace'] ) { |
180 | | - $sqlWhere = ' WHERE page_namespace=' . $this->params['nameSpace'] . ' '; |
181 | | - } else { |
182 | | - $sqlWhere = ' WHERE 1=1 '; |
| 184 | + $conditions['page_namespace'] = $this->params['nameSpace']; |
183 | 185 | } |
184 | 186 | |
185 | 187 | // If flagged revisions is in use, check which options selected. |
186 | | - // FIXME: double check the default options in function::dpl_parm; what should it default to? |
| 188 | + // FIXME: double check the default options; what should it default to? |
187 | 189 | if ( function_exists( 'efLoadFlaggedRevs' ) ) { |
188 | | - $flaggedPages = $this->params['dbr']->tableName( 'flaggedpages' ); |
| 190 | + $flaggedPages = $dbr->tableName( 'flaggedpages' ); |
189 | 191 | $filterSet = array( 'only', 'exclude' ); |
190 | 192 | # Either involves the same JOIN here... |
191 | 193 | if ( in_array( $this->params['stable'], $filterSet ) || in_array( $this->params['quality'], $filterSet ) ) { |
192 | | - $sqlSelectFrom .= " LEFT JOIN $flaggedPages ON page_id = fp_page_id"; |
| 194 | + $joins['flaggedpages'] = Array( 'LEFT JOIN', 'page_id = fp_page_id' ); |
193 | 195 | } |
194 | 196 | switch( $this->params['stable'] ) { |
195 | 197 | case 'only': |
196 | | - $sqlWhere .= ' AND fp_stable IS NOT NULL '; |
| 198 | + $conditions[]='fp_stable IS NOT NULL '; |
197 | 199 | break; |
198 | 200 | case 'exclude': |
199 | | - $sqlWhere .= ' AND fp_stable IS NULL '; |
| 201 | + $conditions['fp_stable'] = null; |
200 | 202 | break; |
201 | 203 | } |
202 | 204 | switch( $this->params['quality'] ) { |
203 | 205 | case 'only': |
204 | | - $sqlWhere .= ' AND fp_quality >= 1'; |
| 206 | + $conditions[]='fp_quality >= 1'; |
205 | 207 | break; |
206 | 208 | case 'exclude': |
207 | | - $sqlWhere .= ' AND fp_quality = 0'; |
| 209 | + $conditions['fp_quality'] = 0; |
208 | 210 | break; |
209 | 211 | } |
210 | 212 | } |
211 | 213 | |
212 | 214 | switch ( $this->params['redirects'] ) { |
213 | 215 | case 'only': |
214 | | - $sqlWhere .= ' AND page_is_redirect = 1 '; |
215 | | - break; |
| 216 | + $conditions['page_is_redirect'] = 1; |
| 217 | + break; |
216 | 218 | case 'exclude': |
217 | | - $sqlWhere .= ' AND page_is_redirect = 0 '; |
218 | | - break; |
| 219 | + $conditions['page_is_redirect'] = 0; |
| 220 | + break; |
219 | 221 | } |
220 | 222 | |
221 | | - $currentTableNumber = 0; |
222 | | - |
223 | | - for ( $i = 0; $i < $this->params['catCount']; $i++ ) { |
224 | | - $sqlSelectFrom .= ' INNER JOIN ' . $this->params['dbr']->tableName( 'categorylinks' ); |
225 | | - $sqlSelectFrom .= ' AS c' . ( $currentTableNumber + 1 ) . ' ON page_id = c'; |
226 | | - $sqlSelectFrom .= ( $currentTableNumber + 1 ) . '.cl_from AND c' . ( $currentTableNumber + 1 ); |
227 | | - |
228 | | - $sqlSelectFrom .= '.cl_to=' . $this->params['dbr']->addQuotes( $this->categories[$i]->getDBkey() ); |
229 | | - |
| 223 | + $currentTableNumber = 1; |
| 224 | + $categorylinks = $dbr->tableName( 'categorylinks' ); |
| 225 | + for ($i = 0; $i < $this->params['catCount']; $i++) { |
| 226 | + $joins["$categorylinks AS c$currentTableNumber"] = Array( 'INNER JOIN', |
| 227 | + Array( "page_id = c{$currentTableNumber}.cl_from", |
| 228 | + "c{$currentTableNumber}.cl_to={$dbr->addQuotes($this->categories[$i]->getDBKey())}" |
| 229 | + ) |
| 230 | + ); |
| 231 | + $tables[] = "$categorylinks AS c$currentTableNumber"; |
230 | 232 | $currentTableNumber++; |
231 | 233 | } |
| 234 | + |
232 | 235 | |
| 236 | + //exclusion categories disabled pending discussion on whether they are necessary |
| 237 | + /* |
233 | 238 | for ( $i = 0; $i < $this->params['notCatCount']; $i++ ) { |
234 | 239 | // echo "notCategory parameter $i<br />\n"; |
235 | 240 | $sqlSelectFrom .= ' LEFT OUTER JOIN ' . $this->params['dbr']->tableName( 'categorylinks' ); |
— | — | @@ -236,45 +241,43 @@ |
237 | 242 | $sqlSelectFrom .= '.cl_from AND c' . ( $currentTableNumber + 1 ); |
238 | 243 | $sqlSelectFrom .= '.cl_to=' . $this->params['dbr']->addQuotes( $this->notCategories[$i]->getDBkey() ); |
239 | 244 | |
240 | | - $sqlWhere .= ' AND c' . ( $currentTableNumber + 1 ) . '.cl_to IS NULL'; |
| 245 | + $conditions .= ' AND c' . ( $currentTableNumber + 1 ) . '.cl_to IS NULL'; |
241 | 246 | |
242 | 247 | $currentTableNumber++; |
243 | 248 | } |
| 249 | + */ |
244 | 250 | |
245 | | - if ( 'lastedit' == $this->params['orderMethod'] ) { |
246 | | - $sqlWhere .= ' ORDER BY page_touched '; |
| 251 | + if ( 'descending' == $this->params['order'] ) { |
| 252 | + $sortOrder = 'DESC'; |
247 | 253 | } else { |
248 | | - $sqlWhere .= ' ORDER BY c1.cl_timestamp '; |
| 254 | + $sortOrder = 'ASC'; |
249 | 255 | } |
250 | 256 | |
251 | | - if ( 'descending' == $this->params['order'] ) { |
252 | | - $sqlWhere .= 'DESC'; |
| 257 | + if ( 'lastedit' == $this->params['orderMethod'] ) { |
| 258 | + $options['ORDER BY'] = 'page_touched ' . $sortOrder; |
253 | 259 | } else { |
254 | | - $sqlWhere .= 'ASC'; |
| 260 | + $options['ORDER BY'] = 'c1.cl_timestamp ' . $sortOrder; |
255 | 261 | } |
256 | 262 | |
257 | | - // FIXME: Note: this is not a boolean type check - will also trap count = 0 which may |
258 | | - // accidentally give unlimited returns |
259 | | - if ( 0 < $this->params['count'] ) { |
260 | | - $sqlWhere .= ' LIMIT ' . $this->params['count']; |
261 | | - } |
262 | 263 | |
263 | | - // debug line |
264 | | - // echo "<p>$sqlSelectFrom$sqlWhere;</p>\n"; |
| 264 | + //earlier validation logic ensures this is a reasonable number |
| 265 | + $options['LIMIT'] = $this->params['count']; |
265 | 266 | |
266 | | - return $sqlSelectFrom . $sqlWhere; |
| 267 | + //return $dbr->query( $sqlSelectFrom . $conditions ); |
| 268 | + return $dbr->select ( $tables, $fields, $conditions, '', $options, $joins); |
267 | 269 | } // end buildSQL |
268 | 270 | |
269 | 271 | /** |
270 | 272 | * Parse parameters, populates $this->params |
271 | 273 | **/ |
272 | 274 | public function unload_params() { |
273 | | - global $wgContLang, $wgRequest; |
| 275 | + global $wgContLang; |
| 276 | + global $wgRequest; |
274 | 277 | |
275 | 278 | $this->params = array(); |
276 | | - //$parser = new Parser; |
277 | | - //$poptions = new ParserOptions; |
278 | | - //$category = $wgRequest->getArray( 'category', 'Published' ); |
| 279 | + $parser = new Parser; |
| 280 | + $poptions = new ParserOptions; |
| 281 | + $category = $wgRequest->getArray( 'category', 'Published' ); |
279 | 282 | // $title = Title::newFromText( $parser->transformMsg( $category, $poptions ) ); |
280 | 283 | // if ( is_object( $title ) ){ |
281 | 284 | // $this->categories[] = $title; |
— | — | @@ -341,8 +344,8 @@ |
342 | 345 | $cats = $title->getParentCategories(); |
343 | 346 | $str = ''; |
344 | 347 | # the following code is based (stolen) from r56954 of flagged revs. |
345 | | - $catMap = array(); |
346 | | - $catMask = array(); |
| 348 | + $catMap = Array(); |
| 349 | + $catMask = Array(); |
347 | 350 | $msg = wfMsg( 'googlenewssitemap_categorymap' ); |
348 | 351 | if ( !wfEmptyMsg( 'googlenewssitemap_categorymap', $msg ) ) { |
349 | 352 | $list = explode( "\n*", "\n$msg" ); |