r57558 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57557‎ | r57558 | r57559 >
Date:12:52, 9 October 2009
Author:demon
Status:resolved (Comments)
Tags:
Comment:
(bug 13750) $wgCapitalLinks should be a per-namespace setting
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/export-0.4.xsd (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/Namespace.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialCategories.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWithoutinterwiki.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/export-0.4.xsd
@@ -10,8 +10,9 @@
1111 as a list of defined namespaces.
1212
1313 Version 0.4 adds per-revision delete flags, log exports,
14 - discussion threading data, and a per-page redirect flag.
15 -
 14+ discussion threading data, a per-page redirect flag, and
 15+ per-namespace capitalization.
 16+
1617 The canonical URL to the schema document is:
1718 http://www.mediawiki.org/xml/export-0.4.xsd
1819
@@ -90,6 +91,7 @@
9192 <simpleContent>
9293 <extension base="string">
9394 <attribute name="key" type="integer" />
 95+ <attribute name="case" type="mw:CaseType" />
9496 </extension>
9597 </simpleContent>
9698 </complexType>
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -305,10 +305,7 @@
306306 * but ignore things like ucfirst() and spaces/underscore things
307307 */
308308 $comparableName = str_replace( ' ', '_', $this->mDesiredDestName );
309 - global $wgCapitalLinks, $wgContLang;
310 - if ( $wgCapitalLinks ) {
311 - $comparableName = $wgContLang->ucfirst( $comparableName );
312 - }
 309+ $comparableName = Title::capitalize( $comparableName, NS_FILE );
313310 if( $this->mDesiredDestName != $filename && $comparableName != $filename )
314311 $warnings['badfilename'] = $filename;
315312
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -28,7 +28,7 @@
2929 $this->name = $info['name'];
3030
3131 // Optional settings
32 - $this->initialCapital = true; // by default
 32+ $this->initialCapital = MWNamespace::isCapitalized( NS_FILE );
3333 foreach ( array( 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
3434 'thumbScriptUrl', 'initialCapital', 'pathDisclosureProtection',
3535 'descriptionCacheExpiry', 'hashLevels', 'url', 'thumbUrl' ) as $var )
@@ -256,7 +256,7 @@
257257 */
258258 function getNameFromTitle( $title ) {
259259 global $wgCapitalLinks;
260 - if ( $this->initialCapital != $wgCapitalLinks ) {
 260+ if ( $this->initialCapital != MWNamespace::isCapitalized( NS_FILE ) ) {
261261 global $wgContLang;
262262 $name = $title->getUserCaseDBKey();
263263 if ( $this->initialCapital ) {
Index: trunk/phase3/includes/Namespace.php
@@ -46,6 +46,13 @@
4747 class MWNamespace {
4848
4949 /**
 50+ * These namespaces should always be first-letter capitalized, now and
 51+ * forevermore. Historically, they could've probably been lowercased too,
 52+ * but some things are just too ingrained now. :)
 53+ */
 54+ private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL, NS_MEDIAWIKI );
 55+
 56+ /**
5057 * Can pages in the given namespace be moved?
5158 *
5259 * @param $index Int: namespace index
@@ -181,5 +188,30 @@
182189 global $wgNamespacesWithSubpages;
183190 return !empty( $wgNamespacesWithSubpages[$index] );
184191 }
185 -
 192+
 193+ /**
 194+ * Is the namespace first-letter capitalized?
 195+ *
 196+ * @param $index int Index to check
 197+ * @return bool
 198+ */
 199+ public static function isCapitalized( $index ) {
 200+ global $wgCapitalLinks, $wgCapitalLinkOverrides;
 201+ // Turn NS_MEDIA into NS_FILE
 202+ $index = $index === NS_MEDIA ? NS_FILE : $index;
 203+
 204+ // Make sure to get the subject of our namespace
 205+ $index = self::getSubject( $index );
 206+
 207+ // Some namespaces are special and should always be upper case
 208+ if ( in_array( $index, self::$alwaysCapitalizedNamespaces ) ) {
 209+ return true;
 210+ }
 211+ if ( isset( $wgCapitalLinkOverrides[ $index ] ) ) {
 212+ // $wgCapitalLinkOverrides is explicitly set
 213+ return $wgCapitalLinkOverrides[ $index ];
 214+ }
 215+ // Default to the global setting
 216+ return $wgCapitalLinks;
 217+ }
186218 }
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -164,7 +164,8 @@
165165 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title )
166166 {
167167 $data[$ns] = array(
168 - 'id' => intval($ns)
 168+ 'id' => intval($ns),
 169+ 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
169170 );
170171 ApiResult :: setContent( $data[$ns], $title );
171172 $canonical = MWNamespace::getCanonicalName( $ns );
Index: trunk/phase3/includes/Setup.php
@@ -8,7 +8,6 @@
99 * MEDIAWIKI is defined
1010 */
1111 if( !defined( 'MEDIAWIKI' ) ) {
12 - echo "This file is part of MediaWiki, it is not a valid entry point.\n";
1312 exit( 1 );
1413 }
1514
@@ -87,7 +86,6 @@
8887 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
8988 'thumbScriptUrl' => $wgThumbnailScriptPath,
9089 'transformVia404' => !$wgGenerateThumbnailOnParse,
91 - 'initialCapital' => $wgCapitalLinks,
9290 'deletedDir' => $wgFileStore['deleted']['directory'],
9391 'deletedHashLevels' => $wgFileStore['deleted']['hash']
9492 );
Index: trunk/phase3/includes/specials/SpecialCategories.php
@@ -36,10 +36,7 @@
3737 parent::__construct();
3838 $from = str_replace( ' ', '_', $from );
3939 if( $from !== '' ) {
40 - global $wgCapitalLinks, $wgContLang;
41 - if( $wgCapitalLinks ) {
42 - $from = $wgContLang->ucfirst( $from );
43 - }
 40+ $from = Title::capitalize( $from, NS_CATEGORY );
4441 $this->mOffset = $from;
4542 }
4643 }
Index: trunk/phase3/includes/specials/SpecialWithoutinterwiki.php
@@ -75,13 +75,10 @@
7676 }
7777
7878 function wfSpecialWithoutinterwiki() {
79 - global $wgRequest, $wgContLang, $wgCapitalLinks;
 79+ global $wgRequest, $wgContLang;
8080 list( $limit, $offset ) = wfCheckLimits();
81 - if( $wgCapitalLinks ) {
82 - $prefix = $wgContLang->ucfirst( $wgRequest->getVal( 'prefix' ) );
83 - } else {
84 - $prefix = $wgRequest->getVal( 'prefix' );
85 - }
 81+ // Only searching the mainspace anyway
 82+ $prefix = Title::capitalize( $wgRequest->getVal( 'prefix' ), NS_MAIN );
8683 $wip = new WithoutInterwikiPage();
8784 $wip->setPrefix( $prefix );
8885 $wip->doQuery( $offset, $limit );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -213,10 +213,10 @@
214214 * thumbScriptUrl The URL for thumb.php (optional, not recommended)
215215 * transformVia404 Whether to skip media file transformation on parse and rely on a 404
216216 * handler instead.
217 - * initialCapital Equivalent to $wgCapitalLinks, determines whether filenames implicitly
218 - * start with a capital letter. The current implementation may give incorrect
219 - * description page links when the local $wgCapitalLinks and initialCapital
220 - * are mismatched.
 217+ * initialCapital Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE],
 218+ * determines whether filenames implicitly start with a capital letter.
 219+ * The current implementation may give incorrect description page links
 220+ * when the local $wgCapitalLinks and initialCapital are mismatched.
221221 * pathDisclosureProtection
222222 * May be 'paranoid' to remove all parameters from error messages, 'none' to
223223 * leave the paths in unchanged, or 'simple' to replace paths with
@@ -2437,6 +2437,18 @@
24382438 $wgCapitalLinks = true;
24392439
24402440 /**
 2441+ * @since 1.16 - This can now be set per-namespace. Some special namespaces (such
 2442+ * as Special, see Namespace::$alwaysCapitalizedNamespaces for the full list) must be
 2443+ * true by default (and setting them has no effect), due to various things that
 2444+ * require them to be so. Also, since Talk namespaces need to directly mirror their
 2445+ * associated content namespaces, the values for those are ignored in favor of the
 2446+ * subject namespace's setting. Setting for NS_MEDIA is taken automatically from
 2447+ * NS_FILE.
 2448+ * EX: $wgCapitalLinkOverrides[ NS_FILE ] = false;
 2449+ */
 2450+$wgCapitalLinkOverrides = array();
 2451+
 2452+/**
24412453 * List of interwiki prefixes for wikis we'll accept as sources for
24422454 * Special:Import (for sysops). Since complete page history can be imported,
24432455 * these should be 'trusted'.
@@ -3448,7 +3460,7 @@
34493461 * 'Main_Page' => 'noindex,follow',
34503462 * # "Project", not the actual project name!
34513463 * 'Project:X' => 'index,follow',
3452 - * # Needs to be "Abc", not "abc" (unless $wgCapitalLinks is false)!
 3464+ * # Needs to be "Abc", not "abc" (unless $wgCapitalLinks is false for that namespace)!
34533465 * 'abc' => 'noindex,nofollow'
34543466 * );
34553467 */
Index: trunk/phase3/includes/Title.php
@@ -2229,6 +2229,18 @@
22302230
22312231 return $rxTc;
22322232 }
 2233+
 2234+ /**
 2235+ * Capitalize a text if it belongs to a namespace that capitalizes
 2236+ */
 2237+ public static function capitalize( $text, $ns = NS_MAIN ) {
 2238+ global $wgContLang;
 2239+
 2240+ if ( MWNamespace::isCapitalized( $ns ) )
 2241+ return $wgContLang->ucfirst( $text );
 2242+ else
 2243+ return $text;
 2244+ }
