MediaWiki REL1_30
addRFCandPMIDInterwiki.php
Go to the documentation of this file.
1<?php
21require_once __DIR__ . '/Maintenance.php';
22
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';
95require_once RUN_MAINTENANCE_IF_MAIN;
Run automatically with update.php.
getUpdateKey()
Get the update key name to go in the update log table.
doDBUpdates()
Do the actual work.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
__construct()
Default constructor.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:26