MediaWiki master
dumpLinks.php
Go to the documentation of this file.
1<?php
19// @codeCoverageIgnoreStart
20require_once __DIR__ . '/Maintenance.php';
21// @codeCoverageIgnoreEnd
22
26
32class DumpLinks extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
36 }
37
38 public function execute() {
39 $dbr = $this->getServiceContainer()
40 ->getConnectionProvider()
41 ->getReplicaDatabase( PageLinksTable::VIRTUAL_DOMAIN );
42 $linksMigration = $this->getServiceContainer()->getLinksMigration();
43 $queryInfo = $linksMigration->getQueryInfo( 'pagelinks' );
44 $queryInfo['tables'] = array_diff( $queryInfo['tables'], [ 'pagelinks' ] );
45 [ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( 'pagelinks' );
46
47 $result = $dbr->newSelectQueryBuilder()
48 ->select( array_merge( [
49 'page_id',
50 'page_namespace',
51 'page_title',
52 ], $queryInfo['fields'] ) )
53 ->from( 'page' )
54 ->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
55 ->joinConds( $queryInfo['joins'] )
56 ->tables( $queryInfo['tables'] )
57 ->orderBy( 'page_id' )
58 ->caller( __METHOD__ )
59 ->fetchResultSet();
60
61 $lastPage = null;
62 foreach ( $result as $row ) {
63 if ( $lastPage != $row->page_id ) {
64 if ( $lastPage !== null ) {
65 $this->output( "\n" );
66 }
67 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
68 $this->output( $page->getPrefixedURL() );
69 $lastPage = $row->page_id;
70 }
71 $link = Title::makeTitle( $row->$blNamespace, $row->$blTitle );
72 $this->output( " " . $link->getPrefixedURL() );
73 }
74 if ( $lastPage !== null ) {
75 $this->output( "\n" );
76 }
77 }
78}
79
80// @codeCoverageIgnoreStart
81$maintClass = DumpLinks::class;
82require_once RUN_MAINTENANCE_IF_MAIN;
83// @codeCoverageIgnoreEnd
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:69