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