* Duck warning when being run by maintenance/updateSpecialPages.php
[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 function WantedPagesPage( $inc = false ) {
20 $this->setListoutput( $inc );
21 }
22
23 function getName() {
24 return 'Wantedpages';
25 }
26
27 function isExpensive() {
28 return true;
29 }
30 function isSyndicated() { return false; }
31
32 function getSQL() {
33 $dbr =& wfGetDB( DB_SLAVE );
34 $pagelinks = $dbr->tableName( 'pagelinks' );
35 $page = $dbr->tableName( 'page' );
36 return
37 "SELECT 'Wantedpages' AS type,
38 pl_namespace AS namespace,
39 pl_title AS title,
40 COUNT(*) AS value
41 FROM $pagelinks
42 LEFT JOIN $page
43 ON pl_namespace=page_namespace AND pl_title=page_title
44 WHERE page_namespace IS NULL
45 GROUP BY pl_namespace,pl_title
46 HAVING COUNT(*) > 1";
47 }
48
49 /**
50 * Fetch user page links and cache their existence
51 */
52 function preprocessResults( &$db, &$res ) {
53 global $wgLinkCache;
54
55 $batch = new LinkBatch;
56 while ( $row = $db->fetchObject( $res ) )
57 $batch->addObj( Title::makeTitleSafe( NS_USER, $row->title ) );
58 $batch->execute( $wgLinkCache );
59
60 // Back to start for display
61 if ( $db->numRows( $res ) > 0 )
62 // If there are no rows we get an error seeking.
63 $db->dataSeek( $res, 0 );
64 }
65
66
67 function formatResult( $skin, $result ) {
68 global $wgContLang;
69
70 $nt = Title::makeTitle( $result->namespace, $result->title );
71 $text = $wgContLang->convert( $nt->getPrefixedText() );
72 $plink = $this->isCached() ?
73 $skin->makeLinkObj( $nt, $text ) :
74 $skin->makeBrokenLink( $nt->getPrefixedText(), $text );
75
76 $nl = wfMsg( 'nlinks', $result->value );
77 $nlink = $skin->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ), $nl, 'target=' . $nt->getPrefixedURL() );
78
79 return "$plink ($nlink)";
80 }
81 }
82
83 /**
84 * constructor
85 */
86 function wfSpecialWantedpages( $par = null, $specialPage ) {
87 $inc = $specialPage->including();
88
89 if ( $inc ) {
90 $limit = (int)$par;
91 $offset = 0;
92 } else
93 list( $limit, $offset ) = wfCheckLimits();
94
95 $wpp = new WantedPagesPage( $inc );
96
97 $wpp->doQuery( $offset, $limit, !$inc );
98 }
99
100 ?>