(bug 4876) Add __NEWSECTIONLINK__ magic word to force the "new section" link/tab...
authorRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 20:35:08 +0000 (20:35 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 1 May 2006 20:35:08 +0000 (20:35 +0000)
RELEASE-NOTES
includes/MagicWord.php
includes/OutputPage.php
includes/Parser.php
includes/Skin.php
includes/SkinTemplate.php
languages/Language.php
skins/Standard.php

index ef5d819..853cd1f 100644 (file)
@@ -180,6 +180,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Updated initStats maintenance script
 * (bug 5767) Fix date formats in Vietnamese locale
 * (bug 361) URL in URL, they were almost fixed. Now they are.
+* (bug 4876) Add __NEWSECTIONLINK__ magic word to force the "new section" link/tab to
+  show up on specific pages on demand
 
 == Compatibility ==
 
index 0345cd2..1dfadfe 100644 (file)
@@ -83,6 +83,7 @@ $magicWords = array(
        'MAG_SUBJECTPAGENAMEE', 
        'MAG_NUMBEROFUSERS',
        'MAG_RAWSUFFIX',
+       'MAG_NEWSECTIONLINK',
 );
 if ( ! defined( 'MEDIAWIKI_INSTALL' ) )
        wfRunHooks( 'MagicWordMagicWords', array( &$magicWords ) );
@@ -128,6 +129,7 @@ $wgVariableIDs = array(
        MAG_SUBJECTPAGENAMEE,
        MAG_NUMBEROFUSERS,
        MAG_RAWSUFFIX,
+       MAG_NEWSECTIONLINK,
 );
 if ( ! defined( 'MEDIAWIKI_INSTALL' ) )
        wfRunHooks( 'MagicWordwgVariableIDs', array( &$wgVariableIDs ) );
index f432f77..1f531a6 100644 (file)
@@ -29,6 +29,8 @@ class OutputPage {
        var $mShowFeedLinks = false;
        var $mEnableClientCache = true;
        var $mArticleBodyOnly = false;
+       
+       var $mNewSectionLink = false;
 
        /**
         * Constructor
@@ -52,6 +54,7 @@ class OutputPage {
                $this->mScripts = '';
                $this->mETag = false;
                $this->mRevisionId = null;
+               $this->mNewSectionLink = false;
        }
 
        function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ); }
@@ -291,6 +294,7 @@ class OutputPage {
        function addParserOutputNoText( &$parserOutput ) {
                $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                $this->addCategoryLinks( $parserOutput->getCategories() );
+               $this->mNewSectionLink = $parserOutput->getNewSection();
                $this->addKeywords( $parserOutput );
                if ( $parserOutput->getCacheTime() == -1 ) {
                        $this->enableClientCache( false );
@@ -376,6 +380,7 @@ class OutputPage {
                        $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                        $this->addCategoryLinks( $parserOutput->getCategories() );
                        $this->addKeywords( $parserOutput );
+                       $this->mNewSectionLink = $parserOutput->getNewSection();
                        $text = $parserOutput->getText();
                        wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
                        $this->addHTML( $text );
@@ -1042,6 +1047,15 @@ class OutputPage {
                        'Sorry, the server has encountered an internal error. ' .
                        'Please wait a moment and hit "refresh" to submit the request again.' );
        }
+       
+       /**
+        * Show an "add new section" link?
+        *
+        * @return bool True if the parser output instructs us to add one
+        */
+       function showNewSectionLink() {
+               return $this->mNewSectionLink;
+       }
 
 }
 ?>
index bc204c5..b4eeb0d 100644 (file)
@@ -15,7 +15,7 @@ require_once( 'HttpFunctions.php' );
  * changes in an incompatible way, so the parser cache
  * can automatically discard old data.
  */
-define( 'MW_PARSER_VERSION', '1.6.0' );
+define( 'MW_PARSER_VERSION', '1.6.1' );
 
 /**
  * Variable substitution O(N^2) attack
@@ -3084,6 +3084,12 @@ class Parser
                        $doShowToc = false;
                }
 
+               # Allow user to stipulate that a page should have a "new section"
+               # link added via __NEWSECTIONLINK__
+               $mw =& MagicWord::get( MAG_NEWSECTIONLINK );
+               if( $mw->matchAndRemove( $text ) )
+                       $this->mOutput->setNewSection( true );
+
                # if the string __TOC__ (not case-sensitive) occurs in the HTML,
                # override above conditions and always show TOC at that place
 
@@ -4094,7 +4100,8 @@ class ParserOutput
                $mImages,           # DB keys of the images used, in the array key only
                $mExternalLinks,    # External link URLs, in the key only
                $mHTMLtitle,            # Display HTML title
-               $mSubtitle;                     # Additional subtitle
+               $mSubtitle,                     # Additional subtitle
+               $mNewSection;           # Show a new section link?
 
        function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
                $containsOldMagic = false, $titletext = '' )
@@ -4112,6 +4119,7 @@ class ParserOutput
                $this->mExternalLinks = array();
                $this->mHTMLtitle = "" ;
                $this->mSubtitle = "" ;
+               $this->mNewSection = false;
        }
 
        function getText()                   { return $this->mText; }
@@ -4137,6 +4145,13 @@ class ParserOutput
        function addImage( $name )           { $this->mImages[$name] = 1; }
        function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }
        function addExternalLink( $url )     { $this->mExternalLinks[$url] = 1; }
+       
+       function setNewSection( $value ) {
+               $this->mNewSection = (bool)$value;
+       }
+       function getNewSection() {
+               return (bool)$this->mNewSection;
+       }
 
        function addLink( $title, $id ) {
                $ns = $title->getNamespace();
index 0e60b9f..d1be56e 100644 (file)
@@ -1349,13 +1349,24 @@ END;
        }
 
        function commentLink() {
-               global $wgTitle;
+               global $wgTitle, $wgOut;
 
                if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
                        return '';
                }
-               return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
-                       wfMsg( 'postcomment' ), 'action=edit&section=new' );
+               
+               # __NEWSECTIONLINK___ changes behaviour here
+               # If it's present, the link points to this page, otherwise
+               # it points to the talk page
+               if( $wgTitle->isTalkPage() ) {
+                       $title =& $wgTitle;
+               } elseif( $wgOut->showNewSectionLink() ) {
+                       $title =& $wgTitle;
+               } else {
+                       $title =& $wgTitle->getTalkPage();
+               }
+               
+               return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
        }
 
        /* these are used extensively in SkinTemplate, but also some other places */
index 24f0d2a..e87987f 100644 (file)
@@ -585,7 +585,7 @@ class SkinTemplate extends Skin {
         * @private
         */
        function buildContentActionUrls () {
-               global $wgContLang;
+               global $wgContLang, $wgOut;
                $fname = 'SkinTemplate::buildContentActionUrls';
                wfProfileIn( $fname );
 
@@ -625,7 +625,7 @@ class SkinTemplate extends Skin {
                                        'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
                                );
 
-                               if ( $istalk ) {
+                               if ( $istalk || $wgOut->showNewSectionLink() ) {
                                        $content_actions['addsection'] = array(
                                                'class' => $section == 'new'?'selected':false,
                                                'text' => wfMsg('addsection'),
index 4051a5f..53f98cb 100644 (file)
@@ -281,6 +281,7 @@ $wgLanguageNamesEn =& $wgLanguageNames;
        MAG_RAW                  => array( 0,    'RAW:'                   ),
        MAG_DISPLAYTITLE         => array( 1,    'DISPLAYTITLE'           ),
        MAG_RAWSUFFIX                    => array( 1,    'R'                                      ),
+       MAG_NEWSECTIONLINK               => array( 1,    '__NEWSECTIONLINK__'     ),
 );
 
 if (!$wgCachedMessageArrays) {
index 0d209bd..40fe624 100644 (file)
@@ -219,10 +219,13 @@ class SkinStandard extends Skin {
 
                        }
 
-
-                       if( $tns%2 && $action!='edit' && !$wpPreview) {
-                               $s.= '<br />'.$this->makeKnownLink($wgTitle->getPrefixedText(),wfMsg('postcomment'),'action=edit&section=new');
-                       }
+                       # "Post a comment" link
+                       if( ( $tns % 2 || $wgOut->showNewSectionLink() ) && $action != 'edit' && !$wpPreview )
+                               $s .= '<br />' . $this->makeKnownLinkObj( $wgTitle, wfMsg( 'postcomment' ), 'action=edit&section=new' );
+                       
+                       #if( $tns%2 && $action!='edit' && !$wpPreview) {
+                               #$s.= '<br />'.$this->makeKnownLink($wgTitle->getPrefixedText(),wfMsg('postcomment'),'action=edit&section=new');
+                       #}
 
                        /*
                        watching could cause problems in edit mode: