X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FrefreshLinks.php;h=0e6725cd6083cb5a63aaf14b1c780ba339c5d8da;hb=beb1c4a0eced04ce2098433c383f1fbe469569c9;hp=fe03f51e5d49ad74fdbde8f2fe0afd068bf1c0e9;hpb=4477e5dbac5764af4b40d338e58f2975e34bd159;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index fe03f51e5d..0e6725cd60 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -21,7 +21,7 @@ * @ingroup Maintenance */ -require_once( __DIR__ . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; /** * Maintenance script to refresh link tables. @@ -176,8 +176,16 @@ class RefreshLinks extends Maintenance { } /** - * Update the redirect entry for a given page - * @param $id int The page_id of the redirect + * Update the redirect entry for a given page. + * + * This methods bypasses the "redirect" table to get the redirect target, + * and parses the page's content to fetch it. This allows to be sure that + * the redirect target is up to date and valid. + * This is particularly useful when modifying namespaces to be sure the + * entry in the "redirect" table points to the correct page and not to an + * invalid one. + * + * @param $id int The page ID to check */ private function fixRedirect( $id ) { $page = WikiPage::newFromID( $id ); @@ -191,14 +199,25 @@ class RefreshLinks extends Maintenance { return; } - $rt = $page->getRedirectTarget(); + $rt = null; + $content = $page->getContent( Revision::RAW ); + if ( $content !== null ) { + $rt = $content->getUltimateRedirectTarget(); + } if ( $rt === null ) { // The page is not a redirect // Delete any redirect table entry for it - $dbw->delete( 'redirect', array( 'rd_from' => $id ), - __METHOD__ ); + $dbw->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__ ); + $fieldValue = 0; + } else { + $page->insertRedirectEntry( $rt ); + $fieldValue = 1; } + + // Update the page table to be sure it is an a consistent state + $dbw->update( 'page', array( 'page_is_redirect' => $fieldValue ), + array( 'page_id' => $id ), __METHOD__ ); } /** @@ -262,12 +281,13 @@ class RefreshLinks extends Maintenance { $this->output( "Retrieving illegal entries from $table... " ); // SELECT DISTINCT( $field ) FROM $table LEFT JOIN page ON $field=page_id WHERE page_id IS NULL; - $results = $dbr->select( array( $table, 'page' ), - $field, - array( 'page_id' => null ), - __METHOD__, - 'DISTINCT', - array( 'page' => array( 'LEFT JOIN', "$field=page_id" ) ) + $results = $dbr->select( + array( $table, 'page' ), + $field, + array( 'page_id' => null ), + __METHOD__, + 'DISTINCT', + array( 'page' => array( 'LEFT JOIN', "$field=page_id" ) ) ); $counter = 0; @@ -296,4 +316,4 @@ class RefreshLinks extends Maintenance { } $maintClass = 'RefreshLinks'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN;