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