addRFCandPMIDInterwiki.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.
  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. require_once __DIR__ . '/Maintenance.php';
  21. /**
  22. * Run automatically with update.php
  23. *
  24. * - Changes "rfc" URL to use tools.ietf.org domain
  25. * - Adds "pmid" interwiki
  26. *
  27. * @since 1.28
  28. */
  29. class AddRFCAndPMIDInterwiki extends LoggedUpdateMaintenance {
  30. public function __construct() {
  31. parent::__construct();
  32. $this->addDescription( 'Add RFC and PMID to the interwiki database table' );
  33. }
  34. protected function getUpdateKey() {
  35. return __CLASS__;
  36. }
  37. protected function updateSkippedMessage() {
  38. return 'RFC and PMID already added to interwiki database table';
  39. }
  40. protected function doDBUpdates() {
  41. $interwikiCache = $this->getConfig()->get( 'InterwikiCache' );
  42. // Using something other than the database,
  43. if ( $interwikiCache !== false ) {
  44. return true;
  45. }
  46. $dbw = $this->getDB( DB_MASTER );
  47. $rfc = $dbw->selectField(
  48. 'interwiki',
  49. 'iw_url',
  50. [ 'iw_prefix' => 'rfc' ],
  51. __METHOD__
  52. );
  53. // Old pre-1.28 default value, or not set at all
  54. if ( $rfc === false || $rfc === 'http://www.rfc-editor.org/rfc/rfc$1.txt' ) {
  55. $dbw->replace(
  56. 'interwiki',
  57. [ 'iw_prefix' ],
  58. [
  59. 'iw_prefix' => 'rfc',
  60. 'iw_url' => 'https://tools.ietf.org/html/rfc$1',
  61. 'iw_api' => '',
  62. 'iw_wikiid' => '',
  63. 'iw_local' => 0,
  64. ],
  65. __METHOD__
  66. );
  67. }
  68. $dbw->insert(
  69. 'interwiki',
  70. [
  71. 'iw_prefix' => 'pmid',
  72. 'iw_url' => 'https://www.ncbi.nlm.nih.gov/pubmed/$1?dopt=Abstract',
  73. 'iw_api' => '',
  74. 'iw_wikiid' => '',
  75. 'iw_local' => 0,
  76. ],
  77. __METHOD__,
  78. // If there's already a pmid interwiki link, don't
  79. // overwrite it
  80. [ 'IGNORE' ]
  81. );
  82. return true;
  83. }
  84. }
  85. $maintClass = 'AddRFCAndPMIDInterwiki';
  86. require_once RUN_MAINTENANCE_IF_MAIN;