+
+/**
+ * Class definition for a wanted query page like
+ * WantedPages, WantedTemplates, etc
+ */
+abstract class WantedQueryPage extends QueryPage {
+
+ function isExpensive() {
+ return true;
+ }
+
+ function isSyndicated() {
+ return false;
+ }
+
+ /**
+ * Cache page existence for performance
+ */
+ function preprocessResults( $db, $res ) {
+ $batch = new LinkBatch;
+ foreach ( $res as $row ) {
+ $batch->add( $row->namespace, $row->title );
+ }
+ $batch->execute();
+
+ // Back to start for display
+ if ( $db->numRows( $res ) > 0 )
+ // If there are no rows we get an error seeking.
+ $db->dataSeek( $res, 0 );
+ }
+
+ /**
+ * Should formatResult() always check page existence, even if
+ * the results are fresh? This is a (hopefully temporary)
+ * kluge for Special:WantedFiles, which may contain false
+ * positives for files that exist e.g. in a shared repo (bug
+ * 6220).
+ */
+ function forceExistenceCheck() {
+ return false;
+ }
+
+ /**
+ * Format an individual result
+ *
+ * @param $skin Skin to use for UI elements
+ * @param $result Result row
+ * @return string
+ */
+ public function formatResult( $skin, $result ) {
+ $title = Title::makeTitleSafe( $result->namespace, $result->title );
+ if( $title instanceof Title ) {
+ if( $this->isCached() || $this->forceExistenceCheck() ) {
+ $pageLink = $title->isKnown()
+ ? '<del>' . $skin->link( $title ) . '</del>'
+ : $skin->link(
+ $title,
+ null,
+ array(),
+ array(),
+ array( 'broken' )
+ );
+ } else {
+ $pageLink = $skin->link(
+ $title,
+ null,
+ array(),
+ array(),
+ array( 'broken' )
+ );
+ }
+ return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
+ } else {
+ $tsafe = htmlspecialchars( $result->title );
+ return wfMsgHtml( 'wantedpages-badtitle', $tsafe );
+ }
+ }
+
+ /**
+ * Make a "what links here" link for a given title
+ *
+ * @param $title Title to make the link for
+ * @param $skin Skin object to use
+ * @param $result Object: result row
+ * @return string
+ */
+ private function makeWlhLink( $title, $skin, $result ) {
+ global $wgLang;
+ $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
+ $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
+ $wgLang->formatNum( $result->value ) );
+ return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
+ }
+}