Merge "Make it possible to disable the upload dialog functionality"
[lhc/web/wiklou.git] / maintenance / namespaceDupes.php
index 21e31ed..8fd25a6 100644 (file)
@@ -24,6 +24,8 @@
  * @ingroup Maintenance
  */
 
+use MediaWiki\Linker\LinkTarget;
+
 require_once __DIR__ . '/Maintenance.php';
 
 /**
@@ -69,14 +71,14 @@ class NamespaceConflictChecker extends Maintenance {
        public function execute() {
                $this->db = $this->getDB( DB_MASTER );
 
-               $options = array(
+               $options = [
                        'fix' => $this->hasOption( 'fix' ),
                        'merge' => $this->hasOption( 'merge' ),
                        'add-suffix' => $this->getOption( 'add-suffix', '' ),
                        'add-prefix' => $this->getOption( 'add-prefix', '' ),
                        'move-talk' => $this->hasOption( 'move-talk' ),
                        'source-pseudo-namespace' => $this->getOption( 'source-pseudo-namespace', '' ),
-                       'dest-namespace' => intval( $this->getOption( 'dest-namespace', 0 ) ) );
+                       'dest-namespace' => intval( $this->getOption( 'dest-namespace', 0 ) ) ];
 
                if ( $options['source-pseudo-namespace'] !== '' ) {
                        $retval = $this->checkPrefix( $options );
@@ -101,7 +103,7 @@ class NamespaceConflictChecker extends Maintenance {
        private function checkAll( $options ) {
                global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks;
 
-               $spaces = array();
+               $spaces = [];
 
                // List interwikis first, so they'll be overridden
                // by any conflicting local namespaces.
@@ -132,7 +134,7 @@ class NamespaceConflictChecker extends Maintenance {
                // We'll need to check for lowercase keys as well,
                // since we're doing case-sensitive searches in the db.
                foreach ( $spaces as $name => $ns ) {
-                       $moreNames = array();
+                       $moreNames = [];
                        $moreNames[] = $wgContLang->uc( $name );
                        $moreNames[] = $wgContLang->ucfirst( $wgContLang->lc( $name ) );
                        $moreNames[] = $wgContLang->ucwords( $name );
@@ -204,9 +206,9 @@ class NamespaceConflictChecker extends Maintenance {
                                // have rd_interwiki=w and rd_namespace=0, which would match the
                                // query for a conflicting namespace "Foo" if filtering wasn't done.
                                $this->checkLinkTable( 'redirect', 'rd', $ns, $name, $options,
-                                       array( 'rd_interwiki' => null ) );
+                                       [ 'rd_interwiki' => null ] );
                                $this->checkLinkTable( 'redirect', 'rd', $ns, $name, $options,
-                                       array( 'rd_interwiki' => '' ) );
+                                       [ 'rd_interwiki' => '' ] );
                        }
                }
 
@@ -223,7 +225,7 @@ class NamespaceConflictChecker extends Maintenance {
         */
        private function getInterwikiList() {
                $result = Interwiki::getAllPrefixes();
-               $prefixes = array();
+               $prefixes = [];
                foreach ( $result as $row ) {
                        $prefixes[] = $row['iw_prefix'];
                }
@@ -336,9 +338,9 @@ class NamespaceConflictChecker extends Maintenance {
         * @param array $extraConds Extra conditions for the SQL query
         */
        private function checkLinkTable( $table, $fieldPrefix, $ns, $name, $options,
-               $extraConds = array()
+               $extraConds = []
        ) {
-               $batchConds = array();
+               $batchConds = [];
                $fromField = "{$fieldPrefix}_from";
                $namespaceField = "{$fieldPrefix}_namespace";
                $titleField = "{$fieldPrefix}_title";
@@ -346,16 +348,16 @@ class NamespaceConflictChecker extends Maintenance {
                while ( true ) {
                        $res = $this->db->select(
                                $table,
-                               array( $fromField, $namespaceField, $titleField ),
-                               array_merge( $batchConds, $extraConds, array(
+                               [ $fromField, $namespaceField, $titleField ],
+                               array_merge( $batchConds, $extraConds, [
                                        $namespaceField => 0,
                                        $titleField . $this->db->buildLike( "$name:", $this->db->anyString() )
-                               ) ),
+                               ] ),
                                __METHOD__,
-                               array(
-                                       'ORDER BY' => array( $titleField, $fromField ),
+                               [
+                                       'ORDER BY' => [ $titleField, $fromField ],
                                        'LIMIT' => $batchSize
-                               )
+                               ]
                        );
 
                        if ( $res->numRows() == 0 ) {
@@ -380,18 +382,18 @@ class NamespaceConflictChecker extends Maintenance {
 
                                $this->db->update( $table,
                                        // SET
-                                       array(
+                                       [
                                                $namespaceField => $destTitle->getNamespace(),
                                                $titleField => $destTitle->getDBkey()
-                                       ),
+                                       ],
                                        // WHERE
-                                       array(
+                                       [
                                                $namespaceField => 0,
                                                $titleField => $row->$titleField,
                                                $fromField => $row->$fromField
-                                       ),
+                                       ],
                                        __METHOD__,
-                                       array( 'IGNORE' )
+                                       [ 'IGNORE' ]
                                );
                                $this->output( "$table $logTitle -> " .
                                        $destTitle->getPrefixedDBkey() . "\n" );
@@ -399,9 +401,9 @@ class NamespaceConflictChecker extends Maintenance {
                        $encLastTitle = $this->db->addQuotes( $row->$titleField );
                        $encLastFrom = $this->db->addQuotes( $row->$fromField );
 
-                       $batchConds = array(
+                       $batchConds = [
                                "$titleField > $encLastTitle " .
-                               "OR ($titleField = $encLastTitle AND $fromField > $encLastFrom)" );
+                               "OR ($titleField = $encLastTitle AND $fromField > $encLastFrom)" ];
 
                        wfWaitForSlaves();
                }
@@ -434,21 +436,21 @@ class NamespaceConflictChecker extends Maintenance {
         */
        private function getTargetList( $ns, $name, $options ) {
                if ( $options['move-talk'] && MWNamespace::isSubject( $ns ) ) {
-                       $checkNamespaces = array( NS_MAIN, NS_TALK );
+                       $checkNamespaces = [ NS_MAIN, NS_TALK ];
                } else {
                        $checkNamespaces = NS_MAIN;
                }
 
                return $this->db->select( 'page',
-                       array(
+                       [
                                'page_id',
                                'page_title',
                                'page_namespace',
-                       ),
-                       array(
+                       ],
+                       [
                                'page_namespace' => $checkNamespaces,
                                'page_title' . $this->db->buildLike( "$name:", $this->db->anyString() ),
-                       ),
+                       ],
                        __METHOD__
                );
        }
@@ -515,27 +517,27 @@ class NamespaceConflictChecker extends Maintenance {
         */
        private function movePage( $id, LinkTarget $newLinkTarget ) {
                $this->db->update( 'page',
-                       array(
+                       [
                                "page_namespace" => $newLinkTarget->getNamespace(),
                                "page_title" => $newLinkTarget->getDBkey(),
-                       ),
-                       array(
+                       ],
+                       [
                                "page_id" => $id,
-                       ),
+                       ],
                        __METHOD__ );
 
                // Update *_from_namespace in links tables
-               $fromNamespaceTables = array(
-                       array( 'pagelinks', 'pl' ),
-                       array( 'templatelinks', 'tl' ),
-                       array( 'imagelinks', 'il' ) );
+               $fromNamespaceTables = [
+                       [ 'pagelinks', 'pl' ],
+                       [ 'templatelinks', 'tl' ],
+                       [ 'imagelinks', 'il' ] ];
                foreach ( $fromNamespaceTables as $tableInfo ) {
                        list( $table, $fieldPrefix ) = $tableInfo;
                        $this->db->update( $table,
                                // SET
-                               array( "{$fieldPrefix}_from_namespace" => $newLinkTarget->getNamespace() ),
+                               [ "{$fieldPrefix}_from_namespace" => $newLinkTarget->getNamespace() ],
                                // WHERE
-                               array( "{$fieldPrefix}_from" => $id ),
+                               [ "{$fieldPrefix}_from" => $id ],
                                __METHOD__ );
                }
 
@@ -583,16 +585,16 @@ class NamespaceConflictChecker extends Maintenance {
                $wikiPage = new WikiPage( $sourceTitle );
                $wikiPage->loadPageData( 'fromdbmaster' );
 
-               $destId = $newTitle->getArticleId();
+               $destId = $newTitle->getArticleID();
                $this->beginTransaction( $this->db, __METHOD__ );
                $this->db->update( 'revision',
                        // SET
-                       array( 'rev_page' => $destId ),
+                       [ 'rev_page' => $destId ],
                        // WHERE
-                       array( 'rev_page' => $id ),
+                       [ 'rev_page' => $id ],
                        __METHOD__ );
 
-               $this->db->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
+               $this->db->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
 
                /* Call LinksDeletionUpdate to delete outgoing links from the old title,
                 * and update category counts.