r28986 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28985‎ | r28986 | r28987 >
Date:09:32, 29 December 2007
Author:vasilievvv
Status:old
Tags:
Comment:
* Support images-redirects
Note: this revision requires schema change
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-image_reditects.sql (added) (history)
  • /trunk/phase3/maintenance/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

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
18 + native
Index: trunk/phase3/maintenance/updaters.inc
@@ -23,22 +23,23 @@
2424
2525 $wgNewTables = array(
2626 # 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' ),
4242 array( 'protected_titles', 'patch-protected_titles.sql' ),
 43+ array( 'imageredirects', 'patch-image_reditects.sql' ),
4344 );
4445
4546 $wgNewFields = array(
Index: trunk/phase3/maintenance/tables.sql
@@ -711,6 +711,17 @@
712712 ) /*$wgDBTableOptions*/;
713713
714714 --
 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+--
715726 -- Previous revisions of uploaded files.
716727 -- Awkwardly, image rows have to be moved into
717728 -- this table at re-upload time.
Index: trunk/phase3/includes/Article.php
@@ -1098,6 +1098,28 @@
10991099 $isRedirect = !is_null($redirectTitle);
11001100 if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
11011101
 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+
11021124 wfProfileIn( __METHOD__ );
11031125
11041126 if ($isRedirect) {
@@ -1117,7 +1139,7 @@
11181140 }
11191141
11201142 wfProfileOut( __METHOD__ );
1121 - return ( $dbw->affectedRows() != 0 );
 1143+ return ( $dbw->affectedRows() != 0 ) && $imageResult;
11221144 }
11231145
11241146 return true;
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -76,7 +76,14 @@
7777 *
7878 * @param mixed $time 14-character timestamp, or false for the current version
7979 */
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+
8188 # First try the current version of the file to see if it precedes the timestamp
8289 $img = $this->newFile( $title );
8390 if ( !$img ) {
@@ -90,6 +97,13 @@
9198 if ( $img->exists() ) {
9299 return $img;
93100 }
 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+ }
94108 }
95109
96110 /**
@@ -400,5 +414,20 @@
401415 * STUB
402416 */
403417 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+ }
404433 }
405434
Index: trunk/phase3/RELEASE-NOTES
@@ -112,6 +112,7 @@
113113 * Add HTML ID's mw-read-only-warning and mw-anon-edit-warning to warnings when
114114 editing to allow CSS styling.
115115 * Parser now returns list of sections
 116+* Support images-redirects
116117
117118 === Bug fixes in 1.12 ===
118119

Follow-up revisions

RevisionCommit summaryAuthorDate
r29128Revert for now r28986, 28987, 28992 - image redirects....brion20:26, 31 December 2007

Status & tagging log