* Reorganised the includes directory, creating subdirectories db, parser and specials
[lhc/web/wiklou.git] / includes / specials / MissingFiles.php
1 <?php
2 /**
3 * A querypage to list the missing files - implements Special:Missingfiles
4 *
5 * @addtogroup SpecialPage
6 *
7 * @author Matěj Grabovský <65s.mg@atlas.cz>
8 * @copyright Copyright © 2008, Matěj Grabovský
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
10 */
11 class MissingFilesPage extends QueryPage {
12 function getName() {
13 return 'Missingfiles';
14 }
15
16 function isExpensive() {
17 return true;
18 }
19
20 function isSyndicated() {
21 return false;
22 }
23
24 function getSQL() {
25 $dbr = wfGetDB( DB_SLAVE );
26 list( $imagelinks, $page ) = $dbr->tableNamesN( 'imagelinks', 'page' );
27 $name = $dbr->addQuotes( $this->getName() );
28
29 return "SELECT $name as type,
30 " . NS_IMAGE . " as namespace,
31 il_to as title,
32 COUNT(*) as value
33 FROM $imagelinks
34 LEFT JOIN $page ON il_to = page_title AND page_namespace = ". NS_IMAGE ."
35 WHERE page_title IS NULL
36 GROUP BY 1,2,3
37 ";
38 }
39
40 function sortDescending() {
41 return true;
42 }
43
44 /**
45 * Fetch user page links and cache their existence
46 */
47 function preprocessResults( $db, $res ) {
48 $batch = new LinkBatch;
49
50 while ( $row = $db->fetchObject( $res ) )
51 $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
52
53 $batch->execute();
54
55 // Back to start for display
56 if ( $db->numRows( $res ) > 0 )
57
58 // If there are no rows we get an error seeking.
59 $db->dataSeek( $res, 0 );
60 }
61
62 public function formatResult( $skin, $result ) {
63 global $wgLang, $wgContLang;
64
65 $nt = Title::makeTitle( $result->namespace, $result->title );
66 $text = $wgContLang->convert( $nt->getText() );
67
68 $plink = $this->isCached()
69 ? '<s>' . $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) . '</s>'
70 : $skin->makeBrokenImageLinkObj( $nt, htmlspecialchars( $text ) );
71
72 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->value ) );
73 $nlinks = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Whatlinkshere' ), $label, 'target=' . $nt->getPrefixedUrl() );
74 return wfSpecialList( $plink, $nlinks );
75 }
76 }
77
78 /**
79 * Constructor
80 */
81 function wfSpecialMissingFiles() {
82 list( $limit, $offset ) = wfCheckLimits();
83
84 $wpp = new MissingFilesPage();
85
86 $wpp->doQuery( $offset, $limit );
87 }