* Added many missing formatNum calls
[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 global $wgWantedPagesThreshold;
37 $count = $wgWantedPagesThreshold - 1;
38 $dbr =& wfGetDB( DB_SLAVE );
39 $pagelinks = $dbr->tableName( 'pagelinks' );
40 $page = $dbr->tableName( 'page' );
41 return
42 "SELECT 'Wantedpages' AS type,
43 pl_namespace AS namespace,
44 pl_title AS title,
45 COUNT(*) AS value
46 FROM $pagelinks
47 LEFT JOIN $page AS pg1
48 ON pl_namespace = pg1.page_namespace AND pl_title = pg1.page_title
49 LEFT JOIN $page AS pg2
50 ON pl_from = pg2.page_id
51 WHERE pg1.page_namespace IS NULL
52 AND pg2.page_namespace != 8
53 GROUP BY pl_namespace, pl_title
54 HAVING COUNT(*) > $count";
55 }
56
57 /**
58 * Cache page existence for performance
59 */
60 function preprocessResults( &$db, &$res ) {
61 $batch = new LinkBatch;
62 while ( $row = $db->fetchObject( $res ) )
63 $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
64 $batch->execute();
65
66 // Back to start for display
67 if ( $db->numRows( $res ) > 0 )
68 // If there are no rows we get an error seeking.
69 $db->dataSeek( $res, 0 );
70 }
71
72
73 function formatResult( $skin, $result ) {
74 global $wgLang;
75
76 $title = Title::makeTitleSafe( $result->namespace, $result->title );
77
78 if( $this->isCached() ) {
79 # Check existence; which is stored in the link cache
80 if( !$title->exists() ) {
81 # Make a redlink
82 $pageLink = $skin->makeBrokenLinkObj( $title );
83 } else {
84 # Make a struck-out blue link
85 $pageLink = "<s>" . $skin->makeKnownLinkObj( $title ) . "</s>";
86 }
87 } else {
88 # Not cached? Don't bother checking existence; it can't
89 $pageLink = $skin->makeBrokenLinkObj( $title );
90 }
91
92 # Make a link to "what links here" if it's required
93 $wlhLink = $this->nlinks
94 ? $this->makeWlhLink( $title, $skin, wfMsgHtml( 'nlinks',
95 $wgLang->formatNum( $result->value ) ) )
96 : null;
97
98 return wfSpecialList($pageLink, $wlhLink);
99 }
100
101 /**
102 * Make a "what links here" link for a specified title
103 * @param $title Title to make the link for
104 * @param $skin Skin to use
105 * @param $text Link text
106 * @return string
107 */
108 function makeWlhLink( &$title, &$skin, $text ) {
109 $wlhTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
110 return $skin->makeKnownLinkObj( $wlhTitle, $text, 'target=' . $title->getPrefixedUrl() );
111 }
112
113 }
114
115 /**
116 * constructor
117 */
118 function wfSpecialWantedpages( $par = null, $specialPage ) {
119 $inc = $specialPage->including();
120
121 if ( $inc ) {
122 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
123 $limit = (int)$limit;
124 $nlinks = $nlinks === 'nlinks';
125 $offset = 0;
126 } else {
127 list( $limit, $offset ) = wfCheckLimits();
128 $nlinks = true;
129 }
130
131 $wpp = new WantedPagesPage( $inc, $nlinks );
132
133 $wpp->doQuery( $offset, $limit, !$inc );
134 }
135
136 ?>