* (bug 7405) Make Linker methods static. Patch by Dan Li.
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 * @package MediaWiki
11 * @subpackage SpecialPage
12 */
13 class WantedPagesPage extends QueryPage {
14 var $nlinks;
15
16 function WantedPagesPage( $inc = false, $nlinks = true ) {
17 $this->setListoutput( $inc );
18 $this->nlinks = $nlinks;
19 }
20
21 function getName() {
22 return 'Wantedpages';
23 }
24
25 function isExpensive() {
26 return true;
27 }
28 function isSyndicated() { return false; }
29
30 function getSQL() {
31 global $wgWantedPagesThreshold;
32 $count = $wgWantedPagesThreshold - 1;
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 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
49 GROUP BY 1,2,3
50 HAVING COUNT(*) > $count";
51 }
52
53 /**
54 * Cache page existence for performance
55 */
56 function preprocessResults( &$db, &$res ) {
57 $batch = new LinkBatch;
58 while ( $row = $db->fetchObject( $res ) )
59 $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
60 $batch->execute();
61
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 );
66 }
67
68
69 function formatResult( $result ) {
70 global $wgLang;
71
72 $title = Title::makeTitleSafe( $result->namespace, $result->title );
73
74 if( $this->isCached() ) {
75 # Check existence; which is stored in the link cache
76 if( !$title->exists() ) {
77 # Make a redlink
78 $pageLink = Linker::makeBrokenLinkObj( $title );
79 } else {
80 # Make a a struck-out normal link
81 $pageLink = "<s>" . Linker::makeLinkObj( $title ) . "</s>";
82 }
83 } else {
84 # Not cached? Don't bother checking existence; it can't
85 $pageLink = Linker::makeBrokenLinkObj( $title );
86 }
87
88 # Make a link to "what links here" if it's required
89 $wlhLink = $this->nlinks
90 ? $this->makeWlhLink( $title,
91 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
92 $wgLang->formatNum( $result->value ) ) )
93 : null;
94
95 return wfSpecialList($pageLink, $wlhLink);
96 }
97
98 /**
99 * Make a "what links here" link for a specified title
100 * @param $title Title to make the link for
101 * @param $text Link text
102 * @return string
103 */
104 function makeWlhLink( &$title, $text ) {
105 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere' );
106 return Linker::makeKnownLinkObj( $wlhTitle, $text, 'target=' . $title->getPrefixedUrl() );
107 }
108
109 }
110
111 /**
112 * constructor
113 */
114 function wfSpecialWantedpages( $par = null, $specialPage ) {
115 $inc = $specialPage->including();
116
117 if ( $inc ) {
118 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
119 $limit = (int)$limit;
120 $nlinks = $nlinks === 'nlinks';
121 $offset = 0;
122 } else {
123 list( $limit, $offset ) = wfCheckLimits();
124 $nlinks = true;
125 }
126
127 $wpp = new WantedPagesPage( $inc, $nlinks );
128
129 $wpp->doQuery( $offset, $limit, !$inc );
130 }
131
132 ?>