Refactor a bit preparatory to fixing bug 8068: rewrite the robot policy stuff in OutputPage to allow index and follow policy to be set separately. Also now validates input to setRobotPolicy(). And renamed setRobotpolicy to setRobotPolicy, too. If anyone was accessing $mRobotpolicy directly they're out of luck, though.

This commit is contained in:
Aryeh Gregor 2008-07-23 19:05:43 +00:00
parent 3a711565e4
commit 650be91fb8
16 changed files with 97 additions and 41 deletions

View 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' ) . ']]';

View 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' );

View 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__ );
}

View 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 );

View 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( '' );

View 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 );

View 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 );

View 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' );

View 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 ) {

View 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' );
}

View 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.

View 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' );
}
/**

View 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();

View 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 );

View 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 );

View file

@ -12,7 +12,7 @@ function wfSpecialUserlogout() {
$oldName = $wgUser->getName();
$wgUser->logout();
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
// Hook.
$injected_html = '';