Completed
Push — master ( 727675...c7064c )
by mw
04:03 queued 01:25
created

AppFactory::newExifDataAnnotator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace SESP;
4
5
use SESP\Annotator\ShortUrlAnnotator;
6
use SESP\Annotator\ExifDataAnnotator;
7
use SMW\SemanticData;
8
use File;
9
use Title;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @since 1.3
14
 *
15
 * @author mwjames
16
 */
17
class AppFactory {
18
19
	/**
20
	 * @var string
21
	 */
22
	private $shortUrlPrefix;
23
24 6
	public function __construct( $shortUrlPrefix = '' ) {
25 6
		$this->shortUrlPrefix = $shortUrlPrefix;
26 6
	}
27
28
	/**
29
	 * @since 1.3
30
	 *
31
	 * @return DatabaseBase
32
	 */
33 1
	public function newDatabaseConnection() {
34 1
		return wfGetDB( DB_SLAVE );
35
	}
36
37
	/**
38
	 * @since 1.3
39
	 *
40
	 * @param Title $title
41
	 *
42
	 * @return WikiPage
43
	 */
44 1
	public function newWikiPage( Title $title ) {
45
46
		// #55
47
		// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE"
48 1
		if ( $title->getNamespace() === NS_MEDIA ) {
49
			$title = Title::makeTitleSafe(
50
				NS_FILE,
51
				$title->getDBkey(),
52
				$title->getInterwiki(),
53
				$title->getFragment()
54
			);
55
		}
56
57 1
		return \WikiPage::factory( $title );
58
	}
59
60
	/**
61
	 * @since 1.3
62
	 *
63
	 * @param Title $title
64
	 *
65
	 * @return User
66
	 */
67 1
	public function newUserFromTitle( Title $title ) {
68 1
		return \User::newFromName( $title->getText() );
69
	}
70
71
	/**
72
	 * @since 1.3
73
	 *
74
	 * @param SemanticData $semanticData
75
	 *
76
	 * @return ShortUrlAnnotator
77
	 */
78 1
	public function newShortUrlAnnotator( SemanticData $semanticData ) {
79
80 1
		$shortUrlAnnotator = new ShortUrlAnnotator( $semanticData );
81 1
		$shortUrlAnnotator->setShortUrlPrefix( $this->shortUrlPrefix );
82
83 1
		return $shortUrlAnnotator;
84
	}
85
86
	/**
87
	 * @since 1.3
88
	 *
89
	 * @param SemanticData $semanticData
90
	 * @param File $file
91
	 *
92
	 * @return ExifDataAnnotator
93
	 */
94 1
	public function newExifDataAnnotator( SemanticData $semanticData, File $file ) {
95 1
		return new ExifDataAnnotator( $semanticData, $file );
96
	}
97
98
}
99