From 683e5771be9dfc21ed76e683dd11ad80d1492e57 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 5 Jun 2008 16:19:29 +0000 Subject: [PATCH] Bug 13702 - Add Special:MissingFiles to list pages where an [[Image:]] link exists but no appropriate file is there. --- RELEASE-NOTES | 2 + includes/DefaultSettings.php | 1 + includes/SpecialMissingfiles.php | 87 +++++++++++++++++++++++++++++++ includes/SpecialPage.php | 1 + languages/messages/MessagesEn.php | 3 ++ maintenance/language/messages.inc | 4 ++ 6 files changed, 98 insertions(+) create mode 100644 includes/SpecialMissingfiles.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 234ce890fd..3ae945a529 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -143,6 +143,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * The User class now contains a public function called isActiveEditor. Figures out if a user is active based on at least $wgActiveUserEditCount number of edits in the last $wgActiveUserDays days. +* (bug 13702) Add Special:MissingFiles to list places where an image link is + used but no such file exists. === Bug fixes in 1.13 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7f9bab943d..42effd5b90 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2627,6 +2627,7 @@ $wgSpecialPageGroups = array( 'Wantedcategories' => 'maintenance', 'Unwatchedpages' => 'maintenance', 'Fewestrevisions' => 'maintenance', + 'MissingFiles' => 'maintenance', 'Userlogin' => 'login', 'Userlogout' => 'login', diff --git a/includes/SpecialMissingfiles.php b/includes/SpecialMissingfiles.php new file mode 100644 index 0000000000..d2da51c741 --- /dev/null +++ b/includes/SpecialMissingfiles.php @@ -0,0 +1,87 @@ + + * @copyright Copyright © 2008, Matěj Grabovský + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ +class MissingFilesPage extends QueryPage { + function getName() { + return 'Missingfiles'; + } + + function isExpensive() { + return true; + } + + function isSyndicated() { + return false; + } + + function getSQL() { + $dbr = wfGetDB( DB_SLAVE ); + list( $imagelinks, $page ) = $dbr->tableNamesN( 'imagelinks', 'page' ); + $name = $dbr->addQuotes( $this->getName() ); + + return "SELECT $name as type, + " . NS_IMAGE . " as namespace, + il_to as title, + COUNT(*) as value + FROM $imagelinks + LEFT JOIN $page ON il_to = page_title AND page_namespace = ". NS_IMAGE ." + WHERE page_title IS NULL + GROUP BY 1,2,3 + "; + } + + function sortDescending() { + return true; + } + + /** + * Fetch user page links and cache their existence + */ + function preprocessResults( $db, $res ) { + $batch = new LinkBatch; + + while ( $row = $db->fetchObject( $res ) ) + $batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) ); + + $batch->execute(); + + // Back to start for display + if ( $db->numRows( $res ) > 0 ) + + // If there are no rows we get an error seeking. + $db->dataSeek( $res, 0 ); + } + + public function formatResult( $skin, $result ) { + global $wgLang, $wgContLang; + + $nt = Title::makeTitle( $result->namespace, $result->title ); + $text = $wgContLang->convert( $nt->getText() ); + + $plink = $this->isCached() + ? '' . $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) . '' + : $skin->makeBrokenImageLinkObj( $nt, htmlspecialchars( $text ) ); + + $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->value ) ); + $nlinks = $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Whatlinkshere' ), $label, 'target=' . $nt->getPrefixedUrl() ); + return wfSpecialList( $plink, $nlinks ); + } +} + +/** + * Constructor + */ +function wfSpecialMissingFiles() { + list( $limit, $offset ) = wfCheckLimits(); + + $wpp = new MissingFilesPage(); + + $wpp->doQuery( $offset, $limit ); +} \ No newline at end of file diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index fe41c421c7..d04fd65421 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -107,6 +107,7 @@ class SpecialPage 'Unusedimages' => array( 'SpecialPage', 'Unusedimages' ), 'Wantedpages' => array( 'IncludableSpecialPage', 'Wantedpages' ), 'Wantedcategories' => array( 'SpecialPage', 'Wantedcategories' ), + 'Missingfiles' => array( 'SpecialPage', 'MissingFiles' ), 'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ), 'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ), 'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ), diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index fb66e8349f..70c195b334 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -376,6 +376,7 @@ $specialPageAliases = array( 'Unusedimages' => array( 'UnusedImages' ), 'Wantedpages' => array( 'WantedPages', 'BrokenLinks' ), 'Wantedcategories' => array( 'WantedCategories' ), + 'Missingfiles' => array( 'MissingFiles', 'MissingImages' ), 'Mostlinked' => array( 'MostLinked' ), 'Mostlinkedcategories' => array( 'MostLinkedCategories', 'MostUsedCategories' ), 'Mostlinkedtemplates' => array( 'MostLinkedTemplates', 'MostUsedTemplates' ), @@ -1875,6 +1876,8 @@ A page is treated as disambiguation page if it uses a template which is linked f 'wantedcategories-summary' => '', # only translate this message to other languages if you have to change it 'wantedpages' => 'Wanted pages', 'wantedpages-summary' => '', # only translate this message to other languages if you have to change it +'missingfiles' => 'Missing files', +'missingfiles-summary' => '', # only translate this message to other languages if you have to change it 'mostlinked' => 'Most linked-to pages', 'mostlinked-summary' => '', # only translate this message to other languages if you have to change it 'mostlinkedcategories' => 'Most linked-to categories', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index dc512bab1f..5b22545506 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1203,6 +1203,10 @@ $wgMessageStructure = array( 'wantedcategories-summary', 'wantedpages', 'wantedpages-summary', + 'missingfiles', + 'missingfiles-summary', + 'missingimages', + 'missingimages-summary', 'mostlinked', 'mostlinked-summary', 'mostlinkedcategories', -- 2.20.1