r37973 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r37972 | r37973 (on ViewVC) | r37974 >
Date:19:49, 23 July 2008
Author:simetrical
Status:ok
Tags:
Comment:(bug 8068) New __INDEX__ and __NOINDEX__ magic words allow control of search engine indexing on a per-article basis. Remarks:
* Currently __INDEX__ will override __NOINDEX__ regardless of their relative positions, due to the way things are written. Instead, the last one on the page should win. This should be pretty easy to fix.
* __INDEX__ and __NOINDEX__ override $wgArticleRobotPolicies. This is almost certainly incorrect, but it's not totally obvious how to fix it, because of the way the code is structured. Probably not a big deal, but should probably be fixed at some point.
* Anyone can add and remove the magic words, and there's no config option to disable them. It's not obvious whether this is okay or not. It would be a one-line change to OutputPage.php to have a config option to ignore the magic words, maybe per-namespace or who knows what.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php	(revision 37972)
+++ trunk/phase3/includes/parser/Parser.php	(revision 37973)
@@ -3380,6 +3380,15 @@
 				wfDebug( __METHOD__.": [[MediaWiki:hidden-category-category]] is not a valid title!\n" );
 			}
 		}
+		# (bug 8068) Allow control over whether robots index a page.  FIXME:
+		# __INDEX__ always overrides __NOINDEX__ here!  This is not desirable,
+		# the last one on the page should win.
+		if( isset( $this->mDoubleUnderscores['noindex'] ) ) {
+			$this->mOutput->setIndexPolicy( 'noindex' );
+		} elseif( isset( $this->mDoubleUnderscores['index'] ) ) {
+			$this->mOutput->setIndexPolicy( 'index' );
+		}
+
 		return $text;
 	}
 
Index: trunk/phase3/includes/parser/ParserOutput.php
===================================================================
--- trunk/phase3/includes/parser/ParserOutput.php	(revision 37972)
+++ trunk/phase3/includes/parser/ParserOutput.php	(revision 37973)
@@ -24,6 +24,7 @@
 		$mWarnings,         # Warning text to be returned to the user. Wikitext formatted, in the key only
 		$mSections,         # Table of contents
 		$mProperties;       # Name/value pairs to be cached in the DB
+	private $mIndexPolicy = '';	# 'index' or 'noindex'?  Any other value will result in no change.
 
 	/**
 	 * Overridden title for display
@@ -69,6 +70,7 @@
 	function getSubtitle()               { return $this->mSubtitle; }
 	function getOutputHooks()            { return (array)$this->mOutputHooks; }
 	function getWarnings()               { return array_keys( $this->mWarnings ); }
+	function getIndexPolicy()            { return $this->mIndexPolicy; }
 
 	function containsOldMagic()          { return $this->mContainsOldMagic; }
 	function setText( $text )            { return wfSetVar( $this->mText, $text ); }
@@ -78,6 +80,7 @@
 	function setCacheTime( $t )          { return wfSetVar( $this->mCacheTime, $t ); }
 	function setTitleText( $t )          { return wfSetVar( $this->mTitleText, $t ); }
 	function setSections( $toc )         { return wfSetVar( $this->mSections, $toc ); }
+	function setIndexPolicy( $policy )   { return wfSetVar( $this->mIndexPolicy, $policy ); }
 
 	function addCategory( $c, $sort )    { $this->mCategories[$c] = $sort; }
 	function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }
Index: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php	(revision 37972)
+++ trunk/phase3/includes/OutputPage.php	(revision 37973)
@@ -475,6 +475,8 @@
 		$this->mLanguageLinks += $parserOutput->getLanguageLinks();
 		$this->addCategoryLinks( $parserOutput->getCategories() );
 		$this->mNewSectionLink = $parserOutput->getNewSection();
+		# FIXME: This probably overrides $wgArticleRobotPolicies, is that wise?
+		$this->setIndexPolicy( $parserOutput->getIndexPolicy() );
 		$this->addKeywords( $parserOutput );
 		$this->mParseWarnings = $parserOutput->getWarnings();
 		if ( $parserOutput->getCacheTime() == -1 ) {
Index: trunk/phase3/includes/MagicWord.php
===================================================================
--- trunk/phase3/includes/MagicWord.php	(revision 37972)
+++ trunk/phase3/includes/MagicWord.php	(revision 37973)
@@ -105,6 +105,8 @@
 		'numberofadmins',
 		'defaultsort',
 		'pagesincategory',
+		'index',
+		'noindex',
 	);
 
 	/* Array of caching hints for ParserCache */
@@ -153,6 +155,8 @@
 		'noeditsection',
 		'newsectionlink',
 		'hiddencat',
+		'index',
+		'noindex',
 	);
 
 
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 37972)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 37973)
@@ -340,6 +340,8 @@
 	'hiddencat'              => array( 1,    '__HIDDENCAT__'          ),
 	'pagesincategory'        => array( 1,    'PAGESINCATEGORY', 'PAGESINCAT' ),
 	'pagesize'               => array( 1,    'PAGESIZE'               ),
+	'index'                  => array( 1,    '__INDEX__'              ),
+	'noindex'                => array( 1,    '__NOINDEX__'            ),
 );
 
 /**
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 37972)
+++ trunk/phase3/RELEASE-NOTES	(revision 37973)
@@ -24,7 +24,8 @@
 
 === New features in 1.14 ===
 
-None yet
+* (bug 8068) New __INDEX__ and __NOINDEX__ magic words allow control of search
+engine indexing on a per-article basis.
 
 === Bug fixes in 1.14 ===
 
Views
Toolbox