Index: trunk/extensions/SwiftMedia/LocalSettings.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | $wgDBpassword = "leakywiks"; |
57 | 57 | |
58 | 58 | # MySQL specific settings |
59 | | -$wgDBprefix = ""; |
| 59 | +$wgDBprefix = "mw2"; |
60 | 60 | |
61 | 61 | # MySQL table options to use during installation or update |
62 | 62 | $wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary"; |
— | — | @@ -99,11 +99,11 @@ |
100 | 100 | # Site language code, should be one of ./languages/Language(.*).php |
101 | 101 | $wgLanguageCode = "en"; |
102 | 102 | |
103 | | -$wgSecretKey = "790d7ee286c2fb4187b434ceb0fef12b45f30023a3d4613af8cddb164d7705aa"; |
| 103 | +$wgSecretKey = "cea5a22adfa63e596b38ff892af5ab63fecaca26a43a4c9df1a35c0a85e85259"; |
104 | 104 | |
105 | 105 | # Site upgrade key. Must be set to a string (default provided) to turn on the |
106 | 106 | # web installer while LocalSettings.php is in place |
107 | | -$wgUpgradeKey = "ab66efc4edb006fd"; |
| 107 | +$wgUpgradeKey = "5fd6cb729fc715bf"; |
108 | 108 | |
109 | 109 | ## Default skin: you can change the default skin. Use the internal symbolic |
110 | 110 | ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector': |
— | — | @@ -122,12 +122,15 @@ |
123 | 123 | # Path to the GNU diff3 utility. Used for conflict resolution. |
124 | 124 | $wgDiff3 = "/usr/bin/diff3"; |
125 | 125 | |
| 126 | +# Enabled Extensions. Most extensions are enabled by including the base extension file here |
| 127 | +# but check specific extension documentation for more details |
| 128 | +# The following extensions were automatically enabled: |
| 129 | +require( "extensions/SwiftMedia/SwiftMedia.php" ); |
126 | 130 | |
| 131 | + |
127 | 132 | # End of automatically generated settings. |
128 | 133 | # Add more configuration options below. |
129 | 134 | |
130 | | -require_once( "$IP/extensions/SwiftMedia/SwiftMedia.php" ); |
131 | | - |
132 | 135 | $wgUploadDirectory = "$IP/images/swift"; |
133 | 136 | // we don't need this and will ignore it. $wgDeletedDirectory = "{$wgUploadDirectory}/deleted"; |
134 | 137 | $wgUploadPath = "http://alsted.wikimedia.org/images/swift"; |
— | — | @@ -155,3 +158,4 @@ |
156 | 159 | $wgDebugLogFile = "/var/www/debug/abcd"; |
157 | 160 | $wgDebugTimestamps = true; |
158 | 161 | $wgShowExceptionDetails = true; |
| 162 | + |
Index: trunk/extensions/SwiftMedia/SwiftMedia.body.php |
— | — | @@ -98,12 +98,14 @@ |
99 | 99 | /** isVisible inherited */ |
100 | 100 | |
101 | 101 | function getPath() { |
102 | | - return $this->getLocalCopy($this->repo->container, $this->getRel()); |
| 102 | + $this->temp_path = $this->repo->getLocalCopy($this->repo->container, $this->getRel()); |
| 103 | + return $this->temp_path; |
103 | 104 | } |
104 | 105 | |
105 | 106 | /** Get the path of the archive directory, or a particular file if $suffix is specified */ |
106 | 107 | function getArchivePath( $suffix = false ) { |
107 | | - return $this->getLocalCopy($this->repo->getZoneContainer('public'), $this->getArchiveRel( $suffix )); |
| 108 | + $this->temp_path = $this->repo->getLocalCopy($this->repo->getZoneContainer('public'), $this->getArchiveRel( $suffix )); |
| 109 | + return $this->temp_path; |
108 | 110 | } |
109 | 111 | |
110 | 112 | /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */ |
— | — | @@ -112,76 +114,14 @@ |
113 | 115 | if ( $suffix !== false ) { |
114 | 116 | $path .= '/' . $suffix; |
115 | 117 | } |
116 | | - return $this->getLocalCopy($this->repo->getZoneContainer('thumb'), $path); |
117 | | - } |
118 | | - |
119 | | - /** |
120 | | - * Get a local path corresponding to a virtual URL |
121 | | - */ |
122 | | - function getContainerRel( $url ) { |
123 | | - if ( substr( $url, 0, 9 ) != 'mwrepo://' ) { |
124 | | - throw new MWException( __METHOD__.": unknown protocol" ); |
125 | | - } |
126 | | - |
127 | | - $bits = explode( '/', substr( $url, 9 ), 3 ); |
128 | | - if ( count( $bits ) != 3 ) { |
129 | | - throw new MWException( __METHOD__.": invalid mwrepo URL: $url" ); |
130 | | - } |
131 | | - list( $repo, $zone, $rel ) = $bits; |
132 | | - if ( $repo !== $this->name ) { |
133 | | - throw new MWException( __METHOD__.": fetching from a foreign repo is not supported" ); |
134 | | - } |
135 | | - $container = $this->getZoneContainer( $zone ); |
136 | | - if ( $container === false) { |
137 | | - throw new MWException( __METHOD__.": invalid zone: $zone" ); |
138 | | - } |
139 | | - return array($container, rawurldecode( $rel )); |
140 | | - } |
141 | | - |
142 | | - /** |
143 | | - * Called from elsewhere to turn a virtual URL into a path. |
144 | | - */ |
145 | | - function resolveVirtualUrl( $url ) { |
146 | | - $path = getContainerRel( $url ); |
147 | | - list($c, $r) = $path; |
148 | | - return $this->getLocalCopy($c, $r); |
149 | | - } |
150 | | - |
151 | | - |
152 | | - /** Given a container and relative path, return an absolute path pointing at a copy of the file */ |
153 | | - function getLocalCopy($container, $rel) { |
154 | | - // if we already have a local copy, return it. |
155 | | - if ($this->temp_path) { return $this->temp_path; } |
156 | | - |
157 | | - // get a temporary place to put the original. |
158 | | - $this->temp_path = tempnam( wfTempDir(), 'swift_in_' ); |
159 | | - |
160 | | - /* Fetch the image out of Swift */ |
161 | | - $conn = $this->repo->connect(); |
162 | | - $cont = $this->repo->get_container($conn,$container); |
163 | | - |
164 | | - try { |
165 | | - $obj = $cont->get_object($rel); |
166 | | - } catch (NoSuchObjectException $e) { |
167 | | - throw new MWException( "Unable to open original file at $container/$rel"); |
168 | | - } |
169 | | - |
170 | | - wfDebug( __METHOD__ . " writing to " . $this->temp_path . "\n"); |
171 | | - try { |
172 | | - $obj->save_to_filename( $this->temp_path); |
173 | | - } catch (IOException $e) { |
174 | | - throw new MWException( __METHOD__ . ": error opening '$e'" ); |
175 | | - } catch (InvalidResponseException $e) { |
176 | | - throw new MWException( __METHOD__ . "unexpected response '$e'" ); |
177 | | - } |
178 | | - |
| 118 | + $this->temp_path = $this->repo->getLocalCopy($this->repo->getZoneContainer('thumb'), $path); |
179 | 119 | return $this->temp_path; |
180 | 120 | } |
181 | 121 | |
182 | 122 | function __destruct() { |
183 | 123 | if ($this->temp_path) { |
184 | 124 | // Clean up temporary data. |
185 | | - unlink($this->temp_path); |
| 125 | + unlink( $this->temp_path ); |
186 | 126 | $this->temp_path = null; |
187 | 127 | } |
188 | 128 | } |
— | — | @@ -707,8 +647,6 @@ |
708 | 648 | * that the source files should be deleted if possible |
709 | 649 | */ |
710 | 650 | function publishBatch( $triplets, $flags = 0 ) { |
711 | | - $conn = $this->connect(); |
712 | | - $container = $this->get_container($conn,$this->container); |
713 | 651 | |
714 | 652 | # paranoia |
715 | 653 | $status = $this->newGood( array() ); |
— | — | @@ -721,16 +659,15 @@ |
722 | 660 | if ( !$this->validateFilename( $archiveRel ) ) { |
723 | 661 | throw new MWException( "Validation error in $archiveRel" ); |
724 | 662 | } |
725 | | - if ( !is_file( $srcPath ) ) { |
726 | | - // Make a list of files that don't exist for return to the caller |
727 | | - $status->fatal( 'filenotfound', $srcPath ); |
728 | | - } |
729 | 663 | } |
730 | 664 | |
731 | 665 | if ( !$status->ok ) { |
732 | 666 | return $status; |
733 | 667 | } |
734 | 668 | |
| 669 | + $conn = $this->connect(); |
| 670 | + $container = $this->get_container($conn,$this->container); |
| 671 | + |
735 | 672 | foreach ( $triplets as $i => $triplet ) { |
736 | 673 | list( $srcPath, $dstRel, $archiveRel ) = $triplet; |
737 | 674 | |
— | — | @@ -748,12 +685,25 @@ |
749 | 686 | $status->value[$i] = 'new'; |
750 | 687 | } |
751 | 688 | |
| 689 | + // Where are we copying this from? |
| 690 | + if (self::isVirtualUrl( $srcPath )) { |
| 691 | + $src = $this->getContainerRel( $srcPath ); |
| 692 | + list ($srcContainer, $srcRel) = $src; |
| 693 | + $srcc = $this->get_container($conn, $srcContainer); |
| 694 | + |
| 695 | + $this->swiftcopy($srcc, $srcRel, $container, $dstRel); |
| 696 | + if ( $flags & self::DELETE_SOURCE ) { |
| 697 | + $this->swift_delete( $srcc, $srcRel ); |
| 698 | + } |
| 699 | + } else { |
| 700 | + $this->write_swift_object( $srcPath, $container, $dstRel); |
| 701 | + // php-cloudfiles throws exceptions, so failure never gets here. |
| 702 | + if ( $flags & self::DELETE_SOURCE ) { |
| 703 | + unlink ( $srcPath ); |
| 704 | + } |
| 705 | + } |
| 706 | + |
752 | 707 | $good = true; |
753 | | - $this->write_swift_object( $srcPath, $container, $dstRel); |
754 | | - // php-cloudfiles throws exceptions, so failure never gets here. |
755 | | - if ( $flags & self::DELETE_SOURCE ) { |
756 | | - unlink ( $srcPath ); |
757 | | - } |
758 | 708 | |
759 | 709 | if ( $good ) { |
760 | 710 | $status->successCount++; |
— | — | @@ -863,7 +813,31 @@ |
864 | 814 | return false; |
865 | 815 | } |
866 | 816 | } |
| 817 | + |
867 | 818 | /** |
| 819 | + * Get a local path corresponding to a virtual URL |
| 820 | + */ |
| 821 | + function getContainerRel( $url ) { |
| 822 | + if ( substr( $url, 0, 9 ) != 'mwrepo://' ) { |
| 823 | + throw new MWException( __METHOD__.": unknown protocol" ); |
| 824 | + } |
| 825 | + |
| 826 | + $bits = explode( '/', substr( $url, 9 ), 3 ); |
| 827 | + if ( count( $bits ) != 3 ) { |
| 828 | + throw new MWException( __METHOD__.": invalid mwrepo URL: $url" ); |
| 829 | + } |
| 830 | + list( $repo, $zone, $rel ) = $bits; |
| 831 | + if ( $repo !== $this->name ) { |
| 832 | + throw new MWException( __METHOD__.": fetching from a foreign repo is not supported" ); |
| 833 | + } |
| 834 | + $container = $this->getZoneContainer( $zone ); |
| 835 | + if ( $container === false) { |
| 836 | + throw new MWException( __METHOD__.": invalid zone: $zone" ); |
| 837 | + } |
| 838 | + return array($container, rawurldecode( $rel )); |
| 839 | + } |
| 840 | + |
| 841 | + /** |
868 | 842 | * Remove a temporary file or mark it for garbage collection |
869 | 843 | * @param $virtualUrl String: the virtual URL returned by storeTemp |
870 | 844 | * @return Boolean: true on success, false on failure |
— | — | @@ -882,6 +856,62 @@ |
883 | 857 | } |
884 | 858 | |
885 | 859 | /** |
| 860 | + * Called from elsewhere to turn a virtual URL into a path. |
| 861 | + * Make sure you delete this file after you've used it!! |
| 862 | + */ |
| 863 | + function resolveVirtualUrl( $url ) { |
| 864 | + $path = $this->getContainerRel( $url ); |
| 865 | + list($c, $r) = $path; |
| 866 | + return $this->getLocalCopy($c, $r); |
| 867 | + } |
| 868 | + |
| 869 | + |
| 870 | + /** |
| 871 | + * Given a container and relative path, return an absolute path pointing at a |
| 872 | + * copy of the file MUST delete the produced file, or else store it in |
| 873 | + * SwiftFile->temp_path so it will be deleted when the object goes out of |
| 874 | + * scope. |
| 875 | + */ |
| 876 | + function getLocalCopy($container, $rel) { |
| 877 | + |
| 878 | + // get a temporary place to put the original. |
| 879 | + $temp_path = tempnam( wfTempDir(), 'swift_in_' ); |
| 880 | + |
| 881 | + /* Fetch the image out of Swift */ |
| 882 | + $conn = $this->connect(); |
| 883 | + $cont = $this->get_container($conn,$container); |
| 884 | + |
| 885 | + try { |
| 886 | + $obj = $cont->get_object($rel); |
| 887 | + } catch (NoSuchObjectException $e) { |
| 888 | + throw new MWException( "Unable to open original file at $container/$rel"); |
| 889 | + } |
| 890 | + |
| 891 | + wfDebug( __METHOD__ . " writing to " . $temp_path . "\n"); |
| 892 | + try { |
| 893 | + $obj->save_to_filename( $temp_path); |
| 894 | + } catch (IOException $e) { |
| 895 | + throw new MWException( __METHOD__ . ": error opening '$e'" ); |
| 896 | + } catch (InvalidResponseException $e) { |
| 897 | + throw new MWException( __METHOD__ . "unexpected response '$e'" ); |
| 898 | + } |
| 899 | + |
| 900 | + return $temp_path; |
| 901 | + } |
| 902 | + |
| 903 | + |
| 904 | + /** |
| 905 | + * Get properties of a file with a given virtual URL |
| 906 | + * The virtual URL must refer to this repo |
| 907 | + */ |
| 908 | + function getFileProps( $virtualUrl ) { |
| 909 | + $path = $this->resolveVirtualUrl( $virtualUrl ); |
| 910 | + $ret = File::getPropsFromPath( $path ); |
| 911 | + unlink( $path ); |
| 912 | + } |
| 913 | + |
| 914 | + |
| 915 | + /** |
886 | 916 | * Get an UploadStash associated with this repo. |
887 | 917 | * |
888 | 918 | * @return UploadStash |
— | — | @@ -892,9 +922,31 @@ |
893 | 923 | } |
894 | 924 | |
895 | 925 | class SwiftStash extends UploadStash { |
| 926 | + /** |
| 927 | + * Wrapper function for subclassing. |
| 928 | + */ |
| 929 | + protected function newFile( $path, $key, $data ) { |
| 930 | + wfDebug( __METHOD__ . ": deleting $key\n" ); |
| 931 | + return new SwiftStashFile( $this, $this->repo, $path, $key, $data ); |
| 932 | + } |
| 933 | + |
896 | 934 | } |
897 | 935 | |
898 | 936 | class SwiftStashFile extends UploadStashFile { |
| 937 | + //public function __construct( $stash, $repo, $path, $key, $data ) { |
| 938 | + // // We don't call parent:: because UploadStashFile expects to be able to call $this->resolveURL() and get a pathname. |
| 939 | + // $this->sessionStash = $stash; |
| 940 | + // $this->sessionKey = $key; |
| 941 | + // $this->sessionData = $data; |
| 942 | + // wfDebug( __METHOD__ . ": ($stash, $repo, $path, $key, $data)\n" ); |
| 943 | + |
| 944 | + // UnregisteredLocalFile::__construct( false, $repo, $path, false ); |
| 945 | + // $this->name = basename( $this->path ); |
| 946 | + |
| 947 | + //} |
| 948 | + |
| 949 | + //function getPath() { |
| 950 | + //} |
899 | 951 | } |
900 | 952 | |
901 | 953 | /** |