MediaWiki  1.23.15
deleteImageMemcached.php
Go to the documentation of this file.
1 <?php
27 require_once __DIR__ . '/Maintenance.php';
28 
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = "Delete image information from the cache";
38  $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true );
39  $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true );
40  }
41 
42  public function execute() {
44 
45  $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) );
46  $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds
47 
48  ini_set( 'display_errors', false );
49 
50  $dbr = wfGetDB( DB_SLAVE );
51 
52  $res = $dbr->select( 'image',
53  array( 'img_name' ),
54  array( "img_timestamp < {$until}" ),
55  __METHOD__
56  );
57 
58  $i = 0;
59  $total = $this->getImageCount();
60 
61  foreach ( $res as $row ) {
62  if ( $i % $this->report == 0 ) {
63  $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) );
64  }
65  $md5 = md5( $row->img_name );
66  $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
67 
68  if ( $sleep != 0 ) {
69  usleep( $sleep );
70  }
71 
72  ++$i;
73  }
74  }
75 
76  private function getImageCount() {
77  $dbr = wfGetDB( DB_SLAVE );
78  return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
79  }
80 }
81 
82 $maintClass = "DeleteImageCache";
83 require_once RUN_MAINTENANCE_IF_MAIN;
wfPercent
wfPercent( $nr, $acc=2, $round=true)
Definition: GlobalFunctions.php:2704
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$sleep
$sleep
Definition: importImages.php:93
$dbr
$dbr
Definition: testCompression.php:48
$total
$total
Definition: Utf8Test.php:92
wfMemcKey
wfMemcKey()
Get a cache key.
Definition: GlobalFunctions.php:3635
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3668
DeleteImageCache\execute
execute()
Do the actual work.
Definition: deleteImageMemcached.php:42
DeleteImageCache\getImageCount
getImageCount()
Definition: deleteImageMemcached.php:76
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
$maintClass
$maintClass
Definition: deleteImageMemcached.php:82
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
DeleteImageCache
Maintenance script that deletes image information from the object cache.
Definition: deleteImageMemcached.php:34
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
$res
$res
Definition: database.txt:21
DeleteImageCache\__construct
__construct()
Default constructor.
Definition: deleteImageMemcached.php:35