r60772 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60771‎ | r60772 | r60773 >
Date:07:13, 7 January 2010
Author:robla
Status:deferred
Tags:
Comment:
Adding new functions in preparation for decoupling page title from MIME type (bug 4421)
Modified paths:
  • /branches/extensionless-files/includes/FileRevertForm.php (modified) (history)
  • /branches/extensionless-files/includes/ImagePage.php (modified) (history)
  • /branches/extensionless-files/includes/filerepo/File.php (modified) (history)
  • /branches/extensionless-files/includes/filerepo/FileRepo.php (modified) (history)
  • /branches/extensionless-files/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: branches/extensionless-files/includes/FileRevertForm.php
@@ -64,7 +64,7 @@
6565
6666 // Perform the reversion if appropriate
6767 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->archiveName ) ) {
68 - $source = $this->file->getArchiveVirtualUrl( $this->archiveName );
 68+ $source = $this->file->getArchiveVirtualUrl( $this->getOldFile()->getArchiveFilename() );
6969 $comment = $wgRequest->getText( 'wpComment' );
7070 // TODO: Preserve file properties from database instead of reloading from file
7171 $status = $this->file->upload( $source, $comment, $comment );
@@ -72,9 +72,10 @@
7373 $wgOut->addHTML( wfMsgExt( 'filerevert-success', 'parse', $this->title->getText(),
7474 $wgLang->date( $this->getTimestamp(), true ),
7575 $wgLang->time( $this->getTimestamp(), true ),
76 - wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) ) );
 76+ wfExpandUrl( $this->file->getArchiveUrl( $this->getOldFile()->getArchiveFilename() ) ) ) );
7777 $wgOut->returnToMain( false, $this->title );
7878 } else {
 79+ wfDebugLog('filerevert', __METHOD__.": revert failed during upload. source: $source\n");
7980 $wgOut->addWikiText( $status->getWikiText() );
8081 }
8182 return;
@@ -96,7 +97,7 @@
9798 $form .= '<fieldset><legend>' . wfMsgHtml( 'filerevert-legend' ) . '</legend>';
9899 $form .= wfMsgExt( 'filerevert-intro', 'parse', $this->title->getText(),
99100 $wgLang->date( $timestamp, true ), $wgLang->time( $timestamp, true ),
100 - wfExpandUrl( $this->file->getArchiveUrl( $this->archiveName ) ) );
 101+ wfExpandUrl( $this->file->getArchiveUrl( $this->getOldFile()->getArchiveFilename() ) ) );
101102 $form .= '<p>' . Xml::inputLabel( wfMsg( 'filerevert-comment' ), 'wpComment', 'wpComment',
102103 60, wfMsgForContent( 'filerevert-defaultcomment',
103104 $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ) ) . '</p>';
Index: branches/extensionless-files/includes/filerepo/FileRepo.php
@@ -252,7 +252,8 @@
253253 }
254254
255255 /**
256 - * Get the name of an image from its title object
 256+ * Get the name of an image from its title object. Only use this for
 257+ * generating hash keys.
257258 */
258259 function getNameFromTitle( $title ) {
259260 global $wgCapitalLinks;
@@ -268,6 +269,15 @@
269270 return $name;
270271 }
271272
 273+ /**
 274+ * Get the file name of an image from its title object, possibly with a
 275+ * generated extension.
 276+ * Stub function pending full implementation of bug 4421.
 277+ */
 278+ function getFilenameFromTitle( $title , $mime = NULL ) {
 279+ return $this->getNameFromTitle( $title );
 280+ }
 281+
