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