r96529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96528‎ | r96529 | r96530 >
Date:00:35, 8 September 2011
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Tweaks to WikimediaMaintenance:
* Rename Site to WMFSite, less likely to conflict
* Create generic inclusion point for these scripts, so they don't have to duplicate the $IP detection
* Make them all subclass WikimediaMaintenance and move some of the wmf-specific hacks out of core -- almost resolved this crap :D
* Fix rebuildInterwiki to be protocol-relative (like r96139)
* By the way: rebuildInterwiki and dumpInterwiki seem awfully alike...maybe we can merge the two :)
Modified paths:
  • /trunk/extensions/WikimediaMaintenance/Site.php (deleted) (history)
  • /trunk/extensions/WikimediaMaintenance/WMFSite.php (added) (history)
  • /trunk/extensions/WikimediaMaintenance/addWiki.php (modified) (history)
  • /trunk/extensions/WikimediaMaintenance/dumpInterwiki.php (modified) (history)
  • /trunk/extensions/WikimediaMaintenance/rebuildInterwiki.php (modified) (history)
  • /trunk/extensions/WikimediaMaintenance/renameWiki.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/doMaintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/doMaintenance.php
@@ -82,11 +82,9 @@
8383 global $cluster;
8484 $cluster = 'pmtpa';
8585 require( MWInit::interpretedPath( '../wmf-config/wgConf.php' ) );
86 - $maintenance->loadWikimediaSettings();
87 - require( MWInit::interpretedPath( '../wmf-config/CommonSettings.php' ) );
88 -} else {
89 - require_once( $maintenance->loadSettings() );
9086 }
 87+// Require the configuration (probably LocalSettings.php)
 88+require( MWInit::interpretedPath( $maintenance->loadSettings() ) );
9189
9290 if ( $maintenance->getDbType() === Maintenance::DB_ADMIN &&
9391 is_readable( "$IP/AdminSettings.php" ) )
Index: trunk/phase3/maintenance/Maintenance.php
@@ -891,57 +891,6 @@
892892 }
893893
894894 /**
895 - * Do setup specific to WMF
896 - */
897 - public function loadWikimediaSettings() {
898 - global $IP, $wgNoDBParam, $wgUseNormalUser, $wgConf, $site, $lang;
899 -
900 - if ( empty( $wgNoDBParam ) ) {
901 - # Check if we were passed a db name
902 - if ( isset( $this->mOptions['wiki'] ) ) {
903 - $db = $this->mOptions['wiki'];
904 - } else {
905 - $db = array_shift( $this->mArgs );
906 - }
907 - list( $site, $lang ) = $wgConf->siteFromDB( $db );
908 -
909 - # If not, work out the language and site the old way
910 - if ( is_null( $site ) || is_null( $lang ) ) {
911 - if ( !$db ) {
912 - $lang = 'aa';
913 - } else {
914 - $lang = $db;
915 - }
916 - if ( isset( $this->mArgs[0] ) ) {
917 - $site = array_shift( $this->mArgs );
918 - } else {
919 - $site = 'wikipedia';
920 - }
921 - }
922 - } else {
923 - $lang = 'aa';
924 - $site = 'wikipedia';
925 - }
926 -
927 - # This is for the IRC scripts, which now run as the apache user
928 - # The apache user doesn't have access to the wikiadmin_pass command
929 - if ( $_ENV['USER'] == 'apache' ) {
930 - # if ( posix_geteuid() == 48 ) {
931 - $wgUseNormalUser = true;
932 - }
933 -
934 - putenv( 'wikilang=' . $lang );
935 -
936 - ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
937 -
938 - if ( $lang == 'test' && $site == 'wikipedia' ) {
939 - if ( !defined( 'TESTWIKI' ) ) {
940 - define( 'TESTWIKI', 1 );
941 - }
942 - }
943 - }
944 -
945 - /**
946895 * Generic setup for most installs. Returns the location of LocalSettings
947896 * @return String
948897 */
Index: trunk/extensions/WikimediaMaintenance/Site.php
@@ -1,19 +0,0 @@
2 -<?php
3 -/**
4 - * @todo document
5 - * @ingroup Maintenance
6 - */
7 -class Site {
8 - var $suffix, $lateral, $url;
9 -
10 - function __construct( $s, $l, $u ) {
11 - $this->suffix = $s;
12 - $this->lateral = $l;
13 - $this->url = $u;
14 - }
15 -
16 - function getURL( $lang, $urlprotocol ) {
17 - $xlang = str_replace( '_', '-', $lang );
18 - return "$urlprotocol//$xlang.{$this->url}/wiki/\$1";
19 - }
20 -}
Index: trunk/extensions/WikimediaMaintenance/dumpInterwiki.php
@@ -23,17 +23,10 @@
2424 * @ingroup Maintenance
2525 * @ingroup Wikimedia
2626 */
 27+require_once( dirname( __FILE__ ) . '/WikimediaMaintenance.php' );
