5 * @subpackage SpecialPage
11 * @subpackage SpecialPage
13 class WantedPagesPage
extends QueryPage
{
16 function WantedPagesPage( $inc = false, $nlinks = true ) {
17 $this->setListoutput( $inc );
18 $this->nlinks
= $nlinks;
25 function isExpensive() {
28 function isSyndicated() { return false; }
31 global $wgWantedPagesThreshold;
32 $count = $wgWantedPagesThreshold - 1;
33 $dbr =& wfGetDB( DB_SLAVE
);
34 $pagelinks = $dbr->tableName( 'pagelinks' );
35 $page = $dbr->tableName( 'page' );
37 "SELECT 'Wantedpages' AS type,
38 pl_namespace AS namespace,
42 LEFT JOIN $page AS pg1
43 ON pl_namespace = pg1.page_namespace AND pl_title = pg1.page_title
44 LEFT JOIN $page AS pg2
45 ON pl_from = pg2.page_id
46 WHERE pg1.page_namespace IS NULL
47 AND pl_namespace NOT IN ( 2, 3 )
48 AND pg2.page_namespace != 8
50 HAVING COUNT(*) > $count";
54 * Cache page existence for performance
56 function preprocessResults( &$db, &$res ) {
57 $batch = new LinkBatch
;
58 while ( $row = $db->fetchObject( $res ) )
59 $batch->addObj( Title
::makeTitleSafe( $row->namespace, $row->title
) );
62 // Back to start for display
63 if ( $db->numRows( $res ) > 0 )
64 // If there are no rows we get an error seeking.
65 $db->dataSeek( $res, 0 );
69 function formatResult( $skin, $result ) {
72 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
74 if( $this->isCached() ) {
75 # Check existence; which is stored in the link cache
76 if( !$title->exists() ) {
78 $pageLink = $skin->makeBrokenLinkObj( $title );
80 # Make a a struck-out normal link
81 $pageLink = "<s>" . $skin->makeLinkObj( $title ) . "</s>";
84 # Not cached? Don't bother checking existence; it can't
85 $pageLink = $skin->makeBrokenLinkObj( $title );
88 # Make a link to "what links here" if it's required
89 $wlhLink = $this->nlinks
90 ?
$this->makeWlhLink( $title, $skin,
91 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
92 $wgLang->formatNum( $result->value
) ) )
95 return wfSpecialList($pageLink, $wlhLink);
99 * Make a "what links here" link for a specified title
100 * @param $title Title to make the link for
101 * @param $skin Skin to use
102 * @param $text Link text
105 function makeWlhLink( &$title, &$skin, $text ) {
106 $wlhTitle = Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' );
107 return $skin->makeKnownLinkObj( $wlhTitle, $text, 'target=' . $title->getPrefixedUrl() );
115 function wfSpecialWantedpages( $par = null, $specialPage ) {
116 $inc = $specialPage->including();
119 @list
( $limit, $nlinks ) = explode( '/', $par, 2 );
120 $limit = (int)$limit;
121 $nlinks = $nlinks === 'nlinks';
124 list( $limit, $offset ) = wfCheckLimits();
128 $wpp = new WantedPagesPage( $inc, $nlinks );
130 $wpp->doQuery( $offset, $limit, !$inc );