Go to the documentation of this file.
30 require_once __DIR__ .
'/cleanupTable.inc';
41 'index' =>
'img_name',
42 'callback' =>
'processRow',
49 parent::__construct();
50 $this->
addDescription(
'Script to clean up broken, unparseable upload filenames' );
65 $cleaned = rawurldecode( $cleaned );
70 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
73 $cleaned = $contLang->checkTitleEncoding( $cleaned );
76 $cleaned = $contLang->normalize( $cleaned );
81 $this->
output(
"page $source ($cleaned) is illegal.\n" );
83 if ( $safe ===
false ) {
92 $munged =
$title->getDBkey();
93 $this->
output(
"page $source ($munged) doesn't match self.\n" );
106 if ( $this->dryrun ) {
107 $this->
output(
"DRY RUN: would delete bogus row '$name'\n" );
109 $this->
output(
"deleting bogus row '$name'\n" );
111 $db->delete(
'image',
112 [
'img_name' => $name ],
122 if ( $this->repo ===
null ) {
126 return $this->repo->getRootDirectory() .
'/' . $this->repo->getHashPath( $name ) . $name;
130 return $db->selectField(
'image',
'1', [
'img_name' => $name ], __METHOD__ );
134 return $db->selectField(
137 [
'page_namespace' =>
NS_FILE,
'page_title' => $name ],
144 if ( !file_exists(
$path ) ) {
145 $this->
output(
"missing file: $path\n" );
165 while ( $conflict ) {
166 $this->
output(
"Rename conflicts with '$final'...\n" );
172 $finalPath = $this->
filePath( $final );
174 if ( $this->dryrun ) {
175 $this->
output(
"DRY RUN: would rename $path to $finalPath\n" );
177 $this->
output(
"renaming $path to $finalPath\n" );
180 $db->update(
'image',
181 [
'img_name' => $final ],
182 [
'img_name' => $orig ],
184 $db->update(
'oldimage',
185 [
'oi_name' => $final ],
186 [
'oi_name' => $orig ],
189 [
'page_title' => $final ],
190 [
'page_title' => $orig,
'page_namespace' =>
NS_FILE ],
192 $dir = dirname( $finalPath );
193 if ( !file_exists( $dir ) ) {
195 $this->
output(
"RENAME FAILED, COULD NOT CREATE $dir" );
201 if ( rename(
$path, $finalPath ) ) {
204 $this->
error(
"RENAME FAILED" );
211 return preg_replace(
'/^(.*)(\..*?)$/',
212 "\\1$suffix\\2", $name );
216 $x = preg_replace_callback(
218 [ $this,
'hexChar' ],
222 if ( is_null( $test ) || $test->getDBkey() !== $x ) {
223 $this->
error(
"Unable to generate safe title from '$name', got '$x'" );
const RUN_MAINTENANCE_IF_MAIN
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
addDescription( $text)
Set the description text.
rollbackTransaction(IDatabase $dbw, $fname)
Rollback the transcation on a DB handle.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Generic class to cleanup a database table.
Maintenance script to clean up broken, unparseable upload filenames.
__construct()
Default constructor.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
static legalChars()
Get a regex character class describing the legal characters in a link.
static decodeCharReferences( $text)
Decode any character references, numeric or named entities, in the text and return a UTF-8 string.
appendTitle( $name, $suffix)
A repository that stores files in the local filesystem and registers them in the wiki's own database.