22332245
22342246 /**
22352247 * Secure and split - main initialisation function for this object
@@ -2241,7 +2253,7 @@
22422254 * @return \type{\bool} true on success
22432255 */
22442256 private function secureAndSplit() {
2245 - global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
 2257+ global $wgContLang, $wgLocalInterwiki;
22462258
22472259 # Initialisation
22482260 $rxTc = self::getTitleInvalidRegex();
@@ -2403,8 +2415,8 @@
24042416 * site might be case-sensitive.
24052417 */
24062418 $this->mUserCaseDBKey = $dbkey;
2407 - if( $wgCapitalLinks && $this->mInterwiki == '') {
2408 - $dbkey = $wgContLang->ucfirst( $dbkey );
 2419+ if( $this->mInterwiki == '') {
 2420+ $dbkey = self::capitalize( $dbkey, $this->mNamespace );
24092421 }
24102422
24112423 /**
Index: trunk/phase3/includes/User.php
@@ -521,7 +521,7 @@
522522 || User::isIP( $name )
523523 || strpos( $name, '/' ) !== false
524524 || strlen( $name ) > $wgMaxNameChars
525 - || $name != $wgContLang->ucfirst( $name ) ) {
 525+ || $name != Title::capitalize( $name, NS_USER ) ) {
526526 wfDebugLog( 'username', __METHOD__ .
527527 ": '$name' invalid due to empty, IP, slash, length, or lowercase" );
528528 return false;
@@ -669,9 +669,8 @@
670670 * - 'creatable' Valid for batch processes, login and account creation
671671 */
672672 static function getCanonicalName( $name, $validate = 'valid' ) {
673 - # Force usernames to capital
674 - global $wgContLang;
675 - $name = $wgContLang->ucfirst( $name );
 673+ # Maybe force usernames to capital
 674+ $name = Title::capitalize( $name, NS_USER );
676675
677676 # Reject names containing '#'; these will be cleaned up
678677 # with title normalisation, but then it's too late to
Index: trunk/phase3/includes/Export.php
@@ -414,7 +414,11 @@
415415 global $wgContLang;
416416 $spaces = "<namespaces>\n";
417417 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
418 - $spaces .= ' ' . Xml::element( 'namespace', array( 'key' => $ns ), $title ) . "\n";
 418+ $spaces .= ' ' .
 419+ Xml::element( 'namespace',
 420+ array( 'key' => $ns,
 421+ 'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
 422+ ), $title ) . "\n";
419423 }
420424 $spaces .= " </namespaces>";
421425 return $spaces;
Index: trunk/phase3/RELEASE-NOTES
@@ -89,6 +89,7 @@
9090 maintenance
9191 * New hook AbortNewAccountAuto, called before account creation from AuthPlugin-
9292 or ExtUser-driven requests.
 93+* $wgCapitalLinkOverrides added to configure per-namespace capitalization
9394
9495 === New features in 1.16 ===
9596
@@ -241,8 +242,8 @@
242243 called after a user's email has been successfully confirmed or invalidated.
243244 * (bug 19741) Moved the XCF files out of the main MediaWiki distribution, for
244245 a smaller subversion checkout.
 246+* (bug 13750) First letter capitalization can now be a per-namespace setting
245247
246 -
247248 === Bug fixes in 1.16 ===
248249
249250 * (bug 18031) Make namespace selector on Special:Export remember the previous

Follow-up revisions

RevisionCommit summaryAuthorDate
r57559Back out the bit of r57558 for allowing lowercased usernames. That needs more...demon13:01, 9 October 2009
r58401Fix another regression from r57558, bug 21369 - Lowercase logins causes Media...demon13:58, 1 November 2009
r60063Add NS_USER to MWNamespace::$alwaysCapitalizedNamespaces, as suggested by Hap...tstarling04:20, 15 December 2009

Comments

#Comment by Happy-melon (talk | contribs)   22:57, 13 December 2009

Why were the follow-ups not done just by adding NS_USER to Namespace::$alwaysCapitalizedNamespaces??

#Comment by Tim Starling (talk | contribs)   04:23, 15 December 2009

We can have both, done in r60063. Some pages will be made inaccessible when this commit and r60053 are deployed, and they will need to be cleaned up, by running something like cleanupTitles.php. Marking this as scaptrap for that reason. Better documentation of this issue would be useful for the 1.16 release.

Status & tagging log