From cc001cf787ab74731fada36454aa85410af2545b Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 1 May 2006 20:35:08 +0000 Subject: [PATCH] (bug 4876) Add __NEWSECTIONLINK__ magic word to force the "new section" link/tab to show up on specific pages on demand --- RELEASE-NOTES | 2 ++ includes/MagicWord.php | 2 ++ includes/OutputPage.php | 14 ++++++++++++++ includes/Parser.php | 19 +++++++++++++++++-- includes/Skin.php | 17 ++++++++++++++--- includes/SkinTemplate.php | 4 ++-- languages/Language.php | 1 + skins/Standard.php | 11 +++++++---- 8 files changed, 59 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index ef5d8192b5..853cd1f27d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 0345cd2f7e..1dfadfea22 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -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 ) ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index f432f7754b..1f531a6e75 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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; + } } ?> diff --git a/includes/Parser.php b/includes/Parser.php index bc204c51d5..b4eeb0db5b 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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(); diff --git a/includes/Skin.php b/includes/Skin.php index 0e60b9f71b..d1be56eb47 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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§ion=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§ion=new' ); } /* these are used extensively in SkinTemplate, but also some other places */ diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 24f0d2a5e1..e87987fc78 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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'), diff --git a/languages/Language.php b/languages/Language.php index 4051a5fbf2..53f98cb548 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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) { diff --git a/skins/Standard.php b/skins/Standard.php index 0d209bd4a0..40fe624573 100644 --- a/skins/Standard.php +++ b/skins/Standard.php @@ -219,10 +219,13 @@ class SkinStandard extends Skin { } - - if( $tns%2 && $action!='edit' && !$wpPreview) { - $s.= '
'.$this->makeKnownLink($wgTitle->getPrefixedText(),wfMsg('postcomment'),'action=edit§ion=new'); - } + # "Post a comment" link + if( ( $tns % 2 || $wgOut->showNewSectionLink() ) && $action != 'edit' && !$wpPreview ) + $s .= '
' . $this->makeKnownLinkObj( $wgTitle, wfMsg( 'postcomment' ), 'action=edit§ion=new' ); + + #if( $tns%2 && $action!='edit' && !$wpPreview) { + #$s.= '
'.$this->makeKnownLink($wgTitle->getPrefixedText(),wfMsg('postcomment'),'action=edit§ion=new'); + #} /* watching could cause problems in edit mode: -- 2.20.1