]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialWantedfiles.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialWantedfiles.php
1 <?php
2 /*
3  * @file
4  * @ingroup SpecialPage
5  */
6
7 /**
8  * Querypage that lists the most wanted files - implements Special:Wantedfiles
9  *
10  * @ingroup SpecialPage
11  *
12  * @author Soxred93 <soxred93@gmail.com>
13  * @copyright Copyright © 2008, Soxred93
14  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
15  */
16 class WantedFilesPage extends QueryPage {
17
18         function getName() {
19                 return 'Wantedfiles';
20         }
21
22         function isExpensive() {
23                 return true;
24         }
25
26         function isSyndicated() {
27                 return false;
28         }
29
30         function getSQL() {
31                 $dbr = wfGetDB( DB_SLAVE );
32                 list( $imagelinks, $page ) = $dbr->tableNamesN( 'imagelinks', 'page' );
33                 $name = $dbr->addQuotes( $this->getName() );
34                 return
35                         "
36                         SELECT
37                                 $name as type,
38                                 " . NS_FILE . " as namespace,
39                                 il_to as title,
40                                 COUNT(*) as value
41                         FROM $imagelinks
42                         LEFT JOIN $page ON il_to = page_title AND page_namespace = ". NS_FILE ."
43                         WHERE page_title IS NULL
44                         GROUP BY il_to
45                         ";
46         }
47
48         function sortDescending() { return true; }
49
50         /**
51          * Fetch user page links and cache their existence
52          */
53         function preprocessResults( $db, $res ) {
54                 $batch = new LinkBatch;
55                 while ( $row = $db->fetchObject( $res ) )
56                         $batch->add( $row->namespace, $row->title );
57                 $batch->execute();
58
59                 // Back to start for display
60                 if ( $db->numRows( $res ) > 0 )
61                         // If there are no rows we get an error seeking.
62                         $db->dataSeek( $res, 0 );
63         }
64
65         function formatResult( $skin, $result ) {
66                 global $wgLang, $wgContLang;
67
68                 $nt = Title::makeTitle( $result->namespace, $result->title );
69                 $text = $wgContLang->convert( $nt->getText() );
70
71                 $plink = $this->isCached() ?
72                         $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
73                         $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
74
75                 $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
76                         $wgLang->formatNum( $result->value ) );
77                 return wfSpecialList($plink, $nlinks);
78         }
79 }
80
81 /**
82  * constructor
83  */
84 function wfSpecialWantedFiles() {
85         list( $limit, $offset ) = wfCheckLimits();
86
87         $wpp = new WantedFilesPage();
88
89         $wpp->doQuery( $offset, $limit );
90 }