r87635 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87634‎ | r87635 | r87636 >
Date:14:53, 7 May 2011
Author:happy-melon
Status:reverted (Comments)
Tags:
Comment:
* Implement MW_VERSION constant in Defines.php and use it in preference to $wgVersion. Defines.php will have been loaded anywhere that DefaultSettings.php has been loaded.
* Move the declaration of $wgFeedClasses from Defines.php to WebStart.php
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Defines.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/Feed.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/WebInstallerOutput.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)
  • /trunk/phase3/tests/parserTests.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -33,8 +33,11 @@
3434 $wgConf = new SiteConfiguration;
3535 /** @endcond */
3636
37 -/** MediaWiki version number */
38 -$wgVersion = '1.19alpha';
 37+/**
 38+ * MediaWiki version number
 39+ * @deprecated use the constant MW_VERSION instead
 40+ */
 41+$wgVersion = MW_VERSION;
3942
4043 /** Name of the site. It must be changed in LocalSettings.php */
4144 $wgSitename = 'MediaWiki';
@@ -4311,6 +4314,16 @@
43124315 /** Provide syndication feeds (RSS, Atom) for, e.g., Recentchanges, Newpages */
43134316 $wgFeed = true;
43144317
 4318+/**
 4319+ * Available feeds objects
 4320+ * Should probably only be defined when a page is syndicated ie when
 4321+ * $wgOut->isSyndicated() is true
 4322+ */
 4323+$wgFeedClasses = array(
 4324+ 'rss' => 'RSSFeed',
 4325+ 'atom' => 'AtomFeed',
 4326+);
 4327+
