MediaWiki REL1_28
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.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:23