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