From 71f1c34ce4e6b98190b11f2f84b793c47a01f1c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 15 May 2005 17:21:58 +0000 Subject: [PATCH] * (bug 2118) Added a __LCFIRST__ magic word for forcing the first character of a pages heading to render in its lower case form on output, however the page is still saved under its upper case name in the database so this is purely an aesthetic change (unlike setting $wgCapitalLinks to false). --- RELEASE-NOTES | 4 ++++ includes/EditPage.php | 7 ++++++- includes/MagicWord.php | 1 + includes/OutputPage.php | 4 +++- includes/Parser.php | 14 ++++++++++++-- includes/Title.php | 11 +++++++++++ languages/Language.php | 1 + 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c7c20a69e0..cc1a46a5c3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -191,6 +191,10 @@ Various bugfixes, small features, and a few experimental things: * New fileicons for c, cpp, deb, dvi, exe, h, html, iso, java, mid, mov, o, ogg, pdf, ps, rm, rpm, tar, tex, ttf and txt files based on the KDE crystalsvg theme. +* (bug 2118) Added a __LCFIRST__ magic word for forcing the first character of + a pages heading to render in its lower case form on output, however the page + is still saved under its upper case name in the database so this is purely an + aesthetic change (unlike setting $wgCapitalLinks to false). === Caveats === diff --git a/includes/EditPage.php b/includes/EditPage.php index fbcb6af407..e6f9a7534e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -443,6 +443,12 @@ class EditPage { # Enabled article-related sidebar, toplinks, etc. $wgOut->setArticleRelated( true ); + # Calculate preview html - must be here, because for the next things you + # have to know, if the title changes because of __LCFIRST__ + if ( 'preview' == $formtype) { + $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage ); + } + if ( $isConflict ) { $s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() ); $wgOut->setPageTitle( $s ); @@ -566,7 +572,6 @@ class EditPage { $wgOut->addHTML( '
' ); if ( 'preview' == $formtype) { - $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage ); if ( $wgUser->getOption('previewontop' ) ) { $wgOut->addHTML( $previewOutput ); $wgOut->addHTML( "
\n" ); diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 4c1f9a9f52..cc86426665 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -51,6 +51,7 @@ define('MAG_NOCONTENTCONVERT', 36); define('MAG_CURRENTWEEK', 37); define('MAG_CURRENTDOW', 38); define('MAG_REVISIONID', 39); +define('MAG_LCFIRST', 40); $wgVariableIDs = array( MAG_CURRENTMONTH, diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 32896a9b18..8990bdfa55 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -284,12 +284,14 @@ class OutputPage { * @return bool */ function tryParserCache( $article, $user ) { - global $wgParserCache; + global $wgParserCache, $wgTitle; $parserOutput = $wgParserCache->get( $article, $user ); if ( $parserOutput !== false ) { $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); $this->addHTML( $parserOutput->getText() ); + if( $parserOutput->getLcfirstTitle() ) + $wgTitle->lcfirst(); $t = $parserOutput->getTitleText(); if( !empty( $t ) ) { $this->setPageTitle( $t ); diff --git a/includes/Parser.php b/includes/Parser.php index fc6db01c67..1ab8b03374 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -163,7 +163,7 @@ class Parser * @return ParserOutput a ParserOutput */ function parse( $text, &$title, $options, $linestart = true, $clearState = true ) { - global $wgUseTidy, $wgContLang; + global $wgUseTidy, $wgContLang, $wgCapitalLinks; $fname = 'Parser::parse'; wfProfileIn( $fname ); @@ -173,6 +173,7 @@ class Parser $this->mOptions = $options; $this->mTitle =& $title; + $this->mOutput->mLcfirstTitle = false; $this->mOutputType = OT_HTML; $this->mStripState = NULL; @@ -184,7 +185,14 @@ class Parser $text = $this->internalParse( $text ); - + // if the string __LCFIRST__ (make the first character of the title + // lower case) occurs in the HTML, set the mLcfirstTitle to true + $mw =& MagicWord::get( MAG_LCFIRST ); + if( $mw->matchAndRemove( $text ) && $wgCapitalLinks ) { + $title->lcfirst(); + $this->mOutput->mLcfirstTitle = true; + } + $text = $this->unstrip( $text, $this->mStripState ); # Clean up special characters, only run once, next-to-last before doBlockLevels @@ -3112,6 +3120,7 @@ class ParserOutput var $mCacheTime; # Used in ParserCache var $mVersion; # Compatibility check var $mTitleText; # title text of the chosen language variant + var $mLcfirstTitle; # This is true if the first letter in the title has to be lowercase function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(), $containsOldMagic = false, $titletext = '' ) @@ -3130,6 +3139,7 @@ class ParserOutput function getCategoryLinks() { return array_keys( $this->mCategoryLinks ); } function getCacheTime() { return $this->mCacheTime; } function getTitleText() { return $this->mTitleText; } + function getLcfirstTitle() { return $this->mLcfirstTitle; } function containsOldMagic() { return $this->mContainsOldMagic; } function setText( $text ) { return wfSetVar( $this->mText, $text ); } function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); } diff --git a/includes/Title.php b/includes/Title.php index a5e119f073..bfdc6111da 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2015,5 +2015,16 @@ class Title { return ( 0 == $this->mNamespace && "" == $this->mDbkeyform ) || NS_SPECIAL == $this->mNamespace || NS_IMAGE == $this->mNamespace; } + + /** + * Changes the title to lowercase - used, when __LCFIRST__ occurs + */ + function lcfirst() { + global $wgContLang; + $this->mTextform = $wgContLang->lcfirst($this->mTextform); + // reset mPrefixedText, so that it's recalculated when already created + // with uppercase title + unset($this->mPrefixedText); + } } ?> diff --git a/languages/Language.php b/languages/Language.php index f32c342441..d31788a9b8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -247,6 +247,7 @@ $wgLanguageNamesEn =& $wgLanguageNames; MAG_CURRENTWEEK => array( 1, 'CURRENTWEEK' ), MAG_CURRENTDOW => array( 1, 'CURRENTDOW' ), MAG_REVISIONID => array( 1, 'REVISIONID' ), + MAG_LCFIRST => array( 0, '__LCFIRST__' ), ); #------------------------------------------------------------------- -- 2.20.1