* Don't display nlinks by default when being included but allow them to be displayed...
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once 'QueryPage.php';
12
13 /**
14 *
15 * @package MediaWiki
16 * @subpackage SpecialPage
17 */
18 class WantedPagesPage extends QueryPage {
19 var $nlinks;
20
21 function WantedPagesPage( $inc = false, $nlinks = true ) {
22 $this->setListoutput( $inc );
23 $this->nlinks = $nlinks;
24 }
25
26 function getName() {
27 return 'Wantedpages';
28 }
29
30 function isExpensive() {
31 return true;
32 }
33 function isSyndicated() { return false; }
34
35 function getSQL() {
36 $dbr =& wfGetDB( DB_SLAVE );
37 $pagelinks = $dbr->tableName( 'pagelinks' );
38 $page = $dbr->tableName( 'page' );
39 return
40 "SELECT 'Wantedpages' AS type,
41 pl_namespace AS namespace,
42 pl_title AS title,
43 COUNT(*) AS value
44 FROM $pagelinks
45 LEFT JOIN $page
46 ON pl_namespace=page_namespace AND pl_title=page_title
47 WHERE page_namespace IS NULL
48 GROUP BY pl_namespace,pl_title
49 HAVING COUNT(*) > 1";
50 }
51
52 /**
53 * Fetch user page links and cache their existence
54 */
55 function preprocessResults( &$db, &$res ) {
56 global $wgLinkCache;
57
58 $batch = new LinkBatch;
59 while ( $row = $db->fetchObject( $res ) )
60 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->title ) );
61 $batch->execute( $wgLinkCache );
62
63 // Back to start for display
64 if ( $db->numRows( $res ) > 0 )
65 // If there are no rows we get an error seeking.
66 $db->dataSeek( $res, 0 );
67 }
68
69
70 function formatResult( $skin, $result ) {
71 global $wgContLang;
72
73 $nt = Title::makeTitle( $result->namespace, $result->title );
74 $text = $wgContLang->convert( $nt->getPrefixedText() );
75 $plink = $this->isCached() ?
76 $skin->makeLinkObj( $nt, $text ) :
77 $skin->makeBrokenLink( $nt->getPrefixedText(), $text );
78
79 $nl = wfMsg( 'nlinks', $result->value );
80 $nlink = $skin->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ), $nl, 'target=' . $nt->getPrefixedURL() );
81
82 return $this->nlinks ? "$plink ($nlink)" : $plink;
83 }
84 }
85
86 /**
87 * constructor
88 */
89 function wfSpecialWantedpages( $par = null, $specialPage ) {
90 $inc = $specialPage->including();
91
92 if ( $inc ) {
93 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
94 $limit = (int)$limit;
95 $nlinks = $nlinks === 'nlinks';
96 $offset = 0;
97 } else {
98 list( $limit, $offset ) = wfCheckLimits();
99 $nlinks = true;
100 }
101
102 $wpp = new WantedPagesPage( $inc, $nlinks );
103
104 $wpp->doQuery( $offset, $limit, !$inc );
105 }
106
107 ?>