MediaWiki  1.27.2
cleanupCaps.php
Go to the documentation of this file.
1 <?php
32 require_once __DIR__ . '/cleanupTable.inc';
33 
39 class CapsCleanup extends TableCleanup {
40 
41  private $user;
42 
43  public function __construct() {
44  parent::__construct();
45  $this->addDescription( 'Script to cleanup capitalization' );
46  $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
47  }
48 
49  public function execute() {
51 
52  if ( $wgCapitalLinks ) {
53  $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
54  }
55 
56  $this->user = User::newSystemUser( 'Conversion script', [ 'steal' => true ] );
57 
58  $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
59  $this->dryrun = $this->hasOption( 'dry-run' );
60 
61  $this->runTable( [
62  'table' => 'page',
63  'conds' => [ 'page_namespace' => $this->namespace ],
64  'index' => 'page_id',
65  'callback' => 'processRow' ] );
66  }
67 
68  protected function processRow( $row ) {
70 
71  $current = Title::makeTitle( $row->page_namespace, $row->page_title );
72  $display = $current->getPrefixedText();
73  $upper = $row->page_title;
74  $lower = $wgContLang->lcfirst( $row->page_title );
75  if ( $upper == $lower ) {
76  $this->output( "\"$display\" already lowercase.\n" );
77 
78  return $this->progress( 0 );
79  }
80 
81  $target = Title::makeTitle( $row->page_namespace, $lower );
82  $targetDisplay = $target->getPrefixedText();
83  if ( $target->exists() ) {
84  $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
85 
86  return $this->progress( 0 );
87  }
88 
89  if ( $this->dryrun ) {
90  $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
91  $ok = true;
92  } else {
93  $mp = new MovePage( $current, $target );
94  $status = $mp->move( $this->user, 'Converting page titles to lowercase', true );
95  $ok = $status->isOK() ? 'OK' : $status->getWikiText( false, false, 'en' );
96  $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
97  }
98  if ( $ok === true ) {
99  $this->progress( 1 );
100  if ( $row->page_namespace == $this->namespace ) {
101  $talk = $target->getTalkPage();
102  $row->page_namespace = $talk->getNamespace();
103  if ( $talk->exists() ) {
104  return $this->processRow( $row );
105  }
106  }
107  }
108 
109  return $this->progress( 0 );
110  }
111 }
112 
113 $maintClass = "CapsCleanup";
114 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to clean up broken page links when somebody turns on $wgCapitalLinks.
Definition: cleanupCaps.php:39
Handles the backend logic of moving a page from one title to another.
Definition: MovePage.php:28
progress($updated)
hasOption($name)
Checks to see if a particular param exists.
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
addOption($name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$wgCapitalLinks
Set this to false to avoid forcing the first letter of links to capitals.
Generic class to cleanup a database table.
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
Definition: distributors.txt:9
static newSystemUser($name, $options=[])
Static factory method for creation of a "system" user from username.
Definition: User.php:695
addDescription($text)
Set the description text.
$maintClass
output($out, $channel=null)
Throw some output to the user.
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
processRow($row)
Definition: cleanupCaps.php:68
runTable($params)
error($err, $die=0)
Throw an error to the user.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524