Merge "MessageCache::destroyInstance() is static."
[lhc/web/wiklou.git] / includes / QueryPage.php
1 <?php
2 /**
3 * Base code for "query" special pages.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * List of query page classes and their associated special pages,
26 * for periodic updates.
27 *
28 * DO NOT CHANGE THIS LIST without testing that
29 * maintenance/updateSpecialPages.php still works.
30 */
31 global $wgQueryPages; // not redundant
32 $wgQueryPages = array(
33 // QueryPage subclass Special page name Limit (false for none, none for the default)
34 // ----------------------------------------------------------------------------
35 array( 'AncientPagesPage', 'Ancientpages' ),
36 array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
37 array( 'DeadendPagesPage', 'Deadendpages' ),
38 array( 'DisambiguationsPage', 'Disambiguations' ),
39 array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
40 array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
41 array( 'LinkSearchPage', 'LinkSearch' ),
42 array( 'ListredirectsPage', 'Listredirects' ),
43 array( 'LonelyPagesPage', 'Lonelypages' ),
44 array( 'LongPagesPage', 'Longpages' ),
45 array( 'MIMEsearchPage', 'MIMEsearch' ),
46 array( 'MostcategoriesPage', 'Mostcategories' ),
47 array( 'MostimagesPage', 'Mostimages' ),
48 array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
49 array( 'MostlinkedtemplatesPage', 'Mostlinkedtemplates' ),
50 array( 'MostlinkedPage', 'Mostlinked' ),
51 array( 'MostrevisionsPage', 'Mostrevisions' ),
52 array( 'FewestrevisionsPage', 'Fewestrevisions' ),
53 array( 'ShortPagesPage', 'Shortpages' ),
54 array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
55 array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
56 array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
57 array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
58 array( 'UnusedCategoriesPage', 'Unusedcategories' ),
59 array( 'UnusedimagesPage', 'Unusedimages' ),
60 array( 'WantedCategoriesPage', 'Wantedcategories' ),
61 array( 'WantedFilesPage', 'Wantedfiles' ),
62 array( 'WantedPagesPage', 'Wantedpages' ),
63 array( 'WantedTemplatesPage', 'Wantedtemplates' ),
64 array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
65 array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
66 array( 'WithoutInterwikiPage', 'Withoutinterwiki' ),
67 );
68 wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
69
70 global $wgDisableCounters;
71 if ( !$wgDisableCounters )
72 $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
73
74
75 /**
76 * This is a class for doing query pages; since they're almost all the same,
77 * we factor out some of the functionality into a superclass, and let
78 * subclasses derive from it.
79 * @ingroup SpecialPage
80 */
81 abstract class QueryPage extends SpecialPage {
82 /**
83 * Whether or not we want plain listoutput rather than an ordered list
84 *
85 * @var bool
86 */
87 var $listoutput = false;
88
89 /**
90 * The offset and limit in use, as passed to the query() function
91 *
92 * @var integer
93 */
94 var $offset = 0;
95 var $limit = 0;
96
97 /**
98 * The number of rows returned by the query. Reading this variable
99 * only makes sense in functions that are run after the query has been
100 * done, such as preprocessResults() and formatRow().
101 */
102 protected $numRows;
103
104 protected $cachedTimestamp = null;
105
106 /**
107 * Wheter to show prev/next links
108 */
109 protected $shownavigation = true;
110
111 /**
112 * A mutator for $this->listoutput;
113 *
114 * @param $bool Boolean
115 */
116 function setListoutput( $bool ) {
117 $this->listoutput = $bool;
118 }
119
120 /**
121 * Subclasses return an SQL query here, formatted as an array with the
122 * following keys:
123 * tables => Table(s) for passing to Database::select()
124 * fields => Field(s) for passing to Database::select(), may be *
125 * conds => WHERE conditions
126 * options => options
127 * join_conds => JOIN conditions
128 *
129 * Note that the query itself should return the following three columns:
130 * 'namespace', 'title', and 'value'. 'value' is used for sorting.
131 *
132 * These may be stored in the querycache table for expensive queries,
133 * and that cached data will be returned sometimes, so the presence of
134 * extra fields can't be relied upon. The cached 'value' column will be
135 * an integer; non-numeric values are useful only for sorting the
136 * initial query (except if they're timestamps, see usesTimestamps()).
137 *
138 * Don't include an ORDER or LIMIT clause, they will be added.
139 *
140 * If this function is not overridden or returns something other than
141 * an array, getSQL() will be used instead. This is for backwards
142 * compatibility only and is strongly deprecated.
143 * @return array
144 * @since 1.18
145 */
146 function getQueryInfo() {
147 return null;
148 }
149
150 /**
151 * For back-compat, subclasses may return a raw SQL query here, as a string.
152 * This is stronly deprecated; getQueryInfo() should be overridden instead.
153 * @return string
154 */
155 function getSQL() {
156 /* Implement getQueryInfo() instead */
157 throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor getQuery() properly" );
158 }
159
160 /**
161 * Subclasses return an array of fields to order by here. Don't append
162 * DESC to the field names, that'll be done automatically if
163 * sortDescending() returns true.
164 * @return array
165 * @since 1.18
166 */
167 function getOrderFields() {
168 return array( 'value' );
169 }
170
171 /**
172 * Does this query return timestamps rather than integers in its
173 * 'value' field? If true, this class will convert 'value' to a
174 * UNIX timestamp for caching.
175 * NOTE: formatRow() may get timestamps in TS_MW (mysql), TS_DB (pgsql)
176 * or TS_UNIX (querycache) format, so be sure to always run them
177 * through wfTimestamp()
178 * @return bool
179 * @since 1.18
180 */
181 function usesTimestamps() {
182 return false;
183 }
184
185 /**
186 * Override to sort by increasing values
187 *
188 * @return Boolean
189 */
190 function sortDescending() {
191 return true;
192 }
193
194 /**
195 * Is this query expensive (for some definition of expensive)? Then we
196 * don't let it run in miser mode. $wgDisableQueryPages causes all query
197 * pages to be declared expensive. Some query pages are always expensive.
198 *
199 * @return Boolean
200 */
201 function isExpensive() {
202 global $wgDisableQueryPages;
203 return $wgDisableQueryPages;
204 }
205
206 /**
207 * Is the output of this query cacheable? Non-cacheable expensive pages
208 * will be disabled in miser mode and will not have their results written
209 * to the querycache table.
210 * @return Boolean
211 * @since 1.18
212 */
213 public function isCacheable() {
214 return true;
215 }
216
217 /**
218 * Whether or not the output of the page in question is retrieved from
219 * the database cache.
220 *
221 * @return Boolean
222 */
223 function isCached() {
224 global $wgMiserMode;
225
226 return $this->isExpensive() && $wgMiserMode;
227 }
228
229 /**
230 * Sometime we dont want to build rss / atom feeds.
231 *
232 * @return Boolean
233 */
234 function isSyndicated() {
235 return true;
236 }
237
238 /**
239 * Formats the results of the query for display. The skin is the current
240 * skin; you can use it for making links. The result is a single row of
241 * result data. You should be able to grab SQL results off of it.
242 * If the function returns false, the line output will be skipped.
243 * @param $skin Skin
244 * @param $result object Result row
245 * @return mixed String or false to skip
246 *
247 * @param $skin Skin object
248 * @param $result Object: database row
249 */
250 abstract function formatResult( $skin, $result );
251
252 /**
253 * The content returned by this function will be output before any result
254 *
255 * @return String
256 */
257 function getPageHeader() {
258 return '';
259 }
260
261 /**
262 * If using extra form wheely-dealies, return a set of parameters here
263 * as an associative array. They will be encoded and added to the paging
264 * links (prev/next/lengths).
265 *
266 * @return Array
267 */
268 function linkParameters() {
269 return array();
270 }
271
272 /**
273 * Some special pages (for example SpecialListusers) might not return the
274 * current object formatted, but return the previous one instead.
275 * Setting this to return true will ensure formatResult() is called
276 * one more time to make sure that the very last result is formatted
277 * as well.
278 * @return bool
279 */
280 function tryLastResult() {
281 return false;
282 }
283
284 /**
285 * Clear the cache and save new results
286 *
287 * @param $limit Integer: limit for SQL statement
288 * @param $ignoreErrors Boolean: whether to ignore database errors
289 * @return bool|int
290 */
291 function recache( $limit, $ignoreErrors = true ) {
292 if ( !$this->isCacheable() ) {
293 return 0;
294 }
295
296 $fname = get_class( $this ) . '::recache';
297 $dbw = wfGetDB( DB_MASTER );
298 $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, 'vslow' ) );
299 if ( !$dbw || !$dbr ) {
300 return false;
301 }
302
303 if ( $ignoreErrors ) {
304 $ignoreW = $dbw->ignoreErrors( true );
305 $ignoreR = $dbr->ignoreErrors( true );
306 }
307
308 # Clear out any old cached data
309 $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
310 # Do query
311 $res = $this->reallyDoQuery( $limit, false );
312 $num = false;
313 if ( $res ) {
314 $num = $res->numRows();
315 # Fetch results
316 $vals = array();
317 while ( $res && $row = $dbr->fetchObject( $res ) ) {
318 if ( isset( $row->value ) ) {
319 if ( $this->usesTimestamps() ) {
320 $value = wfTimestamp( TS_UNIX,
321 $row->value );
322 } else {
323 $value = intval( $row->value ); // @bug 14414
324 }
325 } else {
326 $value = 0;
327 }
328
329 $vals[] = array( 'qc_type' => $this->getName(),
330 'qc_namespace' => $row->namespace,
331 'qc_title' => $row->title,
332 'qc_value' => $value );
333 }
334
335 # Save results into the querycache table on the master
336 if ( count( $vals ) ) {
337 if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) ) {
338 // Set result to false to indicate error
339 $num = false;
340 }
341 }
342 if ( $ignoreErrors ) {
343 $dbw->ignoreErrors( $ignoreW );
344 $dbr->ignoreErrors( $ignoreR );
345 }
346
347 # Update the querycache_info record for the page
348 $dbw->delete( 'querycache_info', array( 'qci_type' => $this->getName() ), $fname );
349 $dbw->insert( 'querycache_info', array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ), $fname );
350
351 }
352 return $num;
353 }
354
355 /**
356 * Run the query and return the result
357 * @param $limit mixed Numerical limit or false for no limit
358 * @param $offset mixed Numerical offset or false for no offset
359 * @return ResultWrapper
360 * @since 1.18
361 */
362 function reallyDoQuery( $limit, $offset = false ) {
363 $fname = get_class( $this ) . "::reallyDoQuery";
364 $dbr = wfGetDB( DB_SLAVE );
365 $query = $this->getQueryInfo();
366 $order = $this->getOrderFields();
367 if ( $this->sortDescending() ) {
368 foreach ( $order as &$field ) {
369 $field .= ' DESC';
370 }
371 }
372 if ( is_array( $query ) ) {
373 $tables = isset( $query['tables'] ) ? (array)$query['tables'] : array();
374 $fields = isset( $query['fields'] ) ? (array)$query['fields'] : array();
375 $conds = isset( $query['conds'] ) ? (array)$query['conds'] : array();
376 $options = isset( $query['options'] ) ? (array)$query['options'] : array();
377 $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : array();
378 if ( count( $order ) ) {
379 $options['ORDER BY'] = $order;
380 }
381 if ( $limit !== false ) {
382 $options['LIMIT'] = intval( $limit );
383 }
384 if ( $offset !== false ) {
385 $options['OFFSET'] = intval( $offset );
386 }
387
388 $res = $dbr->select( $tables, $fields, $conds, $fname,
389 $options, $join_conds
390 );
391 } else {
392 // Old-fashioned raw SQL style, deprecated
393 $sql = $this->getSQL();
394 $sql .= ' ORDER BY ' . implode( ', ', $order );
395 $sql = $dbr->limitResult( $sql, $limit, $offset );
396 $res = $dbr->query( $sql, $fname );
397 }
398 return $dbr->resultObject( $res );
399 }
400
401 /**
402 * Somewhat deprecated, you probably want to be using execute()
403 * @return ResultWrapper
404 */
405 function doQuery( $offset = false, $limit = false ) {
406 if ( $this->isCached() && $this->isCacheable() ) {
407 return $this->fetchFromCache( $limit, $offset );
408 } else {
409 return $this->reallyDoQuery( $limit, $offset );
410 }
411 }
412
413 /**
414 * Fetch the query results from the query cache
415 * @param $limit mixed Numerical limit or false for no limit
416 * @param $offset mixed Numerical offset or false for no offset
417 * @return ResultWrapper
418 * @since 1.18
419 */
420 function fetchFromCache( $limit, $offset = false ) {
421 $dbr = wfGetDB( DB_SLAVE );
422 $options = array ();
423 if ( $limit !== false ) {
424 $options['LIMIT'] = intval( $limit );
425 }
426 if ( $offset !== false ) {
427 $options['OFFSET'] = intval( $offset );
428 }
429 if ( $this->sortDescending() ) {
430 $options['ORDER BY'] = 'qc_value DESC';
431 } else {
432 $options['ORDER BY'] = 'qc_value ASC';
433 }
434 $res = $dbr->select( 'querycache', array( 'qc_type',
435 'namespace' => 'qc_namespace',
436 'title' => 'qc_title',
437 'value' => 'qc_value' ),
438 array( 'qc_type' => $this->getName() ),
439 __METHOD__, $options
440 );
441 return $dbr->resultObject( $res );
442 }
443
444 public function getCachedTimestamp() {
445 if ( is_null( $this->cachedTimestamp ) ) {
446 $dbr = wfGetDB( DB_SLAVE );
447 $fname = get_class( $this ) . '::getCachedTimestamp';
448 $this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
449 array( 'qci_type' => $this->getName() ), $fname );
450 }
451 return $this->cachedTimestamp;
452 }
453
454 /**
455 * This is the actual workhorse. It does everything needed to make a
456 * real, honest-to-gosh query page.
457 * @return int
458 */
459 function execute( $par ) {
460 global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
461
462 $user = $this->getUser();
463 if ( !$this->userCanExecute( $user ) ) {
464 $this->displayRestrictionError();
465 return;
466 }
467
468 $this->setHeaders();
469 $this->outputHeader();
470
471 $out = $this->getOutput();
472
473 if ( $this->isCached() && !$this->isCacheable() ) {
474 $out->addWikiMsg( 'querypage-disabled' );
475 return 0;
476 }
477
478 $out->setSyndicated( $this->isSyndicated() );
479
480 if ( $this->limit == 0 && $this->offset == 0 ) {
481 list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset();
482 }
483
484 // TODO: Use doQuery()
485 if ( !$this->isCached() ) {
486 # select one extra row for navigation
487 $res = $this->reallyDoQuery( $this->limit + 1, $this->offset );
488 } else {
489 # Get the cached result, select one extra row for navigation
490 $res = $this->fetchFromCache( $this->limit + 1, $this->offset );
491 if ( !$this->listoutput ) {
492
493 # Fetch the timestamp of this update
494 $ts = $this->getCachedTimestamp();
495 $lang = $this->getLanguage();
496 $maxResults = $lang->formatNum( $wgQueryCacheLimit );
497
498 if ( $ts ) {
499 $updated = $lang->userTimeAndDate( $ts, $user );
500 $updateddate = $lang->userDate( $ts, $user );
501 $updatedtime = $lang->userTime( $ts, $user );
502 $out->addMeta( 'Data-Cache-Time', $ts );
503 $out->addJsConfigVars( 'dataCacheTime', $ts );
504 $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime, $maxResults );
505 } else {
506 $out->addWikiMsg( 'perfcached', $maxResults );
507 }
508
509 # If updates on this page have been disabled, let the user know
510 # that the data set won't be refreshed for now
511 if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
512 $out->wrapWikiMsg( "<div class=\"mw-querypage-no-updates\">\n$1\n</div>", 'querypage-no-updates' );
513 }
514 }
515 }
516
517 $this->numRows = $res->numRows();
518
519 $dbr = wfGetDB( DB_SLAVE );
520 $this->preprocessResults( $dbr, $res );
521
522 $out->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) );
523
524 # Top header and navigation
525 if ( $this->shownavigation ) {
526 $out->addHTML( $this->getPageHeader() );
527 if ( $this->numRows > 0 ) {
528 $out->addHTML( $this->msg( 'showingresults' )->numParams(
529 min( $this->numRows, $this->limit ), # do not show the one extra row, if exist
530 $this->offset + 1 )->parseAsBlock() );
531 # Disable the "next" link when we reach the end
532 $paging = $this->getLanguage()->viewPrevNext( $this->getTitle( $par ), $this->offset,
533 $this->limit, $this->linkParameters(), ( $this->numRows <= $this->limit ) );
534 $out->addHTML( '<p>' . $paging . '</p>' );
535 } else {
536 # No results to show, so don't bother with "showing X of Y" etc.
537 # -- just let the user know and give up now
538 $out->addWikiMsg( 'specialpage-empty' );
539 $out->addHTML( Xml::closeElement( 'div' ) );
540 return;
541 }
542 }
543
544 # The actual results; specialist subclasses will want to handle this
545 # with more than a straight list, so we hand them the info, plus
546 # an OutputPage, and let them get on with it
547 $this->outputResults( $out,
548 $this->getSkin(),
549 $dbr, # Should use a ResultWrapper for this
550 $res,
551 min( $this->numRows, $this->limit ), # do not format the one extra row, if exist
552 $this->offset );
553
554 # Repeat the paging links at the bottom
555 if ( $this->shownavigation ) {
556 $out->addHTML( '<p>' . $paging . '</p>' );
557 }
558
559 $out->addHTML( Xml::closeElement( 'div' ) );
560
561 return min( $this->numRows, $this->limit ); # do not return the one extra row, if exist
562 }
563
564 /**
565 * Format and output report results using the given information plus
566 * OutputPage
567 *
568 * @param $out OutputPage to print to
569 * @param $skin Skin: user skin to use
570 * @param $dbr Database (read) connection to use
571 * @param $res Integer: result pointer
572 * @param $num Integer: number of available result rows
573 * @param $offset Integer: paging offset
574 */
575 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
576 global $wgContLang;
577
578 if ( $num > 0 ) {
579 $html = array();
580 if ( !$this->listoutput ) {
581 $html[] = $this->openList( $offset );
582 }
583
584 # $res might contain the whole 1,000 rows, so we read up to
585 # $num [should update this to use a Pager]
586 for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
587 $line = $this->formatResult( $skin, $row );
588 if ( $line ) {
589 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
590 ? ' class="not-patrolled"'
591 : '';
592 $html[] = $this->listoutput
593 ? $line
594 : "<li{$attr}>{$line}</li>\n";
595 }
596 }
597
598 # Flush the final result
599 if ( $this->tryLastResult() ) {
600 $row = null;
601 $line = $this->formatResult( $skin, $row );
602 if ( $line ) {
603 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
604 ? ' class="not-patrolled"'
605 : '';
606 $html[] = $this->listoutput
607 ? $line
608 : "<li{$attr}>{$line}</li>\n";
609 }
610 }
611
612 if ( !$this->listoutput ) {
613 $html[] = $this->closeList();
614 }
615
616 $html = $this->listoutput
617 ? $wgContLang->listToText( $html )
618 : implode( '', $html );
619
620 $out->addHTML( $html );
621 }
622 }
623
624 /**
625 * @param $offset
626 * @return string
627 */
628 function openList( $offset ) {
629 return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n";
630 }
631
632 /**
633 * @return string
634 */
635 function closeList() {
636 return "</ol>\n";
637 }
638
639 /**
640 * Do any necessary preprocessing of the result object.
641 */
642 function preprocessResults( $db, $res ) {}
643
644 /**
645 * Similar to above, but packaging in a syndicated feed instead of a web page
646 * @return bool
647 */
648 function doFeed( $class = '', $limit = 50 ) {
649 global $wgFeed, $wgFeedClasses;
650
651 if ( !$wgFeed ) {
652 $this->getOutput()->addWikiMsg( 'feed-unavailable' );
653 return;
654 }
655
656 global $wgFeedLimit;
657 if ( $limit > $wgFeedLimit ) {
658 $limit = $wgFeedLimit;
659 }
660
661 if ( isset( $wgFeedClasses[$class] ) ) {
662 $feed = new $wgFeedClasses[$class](
663 $this->feedTitle(),
664 $this->feedDesc(),
665 $this->feedUrl() );
666 $feed->outHeader();
667
668 $res = $this->reallyDoQuery( $limit, 0 );
669 foreach ( $res as $obj ) {
670 $item = $this->feedResult( $obj );
671 if ( $item ) {
672 $feed->outItem( $item );
673 }
674 }
675
676 $feed->outFooter();
677 return true;
678 } else {
679 return false;
680 }
681 }
682
683 /**
684 * Override for custom handling. If the titles/links are ok, just do
685 * feedItemDesc()
686 * @return FeedItem|null
687 */
688 function feedResult( $row ) {
689 if ( !isset( $row->title ) ) {
690 return null;
691 }
692 $title = Title::makeTitle( intval( $row->namespace ), $row->title );
693 if ( $title ) {
694 $date = isset( $row->timestamp ) ? $row->timestamp : '';
695 $comments = '';
696 if ( $title ) {
697 $talkpage = $title->getTalkPage();
698 $comments = $talkpage->getFullURL();
699 }
700
701 return new FeedItem(
702 $title->getPrefixedText(),
703 $this->feedItemDesc( $row ),
704 $title->getFullURL(),
705 $date,
706 $this->feedItemAuthor( $row ),
707 $comments );
708 } else {
709 return null;
710 }
711 }
712
713 function feedItemDesc( $row ) {
714 return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
715 }
716
717 function feedItemAuthor( $row ) {
718 return isset( $row->user_text ) ? $row->user_text : '';
719 }
720
721 function feedTitle() {
722 global $wgLanguageCode, $wgSitename;
723 $desc = $this->getDescription();
724 return "$wgSitename - $desc [$wgLanguageCode]";
725 }
726
727 function feedDesc() {
728 return $this->msg( 'tagline' )->text();
729 }
730
731 function feedUrl() {
732 return $this->getTitle()->getFullURL();
733 }
734 }
735
736 /**
737 * Class definition for a wanted query page like
738 * WantedPages, WantedTemplates, etc
739 */
740 abstract class WantedQueryPage extends QueryPage {
741
742 function isExpensive() {
743 return true;
744 }
745
746 function isSyndicated() {
747 return false;
748 }
749
750 /**
751 * Cache page existence for performance
752 */
753 function preprocessResults( $db, $res ) {
754 if ( !$res->numRows() ) {
755 return;
756 }
757
758 $batch = new LinkBatch;
759 foreach ( $res as $row ) {
760 $batch->add( $row->namespace, $row->title );
761 }
762 $batch->execute();
763
764 // Back to start for display
765 $res->seek( 0 );
766 }
767
768 /**
769 * Should formatResult() always check page existence, even if
770 * the results are fresh? This is a (hopefully temporary)
771 * kluge for Special:WantedFiles, which may contain false
772 * positives for files that exist e.g. in a shared repo (bug
773 * 6220).
774 * @return bool
775 */
776 function forceExistenceCheck() {
777 return false;
778 }
779
780 /**
781 * Format an individual result
782 *
783 * @param $skin Skin to use for UI elements
784 * @param $result Result row
785 * @return string
786 */
787 public function formatResult( $skin, $result ) {
788 $title = Title::makeTitleSafe( $result->namespace, $result->title );
789 if ( $title instanceof Title ) {
790 if ( $this->isCached() || $this->forceExistenceCheck() ) {
791 $pageLink = $title->isKnown()
792 ? '<del>' . Linker::link( $title ) . '</del>'
793 : Linker::link(
794 $title,
795 null,
796 array(),
797 array(),
798 array( 'broken' )
799 );
800 } else {
801 $pageLink = Linker::link(
802 $title,
803 null,
804 array(),
805 array(),
806 array( 'broken' )
807 );
808 }
809 return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
810 } else {
811 return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
812 }
813 }
814
815 /**
816 * Make a "what links here" link for a given title
817 *
818 * @param $title Title to make the link for
819 * @param $result Object: result row
820 * @return string
821 */
822 private function makeWlhLink( $title, $result ) {
823 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
824 $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
825 return Linker::link( $wlh, $label );
826 }
827 }