(bug 8068) New __INDEX__ and __NOINDEX__ magic words allow control of search engine...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 23 Jul 2008 19:49:46 +0000 (19:49 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 23 Jul 2008 19:49:46 +0000 (19:49 +0000)
* 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.

RELEASE-NOTES
includes/MagicWord.php
includes/OutputPage.php
includes/parser/Parser.php
includes/parser/ParserOutput.php
languages/messages/MessagesEn.php

index 03a4a6d..7850c0f 100644 (file)
@@ -24,7 +24,8 @@ None yet
 
 === 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 ===
 
index 5284e62..ca2a113 100644 (file)
@@ -105,6 +105,8 @@ class MagicWord {
                'numberofadmins',
                'defaultsort',
                'pagesincategory',
+               'index',
+               'noindex',
        );
 
        /* Array of caching hints for ParserCache */
@@ -153,6 +155,8 @@ class MagicWord {
                'noeditsection',
                'newsectionlink',
                'hiddencat',
+               'index',
+               'noindex',
        );
 
 
index bc7a567..baacbfd 100644 (file)
@@ -475,6 +475,8 @@ class OutputPage {
                $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 b9e0cee..404f94a 100644 (file)
@@ -3380,6 +3380,15 @@ class Parser
                                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 f98d564..a15a71d 100644 (file)
@@ -24,6 +24,7 @@ class ParserOutput
                $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 @@ class ParserOutput
        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 @@ class ParserOutput
        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 2361b84..1ec6886 100644 (file)
@@ -340,6 +340,8 @@ $magicWords = array(
        'hiddencat'              => array( 1,    '__HIDDENCAT__'          ),
        'pagesincategory'        => array( 1,    'PAGESINCATEGORY', 'PAGESINCAT' ),
        'pagesize'               => array( 1,    'PAGESIZE'               ),
+       'index'                  => array( 1,    '__INDEX__'              ),
+       'noindex'                => array( 1,    '__NOINDEX__'            ),
 );
 
 /**