Refactor a bit preparatory to fixing bug 8068: rewrite the robot policy stuff in...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 23 Jul 2008 19:05:43 +0000 (19:05 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 23 Jul 2008 19:05:43 +0000 (19:05 +0000)
16 files changed:
includes/Article.php
includes/Credits.php
includes/DifferenceEngine.php
includes/EditPage.php
includes/Exception.php
includes/ImagePage.php
includes/OutputPage.php
includes/PageHistory.php
includes/ProtectionForm.php
includes/SpecialPage.php
includes/specials/SpecialPreferences.php
includes/specials/SpecialSearch.php
includes/specials/SpecialSpecialpages.php
includes/specials/SpecialUpload.php
includes/specials/SpecialUserlogin.php
includes/specials/SpecialUserlogout.php

index 4d8277b..aee5463 100644 (file)
@@ -204,7 +204,7 @@ class Article {
 
                if ( 0 == $this->getID() ) {
                        wfProfileOut( __METHOD__ );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                $wgMessageCache->loadAllMessages();
@@ -822,7 +822,7 @@ class Article {
 
                        # We're looking at an old revision
                        if ( !empty( $oldid ) ) {
-                               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                                if( is_null( $this->mRevision ) ) {
                                        // FIXME: This would be a nice place to load the 'no such page' text.
                                } else {
@@ -1034,7 +1034,7 @@ class Article {
                                "</form>\n", $msg );
 
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
                        $wgOut->addHTML( $msg );
                }
        }
@@ -1696,7 +1696,7 @@ class Article {
 
                if( $this->doWatch() ) {
                        $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                        $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
                }
@@ -1741,7 +1741,7 @@ class Article {
 
                if( $this->doUnwatch() ) {
                        $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                        $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
                }
@@ -2177,7 +2177,7 @@ class Article {
                wfDebug( "Article::confirmDelete\n" );
 
                $wgOut->setSubtitle( wfMsg( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiMsg( 'confirmdeletetext' );
 
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
@@ -2264,7 +2264,7 @@ class Article {
                                $deleted = $this->mTitle->getPrefixedText();
 
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-                               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                                $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
 
index 6326e3a..4bbac25 100644 (file)
@@ -34,7 +34,7 @@ function showCreditsPage($article) {
        $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
        $wgOut->setArticleFlag( false );
        $wgOut->setArticleRelated( true );
-       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
        if( $article->mTitle->getArticleID() == 0 ) {
                $s = wfMsg( 'nocredits' );
index 0b4028c..eaa706b 100644 (file)
@@ -142,7 +142,7 @@ CONTROL;
                        $wgOut->setPageTitle( $oldTitle . ', ' . $newTitle );
                }
                $wgOut->setSubtitle( wfMsg( 'difference' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                if ( !( $this->mOldPage->userCanRead() && $this->mNewPage->userCanRead() ) ) {
                        $wgOut->loginToUse();
@@ -363,7 +363,7 @@ CONTROL;
                $wgOut->addHTML( $header );
 
                $wgOut->setSubtitle( wfMsg( 'difference' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                wfProfileOut( __METHOD__ );
        }
index ce741a7..dd3544c 100644 (file)
@@ -1042,7 +1042,7 @@ class EditPage {
 
                wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
 
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                # Enabled article-related sidebar, toplinks, etc.
                $wgOut->setArticleRelated( true );
index 7482020..34671ff 100644 (file)
@@ -137,7 +137,7 @@ class MWException extends Exception {
                global $wgOut;
                if ( $this->useOutputPage() ) {
                        $wgOut->setPageTitle( $this->getPageTitle() );
-                       $wgOut->setRobotpolicy( "noindex,nofollow" );
+                       $wgOut->setRobotPolicy( "noindex,nofollow" );
                        $wgOut->setArticleRelated( false );
                        $wgOut->enableClientCache( false );
                        $wgOut->redirect( '' );
index 30fcf13..a0920e7 100644 (file)
@@ -98,7 +98,7 @@ class ImagePage extends Article {
                } else {
                        # Just need to set the right headers
                        $wgOut->setArticleFlag( true );
-                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                        $this->viewUpdates();
                }
@@ -762,7 +762,7 @@ EOT
        function showError( $description ) {
                global $wgOut;
                $wgOut->setPageTitle( wfMsg( "internalerror" ) );
-               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setRobotPolicy( "noindex,nofollow" );
                $wgOut->setArticleRelated( false );
                $wgOut->enableClientCache( false );
                $wgOut->addWikiText( $description );
index 8226cb2..bc7a567 100644 (file)
@@ -8,7 +8,7 @@ if ( ! defined( 'MEDIAWIKI' ) )
 class OutputPage {
        var $mMetatags, $mKeywords;
        var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
-       var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
+       var $mHTMLtitle, $mIsarticle, $mPrintable;
        var $mSubtitle, $mRedirect, $mStatusCode;
        var $mLastModified, $mETag, $mCategoryLinks;
        var $mScripts, $mLinkColours, $mPageLinkTitle;
@@ -30,6 +30,9 @@ class OutputPage {
        var $mPageTitleActionText = '';
        var $mParseWarnings = array();
 
+       private $mIndexPolicy = 'index';
+       private $mFollowPolicy = 'follow';
+
        /**
         * Constructor
         * Initialise private variables
@@ -39,9 +42,8 @@ class OutputPage {
                $this->mAllowUserJs = $wgAllowUserJs;
                $this->mMetatags = $this->mKeywords = $this->mLinktags = array();
                $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
-               $this->mRedirect = $this->mLastModified =
-               $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
-               $this->mOnloadHandler = $this->mPageLinkTitle = '';
+               $this->mRedirect = $this->mLastModified = $this->mSubtitle =
+               $this->mDebugtext = $this->mOnloadHandler = $this->mPageLinkTitle = '';
                $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
                $this->mSuppressQuickbar = $this->mPrintable = false;
                $this->mLanguageLinks = array();
@@ -223,7 +225,61 @@ class OutputPage {
                }
        }
 
-       public function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
+       /**
+        * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
+        *
+        * @param $policy string The literal string to output as the contents of
+        *   the meta tag.  Will be parsed according to the spec and output in
+        *   standardized form.
+        * @return null
+        */
+       public function setRobotPolicy( $policy ) {
+               $policy = explode( ',', $policy );
+               $policy = array_map( 'trim', $policy );
+
+               # The default policy is follow, so if nothing is said explicitly, we
+               # do that.
+               if( in_array( 'nofollow', $policy ) ) {
+                       $this->mFollowPolicy = 'nofollow';
+               } else {
+                       $this->mFollowPolicy = 'follow';
+               }
+
+               if( in_array( 'noindex', $policy ) ) {
+                       $this->mIndexPolicy = 'noindex';
+               } else {
+                       $this->mIndexPolicy = 'index';
+               }
+       }
+
+       /**
+        * Set the index policy for the page, but leave the follow policy un-
+        * touched.
+        *
+        * @param $policy string Either 'index' or 'noindex'.
+        * @return null
+        */
+       public function setIndexPolicy( $policy ) {
+               $policy = trim( $policy );
+               if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
+                       $this->mIndexPolicy = $policy;
+               }
+       }
+
+       /**
+        * Set the follow policy for the page, but leave the index policy un-
+        * touched.
+        *
+        * @param $policy string Either 'follow' or 'nofollow'.
+        * @return null
+        */
+       public function setFollowPolicy( $policy ) {
+               $policy = trim( $policy );
+               if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
+                       $this->mFollowPolicy = $policy;
+               }
+       }
+
        public function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
        public function setPageTitle( $name ) {
                global $action, $wgContLang;
@@ -879,7 +935,7 @@ class OutputPage {
                global $wgUser, $wgContLang, $wgTitle, $wgLang;
 
                $this->setPageTitle( wfMsg( 'blockedtitle' ) );
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
                $name = User::whoIs( $wgUser->blockedBy() );
@@ -945,7 +1001,7 @@ class OutputPage {
                }
                $this->setPageTitle( wfMsg( $title ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
                $this->enableClientCache( false );
                $this->mRedirect = '';
@@ -971,7 +1027,7 @@ class OutputPage {
                $wgTitle->getPrefixedText() . "\n";
                $this->setPageTitle( wfMsg( 'permissionserrors' ) );
                $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
                $this->enableClientCache( false );
                $this->mRedirect = '';
@@ -994,7 +1050,7 @@ class OutputPage {
        public function versionRequired( $version ) {
                $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
                $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
                $this->mBodytext = '';
 
@@ -1012,7 +1068,7 @@ class OutputPage {
 
                $this->setPageTitle( wfMsg( 'badaccess' ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
                $this->mBodytext = '';
 
@@ -1148,7 +1204,7 @@ class OutputPage {
                global $wgUser, $wgTitle;
                $skin = $wgUser->getSkin();
 
-               $this->setRobotpolicy( 'noindex,nofollow' );
+               $this->setRobotPolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
                // If no reason is given, just supply a default "I can't let you do
@@ -1238,7 +1294,7 @@ class OutputPage {
 
        public function showFatalError( $message ) {
                $this->setPageTitle( wfMsg( "internalerror" ) );
-               $this->setRobotpolicy( "noindex,nofollow" );
+               $this->setRobotPolicy( "noindex,nofollow" );
                $this->setArticleRelated( false );
                $this->enableClientCache( false );
                $this->mRedirect = '';
@@ -1386,8 +1442,8 @@ class OutputPage {
                global $wgVersion;
                $this->addMeta( "generator", "MediaWiki $wgVersion" );
                
-               $p = $this->mRobotpolicy;
-               if( $p !== '' && $p != 'index,follow' ) {
+               $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
+               if( $p !== 'index,follow' ) {
                        // http://www.robotstxt.org/wc/meta-user.html
                        // Only show if it's different from the default robots policy
                        $this->addMeta( 'robots', $p );
index 870b57b..9c210cf 100644 (file)
@@ -87,7 +87,7 @@ class PageHistory {
                $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
                $wgOut->setArticleFlag( false );
                $wgOut->setArticleRelated( true );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setSyndicated( true );
                $wgOut->setFeedAppendQuery( 'action=history' );
                $wgOut->addScriptFile( 'history.js' );
index e778782..aa682bf 100644 (file)
@@ -103,7 +103,7 @@ class ProtectionForm {
        function show( $err = null ) {
                global $wgOut, $wgUser;
 
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                if( is_null( $this->mTitle ) ||
                        $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
index d6ad6e6..c7b0308 100644 (file)
@@ -484,7 +484,7 @@ class SpecialPage
                if ( !$page ) {
                        if ( !$including ) {
                                $wgOut->setArticleRelated( false );
-                               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                                $wgOut->setStatusCode( 404 );
                                $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
                        }
index b3468a3..1195253 100644 (file)
@@ -522,7 +522,7 @@ class PreferencesForm {
 
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addScriptFile( 'prefs.js' );
 
                $wgOut->disallowUserJs();  # Prevent hijacked user scripts from sniffing passwords etc.
index 0a483af..f372320 100644 (file)
@@ -282,7 +282,7 @@ class SpecialSearch {
                $subtitlemsg = ( Title::newFromText( $term ) ? 'searchsubtitle' : 'searchsubtitleinvalid' );
                $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
                $wgOut->setArticleRelated( false );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
        }
 
        /**
index ca91ad5..560ba44 100644 (file)
@@ -12,7 +12,7 @@ function wfSpecialSpecialpages() {
 
        $wgMessageCache->loadAllMessages();
 
-       $wgOut->setRobotpolicy( 'noindex,nofollow' );  # Is this really needed?
+       $wgOut->setRobotPolicy( 'noindex,nofollow' );  # Is this really needed?
        $sk = $wgUser->getSkin();
 
        $pages = SpecialPage::getUsablePages();
index 8fe2f52..98ccdcb 100644 (file)
@@ -1699,7 +1699,7 @@ wgUploadAutoFill = {$autofill};
        function showError( $description ) {
                global $wgOut;
                $wgOut->setPageTitle( wfMsg( "internalerror" ) );
-               $wgOut->setRobotpolicy( "noindex,nofollow" );
+               $wgOut->setRobotPolicy( "noindex,nofollow" );
                $wgOut->setArticleRelated( false );
                $wgOut->enableClientCache( false );
                $wgOut->addWikiText( $description );
index 27009ee..20bd853 100644 (file)
@@ -130,7 +130,7 @@ class LoginForm {
                wfRunHooks( 'AddNewAccount', array( $u, true ) );
 
                $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
 
                if( WikiError::isError( $result ) ) {
@@ -655,7 +655,7 @@ class LoginForm {
                wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
 
                $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
                $wgOut->addWikiMsgArray( $msg, $params );
                $wgOut->addHtml( $injected_html );
@@ -671,7 +671,7 @@ class LoginForm {
                global $wgOut;
 
                $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
 
                $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
@@ -694,7 +694,7 @@ class LoginForm {
                # out.
 
                $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
 
                $ip = wfGetIP();
@@ -810,7 +810,7 @@ class LoginForm {
                }
 
                $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setArticleRelated( false );
                $wgOut->disallowUserJs();  // just in case...
                $wgOut->addTemplate( $template );
index 137eadb..3d497bd 100644 (file)
@@ -12,7 +12,7 @@ function wfSpecialUserlogout() {
 
        $oldName = $wgUser->getName();
        $wgUser->logout();
-       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
        // Hook.
        $injected_html = '';