2005-10-31 09:57:38 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Quick demo hack to generate a plaintext link dump,
|
|
|
|
|
* per the proposed wiki link database standard:
|
|
|
|
|
* http://www.usemod.com/cgi-bin/mb.pl?LinkDatabase
|
|
|
|
|
*
|
|
|
|
|
* Includes all (live and broken) intra-wiki links.
|
|
|
|
|
* Does not include interwiki or URL links.
|
|
|
|
|
* Dumps ASCII text to stdout; command-line.
|
|
|
|
|
*
|
2024-02-09 01:02:16 +00:00
|
|
|
* Copyright © 2005 Brooke Vibber <bvibber@wikimedia.org>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2012-07-08 20:47:27 +00:00
|
|
|
*
|
2005-10-31 09:57:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-10-31 09:57:38 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-10-31 09:57:38 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-10-31 09:57:38 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-31 09:57:38 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-08 20:47:27 +00:00
|
|
|
* @file
|
2012-02-08 16:55:54 +00:00
|
|
|
* @ingroup Maintenance
|
2005-10-31 09:57:38 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2005-10-31 09:57:38 +00:00
|
|
|
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
|
|
2012-07-08 20:47:27 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that generates a plaintext link dump.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class DumpLinks extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Quick demo hack to generate a plaintext link dump' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2005-10-31 09:57:38 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2023-10-13 08:38:50 +00:00
|
|
|
$linksMigration = $this->getServiceContainer()->getLinksMigration();
|
2023-10-11 12:51:30 +00:00
|
|
|
$queryInfo = $linksMigration->getQueryInfo( 'pagelinks' );
|
|
|
|
|
$queryInfo['tables'] = array_diff( $queryInfo['tables'], [ 'pagelinks' ] );
|
|
|
|
|
[ $blNamespace, $blTitle ] = $linksMigration->getTitleFields( 'pagelinks' );
|
2022-07-21 09:36:56 +00:00
|
|
|
|
|
|
|
|
$result = $dbr->newSelectQueryBuilder()
|
2023-10-11 12:51:30 +00:00
|
|
|
->select( array_merge( [
|
2009-08-02 19:35:17 +00:00
|
|
|
'page_id',
|
|
|
|
|
'page_namespace',
|
|
|
|
|
'page_title',
|
2023-10-11 12:51:30 +00:00
|
|
|
], $queryInfo['fields'] ) )
|
2022-07-21 09:36:56 +00:00
|
|
|
->from( 'page' )
|
|
|
|
|
->join( 'pagelinks', null, [ 'page_id=pl_from' ] )
|
2023-10-11 12:51:30 +00:00
|
|
|
->joinConds( $queryInfo['joins'] )
|
|
|
|
|
->tables( $queryInfo['tables'] )
|
2022-07-21 09:36:56 +00:00
|
|
|
->orderBy( 'page_id' )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$lastPage = null;
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $result as $row ) {
|
|
|
|
|
if ( $lastPage != $row->page_id ) {
|
2014-05-10 12:23:50 +00:00
|
|
|
if ( $lastPage !== null ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "\n" );
|
|
|
|
|
}
|
|
|
|
|
$page = Title::makeTitle( $row->page_namespace, $row->page_title );
|
2013-03-22 07:39:02 +00:00
|
|
|
$this->output( $page->getPrefixedURL() );
|
2009-08-02 19:35:17 +00:00
|
|
|
$lastPage = $row->page_id;
|
|
|
|
|
}
|
2023-10-11 12:51:30 +00:00
|
|
|
$link = Title::makeTitle( $row->$blNamespace, $row->$blTitle );
|
2013-03-22 07:39:02 +00:00
|
|
|
$this->output( " " . $link->getPrefixedURL() );
|
2005-10-31 09:57:38 +00:00
|
|
|
}
|
2014-05-10 12:23:50 +00:00
|
|
|
if ( $lastPage !== null ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "\n" );
|
2013-04-18 18:48:44 +00:00
|
|
|
}
|
2005-10-31 09:57:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = DumpLinks::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|