MediaWiki  REL1_22
dumpLinks.php
Go to the documentation of this file.
00001 <?php
00033 require_once __DIR__ . '/Maintenance.php';
00034 
00040 class DumpLinks extends Maintenance {
00041     public function __construct() {
00042         parent::__construct();
00043         $this->mDescription = "Quick demo hack to generate a plaintext link dump";
00044     }
00045 
00046     public function execute() {
00047         $dbr = wfGetDB( DB_SLAVE );
00048         $result = $dbr->select( array( 'pagelinks', 'page' ),
00049             array(
00050                 'page_id',
00051                 'page_namespace',
00052                 'page_title',
00053                 'pl_namespace',
00054                 'pl_title' ),
00055             array( 'page_id=pl_from' ),
00056             __METHOD__,
00057             array( 'ORDER BY' => 'page_id' ) );
00058 
00059         $lastPage = null;
00060         foreach ( $result as $row ) {
00061             if ( $lastPage != $row->page_id ) {
00062                 if ( isset( $lastPage ) ) {
00063                     $this->output( "\n" );
00064                 }
00065                 $page = Title::makeTitle( $row->page_namespace, $row->page_title );
00066                 $this->output( $page->getPrefixedURL() );
00067                 $lastPage = $row->page_id;
00068             }
00069             $link = Title::makeTitle( $row->pl_namespace, $row->pl_title );
00070             $this->output( " " . $link->getPrefixedURL() );
00071         }
00072         if ( isset( $lastPage ) ) {
00073             $this->output( "\n" );
00074         }
00075     }
00076 }
00077 
00078 $maintClass = "DumpLinks";
00079 require_once RUN_MAINTENANCE_IF_MAIN;