MediaWiki  1.34.0
addRFCandPMIDInterwiki.php
Go to the documentation of this file.
1 <?php
21 require_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::class;
95 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
$maintClass
$maintClass
Definition: addRFCandPMIDInterwiki.php:94
AddRFCandPMIDInterwiki\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: addRFCandPMIDInterwiki.php:45
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
AddRFCandPMIDInterwiki\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: addRFCandPMIDInterwiki.php:41
Maintenance\getConfig
getConfig()
Definition: Maintenance.php:613
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1727
DB_MASTER
const DB_MASTER
Definition: defines.php:26
AddRFCandPMIDInterwiki\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: addRFCandPMIDInterwiki.php:37
AddRFCandPMIDInterwiki
Run automatically with update.php.
Definition: addRFCandPMIDInterwiki.php:31
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
AddRFCandPMIDInterwiki\__construct
__construct()
Default constructor.
Definition: addRFCandPMIDInterwiki.php:32