Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
NSFileRepoHelper | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
getTitleFromPath | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | class NSFileRepoHelper { |
4 | protected $pathRegEx = '#\\/(thumb\\/|archive\\/|deleted\\/)?(\d*?)?\\/[a-f0-9]{1}\\/[a-f0-9]{2}\\/(.*?)$#'; |
5 | |
6 | /** |
7 | * Returns a Title object that can be used to check permissions against. ATTENTION: It will _not_ return a |
8 | * Title from NS_FILE, but either from NS_MAIN, or from the specific namespace that was found in the path! |
9 | * Examples for $path: |
10 | * /thumb/1502/7/78/Some_File.png/300px-Some_File.png |
11 | * /1502/7/78/Some_File.png |
12 | * @param $path |
13 | * @return null|Title |
14 | */ |
15 | public function getTitleFromPath( $path ) { |
16 | $filename = wfBaseName( $path ); |
17 | if( UploadBase::isThumbName( $filename ) ) { |
18 | //HINT: Thumbname-to-filename-conversion taken from includes/Upload/UploadBase.php |
19 | //Check for filenames like 50px- or 180px-, these are mostly thumbnails |
20 | $filename = substr( $filename , strpos( $filename , '-' ) +1 ); |
21 | } |
22 | |
23 | $title = Title::newFromText( $filename ); |
24 | |
25 | $matches = array(); |
26 | preg_match( $this->pathRegEx , $path, $matches ); |
27 | if( empty( $matches[2] ) ) { //Not a file from a namespace? |
28 | return $title; |
29 | } |
30 | |
31 | $title = Title::makeTitleSafe( (int)$matches[2], $filename ); |
32 | return $title; |
33 | } |
34 | } |