MediaWiki REL1_31
attachLatest.php
Go to the documentation of this file.
1<?php
27require_once __DIR__ . '/Maintenance.php';
28
36 public function __construct() {
37 parent::__construct();
38 $this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
39 $this->addOption( "regenerate-all",
40 "Regenerate the page_latest field for all records in table page" );
41 $this->addDescription( 'Fix page_latest entries in the page table' );
42 }
43
44 public function execute() {
45 $this->output( "Looking for pages with page_latest set to 0...\n" );
46 $dbw = $this->getDB( DB_MASTER );
47 $conds = [ 'page_latest' => 0 ];
48 if ( $this->hasOption( 'regenerate-all' ) ) {
49 $conds = '';
50 }
51 $result = $dbw->select( 'page',
52 [ 'page_id', 'page_namespace', 'page_title' ],
53 $conds,
54 __METHOD__ );
55
56 $n = 0;
57 foreach ( $result as $row ) {
58 $pageId = intval( $row->page_id );
59 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
60 $name = $title->getPrefixedText();
61 $latestTime = $dbw->selectField( 'revision',
62 'MAX(rev_timestamp)',
63 [ 'rev_page' => $pageId ],
64 __METHOD__ );
65 if ( !$latestTime ) {
66 $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
67 continue;
68 }
69
70 $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
71 if ( is_null( $revision ) ) {
72 $this->output( wfWikiID()
73 . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
74 continue;
75 }
76 $id = $revision->getId();
77 $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
78 if ( $this->hasOption( 'fix' ) ) {
79 $page = WikiPage::factory( $title );
80 $page->updateRevisionOn( $dbw, $revision );
81 }
82 $n++;
83 }
84 $this->output( "Done! Processed $n pages.\n" );
85 if ( !$this->hasOption( 'fix' ) ) {
86 $this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
87 }
88 }
89}
90
91$maintClass = AttachLatest::class;
92require_once RUN_MAINTENANCE_IF_MAIN;
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
$maintClass
Maintenance script to correct wrong values in the page_latest field in the database.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:29