fix class_exists() for not existing classes
[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 pl_namespace NOT IN ( 2, 3 )
53 AND pg2.page_namespace != 8
54 GROUP BY pl_namespace, pl_title
55 HAVING COUNT(*) > $count";
56 }
57
58 /**
59 * Cache page existence for performance
60 */
61 function preprocessResults( &$db, &$res ) {
62 $batch = new LinkBatch;
63 while ( $row = $db->fetchObject( $res ) )
64 $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
65 $batch->execute();
66
67 // Back to start for display
68 if ( $db->numRows( $res ) > 0 )
69 // If there are no rows we get an error seeking.
70 $db->dataSeek( $res, 0 );
71 }
72
73
74 function formatResult( $skin, $result ) {
75 global $wgLang;
76
77 $title = Title::makeTitleSafe( $result->namespace, $result->title );
78
79 if( $this->isCached() ) {
80 # Check existence; which is stored in the link cache
81 if( !$title->exists() ) {
82 # Make a redlink
83 $pageLink = $skin->makeBrokenLinkObj( $title );
84 } else {
85 # Make a a struck-out normal link
86 $pageLink = "<s>" . $skin->makeLinkObj( $title ) . "</s>";
87 }
88 } else {
89 # Not cached? Don't bother checking existence; it can't
90 $pageLink = $skin->makeBrokenLinkObj( $title );
91 }
92
93 # Make a link to "what links here" if it's required
94 $wlhLink = $this->nlinks
95 ? $this->makeWlhLink( $title, $skin,
96 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
97 $wgLang->formatNum( $result->value ) ) )
98 : null;
99
100 return wfSpecialList($pageLink, $wlhLink);
101 }
102
103 /**
104 * Make a "what links here" link for a specified title
105 * @param $title Title to make the link for
106 * @param $skin Skin to use
107 * @param $text Link text
108 * @return string
109 */
110 function makeWlhLink( &$title, &$skin, $text ) {
111 $wlhTitle = Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' );
112 return $skin->makeKnownLinkObj( $wlhTitle, $text, 'target=' . $title->getPrefixedUrl() );
113 }
114
115 }
116
117 /**
118 * constructor
119 */
120 function wfSpecialWantedpages( $par = null, $specialPage ) {
121 $inc = $specialPage->including();
122
123 if ( $inc ) {
124 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
125 $limit = (int)$limit;
126 $nlinks = $nlinks === 'nlinks';
127 $offset = 0;
128 } else {
129 list( $limit, $offset ) = wfCheckLimits();
130 $nlinks = true;
131 }
132
133 $wpp = new WantedPagesPage( $inc, $nlinks );
134
135 $wpp->doQuery( $offset, $limit, !$inc );
136 }
137
138 ?>