Index: trunk/extensions/NSFileRepo/NSFileRepo.php |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | 'path' => __FILE__, |
37 | 37 | 'name' => 'NSFileRepo', |
38 | 38 | 'author' => 'Jack D. Pond', |
39 | | - 'version' => '1.3', |
| 39 | + 'version' => '1.4alpha', |
40 | 40 | 'url' => 'http://www.mediawiki.org/wiki/Extension:NSFileRepo', |
41 | 41 | 'descriptionmsg' => 'nsfilerepo-desc' |
42 | 42 | ); |
— | — | @@ -113,6 +113,86 @@ |
114 | 114 | $filename = $bits[count($bits)-1]; |
115 | 115 | return $this->getHashPath() . rawurlencode( $filename ); |
116 | 116 | } |
| 117 | + |
| 118 | + /** Get the URL of the thumbnail directory, or a particular file if $suffix is specified */ |
| 119 | + function getThumbUrl( $suffix = false ) { |
| 120 | + $path = $this->repo->getZoneUrl('thumb') . '/' . $this->getUrlRel(); |
| 121 | + if ( $suffix !== false ) { |
| 122 | + $path .= '/' . rawurlencode( $this->getFileNameStripped($suffix) ); |
| 123 | + } |
| 124 | + return $path; |
| 125 | + } |
| 126 | + |
| 127 | + /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */ |
| 128 | + function getThumbPath( $suffix = false ) { |
| 129 | + $path = $this->repo->getZonePath('thumb') . '/' . $this->getRel(); |
| 130 | + if ( $suffix !== false ) { |
| 131 | + $path .= '/' . $this->getFileNameStripped($suffix); |
| 132 | + } |
| 133 | + return $path; |
| 134 | + } |
| 135 | + |
| 136 | + /** Get the relative path for an archive file */ |
| 137 | + function getArchiveRel( $suffix = false ) { |
| 138 | + $path = 'archive/' . $this->getHashPath(); |
| 139 | + if ( $suffix === false ) { |
| 140 | + $path = substr( $path, 0, -1 ); |
| 141 | + } else { |
| 142 | + $path .= $this->getFileNameStripped($suffix); |
| 143 | + } |
| 144 | + return $path; |
| 145 | + } |
| 146 | + |
| 147 | + /** Get the URL of the archive directory, or a particular file if $suffix is specified */ |
| 148 | + function getArchiveUrl( $suffix = false ) { |
| 149 | + $path = $this->repo->getZoneUrl('public') . '/archive/' . $this->getHashPath(); |
| 150 | + if ( $suffix === false ) { |
| 151 | + $path = substr( $path, 0, -1 ); |
| 152 | + } else { |
| 153 | + $path .= rawurlencode( $this->getFileNameStripped($suffix) ); |
| 154 | + } |
| 155 | + return $path; |
| 156 | + } |
| 157 | + |
| 158 | + /** Get the virtual URL for an archive file or directory */ |
| 159 | + function getArchiveVirtualUrl( $suffix = false ) { |
| 160 | + $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath(); |
| 161 | + if ( $suffix === false ) { |
| 162 | + $path = substr( $path, 0, -1 ); |
| 163 | + } else { |
| 164 | + $path .= rawurlencode( $this->getFileNameStripped($suffix) ); |
| 165 | + } |
| 166 | + return $path; |
| 167 | + } |
| 168 | + |
| 169 | + /** Get the virtual URL for a thumbnail file or directory */ |
| 170 | + function getThumbVirtualUrl( $suffix = false ) { |
| 171 | + $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel(); |
| 172 | + if ( $suffix !== false ) { |
| 173 | + $path .= '/' . rawurlencode( $this->getFileNameStripped($suffix) ); |
| 174 | + } |
| 175 | + return $path; |
| 176 | + } |
| 177 | + |
| 178 | + /** Get the virtual URL for the file itself */ |
| 179 | + function getVirtualUrl( $suffix = false ) { |
| 180 | + $path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel(); |
| 181 | + if ( $suffix !== false ) { |
| 182 | + $path .= '/' . rawurlencode( $this->getFileNameStripped($suffix) ); |
| 183 | + } |
| 184 | + return $path; |
| 185 | + } |
| 186 | + |
| 187 | + /** Strip namespace (if any) from file name */ |
| 188 | + function getFileNameStripped($suffix) { |
| 189 | + $bits=explode(':',$suffix); |
| 190 | + $filename = $bits[count($bits)-1]; |
| 191 | + $pxpos = strpos($suffix,"px-"); |
| 192 | + if (count($bits) > 1 && $pxpos) $filename= substr($suffix,0,$pxpos+3).$filename; |
| 193 | + return $filename; |
| 194 | + } |
| 195 | + |
| 196 | + |
117 | 197 | /** |
118 | 198 | * This function overrides the LocalFile because the archive name should not contain the namespace in the |
119 | 199 | * filename. Otherwise the function would have worked. This only affects reuploads |
— | — | @@ -136,8 +216,7 @@ |
137 | 217 | $this->lock(); |
138 | 218 | $dstRel = $this->getRel(); |
139 | 219 | /* This is the part that changed from LocalFile */ |
140 | | - $bits=explode(':',$this->getName()); |
141 | | - $archiveName = gmdate( 'YmdHis' ) . '!'.$bits[count($bits)-1]; |
| 220 | + $archiveName = gmdate( 'YmdHis' ) . '!'.$this->getFileNameStripped($this->getName()); |
142 | 221 | /* End of changes */ |
143 | 222 | $archiveRel = 'archive/' . $this->getHashPath() . $archiveName; |
144 | 223 | $flags = $flags & File::DELETE_SOURCE ? LocalRepo::DELETE_SOURCE : 0; |
— | — | @@ -151,8 +230,46 @@ |
152 | 231 | return $status; |
153 | 232 | } |
154 | 233 | |
| 234 | + /** |
| 235 | + * The only thing changed here is that the array needs to strip the NS from the file name for the has (oldname is already fixed) |
| 236 | + * Add the old versions of the image to the batch |
| 237 | + */ |
| 238 | + function addOlds() { |
| 239 | + $archiveBase = 'archive'; |
| 240 | + $this->olds = array(); |
| 241 | + $this->oldCount = 0; |
155 | 242 | |
| 243 | + $result = $this->db->select( 'oldimage', |
| 244 | + array( 'oi_archive_name', 'oi_deleted' ), |
| 245 | + array( 'oi_name' => $this->oldName ), |
| 246 | + __METHOD__ |
| 247 | + ); |
| 248 | + while( $row = $this->db->fetchObject( $result ) ) { |
| 249 | + $oldName = $row->oi_archive_name; |
| 250 | + $bits = explode( '!', $oldName, 2 ); |
| 251 | + if( count( $bits ) != 2 ) { |
| 252 | + wfDebug( "Invalid old file name: $oldName \n" ); |
| 253 | + continue; |
| 254 | + } |
| 255 | + list( $timestamp, $filename ) = $bits; |
| 256 | + if( $this->oldName != $filename ) { |
| 257 | + wfDebug( "Invalid old file name: $oldName \n" ); |
| 258 | + continue; |
| 259 | + } |
| 260 | + $this->oldCount++; |
| 261 | + // Do we want to add those to oldCount? |
| 262 | + if( $row->oi_deleted & File::DELETED_FILE ) { |
| 263 | + continue; |
| 264 | + } |
| 265 | + $this->olds[] = array( |
| 266 | + "{$archiveBase}/{$this->oldHash}{$oldName}", |
| 267 | + "{$archiveBase}/{$this->newHash}{$timestamp}!".$this->getFileNameStripped($this->newName) |
| 268 | + ); |
| 269 | + } |
| 270 | + $this->db->freeResult( $result ); |
| 271 | + } |
156 | 272 | |
| 273 | + |
157 | 274 | /** Instantiating this class using "self" |
158 | 275 | * If you're reading this, you're problably wondering why on earth are the following static functions, which are copied |
159 | 276 | * verbatim from the original extended class "LocalFIle" included here? |
— | — | @@ -178,7 +295,7 @@ |
179 | 296 | */ |
180 | 297 | |
181 | 298 | static function newFromRow( $row, $repo ) { |
182 | | - $title = Title::makeTitle( NS_FILE, $row->img_name ); |
| 299 | + $title = Title::makeTitle( NS_IMAGE, $row->img_name ); |
183 | 300 | $file = new self( $title, $repo ); |
184 | 301 | $file->loadFromRow( $row ); |
185 | 302 | return $file; |
— | — | @@ -195,6 +312,33 @@ |
196 | 313 | function publish( $srcPath, $flags = 0 ) { |
197 | 314 | return NSLocalFile::publish( $srcPath, $flags ); |
198 | 315 | } |
| 316 | + function getThumbUrl( $suffix = false ) { |
| 317 | + return(NSLocalFile::getThumbUrl( $suffix ) ); |
| 318 | + } |
| 319 | + function getThumbPath( $suffix = false ) { |
| 320 | + return(NSLocalFile::getThumbPath( $suffix )); |
| 321 | + } |
| 322 | + function getArchiveRel( $suffix = false ) { |
| 323 | + return(NSLocalFile::getArchiveRel( $suffix )); |
| 324 | + } |
| 325 | + function getArchiveUrl( $suffix = false ) { |
| 326 | + return(NSLocalFile::getArchiveUrl( $suffix )); |
| 327 | + } |
| 328 | + function getArchiveVirtualUrl( $suffix = false ) { |
| 329 | + return(NSLocalFile::getArchiveVirtualUrl( $suffix )); |
| 330 | + } |
| 331 | + function getThumbVirtualUrl( $suffix = false ) { |
| 332 | + return(NSLocalFile::getArchiveVirtualUrl( $suffix )); |
| 333 | + } |
| 334 | + function getVirtualUrl( $suffix = false ) { |
| 335 | + return(NSLocalFile::getVirtualUrl( $suffix )); |
| 336 | + } |
| 337 | + function getThumbStripped($suffix) { |
| 338 | + return(NSLocalFile::getThumbStripped($suffix)); |
| 339 | + } |
| 340 | + function addOlds() { |
| 341 | + return(NSLocalFile::addOlds()); |
| 342 | + } |
199 | 343 | |
200 | 344 | /** See comment about Instantiating this class using "self", above */ |
201 | 345 | |
— | — | @@ -210,7 +354,7 @@ |
211 | 355 | } |
212 | 356 | |
213 | 357 | static function newFromRow( $row, $repo ) { |
214 | | - $title = Title::makeTitle( NS_FILE, $row->oi_name ); |
| 358 | + $title = Title::makeTitle( NS_IMAGE, $row->oi_name ); |
215 | 359 | $file = new self( $title, $repo, null, $row->oi_archive_name ); |
216 | 360 | $file->loadFromRow( $row, 'oi_' ); |
217 | 361 | return $file; |
— | — | @@ -251,7 +395,7 @@ |
252 | 396 | global $wgWhitelistRead; |
253 | 397 | if (in_array($title->getPrefixedText(), $wgWhitelistRead)) return true; |
254 | 398 | if (function_exists('lockdownUserCan')){ |
255 | | - if($title->getNamespace() == NS_FILE) { |
| 399 | + if($title->getNamespace() == NS_IMAGE) { |
256 | 400 | $ntitle = Title::newFromText($title->mDbkeyform); |
257 | 401 | return ($ntitle->mNamespace < 100) ? true : lockdownUserCan($ntitle, $user, $action, $result); |
258 | 402 | } |
— | — | @@ -265,9 +409,10 @@ |
266 | 410 | # See if stored in a NS path |
267 | 411 | |
268 | 412 | $subdirs = explode('/',$path); |
269 | | - $x = (strlen($subdirs[1]) <> 3 && ($subdirs[1] == "archive" || $subdirs[1] == "deleted" || $subdirs[1] == "thumb")) ? 2 : 1; |
270 | | - if (strlen($subdirs[$x]) == 3 && is_numeric($subdirs[$x]) && $subdirs[$x] >= 100) { |
271 | | - $title = Title::makeTitleSafe( NS_FILE, $wgContLang->getNsText($subdirs[$x]).":".$name ); |
| 413 | + $x = (!is_numeric($subdirs[1]) && ($subdirs[1] == "archive" || $subdirs[1] == "deleted" || $subdirs[1] == "thumb")) ? 2 : 1; |
| 414 | + $x = ($x == 2 && $subdirs[1] == "thumb" && $subdirs[2] == "archive") ? 3 : $x; |
| 415 | + if (strlen($subdirs[$x]) >= 3 && is_numeric($subdirs[$x]) && $subdirs[$x] >= 100) { |
| 416 | + $title = Title::makeTitleSafe( NS_IMAGE, $wgContLang->getNsText($subdirs[$x]).":".$name ); |
272 | 417 | if( !$title instanceof Title ) { |
273 | 418 | $result = array('img-auth-accessdenied','img-auth-badtitle',$name); |
274 | 419 | return false; |