2728
28 -$IP = getenv( 'MW_INSTALL_PATH' );
29 -if ( $IP === false ) {
30 - $IP = dirname( __FILE__ ) . '/../..';
31 -}
32 -require( "$IP/maintenance/Maintenance.php" );
 29+class DumpInterwiki extends WikimediaMaintenance {
3330
34 -require_once( dirname( __FILE__ ) . '/Site.php' );
35 -
36 -class DumpInterwiki extends Maintenance {
37 -
3831 public function __construct() {
3932 parent::__construct();
4033 $this->mDescription = "Build constant slightly compact database of interwiki prefixes.";
@@ -75,14 +68,14 @@
7669 # Multi-language sites
7770 # db suffix => db suffix, iw prefix, hostname
7871 $sites = array(
79 - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ),
80 - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ),
81 - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ),
82 - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ),
83 - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ),
84 - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ),
85 - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ),
86 - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ),
 72+ 'wiki' => new WMFSite( 'wiki', 'w', 'wikipedia.org' ),
 73+ 'wiktionary' => new WMFSite( 'wiktionary', 'wikt', 'wiktionary.org' ),
 74+ 'wikiquote' => new WMFSite( 'wikiquote', 'q', 'wikiquote.org' ),
 75+ 'wikibooks' => new WMFSite( 'wikibooks', 'b', 'wikibooks.org' ),
 76+ 'wikinews' => new WMFSite( 'wikinews', 'n', 'wikinews.org' ),
 77+ 'wikisource' => new WMFSite( 'wikisource', 's', 'wikisource.org' ),
 78+ 'wikimedia' => new WMFSite( 'wikimedia', 'chapter', 'wikimedia.org' ),
 79+ 'wikiversity' => new WMFSite( 'wikiversity', 'v', 'wikiversity.org' ),
8780 );
8881
8982 # Extra interwiki links that can't be in the intermap for some reason
Index: trunk/extensions/WikimediaMaintenance/renameWiki.php
@@ -22,14 +22,9 @@
2323 * @ingroup Maintenance
2424 * @ingroup Wikimedia
2525 */
 26+require_once( dirname( __FILE__ ) . '/WikimediaMaintenance.php' );
