dumpLinks.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Quick demo hack to generate a plaintext link dump,
  4. * per the proposed wiki link database standard:
  5. * http://www.usemod.com/cgi-bin/mb.pl?LinkDatabase
  6. *
  7. * Includes all (live and broken) intra-wiki links.
  8. * Does not include interwiki or URL links.
  9. * Dumps ASCII text to stdout; command-line.
  10. *
  11. * Copyright © 2005 Brion Vibber <brion@pobox.com>
  12. * https://www.mediawiki.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  27. * http://www.gnu.org/copyleft/gpl.html
  28. *
  29. * @file
  30. * @ingroup Maintenance
  31. */
  32. require_once __DIR__ . '/Maintenance.php';
  33. /**
  34. * Maintenance script that generates a plaintext link dump.
  35. *
  36. * @ingroup Maintenance
  37. */
  38. class DumpLinks extends Maintenance {
  39. public function __construct() {
  40. parent::__construct();
  41. $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
  42. }
  43. public function execute() {
  44. $dbr = $this->getDB( DB_REPLICA );
  45. $result = $dbr->select( [ 'pagelinks', 'page' ],
  46. [
  47. 'page_id',
  48. 'page_namespace',
  49. 'page_title',
  50. 'pl_namespace',
  51. 'pl_title' ],
  52. [ 'page_id=pl_from' ],
  53. __METHOD__,
  54. [ 'ORDER BY' => 'page_id' ] );
  55. $lastPage = null;
  56. foreach ( $result as $row ) {
  57. if ( $lastPage != $row->page_id ) {
  58. if ( $lastPage !== null ) {
  59. $this->output( "\n" );
  60. }
  61. $page = Title::makeTitle( $row->page_namespace, $row->page_title );
  62. $this->output( $page->getPrefixedURL() );
  63. $lastPage = $row->page_id;
  64. }
  65. $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
  66. $this->output( " " . $link->getPrefixedURL() );
  67. }
  68. if ( $lastPage !== null ) {
  69. $this->output( "\n" );
  70. }
  71. }
  72. }
  73. $maintClass = "DumpLinks";
  74. require_once RUN_MAINTENANCE_IF_MAIN;