From: Victor Vasiliev Date: Sat, 29 Dec 2007 09:32:22 +0000 (+0000) Subject: * Support images-redirects X-Git-Tag: 1.31.0-rc.0~50235 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=625dcb58e3cadfc63a1685baac9b753fa6d73075;p=lhc%2Fweb%2Fwiklou.git * Support images-redirects Note: this revision requires schema change --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 5e80096150..704a9a10bf 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -112,6 +112,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Add HTML ID's mw-read-only-warning and mw-anon-edit-warning to warnings when editing to allow CSS styling. * Parser now returns list of sections +* Support images-redirects === Bug fixes in 1.12 === diff --git a/includes/Article.php b/includes/Article.php index 9a7e85bd6d..9cd73f6640 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1098,6 +1098,28 @@ class Article { $isRedirect = !is_null($redirectTitle); if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) { + $imageResult = true; //Result of imageredirects handling + file_put_contents( "C:\\err.txt", strval( $this->mTitle->getNamespace() == NS_IMAGE ) ); + if( $this->mTitle->getNamespace() == NS_IMAGE ) { + wfProfileIn( __METHOD__ . "-img" ); + + $exists = $redirectTitle ? RepoGroup::singleton()->findFile( $redirectTitle->getDBkey() ) !== false : false; + if( $isRedirect && $redirectTitle->getNamespace() == NS_IMAGE && $exists ) { + $set = array( + 'ir_from' => $this->mTitle->getDBkey(), + 'ir_to' => $redirectTitle->getDBkey(), + ); + $dbw->replace( 'imageredirects', array( 'ir_from' ), $set, __METHOD__ ); + $imageResult = $dbw->affectedRows() != 0; + } else { + // Non-redirect or redirect to non-image + $where = array( 'ir_from' => $this->mTitle->getDBkey() ); + $dbw->delete( 'imageredirects', $where, __METHOD__ ); + } + + wfProfileOut( __METHOD__ . "-img" ); + } + wfProfileIn( __METHOD__ ); if ($isRedirect) { @@ -1117,7 +1139,7 @@ class Article { } wfProfileOut( __METHOD__ ); - return ( $dbw->affectedRows() != 0 ); + return ( $dbw->affectedRows() != 0 ) && $imageResult; } return true; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index cf6d65c2ce..90d284ffc6 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -76,7 +76,14 @@ abstract class FileRepo { * * @param mixed $time 14-character timestamp, or false for the current version */ - function findFile( $title, $time = false ) { + function findFile( $title, $time = false, $redirected = false ) { + if ( !($title instanceof Title) ) { + $title = Title::makeTitleSafe( NS_IMAGE, $title ); + if ( !is_object( $title ) ) { + return null; + } + } + # First try the current version of the file to see if it precedes the timestamp $img = $this->newFile( $title ); if ( !$img ) { @@ -90,6 +97,13 @@ abstract class FileRepo { if ( $img->exists() ) { return $img; } + + #Try redirects + if( !$redirected ) { // Prevent redirect loops + $redir = $this->checkRedirects( $title->getDBkey() ); + if( $redir ) + return $this->findFile( $redir, $time, $title ); + } } /** @@ -400,5 +414,20 @@ abstract class FileRepo { * STUB */ function cleanupDeletedBatch( $storageKeys ) {} + + /** + * Check for redirects. + */ + function checkRedirects( $filename ) { + $dbr = $this->getSlaveDB(); + $res = $dbr->selectRow( + 'imageredirects', + array( 'ir_from', 'ir_to' ), + array( 'ir_from' => $filename ), + __METHOD__ + ); + if( !$res ) return false; + return $res->ir_to; + } } diff --git a/maintenance/archives/patch-image_reditects.sql b/maintenance/archives/patch-image_reditects.sql new file mode 100644 index 0000000000..66c9b7ffb4 --- /dev/null +++ b/maintenance/archives/patch-image_reditects.sql @@ -0,0 +1,6 @@ +-- Image redirects. Only existent images are put in this table. +CREATE TABLE /*$wgDBprefix*/imageredirects ( + ir_from varchar(255) binary NOT NULL default '', + ir_to varchar(255) binary NOT NULL default '', + PRIMARY KEY ir_from (ir_from) +) /*$wgDBTableOptions*/; \ No newline at end of file diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 6282f52287..52b0ec5dfc 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -710,6 +710,17 @@ CREATE TABLE /*$wgDBprefix*/image ( ) /*$wgDBTableOptions*/; +-- +-- Image redirects. Only existent images are put in this table. +-- +CREATE TABLE /*$wgDBprefix*/imageredirects ( + -- Source image name + ir_from varchar(255) binary NOT NULL default '', + -- Destination image name + ir_to varchar(255) binary NOT NULL default '', + + PRIMARY KEY ir_from (ir_from) +) /*$wgDBTableOptions*/; -- -- Previous revisions of uploaded files. -- Awkwardly, image rows have to be moved into diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 9f7ce2a29f..4ec57351e1 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -23,22 +23,23 @@ $wgRenamedTables = array( $wgNewTables = array( # table patch file (in maintenance/archives) - array( 'hitcounter', 'patch-hitcounter.sql' ), - array( 'querycache', 'patch-querycache.sql' ), - array( 'objectcache', 'patch-objectcache.sql' ), - array( 'categorylinks', 'patch-categorylinks.sql' ), - array( 'logging', 'patch-logging.sql' ), - array( 'user_newtalk', 'patch-usernewtalk2.sql' ), - array( 'transcache', 'patch-transcache.sql' ), - array( 'trackbacks', 'patch-trackbacks.sql' ), - array( 'externallinks', 'patch-externallinks.sql' ), - array( 'job', 'patch-job.sql' ), - array( 'langlinks', 'patch-langlinks.sql' ), - array( 'querycache_info', 'patch-querycacheinfo.sql' ), - array( 'filearchive', 'patch-filearchive.sql' ), - array( 'querycachetwo', 'patch-querycachetwo.sql' ), - array( 'redirect', 'patch-redirect.sql' ), + array( 'hitcounter', 'patch-hitcounter.sql' ), + array( 'querycache', 'patch-querycache.sql' ), + array( 'objectcache', 'patch-objectcache.sql' ), + array( 'categorylinks', 'patch-categorylinks.sql' ), + array( 'logging', 'patch-logging.sql' ), + array( 'user_newtalk', 'patch-usernewtalk2.sql' ), + array( 'transcache', 'patch-transcache.sql' ), + array( 'trackbacks', 'patch-trackbacks.sql' ), + array( 'externallinks', 'patch-externallinks.sql' ), + array( 'job', 'patch-job.sql' ), + array( 'langlinks', 'patch-langlinks.sql' ), + array( 'querycache_info', 'patch-querycacheinfo.sql' ), + array( 'filearchive', 'patch-filearchive.sql' ), + array( 'querycachetwo', 'patch-querycachetwo.sql' ), + array( 'redirect', 'patch-redirect.sql' ), array( 'protected_titles', 'patch-protected_titles.sql' ), + array( 'imageredirects', 'patch-image_reditects.sql' ), ); $wgNewFields = array(