MediaWiki  1.27.2
LinksDeletionUpdate.php
Go to the documentation of this file.
1 <?php
27  protected $page;
29  protected $pageId;
31  protected $timestamp;
32 
39  function __construct( WikiPage $page, $pageId = null, $timestamp = null ) {
40  parent::__construct( false ); // no implicit transaction
41 
42  $this->page = $page;
43  if ( $pageId ) {
44  $this->pageId = $pageId; // page ID at time of deletion
45  } elseif ( $page->exists() ) {
46  $this->pageId = $page->getId();
47  } else {
48  throw new MWException( "Page ID not known, perhaps the page doesn't exist?" );
49  }
50 
51  $this->timestamp = $timestamp ?: wfTimestampNow();
52  }
53 
54  public function doUpdate() {
55  # Page may already be deleted, so don't just getId()
56  $id = $this->pageId;
57 
58  # Delete restrictions for it
59  $this->mDb->delete( 'page_restrictions', [ 'pr_page' => $id ], __METHOD__ );
60 
61  # Fix category table counts
62  $cats = $this->mDb->selectFieldValues(
63  'categorylinks',
64  'cl_to',
65  [ 'cl_from' => $id ],
66  __METHOD__
67  );
68  $this->page->updateCategoryCounts( [], $cats );
69 
70  # If using cascading deletes, we can skip some explicit deletes
71  if ( !$this->mDb->cascadingDeletes() ) {
72  # Delete outgoing links
73  $this->mDb->delete( 'pagelinks', [ 'pl_from' => $id ], __METHOD__ );
74  $this->mDb->delete( 'imagelinks', [ 'il_from' => $id ], __METHOD__ );
75  $this->mDb->delete( 'categorylinks', [ 'cl_from' => $id ], __METHOD__ );
76  $this->mDb->delete( 'templatelinks', [ 'tl_from' => $id ], __METHOD__ );
77  $this->mDb->delete( 'externallinks', [ 'el_from' => $id ], __METHOD__ );
78  $this->mDb->delete( 'langlinks', [ 'll_from' => $id ], __METHOD__ );
79  $this->mDb->delete( 'iwlinks', [ 'iwl_from' => $id ], __METHOD__ );
80  $this->mDb->delete( 'redirect', [ 'rd_from' => $id ], __METHOD__ );
81  $this->mDb->delete( 'page_props', [ 'pp_page' => $id ], __METHOD__ );
82  }
83 
84  # If using cleanup triggers, we can skip some manual deletes
85  if ( !$this->mDb->cleanupTriggers() ) {
86  $title = $this->page->getTitle();
87  # Find recentchanges entries to clean up...
88  $rcIdsForTitle = $this->mDb->selectFieldValues( 'recentchanges',
89  'rc_id',
90  [
91  'rc_type != ' . RC_LOG,
92  'rc_namespace' => $title->getNamespace(),
93  'rc_title' => $title->getDBkey(),
94  'rc_timestamp < ' .
95  $this->mDb->addQuotes( $this->mDb->timestamp( $this->timestamp ) )
96  ],
97  __METHOD__
98  );
99  $rcIdsForPage = $this->mDb->selectFieldValues( 'recentchanges',
100  'rc_id',
101  [ 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ],
102  __METHOD__
103  );
104 
105  # T98706: delete PK to avoid lock contention with RC delete log insertions
106  $rcIds = array_merge( $rcIdsForTitle, $rcIdsForPage );
107  if ( $rcIds ) {
108  $this->mDb->delete( 'recentchanges', [ 'rc_id' => $rcIds ], __METHOD__ );
109  }
110  }
111  }
112 
113  public function getAsJobSpecification() {
114  return [
115  'wiki' => $this->mDb->getWikiID(),
116  'job' => new JobSpecification(
117  'deleteLinks',
118  [ 'pageId' => $this->pageId, 'timestamp' => $this->timestamp ],
119  [ 'removeDuplicates' => true ],
120  $this->page->getTitle()
121  )
122  ];
123  }
124 }
__construct(WikiPage $page, $pageId=null, $timestamp=null)
Interface that marks a DataUpdate as enqueuable via the JobQueue.
Definition: DataUpdate.php:156
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
Abstract base class for update jobs that put some secondary data extracted from article content into ...
Class representing a MediaWiki article and history.
Definition: WikiPage.php:29
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Job queue task description base code.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk page
Definition: hooks.txt:2338
doUpdate()
Perform the actual work.
Update object handling the cleanup of links tables after a page was deleted.
const RC_LOG
Definition: Defines.php:171