-
- function fixBrokenLinks() {
- /* Update any brokenlinks *to* this page */
- /* Call for a newly created page, or just to make sure state is consistent */
- $fname = "LinksUpdate::fixBrokenLinks";
-
- $dbw =& wfGetDB( DB_MASTER );
- $cur = $dbw->tableName( 'cur' );
- $links = $dbw->tableName( 'links' );
-
- $res = $dbw->select( 'brokenlinks', array( 'bl_from' ), array( 'bl_to' => $this->mTitle ),
- $fname, 'FOR UPDATE' );
- if ( 0 == $dbw->numRows( $res ) ) { return; }
-
- # Ignore errors. If a link existed in both the brokenlinks table and the links
- # table, that's an error which can be fixed at this stage by simply ignoring collisions
- $sql = "INSERT IGNORE INTO $links (l_from,l_to) VALUES ";
- $now = wfTimestampNow();
- $sql2 = "UPDATE $cur SET cur_touched='{$now}' WHERE cur_id IN (";
- $first = true;
- while ( $row = $dbw->fetchObject( $res ) ) {
- if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
- $first = false;
-
- $sql .= "({$row->bl_from},{$this->mId})";
- $sql2 .= $row->bl_from;
- }
- $sql2 .= ")";
- $dbw->query( $sql, $fname );
- $dbw->query( $sql2, $fname );
-
- $dbw->delete( 'brokenlinks', array( 'bl_to' => $this->mTitle ), $fname );
- }