]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialWantedfiles.php
MediaWiki 1.15.4-scripts
[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                 return wfSpecialList(
76                         $plink,
77                         $this->makeWlhLink( $nt, $skin, $result )
78                 );
79         }
80
81         /**
82          * Make a "what links here" link for a given title
83          *
84          * @param Title $title Title to make the link for
85          * @param Skin $skin Skin to use
86          * @param object $result Result row
87          * @return string
88          */
89         private function makeWlhLink( $title, $skin, $result ) {
90                 global $wgLang;
91                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
92                 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
93                 $wgLang->formatNum( $result->value ) );
94                 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
95         }
96 }
97
98 /**
99  * constructor
100  */
101 function wfSpecialWantedFiles() {
102         list( $limit, $offset ) = wfCheckLimits();
103
104         $wpp = new WantedFilesPage();
105
106         $wpp->doQuery( $offset, $limit );
107 }