MediaWiki REL1_35
dumpLinks.php
Go to the documentation of this file.
1<?php
33require_once __DIR__ . '/Maintenance.php';
34
40class DumpLinks extends Maintenance {
41 public function __construct() {
42 parent::__construct();
43 $this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
44 }
45
46 public function execute() {
47 $dbr = $this->getDB( DB_REPLICA );
48 $result = $dbr->select( [ 'pagelinks', 'page' ],
49 [
50 'page_id',
51 'page_namespace',
52 'page_title',
53 'pl_namespace',
54 'pl_title' ],
55 [ 'page_id=pl_from' ],
56 __METHOD__,
57 [ 'ORDER BY' => 'page_id' ] );
58
59 $lastPage = null;
60 foreach ( $result as $row ) {
61 if ( $lastPage != $row->page_id ) {
62 if ( $lastPage !== null ) {
63 $this->output( "\n" );
64 }
65 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
66 $this->output( $page->getPrefixedURL() );
67 $lastPage = $row->page_id;
68 }
69 $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
70 $this->output( " " . $link->getPrefixedURL() );
71 }
72 if ( $lastPage !== null ) {
73 $this->output( "\n" );
74 }
75 }
76}
77
78$maintClass = DumpLinks::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
const RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
const DB_REPLICA
Definition defines.php:25