| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
> |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
require_once __DIR__ . '/Maintenance.php'; |
| 35 |
|
| 36 |
|
| 37 |
use MediaWiki\Title\Title; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class DumpLinks extends Maintenance { |
| 45 |
public function __construct() { |
| 46 |
parent::__construct(); |
| 47 |
$this->addDescription( 'Quick demo hack to generate a plaintext link dump' ); |
| 48 |
} |
| 49 |
|
| 50 |
public function execute() { |
| 51 |
$dbr = $this->getReplicaDB(); |
| 52 |
$linksMigration = $this->getServiceContainer()->getLinksMigration(); |
| 53 |
$queryInfo = $linksMigration->getQueryInfo( 'pagelinks' ); |
| 54 |
$queryInfo['tables'] = array_diff( $queryInfo['tables'], [ 'pagelinks' ] ); |
| 55 |
[ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( 'pagelinks' ); |
| 56 |
|
| 57 |
$result = $dbr->newSelectQueryBuilder() |
| 58 |
->select( array_merge( [ |
| 59 |
'page_id', |
| 60 |
'page_namespace', |
| 61 |
'page_title', |
| 62 |
], $queryInfo['fields'] ) ) |
| 63 |
->from( 'page' ) |
| 64 |
->join( 'pagelinks', null, [ 'page_id=pl_from' ] ) |
| 65 |
->joinConds( $queryInfo['joins'] ) |
| 66 |
->tables( $queryInfo['tables'] ) |
| 67 |
->orderBy( 'page_id' ) |
| 68 |
->caller( __METHOD__ ) |
| 69 |
->fetchResultSet(); |
| 70 |
|
| 71 |
$lastPage = null; |
| 72 |
foreach ( $result as $row ) { |
| 73 |
if ( $lastPage != $row->page_id ) { |
| 74 |
if ( $lastPage !== null ) { |
| 75 |
$this->output( "\n" ); |
| 76 |
} |
| 77 |
$page = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 78 |
$this->output( $page->getPrefixedURL() ); |
| 79 |
$lastPage = $row->page_id; |
| 80 |
} |
| 81 |
$link = Title::makeTitle( $row->$blNamespace, $row->$blTitle ); |
| 82 |
$this->output( " " . $link->getPrefixedURL() ); |
| 83 |
} |
| 84 |
if ( $lastPage !== null ) { |
| 85 |
$this->output( "\n" ); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
$maintClass = DumpLinks::class; |
| 92 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 93 |
|