Index: trunk/phase3/maintenance/archives/patch-image_reditects.sql |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +-- Image redirects. Only existent images are put in this table. |
| 3 | +CREATE TABLE /*$wgDBprefix*/imageredirects ( |
| 4 | + ir_from varchar(255) binary NOT NULL default '', |
| 5 | + ir_to varchar(255) binary NOT NULL default '', |
| 6 | + PRIMARY KEY ir_from (ir_from) |
| 7 | +) /*$wgDBTableOptions*/; |
\ No newline at end of file |
Property changes on: trunk/phase3/maintenance/archives/patch-image_reditects.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -23,22 +23,23 @@ |
24 | 24 | |
25 | 25 | $wgNewTables = array( |
26 | 26 | # table patch file (in maintenance/archives) |
27 | | - array( 'hitcounter', 'patch-hitcounter.sql' ), |
28 | | - array( 'querycache', 'patch-querycache.sql' ), |
29 | | - array( 'objectcache', 'patch-objectcache.sql' ), |
30 | | - array( 'categorylinks', 'patch-categorylinks.sql' ), |
31 | | - array( 'logging', 'patch-logging.sql' ), |
32 | | - array( 'user_newtalk', 'patch-usernewtalk2.sql' ), |
33 | | - array( 'transcache', 'patch-transcache.sql' ), |
34 | | - array( 'trackbacks', 'patch-trackbacks.sql' ), |
35 | | - array( 'externallinks', 'patch-externallinks.sql' ), |
36 | | - array( 'job', 'patch-job.sql' ), |
37 | | - array( 'langlinks', 'patch-langlinks.sql' ), |
38 | | - array( 'querycache_info', 'patch-querycacheinfo.sql' ), |
39 | | - array( 'filearchive', 'patch-filearchive.sql' ), |
40 | | - array( 'querycachetwo', 'patch-querycachetwo.sql' ), |
41 | | - array( 'redirect', 'patch-redirect.sql' ), |
| 27 | + array( 'hitcounter', 'patch-hitcounter.sql' ), |
| 28 | + array( 'querycache', 'patch-querycache.sql' ), |
| 29 | + array( 'objectcache', 'patch-objectcache.sql' ), |
| 30 | + array( 'categorylinks', 'patch-categorylinks.sql' ), |
| 31 | + array( 'logging', 'patch-logging.sql' ), |
| 32 | + array( 'user_newtalk', 'patch-usernewtalk2.sql' ), |
| 33 | + array( 'transcache', 'patch-transcache.sql' ), |
| 34 | + array( 'trackbacks', 'patch-trackbacks.sql' ), |
| 35 | + array( 'externallinks', 'patch-externallinks.sql' ), |
| 36 | + array( 'job', 'patch-job.sql' ), |
| 37 | + array( 'langlinks', 'patch-langlinks.sql' ), |
| 38 | + array( 'querycache_info', 'patch-querycacheinfo.sql' ), |
| 39 | + array( 'filearchive', 'patch-filearchive.sql' ), |
| 40 | + array( 'querycachetwo', 'patch-querycachetwo.sql' ), |
| 41 | + array( 'redirect', 'patch-redirect.sql' ), |
42 | 42 | array( 'protected_titles', 'patch-protected_titles.sql' ), |
| 43 | + array( 'imageredirects', 'patch-image_reditects.sql' ), |
43 | 44 | ); |
44 | 45 | |
45 | 46 | $wgNewFields = array( |
Index: trunk/phase3/maintenance/tables.sql |
— | — | @@ -711,6 +711,17 @@ |
712 | 712 | ) /*$wgDBTableOptions*/; |
713 | 713 | |
714 | 714 | -- |
| 715 | +-- Image redirects. Only existent images are put in this table. |
| 716 | +-- |
| 717 | +CREATE TABLE /*$wgDBprefix*/imageredirects ( |
| 718 | + -- Source image name |
| 719 | + ir_from varchar(255) binary NOT NULL default '', |
| 720 | + -- Destination image name |
| 721 | + ir_to varchar(255) binary NOT NULL default '', |
| 722 | + |
| 723 | + PRIMARY KEY ir_from (ir_from) |
| 724 | +) /*$wgDBTableOptions*/; |
| 725 | +-- |
715 | 726 | -- Previous revisions of uploaded files. |
716 | 727 | -- Awkwardly, image rows have to be moved into |
717 | 728 | -- this table at re-upload time. |
Index: trunk/phase3/includes/Article.php |
— | — | @@ -1098,6 +1098,28 @@ |
1099 | 1099 | $isRedirect = !is_null($redirectTitle); |
1100 | 1100 | if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) { |
1101 | 1101 | |
| 1102 | + $imageResult = true; //Result of imageredirects handling |
| 1103 | + file_put_contents( "C:\\err.txt", strval( $this->mTitle->getNamespace() == NS_IMAGE ) ); |
| 1104 | + if( $this->mTitle->getNamespace() == NS_IMAGE ) { |
| 1105 | + wfProfileIn( __METHOD__ . "-img" ); |
| 1106 | + |
| 1107 | + $exists = $redirectTitle ? RepoGroup::singleton()->findFile( $redirectTitle->getDBkey() ) !== false : false; |
| 1108 | + if( $isRedirect && $redirectTitle->getNamespace() == NS_IMAGE && $exists ) { |
| 1109 | + $set = array( |
| 1110 | + 'ir_from' => $this->mTitle->getDBkey(), |
| 1111 | + 'ir_to' => $redirectTitle->getDBkey(), |
| 1112 | + ); |
| 1113 | + $dbw->replace( 'imageredirects', array( 'ir_from' ), $set, __METHOD__ ); |
| 1114 | + $imageResult = $dbw->affectedRows() != 0; |
| 1115 | + } else { |
| 1116 | + // Non-redirect or redirect to non-image |
| 1117 | + $where = array( 'ir_from' => $this->mTitle->getDBkey() ); |
| 1118 | + $dbw->delete( 'imageredirects', $where, __METHOD__ ); |
| 1119 | + } |
| 1120 | + |
| 1121 | + wfProfileOut( __METHOD__ . "-img" ); |
| 1122 | + } |
| 1123 | + |
1102 | 1124 | wfProfileIn( __METHOD__ ); |
1103 | 1125 | |
1104 | 1126 | if ($isRedirect) { |
— | — | @@ -1117,7 +1139,7 @@ |
1118 | 1140 | } |
1119 | 1141 | |
1120 | 1142 | wfProfileOut( __METHOD__ ); |
1121 | | - return ( $dbw->affectedRows() != 0 ); |
| 1143 | + return ( $dbw->affectedRows() != 0 ) && $imageResult; |
1122 | 1144 | } |
1123 | 1145 | |
1124 | 1146 | return true; |
Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -76,7 +76,14 @@ |
77 | 77 | * |
78 | 78 | * @param mixed $time 14-character timestamp, or false for the current version |
79 | 79 | */ |
80 | | - function findFile( $title, $time = false ) { |
| 80 | + function findFile( $title, $time = false, $redirected = false ) { |
| 81 | + if ( !($title instanceof Title) ) { |
| 82 | + $title = Title::makeTitleSafe( NS_IMAGE, $title ); |
| 83 | + if ( !is_object( $title ) ) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + } |
| 87 | + |
81 | 88 | # First try the current version of the file to see if it precedes the timestamp |
82 | 89 | $img = $this->newFile( $title ); |
83 | 90 | if ( !$img ) { |
— | — | @@ -90,6 +97,13 @@ |
91 | 98 | if ( $img->exists() ) { |
92 | 99 | return $img; |
93 | 100 | } |
| 101 | + |
| 102 | + #Try redirects |
| 103 | + if( !$redirected ) { // Prevent redirect loops |
| 104 | + $redir = $this->checkRedirects( $title->getDBkey() ); |
| 105 | + if( $redir ) |
| 106 | + return $this->findFile( $redir, $time, $title ); |
| 107 | + } |
94 | 108 | } |
95 | 109 | |
96 | 110 | /** |
— | — | @@ -400,5 +414,20 @@ |
401 | 415 | * STUB |
402 | 416 | */ |
403 | 417 | function cleanupDeletedBatch( $storageKeys ) {} |
| 418 | + |
| 419 | + /** |
| 420 | + * Check for redirects. |
| 421 | + */ |
| 422 | + function checkRedirects( $filename ) { |
| 423 | + $dbr = $this->getSlaveDB(); |
| 424 | + $res = $dbr->selectRow( |
| 425 | + 'imageredirects', |
| 426 | + array( 'ir_from', 'ir_to' ), |
| 427 | + array( 'ir_from' => $filename ), |
| 428 | + __METHOD__ |
| 429 | + ); |
| 430 | + if( !$res ) return false; |
| 431 | + return $res->ir_to; |
| 432 | + } |
404 | 433 | } |
405 | 434 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -112,6 +112,7 @@ |
113 | 113 | * Add HTML ID's mw-read-only-warning and mw-anon-edit-warning to warnings when |
114 | 114 | editing to allow CSS styling. |
115 | 115 | * Parser now returns list of sections |
| 116 | +* Support images-redirects |
116 | 117 | |
117 | 118 | === Bug fixes in 1.12 === |
118 | 119 | |