Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
NSLocalRepo
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 getHashPathForLevel
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getHashPath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 storeTemp
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getFileNameStripped
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3use MediaWiki\MediaWikiServices;
4
5/**
6 * Class definitions for NSFileRepo
7 */
8
9class NSLocalRepo extends LocalRepo {
10    protected $fileFactory = array( 'NSLocalFile', 'newFromTitle' );
11    protected $fileFactoryKey = array( 'NSLocalFile', 'newFromKey' );
12    protected $oldFileFactory = array( 'NSOldLocalFile', 'newFromTitle' );
13    protected $fileFromRowFactory = array( 'NSLocalFile', 'newFromRow' );
14    protected $oldFileFromRowFactory = array( 'NSOldLocalFile', 'newFromRow' );
15    protected $oldFileFactoryKey = array( 'NSOldLocalFile', 'newFromKey' );
16
17    static function getHashPathForLevel( $name, $levels ) {
18        $bits = explode( ':',$name );
19        $filename = $bits[ count( $bits ) - 1 ];
20        $path = parent::getHashPathForLevel( $filename, $levels );
21        return count( $bits ) > 1 ?
22            MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $bits[0] ) .'/'. $path : $path;
23    }
24
25    /**
26     * Get a relative path including trailing slash, e.g. f/fa/
27     * If the repo is not hashed, returns an empty string
28     * This is needed because self:: will call parent if not included - exact same as in FSRepo
29     */
30    function getHashPath( $name ) {
31        return self::getHashPathForLevel( $name, $this->hashLevels );
32    }
33
34    /**
35     * Pick a random name in the temp zone and store a file to it.
36     * @param string $originalName The base name of the file as specified
37     *     by the user. The file extension will be maintained.
38     * @param string $srcPath The current location of the file.
39     * @return Status object with the URL in the value.
40     */
41    function storeTemp( $originalName, $srcPath ) {
42        $date = gmdate( "YmdHis" );
43        $hashPath = $this->getHashPath( $originalName );
44        $filename = $this->getFileNameStripped( $originalName );
45        $dstRel = "$hashPath$date!$filename";
46        $dstUrlRel = $hashPath . $date . '!' . rawurlencode( $filename );
47        $result = $this->store( $srcPath, 'temp', $dstRel );
48        $result->value = $this->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
49        return $result;
50    }
51
52    function getFileNameStripped($suffix) {
53        return(NSLocalFile::getFileNameStripped($suffix));
54    }
55}