MediaWiki REL1_33
attachLatest.php
Go to the documentation of this file.
1<?php
28
29require_once __DIR__ . '/Maintenance.php';
30
38 public function __construct() {
39 parent::__construct();
40 $this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
41 $this->addOption( "regenerate-all",
42 "Regenerate the page_latest field for all records in table page" );
43 $this->addDescription( 'Fix page_latest entries in the page table' );
44 }
45
46 public function execute() {
47 $this->output( "Looking for pages with page_latest set to 0...\n" );
48 $dbw = $this->getDB( DB_MASTER );
49 $conds = [ 'page_latest' => 0 ];
50 if ( $this->hasOption( 'regenerate-all' ) ) {
51 $conds = '';
52 }
53 $result = $dbw->select( 'page',
54 [ 'page_id', 'page_namespace', 'page_title' ],
55 $conds,
56 __METHOD__ );
57
58 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
59 $n = 0;
60 foreach ( $result as $row ) {
61 $pageId = intval( $row->page_id );
62 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
63 $name = $title->getPrefixedText();
64 $latestTime = $dbw->selectField( 'revision',
65 'MAX(rev_timestamp)',
66 [ 'rev_page' => $pageId ],
67 __METHOD__ );
68 if ( !$latestTime ) {
69 $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
70 continue;
71 }
72
73 $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
74 if ( is_null( $revision ) ) {
75 $this->output( wfWikiID()
76 . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
77 continue;
78 }
79 $id = $revision->getId();
80 $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
81 if ( $this->hasOption( 'fix' ) ) {
82 $page = WikiPage::factory( $title );
83 $page->updateRevisionOn( $dbw, $revision );
84 $lbFactory->waitForReplication();
85 }
86 $n++;
87 }
88 $this->output( "Done! Processed $n pages.\n" );
89 if ( !$this->hasOption( 'fix' ) ) {
90 $this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
91 }
92 }
93}
94
95$maintClass = AttachLatest::class;
96require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition Revision.php:295
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:26