272282 static function getHashPathForLevel( $name, $levels ) {
273283 if ( $levels == 0 ) {
274284 return '';
Index: branches/extensionless-files/includes/filerepo/File.php
@@ -140,7 +140,9 @@
141141 }
142142
143143 /**
144 - * Return the name of this file
 144+ * Return the name of this file for purposes of reading from the database
 145+ * and generating hash keys. Use getFilename if you're interested in what
 146+ * is actually on the disk
145147 */
146148 public function getName() {
147149 if ( !isset( $this->name ) ) {
@@ -150,6 +152,14 @@
151153 }
152154
153155 /**
 156+ * Return the file name of this file
 157+ * Stub function pending full implementation of bug 4421.
 158+ */
 159+ public function getFilename() {
 160+ return $this->getName();
 161+ }
 162+
 163+ /**
154164 * Get the file extension, e.g. "svg"
155165 */
156166 function getExtension() {
@@ -477,7 +487,7 @@
478488 }
479489 $extension = $this->getExtension();
480490 list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType() );
481 - $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getName();
 491+ $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getFilename();
482492 if ( $thumbExt != $extension ) {
483493 $thumbName .= ".$thumbExt";
484494 }
@@ -748,6 +758,13 @@
749759 * Get the path of the file relative to the public zone root
750760 */
751761 function getRel() {
 762+ return $this->getHashPath() . $this->getFilename();
 763+ }
 764+
 765+ /**
 766+ * Get the path of the thumb directory relative to the public zone root
 767+ */
 768+ function getThumbRel() {
752769 return $this->getHashPath() . $this->getName();
753770 }
754771
@@ -755,6 +772,13 @@
756773 * Get urlencoded relative path of the file
757774 */
758775 function getUrlRel() {
 776+ return $this->getHashPath() . rawurlencode( $this->getFilename() );
 777+ }
 778+
 779+ /**
 780+ * Get urlencoded relative path of the thumb directory
 781+ */
 782+ function getThumbUrlRel() {
759783 return $this->getHashPath() . rawurlencode( $this->getName() );
760784 }
761785
@@ -776,10 +800,11 @@
777801
778802 /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */
779803 function getThumbPath( $suffix = false ) {
780 - $path = $this->repo->getZonePath('thumb') . '/' . $this->getRel();
 804+ $path = $this->repo->getZonePath('thumb') . '/' . $this->getThumbRel();
781805 if ( $suffix !== false ) {
782806 $path .= '/' . $suffix;
783807 }
 808+ wfDebugLog( 'thumb', __METHOD__." path: {$path}\n" );
784809 return $path;
785810 }
786811
@@ -796,7 +821,7 @@
797822
798823 /** Get the URL of the thumbnail directory, or a particular file if $suffix is specified */
799824 function getThumbUrl( $suffix = false ) {
800 - $path = $this->repo->getZoneUrl('thumb') . '/' . $this->getUrlRel();
 825+ $path = $this->repo->getZoneUrl('thumb') . '/' . $this->getThumbUrlRel();
801826 if ( $suffix !== false ) {
802827 $path .= '/' . rawurlencode( $suffix );
803828 }
@@ -816,7 +841,7 @@
817842
818843 /** Get the virtual URL for a thumbnail file or directory */
819844 function getThumbVirtualUrl( $suffix = false ) {
820 - $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
 845+ $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getThumbUrlRel();
821846 if ( $suffix !== false ) {
822847 $path .= '/' . rawurlencode( $suffix );
823848 }
Index: branches/extensionless-files/includes/filerepo/OldLocalFile.php
@@ -95,6 +95,14 @@
9696 return $this->archive_name;
9797 }
9898
 99+ /**
 100+ * This function tacks on file extension to archive_name, if needed.
 101+ * Stub function pending full implementation of bug 4421.
 102+ */
 103+ public function getArchiveFilename() {
 104+ return $this->getArchiveName();
 105+ }
 106+
99107 function isOld() {
100108 return true;
101109 }
@@ -131,11 +139,11 @@
132140 }
133141
134142 function getRel() {
135 - return 'archive/' . $this->getHashPath() . $this->getArchiveName();
 143+ return 'archive/' . $this->getHashPath() . $this->getArchiveFilename();
136144 }
137145
138146 function getUrlRel() {
139 - return 'archive/' . $this->getHashPath() . urlencode( $this->getArchiveName() );
 147+ return 'archive/' . $this->getHashPath() . urlencode( $this->getArchiveFilename() );
140148 }
141149
142150 function upgradeRow() {
Index: branches/extensionless-files/includes/ImagePage.php
@@ -942,7 +942,7 @@
943943 );
944944 $row .= '<span class="history-deleted">'.$url.'</span>';
945945 } else {
946 - $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
 946+ $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $file->getArchiveFilename() );
947947 $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
948948 }
949949 $row .= "</td>";

Follow-up revisions

RevisionCommit summaryAuthorDate
r60773Decouple page titles from MIME type, adding img_file_ext field to db (bug 4421robla07:15, 7 January 2010
r60778Some extra file deletion debug logging (probably superfluous)...robla07:32, 7 January 2010
r60779Adding forgotten patch-img_file_ext.sql. Critical for bug 4421 fixrobla07:41, 7 January 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r60762Development branch for bug 4421 (Image file extension should not be part of t...robla03:14, 7 January 2010

Status & tagging log