2627
27 -$IP = getenv( 'MW_INSTALL_PATH' );
28 -if ( $IP === false ) {
29 - $IP = dirname( __FILE__ ) . '/../..';
30 -}
31 -require( "$IP/maintenance/Maintenance.php" );
32 -
33 -class RenameWiki extends Maintenance {
 28+class RenameWiki extends WikimediaMaintenance {
3429 public function __construct() {
3530 parent::__construct();
3631 $this->mDescription = "Rename external storage dbs and leave a new one";
Index: trunk/extensions/WikimediaMaintenance/addWiki.php
@@ -26,13 +26,8 @@
2727 * @ingroup Maintenance
2828 * @ingroup Wikimedia
2929 */
 30+require_once( dirname( __FILE__ ) . '/WikimediaMaintenance.php' );
3031
31 -$IP = getenv( 'MW_INSTALL_PATH' );
32 -if ( $IP === false ) {
33 - $IP = dirname( __FILE__ ) . '/../..';
34 -}
35 -require( "$IP/maintenance/Maintenance.php" );
36 -
3732 class AddWiki extends Maintenance {
3833 public function __construct() {
3934 global $wgNoDBParam;
Index: trunk/extensions/WikimediaMaintenance/rebuildInterwiki.php
@@ -23,22 +23,16 @@
2424 * @ingroup Maintenance
2525 * @ingroup Wikimedia
2626 */
 27+require_once( dirname( __FILE__ ) . '/WikimediaMaintenance.php' );
2728
28 -$IP = getenv( 'MW_INSTALL_PATH' );
29 -if ( $IP === false ) {
30 - $IP = dirname( __FILE__ ) . '/../..';
31 -}
32 -require( "$IP/maintenance/Maintenance.php" );
33 -
34 -require_once( dirname( __FILE__ ) . '/Site.php' );
35 -
36 -class RebuildInterwiki extends Maintenance {
 29+class RebuildInterwiki extends DumpInterwiki {
3730 public function __construct() {
3831 parent::__construct();
3932 $this->mDescription = "Rebuild the interwiki table using the file on meta and the language list.";
4033 $this->addOption( 'langlist', 'File with one language code per line', false, true );
4134 $this->addOption( 'dblist', 'File with one db per line', false, true );
4235 $this->addOption( 'd', 'Output folder', false, true );
 36+ $this->addOption( 'protocolrelative', 'Output wikimedia interwiki urls as protocol relative', false, false );
4337 }
4438
4539 function execute() {
@@ -52,6 +46,12 @@
5347 //$this->specials = array_flip( array_map( "trim", file( $this->getOption( 'specialdbs', "/home/wikipedia/common/special.dblist" ) ) ) );
5448
5549 $this->makeInterwikiSQL( $this->getOption( 'd', '/home/wikipedia/conf/interwiki/sql' ) );
 50+
 51+ if ( $this->hasOption( 'protocolrelative' ) ) {
 52+ $this->urlprotocol = '';
 53+ } else {
 54+ $this->urlprotocol = 'http:';
 55+ }
5656 }
5757
5858 function makeInterwikiSQL( $destDir ) {
@@ -60,14 +60,14 @@
6161 # Multi-language sites
6262 # db suffix => db suffix, iw prefix, hostname
6363 $sites = array(
64 - 'wiki' => new Site( 'wiki', 'w', 'wikipedia.org' ),
65 - 'wiktionary' => new Site( 'wiktionary', 'wikt', 'wiktionary.org' ),
66 - 'wikiquote' => new Site( 'wikiquote', 'q', 'wikiquote.org' ),
67 - 'wikibooks' => new Site( 'wikibooks', 'b', 'wikibooks.org' ),
68 - 'wikinews' => new Site( 'wikinews', 'n', 'wikinews.org' ),
69 - 'wikisource' => new Site( 'wikisource', 's', 'wikisource.org' ),
70 - 'wikimedia' => new Site( 'wikimedia', 'chapter', 'wikimedia.org' ),
71 - 'wikiversity' => new Site( 'wikiversity', 'v', 'wikiversity.org' ),
 64+ 'wiki' => new WMFSite( 'wiki', 'w', 'wikipedia.org' ),
 65+ 'wiktionary' => new WMFSite( 'wiktionary', 'wikt', 'wiktionary.org' ),
 66+ 'wikiquote' => new WMFSite( 'wikiquote', 'q', 'wikiquote.org' ),
 67+ 'wikibooks' => new WMFSite( 'wikibooks', 'b', 'wikibooks.org' ),
 68+ 'wikinews' => new WMFSite( 'wikinews', 'n', 'wikinews.org' ),
 69+ 'wikisource' => new WMFSite( 'wikisource', 's', 'wikisource.org' ),
 70+ 'wikimedia' => new WMFSite( 'wikimedia', 'chapter', 'wikimedia.org' ),
 71+ 'wikiversity' => new WMFSite( 'wikiversity', 'v', 'wikiversity.org' ),
7272 );
7373
7474 # Special-case hostnames
@@ -83,9 +83,9 @@
8484
8585 # Extra interwiki links that can't be in the intermap for some reason
8686 $extraLinks = array(
87 - array( 'm', 'http://meta.wikimedia.org/wiki/$1', 1 ),
88 - array( 'meta', 'http://meta.wikimedia.org/wiki/$1', 1 ),
89 - array( 'sep11', 'http://sep11.wikipedia.org/wiki/$1', 1 ),
 87+ array( 'm', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
 88+ array( 'meta', $this->urlprotocol . '//meta.wikimedia.org/wiki/$1', 1 ),
 89+ array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ),
9090 );
9191
9292 # Language aliases, usually configured as redirects to the real wiki in apache
@@ -164,7 +164,7 @@
165165
166166 # Links to multilanguage sites
167167 foreach ( $sites as $targetSite ) {
168 - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en' ), 1 ), $first, $db );
 168+ $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( 'en', $this->urlprotocol ), 1 ), $first, $db );
169169 }
170170
171171 # Interlanguage links to wikipedia
@@ -213,7 +213,7 @@
214214 foreach ( $sites as $targetSite ) {
215215 # Suppress link to self
216216 if ( $targetSite->suffix != $site->suffix ) {
217 - $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang ), 1 ), $first, $db );
 217+ $sql .= $this->makeLink( array( $targetSite->lateral, $targetSite->getURL( $lang, $this->urlprotocol ), 1 ), $first, $db );
218218 }
219219 }
220220
@@ -223,7 +223,7 @@
224224 # w link within wikipedias
225225 # Other sites already have it as a lateral link
226226 if ( $site->suffix == "wiki" ) {
227 - $sql .= $this->makeLink( array( "w", "http://en.wikipedia.org/wiki/$1", 1 ), $first, $db );
 227+ $sql .= $this->makeLink( array( "w", "{$this->urlprotocol}//en.wikipedia.org/wiki/$1", 1 ), $first, $db );
228228 }
229229
230230 # Extra links
@@ -244,12 +244,12 @@
245245
246246 # Actual languages with their own databases
247247 foreach ( $this->langlist as $targetLang ) {
248 - $sql .= $this->makeLink( array( $targetLang, $site->getURL( $targetLang ), 1 ), $first, $source );
 248+ $sql .= $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $first, $source );
249249 }
250250
251251 # Language aliases
252252 foreach ( $this->languageAliases as $alias => $lang ) {
253 - $sql .= $this->makeLink( array( $alias, $site->getURL( $lang ), 1 ), $first, $source );
 253+ $sql .= $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $first, $source );
254254 }
255255 return $sql;
256256 }
Index: trunk/extensions/WikimediaMaintenance/WMFSite.php
@@ -0,0 +1,19 @@
 2+<?php
 3+/**
 4+ * A simple little class referring to a specific WMF site.
 5+ * @ingroup Maintenance
 6+ */
 7+class WMFSite {
 8+ var $suffix, $lateral, $url;
 9+
 10+ function __construct( $s, $l, $u ) {
 11+ $this->suffix = $s;
 12+ $this->lateral = $l;
 13+ $this->url = $u;
 14+ }
 15+
 16+ function getURL( $lang, $urlprotocol ) {
 17+ $xlang = str_replace( '_', '-', $lang );
 18+ return "$urlprotocol//$xlang.{$this->url}/wiki/\$1";
 19+ }
 20+}
Property changes on: trunk/extensions/WikimediaMaintenance/WMFSite.php
___________________________________________________________________
Added: svn:eol-style
121 + native
Added: svn:keywords
222 + Author Date Id Revision

Follow-up revisions

RevisionCommit summaryAuthorDate
r96532Followup r96529: forgot svn adddemon00:44, 8 September 2011
r96535Another fix for r96529: using MW_CONFIG_CALLBACK should halt normal settings ...demon00:59, 8 September 2011
r96537Last fix for r96529, I swear...only CommonSettings.php needs interpretPath()....demon01:52, 8 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96139Merge r96132 from 1.17wmf1: support protocol-relative URLs in dumpInterwiki.phpcatrope18:28, 2 September 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   00:42, 8 September 2011

Where is WikimediaMaintenance.php?

#Comment by 😂 (talk | contribs)   00:44, 8 September 2011

Whoops, see followup.

Status & tagging log