r47522 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r47521 | r47522 (on ViewVC) | r47523 >
Date:22:14, 19 February 2009
Author:brion
Status:ok
Tags:
Comment:* (bug 16335) __NONEWSECTIONLINK__ magic word to suppress new section link.
Patch by Carlin: https://bugzilla.wikimedia.org/attachment.cgi?id=5680
With slight whitespace tweaks.
Modified paths:

Diff [purge]

Index: trunk/phase3/CREDITS
===================================================================
--- trunk/phase3/CREDITS	(revision 47521)
+++ trunk/phase3/CREDITS	(revision 47522)
@@ -59,6 +59,7 @@
 * Brad Jorsch
 * Brent G
 * Brianna Laugher
+* Carlin
 * Daniel Arnold
 * Danny B.
 * FunPika
Index: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php	(revision 47521)
+++ trunk/phase3/includes/parser/Parser.php	(revision 47522)
@@ -3388,6 +3388,12 @@
 			$this->mOutput->setNewSection( true );
 		}
 
+		# Allow user to remove the "new section"
+		# link via __NONEWSECTIONLINK__
+		if ( isset( $this->mDoubleUnderscores['nonewsectionlink'] ) ) {
+			$this->mOutput->hideNewSection( true );
+		}
+
 		# if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
 		# override above conditions and always show TOC above first header
 		if ( isset( $this->mDoubleUnderscores['forcetoc'] ) ) {
Index: trunk/phase3/includes/parser/ParserOutput.php
===================================================================
--- trunk/phase3/includes/parser/ParserOutput.php	(revision 47521)
+++ trunk/phase3/includes/parser/ParserOutput.php	(revision 47522)
@@ -18,6 +18,7 @@
 		$mImages = array(),           # DB keys of the images used, in the array key only
 		$mExternalLinks = array(),    # External link URLs, in the key only
 		$mNewSection = false,         # Show a new section link?
+		$mHideNewSection = false,     # Hide the new section link?
 		$mNoGallery = false,          # No gallery on category page? (__NOGALLERY__)
 		$mHeadItems = array(),        # Items to put in the <head> section
 		$mOutputHooks = array(),      # Hook tags as per $wgParserOutputHooks
@@ -80,6 +81,12 @@
 	function setNewSection( $value ) {
 		$this->mNewSection = (bool)$value;
 	}
+	function hideNewSection ( $value ) {
+		$this->mHideNewSection = (bool)$value;
+	}
+	function getHideNewSection () {
+		return (bool)$this->mHideNewSection;
+	}
 	function getNewSection() {
 		return (bool)$this->mNewSection;
 	}
Index: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php	(revision 47521)
+++ trunk/phase3/includes/OutputPage.php	(revision 47522)
@@ -29,6 +29,7 @@
 	var $mArticleBodyOnly = false;
 
 	var $mNewSectionLink = false;
+	var $mHideNewSectionLink = false;
 	var $mNoGallery = false;
 	var $mPageTitleActionText = '';
 	var $mParseWarnings = array();
@@ -516,6 +517,7 @@
 		$this->mLanguageLinks += $parserOutput->getLanguageLinks();
 		$this->addCategoryLinks( $parserOutput->getCategories() );
 		$this->mNewSectionLink = $parserOutput->getNewSection();
+		$this->mHideNewSectionLink = $parserOutput->getHideNewSection();
 
 		if( is_null( $wgExemptFromUserRobotsControl ) ) {
 			$bannedNamespaces = $wgContentNamespaces;
@@ -1778,6 +1780,15 @@
 	}
 
 	/**
+	* Forcibly hide the new section link?
+	*
+	* @return bool
+	*/
+	public function forceHideNewSectionLink() {
+		return $this->mHideNewSectionLink;
+	}
+
+	/**
 	 * Show a warning about slave lag
 	 *
 	 * If the lag is higher than $wgSlaveLagCritical seconds,
Index: trunk/phase3/includes/MagicWord.php
===================================================================
--- trunk/phase3/includes/MagicWord.php	(revision 47521)
+++ trunk/phase3/includes/MagicWord.php	(revision 47522)
@@ -92,6 +92,7 @@
 		'numberofusers',
 		'numberofactiveusers',
 		'newsectionlink',
+		'nonewsectionlink',
 		'numberofpages',
 		'currentversion',
 		'basepagename',
@@ -160,6 +161,7 @@
 		'toc',
 		'noeditsection',
 		'newsectionlink',
+		'nonewsectionlink',
 		'hiddencat',
 		'index',
 		'noindex',
Index: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php	(revision 47521)
+++ trunk/phase3/includes/SkinTemplate.php	(revision 47522)
@@ -690,11 +690,13 @@
 				);
 
 				if ( $istalk || $wgOut->showNewSectionLink() ) {
-					$content_actions['addsection'] = array(
-						'class' => $section == 'new'?'selected':false,
-						'text' => wfMsg('addsection'),
-						'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
-					);
+					if ( !$wgOut->forceHideNewSectionLink() ) {
+						$content_actions['addsection'] = array(
+							'class' => $section == 'new' ? 'selected' : false,
+							'text' => wfMsg('addsection'),
+							'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
+						);
+					}
 				}
 			} elseif ( $this->mTitle->isKnown() ) {
 				$content_actions['viewsource'] = array(
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 47521)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 47522)
@@ -311,6 +311,7 @@
 	'displaytitle'           => array( 1,    'DISPLAYTITLE'           ),
 	'rawsuffix'              => array( 1,    'R'                      ),
 	'newsectionlink'         => array( 1,    '__NEWSECTIONLINK__'     ),
+	'nonewsectionlink'       => array( 1,    '__NONEWSECTIONLINK__'   ),
 	'currentversion'         => array( 1,    'CURRENTVERSION'         ),
 	'urlencode'              => array( 0,    'URLENCODE:'             ),
 	'anchorencode'           => array( 0,    'ANCHORENCODE'           ),
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 47521)
+++ trunk/phase3/RELEASE-NOTES	(revision 47522)
@@ -197,6 +197,7 @@
 * ForeignApiRepos now fetch MIME types, rather than trying to figure it locally
 * (bug 17570) $wgMaxRedirects is now correctly respected when following
   redirects (was previously one more than $wgMaxRedirects)
+* (bug 16335) __NONEWSECTIONLINK__ magic word to suppress new section link.
 
 == API changes in 1.15 ==
 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions

Status & tagging log

Views
Toolbox