AddRFCAndPMIDInterwiki   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUpdateKey() 0 3 1
A updateSkippedMessage() 0 3 1
B doDBUpdates() 0 47 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 */
20
21
require_once __DIR__ . '/Maintenance.php';
22
23
/**
24
 * Run automatically with update.php
25
 *
26
 * - Changes "rfc" URL to use tools.ietf.org domain
27
 * - Adds "pmid" interwiki
28
 *
29
 * @since 1.28
30
 */
31
class AddRFCAndPMIDInterwiki extends LoggedUpdateMaintenance {
32
	public function __construct() {
33
		parent::__construct();
34
		$this->addDescription( 'Add RFC and PMID to the interwiki database table' );
35
	}
36
37
	protected function getUpdateKey() {
38
		return __CLASS__;
39
	}
40
41
	protected function updateSkippedMessage() {
42
		return 'RFC and PMID already added to interwiki database table';
43
	}
44
45
	protected function doDBUpdates() {
46
		$interwikiCache = $this->getConfig()->get( 'InterwikiCache' );
47
		// Using something other than the database,
48
		if ( $interwikiCache !== false ) {
49
			return true;
50
		}
51
		$dbw = $this->getDB( DB_MASTER );
52
		$rfc = $dbw->selectField(
53
			'interwiki',
54
			'iw_url',
55
			[ 'iw_prefix' => 'rfc' ],
56
			__METHOD__
57
		);
58
59
		// Old pre-1.28 default value, or not set at all
60
		if ( $rfc === false || $rfc === 'http://www.rfc-editor.org/rfc/rfc$1.txt' ) {
61
			$dbw->replace(
62
				'interwiki',
63
				[ 'iw_prefix' ],
64
				[
65
					'iw_prefix' => 'rfc',
66
					'iw_url' => 'https://tools.ietf.org/html/rfc$1',
67
					'iw_api' => '',
68
					'iw_wikiid' => '',
69
					'iw_local' => 0,
70
				],
71
				__METHOD__
72
			);
73
		}
74
75
		$dbw->insert(
76
			'interwiki',
77
			[
78
				'iw_prefix' => 'pmid',
79
				'iw_url' => 'https://www.ncbi.nlm.nih.gov/pubmed/$1?dopt=Abstract',
80
				'iw_api' => '',
81
				'iw_wikiid' => '',
82
				'iw_local' => 0,
83
			],
84
			__METHOD__,
85
			// If there's already a pmid interwiki link, don't
86
			// overwrite it
87
			[ 'IGNORE' ]
88
		);
89
90
		return true;
91
	}
92
}
93
94
$maintClass = 'AddRFCAndPMIDInterwiki';
95
require_once RUN_MAINTENANCE_IF_MAIN;
96