* (bug 2118) Added a __LCFIRST__ magic word for forcing the first character of
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 15 May 2005 17:21:58 +0000 (17:21 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 15 May 2005 17:21:58 +0000 (17:21 +0000)
  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
includes/EditPage.php
includes/MagicWord.php
includes/OutputPage.php
includes/Parser.php
includes/Title.php
languages/Language.php

index c7c20a6..cc1a46a 100644 (file)
@@ -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 ===
index fbcb6af..e6f9a75 100644 (file)
@@ -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( '<div id="wikiPreview">' );
                if ( 'preview' == $formtype) {
-                       $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
                        if ( $wgUser->getOption('previewontop' ) ) {
                                $wgOut->addHTML( $previewOutput );
                                $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
index 4c1f9a9..cc86426 100644 (file)
@@ -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,
index 32896a9..8990bdf 100644 (file)
@@ -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 );
index fc6db01..1ab8b03 100644 (file)
@@ -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 ); }
index a5e119f..bfdc611 100644 (file)
@@ -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);
+       }
 }
 ?>
index f32c342..d31788a 100644 (file)
@@ -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__'            ),
 );
 
 #-------------------------------------------------------------------