We need to select the namespace, even hardcoded, this is causing: Notice: Undefined...
[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 var $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 $fname = get_class( $this ) . '::recache';
274 $dbw = wfGetDB( DB_MASTER );
275 $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, 'vslow' ) );
276 if ( !$dbw || !$dbr || !$this->isCacheable() ) {
277 return false;
278 }
279
280 if ( $ignoreErrors ) {
281 $ignoreW = $dbw->ignoreErrors( true );
282 $ignoreR = $dbr->ignoreErrors( true );
283 }
284
285 # Clear out any old cached data
286 $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
287 # Do query
288 $res = $this->reallyDoQuery( $limit, false );
289 $num = false;
290 if ( $res ) {
291 $num = $dbr->numRows( $res );
292 # Fetch results
293 $vals = array();
294 while ( $res && $row = $dbr->fetchObject( $res ) ) {
295 if ( isset( $row->value ) ) {
296 if ( $this->usesTimestamps() ) {
297 $value = wfTimestamp( TS_UNIX,
298 $row->value );
299 } else {
300 $value = intval( $row->value ); // @bug 14414
301 }
302 } else {
303 $value = 0;
304 }
305
306 $vals[] = array( 'qc_type' => $this->getName(),
307 'qc_namespace' => $row->namespace,
308 'qc_title' => $row->title,
309 'qc_value' => $value );
310 }
311
312 # Save results into the querycache table on the master
313 if ( count( $vals ) ) {
314 if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) ) {
315 // Set result to false to indicate error
316 $num = false;
317 }
318 }
319 if ( $ignoreErrors ) {
320 $dbw->ignoreErrors( $ignoreW );
321 $dbr->ignoreErrors( $ignoreR );
322 }
323
324 # Update the querycache_info record for the page
325 $dbw->delete( 'querycache_info', array( 'qci_type' => $this->getName() ), $fname );
326 $dbw->insert( 'querycache_info', array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ), $fname );
327
328 }
329 return $num;
330 }
331
332 /**
333 * Run the query and return the result
334 * @param $limit mixed Numerical limit or false for no limit
335 * @param $offset mixed Numerical offset or false for no offset
336 * @return ResultWrapper
337 * @since 1.18
338 */
339 function reallyDoQuery( $limit, $offset = false ) {
340 $fname = get_class( $this ) . "::reallyDoQuery";
341 $query = $this->getQueryInfo();
342 $order = $this->getOrderFields();
343 if ( $this->sortDescending() ) {
344 foreach ( $order as &$field ) {
345 $field .= ' DESC';
346 }
347 }
348 if ( is_array( $query ) ) {
349 $tables = isset( $query['tables'] ) ? (array)$query['tables'] : array();
350 $fields = isset( $query['fields'] ) ? (array)$query['fields'] : array();
351 $conds = isset( $query['conds'] ) ? (array)$query['conds'] : array();
352 $options = isset( $query['options'] ) ? (array)$query['options'] : array();
353 $join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : array();
354 if ( count( $order ) ) {
355 $options['ORDER BY'] = implode( ', ', $order );
356 }
357 if ( $limit !== false ) {
358 $options['LIMIT'] = intval( $limit );
359 }
360 if ( $offset !== false ) {
361 $options['OFFSET'] = intval( $offset );
362 }
363
364 $dbr = wfGetDB( DB_SLAVE );
365 $res = $dbr->select( $tables, $fields, $conds, $fname,
366 $options, $join_conds
367 );
368 } else {
369 // Old-fashioned raw SQL style, deprecated
370 $sql = $this->getSQL();
371 $sql .= ' ORDER BY ' . implode( ', ', $order );
372 $sql = $dbr->limitResult( $sql, $limit, $offset );
373 $res = $dbr->query( $sql );
374 }
375 return $dbr->resultObject( $res );
376 }
377
378 /**
379 * Parameters and order changed in 1.18
380 */
381 function doQuery( $limit, $offset = false ) {
382 if ( $this->isCached() && $this->isCacheable() ) {
383 return $this->fetchFromCache( $limit, $offset );
384 } else {
385 return $this->reallyDoQuery( $limit, $offset );
386 }
387 }
388
389 /**
390 * Fetch the query results from the query cache
391 * @param $limit mixed Numerical limit or false for no limit
392 * @param $offset mixed Numerical offset or false for no offset
393 * @return ResultWrapper
394 * @since 1.18
395 */
396 function fetchFromCache( $limit, $offset = false ) {
397 $dbr = wfGetDB( DB_SLAVE );
398 $options = array ();
399 if ( $limit !== false ) {
400 $options['LIMIT'] = intval( $limit );
401 }
402 if ( $offset !== false ) {
403 $options['OFFSET'] = intval( $offset );
404 }
405 $res = $dbr->select( 'querycache', array( 'qc_type',
406 'qc_namespace AS namespace',
407 'qc_title AS title',
408 'qc_value AS value' ),
409 array( 'qc_type' => $this->getName() ),
410 __METHOD__, $options
411 );
412 return $dbr->resultObject( $res );
413 }
414
415 /**
416 * This is the actual workhorse. It does everything needed to make a
417 * real, honest-to-gosh query page.
418 */
419 function execute( $par ) {
420 global $wgUser, $wgOut, $wgLang;
421
422 if ( !$this->userCanExecute( $wgUser ) ) {
423 $this->displayRestrictionError();
424 return;
425 }
426
427 if ( $this->limit == 0 && $this->offset == 0 )
428 list( $this->limit, $this->offset ) = wfCheckLimits();
429 $sname = $this->getName();
430 $fname = get_class( $this ) . '::doQuery';
431 $dbr = wfGetDB( DB_SLAVE );
432
433 $this->setHeaders();
434 $wgOut->setSyndicated( $this->isSyndicated() );
435
436 if ( $this->isCached() && !$this->isCacheable() ) {
437 $wgOut->setSyndicated( false );
438 $wgOut->addWikiMsg( 'querypage-disabled' );
439 return 0;
440 }
441
442 // TODO: Use doQuery()
443 // $res = null;
444 if ( !$this->isCached() ) {
445 $res = $this->reallyDoQuery( $this->limit, $this->offset );
446 } else {
447 # Get the cached result
448 $res = $this->fetchFromCache( $this->limit, $this->offset );
449 if ( !$this->listoutput ) {
450
451 # Fetch the timestamp of this update
452 $tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $sname ), $fname );
453 $tRow = $dbr->fetchObject( $tRes );
454
455 if ( $tRow ) {
456 $updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true );
457 $updateddate = $wgLang->date( $tRow->qci_timestamp, true, true );
458 $updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true );
459 $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
460 $wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
461 $wgOut->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime );
462 } else {
463 $wgOut->addWikiMsg( 'perfcached' );
464 }
465
466 # If updates on this page have been disabled, let the user know
467 # that the data set won't be refreshed for now
468 global $wgDisableQueryPageUpdate;
469 if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
470 $wgOut->addWikiMsg( 'querypage-no-updates' );
471 }
472
473 }
474
475 }
476
477 $this->numRows = $dbr->numRows( $res );
478
479 $this->preprocessResults( $dbr, $res );
480
481 $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) );
482
483 # Top header and navigation
484 if ( $this->shownavigation ) {
485 $wgOut->addHTML( $this->getPageHeader() );
486 if ( $this->numRows > 0 ) {
487 $wgOut->addHTML( '<p>' . wfShowingResults( $this->offset, $this->numRows ) . '</p>' );
488 # Disable the "next" link when we reach the end
489 $paging = wfViewPrevNext( $this->offset, $this->limit,
490 $this->getTitle( $par ),
491 wfArrayToCGI( $this->linkParameters() ), ( $this->numRows < $this->limit ) );
492 $wgOut->addHTML( '<p>' . $paging . '</p>' );
493 } else {
494 # No results to show, so don't bother with "showing X of Y" etc.
495 # -- just let the user know and give up now
496 $wgOut->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
497 $wgOut->addHTML( Xml::closeElement( 'div' ) );
498 return;
499 }
500 }
501
502 # The actual results; specialist subclasses will want to handle this
503 # with more than a straight list, so we hand them the info, plus
504 # an OutputPage, and let them get on with it
505 $this->outputResults( $wgOut,
506 $wgUser->getSkin(),
507 $dbr, # Should use a ResultWrapper for this
508 $res,
509 $this->numRows,
510 $this->offset );
511
512 # Repeat the paging links at the bottom
513 if ( $this->shownavigation ) {
514 $wgOut->addHTML( '<p>' . $paging . '</p>' );
515 }
516
517 $wgOut->addHTML( Xml::closeElement( 'div' ) );
518
519 return $this->numRows;
520 }
521
522 /**
523 * Format and output report results using the given information plus
524 * OutputPage
525 *
526 * @param $out OutputPage to print to
527 * @param $skin Skin: user skin to use
528 * @param $dbr Database (read) connection to use
529 * @param $res Integer: result pointer
530 * @param $num Integer: number of available result rows
531 * @param $offset Integer: paging offset
532 */
533 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
534 global $wgContLang;
535
536 if ( $num > 0 ) {
537 $html = array();
538 if ( !$this->listoutput )
539 $html[] = $this->openList( $offset );
540
541 # $res might contain the whole 1,000 rows, so we read up to
542 # $num [should update this to use a Pager]
543 for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
544 $line = $this->formatResult( $skin, $row );
545 if ( $line ) {
546 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
547 ? ' class="not-patrolled"'
548 : '';
549 $html[] = $this->listoutput
550 ? $line
551 : "<li{$attr}>{$line}</li>\n";
552 }
553 }
554
555 # Flush the final result
556 if ( $this->tryLastResult() ) {
557 $row = null;
558 $line = $this->formatResult( $skin, $row );
559 if ( $line ) {
560 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
561 ? ' class="not-patrolled"'
562 : '';
563 $html[] = $this->listoutput
564 ? $line
565 : "<li{$attr}>{$line}</li>\n";
566 }
567 }
568
569 if ( !$this->listoutput )
570 $html[] = $this->closeList();
571
572 $html = $this->listoutput
573 ? $wgContLang->listToText( $html )
574 : implode( '', $html );
575
576 $out->addHTML( $html );
577 }
578 }
579
580 function openList( $offset ) {
581 return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n";
582 }
583
584 function closeList() {
585 return "</ol>\n";
586 }
587
588 /**
589 * Do any necessary preprocessing of the result object.
590 */
591 function preprocessResults( $db, $res ) {}
592
593 /**
594 * Similar to above, but packaging in a syndicated feed instead of a web page
595 */
596 function doFeed( $class = '', $limit = 50 ) {
597 global $wgFeed, $wgFeedClasses;
598
599 if ( !$wgFeed ) {
600 global $wgOut;
601 $wgOut->addWikiMsg( 'feed-unavailable' );
602 return;
603 }
604
605 global $wgFeedLimit;
606 if ( $limit > $wgFeedLimit ) {
607 $limit = $wgFeedLimit;
608 }
609
610 if ( isset( $wgFeedClasses[$class] ) ) {
611 $feed = new $wgFeedClasses[$class](
612 $this->feedTitle(),
613 $this->feedDesc(),
614 $this->feedUrl() );
615 $feed->outHeader();
616
617 $dbr = wfGetDB( DB_SLAVE );
618 $res = $this->reallyDoQuery( $limit, 0 );
619 foreach ( $res as $obj ) {
620 $item = $this->feedResult( $obj );
621 if ( $item ) {
622 $feed->outItem( $item );
623 }
624 }
625
626 $feed->outFooter();
627 return true;
628 } else {
629 return false;
630 }
631 }
632
633 /**
634 * Override for custom handling. If the titles/links are ok, just do
635 * feedItemDesc()
636 */
637 function feedResult( $row ) {
638 if ( !isset( $row->title ) ) {
639 return null;
640 }
641 $title = Title::MakeTitle( intval( $row->namespace ), $row->title );
642 if ( $title ) {
643 $date = isset( $row->timestamp ) ? $row->timestamp : '';
644 $comments = '';
645 if ( $title ) {
646 $talkpage = $title->getTalkPage();
647 $comments = $talkpage->getFullURL();
648 }
649
650 return new FeedItem(
651 $title->getPrefixedText(),
652 $this->feedItemDesc( $row ),
653 $title->getFullURL(),
654 $date,
655 $this->feedItemAuthor( $row ),
656 $comments );
657 } else {
658 return null;
659 }
660 }
661
662 function feedItemDesc( $row ) {
663 return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
664 }
665
666 function feedItemAuthor( $row ) {
667 return isset( $row->user_text ) ? $row->user_text : '';
668 }
669
670 function feedTitle() {
671 global $wgLanguageCode, $wgSitename;
672 $page = SpecialPage::getPage( $this->getName() );
673 $desc = $page->getDescription();
674 return "$wgSitename - $desc [$wgLanguageCode]";
675 }
676
677 function feedDesc() {
678 return wfMsgExt( 'tagline', 'parsemag' );
679 }
680
681 function feedUrl() {
682 $title = SpecialPage::getTitleFor( $this->getName() );
683 return $title->getFullURL();
684 }
685 }
686
687 /**
688 * Class definition for a wanted query page like
689 * WantedPages, WantedTemplates, etc
690 */
691 abstract class WantedQueryPage extends QueryPage {
692
693 function isExpensive() {
694 return true;
695 }
696
697 function isSyndicated() {
698 return false;
699 }
700
701 /**
702 * Cache page existence for performance
703 */
704 function preprocessResults( $db, $res ) {
705 $batch = new LinkBatch;
706 foreach ( $res as $row ) {
707 $batch->add( $row->namespace, $row->title );
708 }
709 $batch->execute();
710
711 // Back to start for display
712 if ( $db->numRows( $res ) > 0 )
713 // If there are no rows we get an error seeking.
714 $db->dataSeek( $res, 0 );
715 }
716
717 /**
718 * Should formatResult() always check page existence, even if
719 * the results are fresh? This is a (hopefully temporary)
720 * kluge for Special:WantedFiles, which may contain false
721 * positives for files that exist e.g. in a shared repo (bug
722 * 6220).
723 */
724 function forceExistenceCheck() {
725 return false;
726 }
727
728 /**
729 * Format an individual result
730 *
731 * @param $skin Skin to use for UI elements
732 * @param $result Result row
733 * @return string
734 */
735 public function formatResult( $skin, $result ) {
736 $title = Title::makeTitleSafe( $result->namespace, $result->title );
737 if ( $title instanceof Title ) {
738 if ( $this->isCached() || $this->forceExistenceCheck() ) {
739 $pageLink = $title->isKnown()
740 ? '<del>' . $skin->link( $title ) . '</del>'
741 : $skin->link(
742 $title,
743 null,
744 array(),
745 array(),
746 array( 'broken' )
747 );
748 } else {
749 $pageLink = $skin->link(
750 $title,
751 null,
752 array(),
753 array(),
754 array( 'broken' )
755 );
756 }
757 return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
758 } else {
759 $tsafe = htmlspecialchars( $result->title );
760 return wfMsgHtml( 'wantedpages-badtitle', $tsafe );
761 }
762 }
763
764 /**
765 * Make a "what links here" link for a given title
766 *
767 * @param $title Title to make the link for
768 * @param $skin Skin object to use
769 * @param $result Object: result row
770 * @return string
771 */
772 private function makeWlhLink( $title, $skin, $result ) {
773 global $wgLang;
774 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
775 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
776 $wgLang->formatNum( $result->value ) );
777 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
778 }
779 }