* (bug 8424) Update for Cantonese language (zh-yue) #9
[mediawiki.git] / includes / SpecialWantedpages.php
blob8e5cee3ec2be391535a6e34be534d30630171361
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
10 * @package MediaWiki
11 * @subpackage SpecialPage
13 class WantedPagesPage extends QueryPage {
14 var $nlinks;
16 function WantedPagesPage( $inc = false, $nlinks = true ) {
17 $this->setListoutput( $inc );
18 $this->nlinks = $nlinks;
21 function getName() {
22 return 'Wantedpages';
25 function isExpensive() {
26 return true;
28 function isSyndicated() { return false; }
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";
53 /**
54 * Cache page existence for performance
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();
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 );
69 function formatResult( $skin, $result ) {
70 global $wgLang;
72 $title = Title::makeTitleSafe( $result->namespace, $result->title );
74 if( $this->isCached() ) {
75 # Check existence; which is stored in the link cache
76 if( !$title->exists() ) {
77 # Make a redlink
78 $pageLink = $skin->makeBrokenLinkObj( $title );
79 } else {
80 # Make a a struck-out normal link
81 $pageLink = "<s>" . $skin->makeLinkObj( $title ) . "</s>";
83 } else {
84 # Not cached? Don't bother checking existence; it can't
85 $pageLink = $skin->makeBrokenLinkObj( $title );
88 # Make a link to "what links here" if it's required
89 $wlhLink = $this->nlinks
90 ? $this->makeWlhLink( $title, $skin,
91 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
92 $wgLang->formatNum( $result->value ) ) )
93 : null;
95 return wfSpecialList($pageLink, $wlhLink);
98 /**
99 * Make a "what links here" link for a specified title
100 * @param $title Title to make the link for
101 * @param $skin Skin to use
102 * @param $text Link text
103 * @return string
105 function makeWlhLink( &$title, &$skin, $text ) {
106 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere' );
107 return $skin->makeKnownLinkObj( $wlhTitle, $text, 'target=' . $title->getPrefixedUrl() );
113 * constructor
115 function wfSpecialWantedpages( $par = null, $specialPage ) {
116 $inc = $specialPage->including();
118 if ( $inc ) {
119 @list( $limit, $nlinks ) = explode( '/', $par, 2 );
120 $limit = (int)$limit;
121 $nlinks = $nlinks === 'nlinks';
122 $offset = 0;
123 } else {
124 list( $limit, $offset ) = wfCheckLimits();
125 $nlinks = true;
128 $wpp = new WantedPagesPage( $inc, $nlinks );
130 $wpp->doQuery( $offset, $limit, !$inc );