43154328 /** Set maximum number of results to return in syndication feeds (RSS, Atom) for
43164329 * eg Recentchanges, Newpages. */
43174330 $wgFeedLimit = 50;
Index: trunk/phase3/includes/HttpFunctions.php
@@ -112,8 +112,7 @@
113113 * @return String
114114 */
115115 public static function userAgent() {
116 - global $wgVersion;
117 - return "MediaWiki/$wgVersion";
 116+ return "MediaWiki/" . MW_VERSION;
118117 }
119118
120119 /**
Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -158,16 +158,16 @@
159159 * @return mixed
160160 */
161161 public static function getVersion( $flags = '' ) {
162 - global $wgVersion, $IP;
 162+ global $IP;
163163 wfProfileIn( __METHOD__ );
164164
165165 $info = self::getSvnInfo( $IP );
166166 if ( !$info ) {
167 - $version = $wgVersion;
 167+ $version = MW_VERSION;
168168 } elseif( $flags === 'nodb' ) {
169 - $version = "$wgVersion (r{$info['checkout-rev']})";
 169+ $version = MW_VERSION . " (r{$info['checkout-rev']})";
170170 } else {
171 - $version = $wgVersion . ' ' .
 171+ $version = MW_VERSION . ' ' .
172172 wfMsg(
173173 'version-svn-revision',
174174 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
@@ -186,11 +186,13 @@
187187 * @return mixed
188188 */
189189 public static function getVersionLinked() {
190 - global $wgVersion, $IP;
 190+ global $IP;
191191 wfProfileIn( __METHOD__ );
192192
193193 $info = self::getSvnInfo( $IP );
194194
 195+ $version = MW_VERSION;
 196+
195197 if ( isset( $info['checkout-rev'] ) ) {
196198 $linkText = wfMsg(
197199 'version-svn-revision',
@@ -199,12 +201,10 @@
200202 );
201203
202204 if ( isset( $info['viewvc-url'] ) ) {
203 - $version = "$wgVersion [{$info['viewvc-url']} $linkText]";
 205+ $version .= " [{$info['viewvc-url']} $linkText]";
204206 } else {
205 - $version = "$wgVersion $linkText";
 207+ $version .= " $linkText";
206208 }
207 - } else {
208 - $version = $wgVersion;
209209 }
210210
211211 wfProfileOut( __METHOD__ );
@@ -680,9 +680,10 @@
681681
682682 function showEasterEgg() {
683683 $rx = $rp = $xe = '';
 684+ $version = MW_VERSION;
684685 $alpha = array("", "kbQW", "\$\n()");
685686 $beta = implode( "', '", $alpha);
686 - $juliet = 'echo $delta + strrev($foxtrot) - $alfa + $wgVersion . base64_decode($bravo) * $charlie';
 687+ $juliet = 'echo $delta + strrev($foxtrot) - $alfa + $version . base64_decode($bravo) * $charlie';
687688 for ( $i = 1; $i <= 4; $i++ ) {
688689 $rx .= '([^j]*)J';
689690 $rp .= "+(\\$i)";
Index: trunk/phase3/includes/Defines.php
@@ -9,9 +9,10 @@
1010 * @file
1111 */
1212
13 -/**
 13+/**@{
1414 * Version constants for the benefit of extensions
1515 */
 16+define( 'MW_VERSION', '1.19alpha' );
1617 define( 'MW_SPECIALPAGE_VERSION', 2 );
1718
1819 /**@{
@@ -85,16 +86,6 @@
8687 define( 'NS_IMAGE_TALK', NS_FILE_TALK );
8788 /**@}*/
8889
89 -/**
90 - * Available feeds objects
91 - * Should probably only be defined when a page is syndicated ie when
92 - * $wgOut->isSyndicated() is true
93 - */
94 -$wgFeedClasses = array(
95 - 'rss' => 'RSSFeed',
96 - 'atom' => 'AtomFeed',
97 -);
98 -
9990 /**@{
10091 * Cache type
10192 */
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2500,10 +2500,8 @@
25012501 * a float
25022502 */
25032503 function wfUseMW( $req_ver ) {
2504 - global $wgVersion;
2505 -
2506 - if ( version_compare( $wgVersion, (string)$req_ver, '<' ) ) {
2507 - throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" );
 2504+ if ( version_compare( MW_VERSION, (string)$req_ver, '<' ) ) {
 2505+ throw new MWException( "MediaWiki $req_ver required--this is only " . MW_VERSION );
25082506 }
25092507 }
25102508
Index: trunk/phase3/includes/Setup.php
@@ -23,6 +23,7 @@
2424 wfProfileIn( $fname );
2525
2626 // Check to see if we are at the file scope
 27+// FIXME: use a different test here, maybe a constant defined at the top of DefaultSettings.php?
2728 if ( !isset( $wgVersion ) ) {
2829 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
2930 die( 1 );
Index: trunk/phase3/includes/Feed.php
@@ -301,7 +301,6 @@
302302 * Ouput an RSS 2.0 header
303303 */
304304 function outHeader() {
305 - global $wgVersion;
306305
307306 $this->outXmlHeader();
308307 ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
@@ -310,7 +309,7 @@
311310 <link><?php print $this->getUrl() ?></link>
312311 <description><?php print $this->getDescription() ?></description>
313312 <language><?php print $this->getLanguage() ?></language>
314 - <generator>MediaWiki <?php print $wgVersion ?></generator>
 313+ <generator>MediaWiki <?php print MW_VERSION ?></generator>
315314 <lastBuildDate><?php print $this->formatTime( wfTimestampNow() ) ?></lastBuildDate>
316315 <?php
317316 }
@@ -361,8 +360,6 @@
362361 * Outputs a basic header for Atom 1.0 feeds.
363362 */
364363 function outHeader() {
365 - global $wgVersion;
366 -
367364 $this->outXmlHeader();
368365 ?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="<?php print $this->getLanguage() ?>">
369366 <id><?php print $this->getFeedId() ?></id>
@@ -371,7 +368,7 @@
372369 <link rel="alternate" type="text/html" href="<?php print $this->getUrl() ?>"/>
373370 <updated><?php print $this->formatTime( wfTimestampNow() ) ?>Z</updated>
374371 <subtitle><?php print $this->getDescription() ?></subtitle>
375 - <generator>MediaWiki <?php print $wgVersion ?></generator>
 372+ <generator>MediaWiki <?php print MW_VERSION ?></generator>
376373
377374 <?php
378375 }
Index: trunk/phase3/includes/Export.php
@@ -406,8 +406,7 @@
407407 }
408408
409409 function generator() {
410 - global $wgVersion;
411 - return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
 410+ return Xml::element( 'generator', array(), "MediaWiki " . MW_VERSION );
412411 }
413412
414413 function homelink() {
Index: trunk/phase3/includes/OutputPage.php
@@ -2683,7 +2683,7 @@
26842684 */
26852685 public function getHeadLinks( Skin $sk, $addContentType = false ) {
26862686 global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
2687 - $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
 2687+ $wgSitename, $wgHtml5, $wgMimeType,
26882688 $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
26892689 $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf,
26902690 $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang,
@@ -2710,7 +2710,7 @@
27112711
27122712 $tags[] = Html::element( 'meta', array(
27132713 'name' => 'generator',
2714 - 'content' => "MediaWiki $wgVersion",
 2714+ 'content' => "MediaWiki " . MW_VERSION,
27152715 ) );
27162716
27172717 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -191,7 +191,6 @@
192192 * @param $what Array: what updates to perform
193193 */
194194 public function doUpdates( $what = array( 'core', 'extensions', 'purge' ) ) {
195 - global $wgVersion;
196195
197196 $what = array_flip( $what );
198197 if ( isset( $what['core'] ) ) {
@@ -202,7 +201,7 @@
203202 $this->runUpdates( $this->getExtensionUpdates(), true );
204203 }
205204
206 - $this->setAppliedUpdates( $wgVersion, $this->updates );
 205+ $this->setAppliedUpdates( MW_VERSION, $this->updates );
207206
208207 if( isset( $what['purge'] ) ) {
209208 $this->purgeCache();
Index: trunk/phase3/includes/installer/WebInstallerOutput.php
@@ -270,8 +270,7 @@
271271 }
272272
273273 public function outputTitle() {
274 - global $wgVersion;
275 - echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
 274+ echo htmlspecialchars( wfMsg( 'config-title', MW_VERSION ) );
276275 }
277276
278277 public function getJQuery() {
Index: trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -35,7 +35,7 @@
3636 protected function getConfig( $context ) {
3737 global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension,
3838 $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang,
39 - $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion,
 39+ $wgVariantArticlePath, $wgActionPaths, $wgUseAjax,
4040 $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest,
4141 $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgProto,
4242 $wgCookiePrefix, $wgResourceLoaderMaxQueryLength;
@@ -71,7 +71,7 @@
7272 'wgServer' => $wgServer,
7373 'wgUserLanguage' => $context->getLanguage(),
7474 'wgContentLanguage' => $wgContLang->getCode(),
75 - 'wgVersion' => $wgVersion,
 75+ 'wgVersion' => MW_VERSION,
7676 'wgEnableAPI' => $wgEnableAPI,
7777 'wgEnableWriteAPI' => $wgEnableWriteAPI,
7878 'wgDefaultDateFormat' => $wgContLang->getDefaultDateFormat(),
Index: trunk/phase3/tests/parserTests.php
@@ -30,8 +30,9 @@
3131 require_once( dirname( __FILE__ ) . '/../maintenance/commandLine.inc' );
3232
3333 if ( isset( $options['help'] ) ) {
 34+ $version = MW_VERSION;
3435 echo <<<ENDS
35 -MediaWiki $wgVersion parser test suite
 36+MediaWiki $version parser test suite
3637 Usage: php parserTests.php [options...]
3738
3839 Options:

Follow-up revisions

RevisionCommit summaryAuthorDate
r88176Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHo...tstarling13:21, 15 May 2011

Comments

#Comment by Nikerabbit (talk | contribs)   16:52, 7 May 2011

-1. It's harder to change constant than variable.

#Comment by Happy-melon (talk | contribs)   16:59, 7 May 2011

When would you ever want to dynamically change the variable describing the MW version?!? The fact that it's immutable is a strength, not a weakness, less chance of it getting accidentally overwritten.

#Comment by Nikerabbit (talk | contribs)   17:05, 7 May 2011

People who run modified version of MediaWiki? People who want to fake the version for unknown reasons? Why is everyone breaking threading when responding to first comment? Bad ui I guess.

#Comment by Happy-melon (talk | contribs)   18:47, 7 May 2011

Anyone running a modified version of MW can and should hack the version number along with whatever else they've changed, precisely so that it gets reverted along with any other changes if they do an upgrade without repatching. Updating the version via LocalSettings, which won't get overwritten by an upgrade, and the code via core hacks which will, is asking for (more than the usual amount of) trouble.

I can see merit in a wfGetVersionText() function which can be hooked to change the display on things like Special:Version and the <meta generator> tag, but being able to fudge version_compare() calls is neither big nor clever. MW_VERSION summarises the state of the other 714,000 lines of code in MW core, version comparisons exist to stop Bad Things™ happening when those structures don't match up with what external code expects to see.

#Comment by 😂 (talk | contribs)   17:53, 7 May 2011

+1 on reverting $wgVersion as a constant.

Status & tagging log