I've added the ability to specify a preference (or no preference) for era names in dates (BC vs. BCE). I've also fixed a couple bugs in the regular expressions that match for dates, that were preventing the parser from recognizing (and converting) dates that ended in BCE or which were written in ISO format and fell between -999-01-01 and 999-12-31 (i.e. had a one-, two-, or three-digit year).
I'm not an actual committer so I'm submitting this as a diff -ru to the mailing list. I'm sure that's the wrong procedure and I'll be scolded for it, but hey I'll learn.
I've tested this and it works on my local version (checked out of svn a few hours ago) but I imagine it should be tested more.
-Bill Clark
---------- Forwarded message ---------- From: Charlie Root root@dell0.ltbx.net Date: Sep 4, 2006 9:12 PM Subject: To: wclarkxoom@gmail.com
Only in phase3.new/: LocalSettings.php Only in phase3.new/config: LocalSettings.php diff -ru --exclude=.svn phase3/includes/DateFormatter.php phase3.new/includes/DateFormatter.php --- phase3/includes/DateFormatter.php Mon Sep 4 21:07:04 2006 +++ phase3.new/includes/DateFormatter.php Mon Sep 4 21:03:26 2006 @@ -49,9 +49,9 @@ # Partial regular expressions $this->prxDM = '[[(\d{1,2})[ _](' . $this->monthNames . ')]]'; $this->prxMD = '[[(' . $this->monthNames . ')[ _](\d{1,2})]]'; - $this->prxY = '[[(\d{1,4}([ _]BC|))]]'; - $this->prxISO1 = '[[(-?\d{4})]]-[[(\d{2})-(\d{2})]]'; - $this->prxISO2 = '[[(-?\d{4})-(\d{2})-(\d{2})]]'; + $this->prxY = '[[(\d{1,4}([ _]BCE?|))]]'; + $this->prxISO1 = '[[(-?\d{1,4})]]-[[(\d{2})-(\d{2})]]'; + $this->prxISO2 = '[[(-?\d{1,4})-(\d{2})-(\d{2})]]';
# Real regular expressions $this->regexes[self::DMY] = "/{$this->prxDM} *,? *{$this->prxY}{$this->regexTrail}"; @@ -121,12 +121,13 @@ * @param string $preference User preference * @param string $text Text to reformat */ - function reformat( $preference, $text ) { + function reformat( $preference, $eraPreference, $text ) { if ( isset( $this->preferences[$preference] ) ) { $preference = $this->preferences[$preference]; } else { $preference = self::NONE; } + $this->eraPreference = $eraPreference; for ( $i=1; $i<=self::LAST; $i++ ) { $this->mSource = $i; if ( @$this->rules[$preference][$i] ) { @@ -219,7 +220,13 @@ if ( !isset( $bits['Y'] ) ) { $text .= $this->makeNormalYear( $bits['y'] ); } else { - $text .= $bits['Y']; + if ( $this->eraPreference == 'BCE' ) { + $text .= preg_replace( '/BC$/', 'BCE', $bits['Y']); + } elseif ( $this->eraPreference == 'BC' ) { + $text .= preg_replace( '/BCE$/', 'BC', $bits['Y']); + } else { + $text .= $bits['Y']; + } } break; default: @@ -264,7 +271,11 @@ */ function makeIsoYear( $year ) { # Assumes the year is in a nice format, as enforced by the regex - if ( substr( $year, -2 ) == 'BC' ) { + if ( substr( $year, -3 ) == 'BCE' ) { + $num = intval(substr( $year, 0, -4 )) - 1; + # PHP bug note: sprintf( "%04d", -1 ) fails poorly + $text = sprintf( '-%04d', $num ); + } elseif ( substr( $year, -2 ) == 'BC' ) { $num = intval(substr( $year, 0, -3 )) - 1; # PHP bug note: sprintf( "%04d", -1 ) fails poorly $text = sprintf( '-%04d', $num ); @@ -280,7 +291,11 @@ */ function makeNormalYear( $iso ) { if ( $iso{0} == '-' ) { - $text = (intval( substr( $iso, 1 ) ) + 1) . ' BC'; + if ( $this->eraPreference == 'BCE' ) { + $text = (intval( substr( $iso, 1 ) ) + 1) . ' BCE'; + } else { + $text = (intval( substr( $iso, 1 ) ) + 1) . ' BC'; + } } else { $text = intval( $iso ); } diff -ru --exclude=.svn phase3/includes/Parser.php phase3.new/includes/Parser.php --- phase3/includes/Parser.php Mon Sep 4 21:07:04 2006 +++ phase3.new/includes/Parser.php Mon Sep 4 20:28:24 2006 @@ -961,7 +961,7 @@ $text = $this->doHeadings( $text ); if($this->mOptions->getUseDynamicDates()) { $df =& DateFormatter::getInstance(); - $text = $df->reformat( $this->mOptions->getDateFormat(), $text ); + $text = $df->reformat( $this->mOptions->getDateFormat(), $this->mOptions->getEraFormat(), $text ); } $text = $this->doAllQuotes( $text ); $text = $this->replaceInternalLinks( $text ); @@ -4613,6 +4613,13 @@ $this->mDateFormat = $this->mUser->getDatePreference(); } return $this->mDateFormat; + } + + function getEraFormat() { + if ( !isset( $this->mEraFormat ) ) { + $this->mEraFormat = $this->mUser->getEraPreference(); + } + return $this->mEraFormat; }
function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); } diff -ru --exclude=.svn phase3/includes/SpecialPreferences.php phase3.new/includes/SpecialPreferences.php --- phase3/includes/SpecialPreferences.php Mon Sep 4 21:07:05 2006 +++ phase3.new/includes/SpecialPreferences.php Mon Sep 4 20:14:50 2006 @@ -23,7 +23,7 @@ */ class PreferencesForm { var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs; - var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick; + var $mRows, $mCols, $mSkin, $mMath, $mDate, $mEra, $mUserEmail, $mEmailFlag, $mNick; var $mUserLanguage, $mUserVariant; var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction; var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize; @@ -46,6 +46,7 @@ $this->mSkin = $request->getVal( 'wpSkin' ); $this->mMath = $request->getVal( 'wpMath' ); $this->mDate = $request->getVal( 'wpDate' ); + $this->mEra = $request->getVal( 'wpEra' ); $this->mUserEmail = $request->getVal( 'wpUserEmail' ); $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : ''; $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1; @@ -169,6 +170,21 @@ }
/** + * @access private + */ + function validateEra( $val ) { + global $wgLang, $wgContLang; + if ( $val !== false && ( + in_array( $val, (array)$wgLang->getEraPreferences() ) || + in_array( $val, (array)$wgContLang->getEraPreferences() ) ) ) + { + return $val; + } else { + return $wgLang->getDefaultEraFormat(); + } + } + + /** * Used to validate the user inputed timezone before saving it as * 'timeciorrection', will return '00:00' if fed bogus data. * Note: It's not a 100% correct implementation timezone-wise, it will @@ -263,6 +279,7 @@ $wgUser->setOption( 'math', $this->mMath ); } $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) ); + $wgUser->setOption( 'era', $this->validateEra( $this->mEra ) ); $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) ); $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) ); $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) ); @@ -362,6 +379,7 @@ $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) ); $this->mMath = $wgUser->getOption( 'math' ); $this->mDate = $wgUser->getDatePreference(); + $this->mEra = $wgUser->getEraPreference(); $this->mRows = $wgUser->getOption( 'rows' ); $this->mCols = $wgUser->getOption( 'cols' ); $this->mStubs = $wgUser->getOption( 'stubthreshold' ); @@ -476,6 +494,7 @@ $skinNames = $wgLang->getSkinNames(); $mathopts = $wgLang->getMathNames(); $dateopts = $wgLang->getDatePreferences(); + $eraopts = $wgLang->getEraPreferences(); $togs = User::getToggles();
$titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' ); @@ -805,6 +824,19 @@ $wgOut->addHTML( "</fieldset>\n" ); }
+ if ($eraopts) { + $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'eraformat' ) . "</legend>\n" ); + $idCnt = 0; + foreach( $eraopts as $key ) { + $formatted = wfMsgHtml( 'era'.$key ); + ($key == $this->mEra) ? $checked = ' checked="checked"' : $checked = ''; + $wgOut->addHTML( "<div><input type='radio' name="wpEra" id="wpEra$idCnt" ". + "value="$key"$checked /> <label for="wpEra$idCnt">$formatted</label></div>\n" ); + $idCnt++; + } + $wgOut->addHTML( "</fieldset>\n" ); + } + $nowlocal = $wgLang->time( $now = wfTimestampNow(), true ); $nowserver = $wgLang->time( $now, false );
@@ -820,6 +852,7 @@ </td></tr></table></fieldset> <div class='prefsectiontip'>¹" . wfMsg( 'timezonetext' ) . "</div> </fieldset>\n\n" ); +
# Editing # diff -ru --exclude=.svn phase3/includes/User.php phase3.new/includes/User.php --- phase3/includes/User.php Mon Sep 4 21:07:04 2006 +++ phase3.new/includes/User.php Mon Sep 4 20:13:47 2006 @@ -1174,6 +1174,18 @@ }
/** + * Get the user's era names preference. + */ + function getEraPreference() { + if ( is_null( $this->mEraPreference ) ) { + global $wgLang; + $value = $this->getOption( 'era' ); + $this->mEraPreference = $value; + } + return $this->mEraPreference; + } + + /** * @param string $oname The option to check * @return bool False if the option is not selected, true if it is */ diff -ru --exclude=.svn phase3/languages/Language.php phase3.new/languages/Language.php --- phase3/languages/Language.php Mon Sep 4 21:07:24 2006 +++ phase3.new/languages/Language.php Mon Sep 4 20:01:35 2006 @@ -67,7 +67,7 @@ 'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension', 'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases', 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap', - 'defaultDateFormat', 'extraUserToggles' ); + 'defaultDateFormat', 'eraPreferences', 'extraUserToggles' );
static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames', 'dateFormats', 'defaultUserOptionOverrides', 'magicWords' ); @@ -269,6 +269,11 @@ function getDatePreferences() { $this->load(); return $this->datePreferences; + } + + function getEraPreferences() { + $this->load(); + return $this->eraPreferences; }
function getDateFormats() { diff -ru --exclude=.svn phase3/languages/MessagesEn.php phase3.new/languages/MessagesEn.php --- phase3/languages/MessagesEn.php Mon Sep 4 21:07:24 2006 +++ phase3.new/languages/MessagesEn.php Mon Sep 4 21:05:23 2006 @@ -179,6 +179,17 @@ 'ISO 8601 both' => 'xnY-xnm-xnd"T"xnH:xni:xns', );
+/** + * A list of era naming preference keys which can be selected in user + * preferences. + * + */ +$eraPreferences = array( + 'default', + 'BC', + 'BCE', +); + $bookstoreList = array( 'AddALL' => 'http://www.addall.com/New/Partner.cgi?query=$1&type=ISBN', 'PriceSCAN' => 'http://www.pricescan.com/books/bookDetail.asp?isbn=$1', @@ -1007,6 +1018,10 @@ 'dateformat' => 'Date format', 'datedefault' => 'No preference', 'datetime' => 'Date and time', +'eraformat' => 'Era Names', +'eradefault' => 'No Preference', +'eraBC' => 'AD/BC', +'eraBCE' => 'CE/BCE', 'math_failure' => 'Failed to parse', 'math_unknown_error' => 'unknown error', 'math_unknown_function' => 'unknown function',
On 9/5/06, Bill Clark wclarkxoom@gmail.com wrote:
I'm not an actual committer so I'm submitting this as a diff -ru to the mailing list. I'm sure that's the wrong procedure and I'll be scolded for it, but hey I'll learn.
The procedure is to file a feature request (bug) at http://bugs.wikimedia.org/, then attach this as a patch. That provides a centralized place to discuss, note updates, get people to vote for it, etc.
On 9/4/06, Simetrical Simetrical+wikitech@gmail.com wrote:
On 9/5/06, Bill Clark wclarkxoom@gmail.com wrote:
I'm not an actual committer so I'm submitting this as a diff -ru to the mailing list. I'm sure that's the wrong procedure and I'll be scolded for it, but hey I'll learn.
The procedure is to file a feature request (bug) at http://bugs.wikimedia.org/, then attach this as a patch. That provides a centralized place to discuss, note updates, get people to vote for it, etc.
Thanks! I've submitted the bug and attached the patch.
-Bill
Bill Clark wrote:
I've added the ability to specify a preference (or no preference) for era names in dates (BC vs. BCE). I've also fixed a couple bugs in the regular expressions that match for dates, that were preventing the parser from recognizing (and converting) dates that ended in BCE or which were written in ISO format and fell between -999-01-01 and 999-12-31 (i.e. had a one-, two-, or three-digit year).
I'm not an actual committer so I'm submitting this as a diff -ru to the mailing list. I'm sure that's the wrong procedure and I'll be scolded for it, but hey I'll learn.
I've tested this and it works on my local version (checked out of svn a few hours ago) but I imagine it should be tested more.
-Bill Clark
That's a great idea. It might also be useful to make the code also switch 'AD' and 'CE', for dates such as, for example, 4 AD / 4 CE.
-- Neil
On 9/5/06, Neil Harris neil@tonal.clara.co.uk wrote:
That's a great idea. It might also be useful to make the code also switch 'AD' and 'CE', for dates such as, for example, 4 AD / 4 CE.
I didn't think anybody actually used AD or CE in articles, but I see now on the Manual of Style page that it reads:
Normally you should use plain numbers for years in the Anno
Domini/Common Era,
but when events span the start of the Anno Domini/Common Era, use
AD or CE for
the date at the end of the range (note that AD precedes the date
and CE follows it).
For example, [[1 BC]]–[[1|AD 1]] or [[1 BCE]]–[[1|1 CE]].
There doesn't seem to be any code to handle this currently for AD, which is why it didn't occur to me right off the bat. You're right though, and it should be included. I'm busy over the next few days but I can add this into the patch sometime this week (along with whatever other changes people suggest).
-Bill
On 05/09/06, Bill Clark wclarkxoom@gmail.com wrote:
There doesn't seem to be any code to handle this currently for AD, which is why it didn't occur to me right off the bat. You're right though, and it should be included. I'm busy over the next few days but I can add this into the patch sometime this week (along with whatever other changes people suggest).
It's been a vexed question on en:. I mentioned it on wikien-l, you may want to ask there for any missing features (though I can't think of any past automatic conversion).
- d.
On 05/09/06, Bill Clark wclarkxoom@gmail.com wrote:
There doesn't seem to be any code to handle this currently for AD, which is why it didn't occur to me right off the bat. You're right though, and it should be included. I'm busy over the next few days but I can add this into the patch sometime this week (along with whatever other changes people suggest).
On 9/5/06, David Gerard dgerard@gmail.com wrote:
It's been a vexed question on en:. I mentioned it on wikien-l, you may want to ask there for any missing features (though I can't think of any past automatic conversion).
Thanks for the pointer; I've subscribed to that list.
I went ahead and started looking into adding AD/CE rewriting functionality, and noticed something that might put a damper on those plans.. AD or CE only ever appear in the right (display) portion of a wikilinked date, as in:
... lasted from [[August 13]], [[10 BC]]–[[January 23]], [[15|AD 15]] ...
Both the current code and my patch would leave the date on the right entirely alone, since it contains explicit display text. This makes sense, since the editor actually went to the trouble of specifying how to display the date, and we wouldn't want to thoughtlessly override that.
So it seems we're left with three options:
1) Ignore wikilinked dates that contain explicit display text, leaving them untouched. 2) Change all wikilinked dates and associated display text according to user preferences. 3) Encourage a mass renaming of year articles from (e.g.) [[1984]] to [[AD 1984]].
Even though option 3 is completely unrealistic, I mention it because it actually makes the most sense (how did we get started having bare numbers assumed to be a date by default, anyway?). That said, I think option 2 is the best bet, so long as it's considered more important to have consistent date formatting than to honor the display text put in place by editors.
Note that this is already a problem on the current WP, since the following won't display according to a user's preferences anyway:
[[March 21]], [[1974|1974]]
The current solution is to follow option 1, and that's what's already in place in the patch I just submitted. I've posted some of this discussion there as well (bug 7239) in case people would rather follow up there.
I'm really really going to bed now and not going to work on this anymore for a few days, I swear, so I'll get back to this later.
-Bill Clark
On 9/5/06, Bill Clark wclarkxoom@gmail.com wrote:
- Ignore wikilinked dates that contain explicit display text, leaving
them untouched. 2) Change all wikilinked dates and associated display text according to user preferences. 3) Encourage a mass renaming of year articles from (e.g.) [[1984]] to [[AD 1984]].
Even though option 3 is completely unrealistic, I mention it because it actually makes the most sense (how did we get started having bare numbers assumed to be a date by default, anyway?). That said, I think option 2 is the best bet, so long as it's considered more important to have consistent date formatting than to honor the display text put in place by editors.
I vote for option 3. There are only 2006 or so of them.
Steve
Steve Bennett wrote:
On 9/5/06, Bill Clark wclarkxoom@gmail.com wrote:
- Ignore wikilinked dates that contain explicit display text, leaving
them untouched. 2) Change all wikilinked dates and associated display text according to user preferences. 3) Encourage a mass renaming of year articles from (e.g.) [[1984]] to [[AD 1984]].
Even though option 3 is completely unrealistic, I mention it because it actually makes the most sense (how did we get started having bare numbers assumed to be a date by default, anyway?). That said, I think option 2 is the best bet, so long as it's considered more important to have consistent date formatting than to honor the display text put in place by editors.
I vote for option 3. There are only 2006 or so of them.
Steve
Oh, please, please, don't even _think_ about option 3. You are now required to chant WP:LAME backwards whilst throwing salt over your left shoulder.
-- Neil, on baktun 12 katun 19 tun 13 uinal 11 kin 1.
On 9/5/06, Neil Harris neil@tonal.clara.co.uk wrote:
Oh, please, please, don't even _think_ about option 3. You are now required to chant WP:LAME backwards whilst throwing salt over your left shoulder.
Ok, I'm going to plead ignorance. Is the problem with option 3 that 1995 is a better name for an article than AD 1995, or that renaming 1995 to *anything* is not worth the trouble?
Steve
Steve Bennett wrote:
Ok, I'm going to plead ignorance. Is the problem with option 3 that 1995 is a better name for an article than AD 1995, or that renaming 1995 to *anything* is not worth the trouble?
It may be that 1995 is a better name, but renaming 1995 to *anything is indeed not worth the trouble. After 2060 page moves, you have to check for double redirects, and maybe correct all links to "1995". Also, you're left with the choise: do you leave the 2060 redirects the way they are, or do you make a disambiguation page from them? Of worse, do you move the number where the year used to be.
Whatever you do, interwikilinking will be totally (and really totally) broken for the year-articles, and will probably take years to correct it. In my point of view, this is the most significant reason to not move the year-pages.
Greetings, Tuvic
Tuvic wrote:
Steve Bennett wrote:
Ok, I'm going to plead ignorance. Is the problem with option 3 that 1995 is a better name for an article than AD 1995, or that renaming 1995 to *anything* is not worth the trouble?
It may be that 1995 is a better name, but renaming 1995 to *anything is indeed not worth the trouble. After 2060 page moves, you have to check for double redirects, and maybe correct all links to "1995". Also, you're left with the choise: do you leave the 2060 redirects the way they are, or do you make a disambiguation page from them? Of worse, do you move the number where the year used to be.
Whatever you do, interwikilinking will be totally (and really totally) broken for the year-articles, and will probably take years to correct it. In my point of view, this is the most significant reason to not move the year-pages.
And, _then_, you will have problem of fixing all the links in the continual move/edit war that will inevitably result from this, as each of the 2060 different year articles is repeatedly moved from [[AD X]] to [[X CE]], to [[X AD]], then to [[X]] again, and on, and on, and on, whilst each group of combatants desperately tries to fix the links in all linking articles to point to their preferred version, in the greatest and [[WP:LAME]]st ever edit war in the history of Wikipedia.
-- Neil
2006/9/7, Tuvic tuvic.tuvic@gmail.com:
Whatever you do, interwikilinking will be totally (and really totally) broken for the year-articles, and will probably take years to correct it. In my point of view, this is the most significant reason to not move the year-pages.
That's much less work than you think - if I set my interwiki bot to work on it (it already has settings for it, actually), I will have things fixed in about 2 days. Although I would suppose that some languages would get angry with me for flooding recent changes....
Andre Engels wrote:
That's much less work than you think - if I set my interwiki bot to work on it (it already has settings for it, actually), I will have things fixed in about 2 days. Although I would suppose that some languages would get angry with me for flooding recent changes....
Indeed, you'll probably get blocked, most likely somewhere halfway. Also, you take to take into account that a lot of interwikilinks are pointing to the wrong things. For example, the Japanese articles about years have a Japanese character after the name, but in som wiki's, all interwikilinks are pointing to the wrong articles, the ones about numbers. Also, some wikis have turned the years into redirects to decades, and some of those decades are already spread around in the years.
I did a bot-run on the years (a lot of small ones actually) in july, ranging from -500 up to 2060, and I found a lot of really stupid mistakes and silly things: like making an typo, which off course makes it ambigious. I fixed a lot of things, but there's still a lot of mistakes out there...
Greetings, Tuvic
P.S. This might be a little off topic.
wikitech-l@lists.wikimedia.org