maintenance/version: Namespace and rename
[mediawiki.git] / maintenance / addRFCandPMIDInterwiki.php
blobea428621a4a515aa30473073ea093773eb95150d
1 <?php
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.
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.
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
18 * @file
21 use MediaWiki\MainConfigNames;
23 require_once __DIR__ . '/Maintenance.php';
25 /**
26 * Run automatically with update.php
28 * - Changes "rfc" URL to use tools.ietf.org domain
29 * - Adds "pmid" interwiki
31 * @since 1.28
33 class AddRFCandPMIDInterwiki extends LoggedUpdateMaintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Add RFC and PMID to the interwiki database table' );
39 protected function getUpdateKey() {
40 return __CLASS__;
43 protected function updateSkippedMessage() {
44 return 'RFC and PMID already added to interwiki database table.';
47 protected function doDBUpdates() {
48 $interwikiCache = $this->getConfig()->get( MainConfigNames::InterwikiCache );
49 // Using something other than the database,
50 if ( $interwikiCache !== false ) {
51 return true;
53 $dbw = $this->getDB( DB_PRIMARY );
55 $rfc = $dbw->newSelectQueryBuilder()
56 ->select( 'iw_url' )
57 ->from( 'interwiki' )
58 ->where( [ 'iw_prefix' => 'rfc' ] )
59 ->caller( __METHOD__ )
60 ->fetchField();
62 // Old pre-1.28 default value, or not set at all
63 if ( $rfc === false || $rfc === 'http://www.rfc-editor.org/rfc/rfc$1.txt' ) {
64 $dbw->newReplaceQueryBuilder()
65 ->replaceInto( 'interwiki' )
66 ->uniqueIndexFields( [ 'iw_prefix' ] )
67 ->rows( [
68 'iw_prefix' => 'rfc',
69 'iw_url' => 'https://tools.ietf.org/html/rfc$1',
70 'iw_api' => '',
71 'iw_wikiid' => '',
72 'iw_local' => 0,
73 ] )
74 ->caller( __METHOD__ )->execute();
77 $dbw->insert(
78 'interwiki',
80 'iw_prefix' => 'pmid',
81 'iw_url' => 'https://www.ncbi.nlm.nih.gov/pubmed/$1?dopt=Abstract',
82 'iw_api' => '',
83 'iw_wikiid' => '',
84 'iw_local' => 0,
86 __METHOD__,
87 // If there's already a pmid interwiki link, don't
88 // overwrite it
89 [ 'IGNORE' ]
92 return true;
96 $maintClass = AddRFCandPMIDInterwiki::class;
97 require_once RUN_MAINTENANCE_IF_MAIN;