r37968 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37967‎ | r37968 | r37969 >
Date:19:05, 23 July 2008
Author:simetrical
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Credits.php (modified) (history)
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialSpecialpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogout.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -103,7 +103,7 @@
104104 function show( $err = null ) {
105105 global $wgOut, $wgUser;
106106
107 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 107+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
108108
109109 if( is_null( $this->mTitle ) ||
110110 $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
Index: trunk/phase3/includes/Article.php
@@ -204,7 +204,7 @@
205205
206206 if ( 0 == $this->getID() ) {
207207 wfProfileOut( __METHOD__ );
208 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 208+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
209209
210210 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
211211 $wgMessageCache->loadAllMessages();
@@ -822,7 +822,7 @@
823823
824824 # We're looking at an old revision
825825 if ( !empty( $oldid ) ) {
826 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 826+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
827827 if( is_null( $this->mRevision ) ) {
828828 // FIXME: This would be a nice place to load the 'no such page' text.
829829 } else {
@@ -1034,7 +1034,7 @@
10351035 "</form>\n", $msg );
10361036
10371037 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
1038 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 1038+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
10391039 $wgOut->addHTML( $msg );
10401040 }
10411041 }
@@ -1696,7 +1696,7 @@
16971697
16981698 if( $this->doWatch() ) {
16991699 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1700 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 1700+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
17011701
17021702 $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
17031703 }
@@ -1741,7 +1741,7 @@
17421742
17431743 if( $this->doUnwatch() ) {
17441744 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1745 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 1745+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
17461746
17471747 $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
17481748 }
@@ -2177,7 +2177,7 @@
21782178 wfDebug( "Article::confirmDelete\n" );
21792179
21802180 $wgOut->setSubtitle( wfMsg( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
2181 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 2181+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
21822182 $wgOut->addWikiMsg( 'confirmdeletetext' );
21832183
21842184 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
@@ -2264,7 +2264,7 @@
22652265 $deleted = $this->mTitle->getPrefixedText();
22662266
22672267 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2268 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 2268+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
22692269
22702270 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
22712271
Index: trunk/phase3/includes/ImagePage.php
@@ -98,7 +98,7 @@
9999 } else {
100100 # Just need to set the right headers
101101 $wgOut->setArticleFlag( true );
102 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 102+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
103103 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
104104 $this->viewUpdates();
105105 }
@@ -762,7 +762,7 @@
763763 function showError( $description ) {
764764 global $wgOut;
765765 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
766 - $wgOut->setRobotpolicy( "noindex,nofollow" );
 766+ $wgOut->setRobotPolicy( "noindex,nofollow" );
767767 $wgOut->setArticleRelated( false );
768768 $wgOut->enableClientCache( false );
769769 $wgOut->addWikiText( $description );
Index: trunk/phase3/includes/EditPage.php
@@ -1042,7 +1042,7 @@
10431043
10441044 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
10451045
1046 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 1046+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
10471047
10481048 # Enabled article-related sidebar, toplinks, etc.
10491049 $wgOut->setArticleRelated( true );
Index: trunk/phase3/includes/OutputPage.php
@@ -8,7 +8,7 @@
99 class OutputPage {
1010 var $mMetatags, $mKeywords;
1111 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
12 - var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
 12+ var $mHTMLtitle, $mIsarticle, $mPrintable;
1313 var $mSubtitle, $mRedirect, $mStatusCode;
1414 var $mLastModified, $mETag, $mCategoryLinks;
1515 var $mScripts, $mLinkColours, $mPageLinkTitle;
@@ -30,6 +30,9 @@
3131 var $mPageTitleActionText = '';
3232 var $mParseWarnings = array();
3333
 34+ private $mIndexPolicy = 'index';
 35+ private $mFollowPolicy = 'follow';
 36+
3437 /**
3538 * Constructor
3639 * Initialise private variables
@@ -39,9 +42,8 @@
4043 $this->mAllowUserJs = $wgAllowUserJs;
4144 $this->mMetatags = $this->mKeywords = $this->mLinktags = array();
4245 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
43 - $this->mRedirect = $this->mLastModified =
44 - $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
45 - $this->mOnloadHandler = $this->mPageLinkTitle = '';
 46+ $this->mRedirect = $this->mLastModified = $this->mSubtitle =
 47+ $this->mDebugtext = $this->mOnloadHandler = $this->mPageLinkTitle = '';
4648 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
4749 $this->mSuppressQuickbar = $this->mPrintable = false;
4850 $this->mLanguageLinks = array();
@@ -223,7 +225,61 @@
224226 }
225227 }
226228
227 - public function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
 229+ /**
 230+ * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
 231+ *
 232+ * @param $policy string The literal string to output as the contents of
 233+ * the meta tag. Will be parsed according to the spec and output in
 234+ * standardized form.
 235+ * @return null
 236+ */
 237+ public function setRobotPolicy( $policy ) {
 238+ $policy = explode( ',', $policy );
 239+ $policy = array_map( 'trim', $policy );
 240+
 241+ # The default policy is follow, so if nothing is said explicitly, we
 242+ # do that.
 243+ if( in_array( 'nofollow', $policy ) ) {
 244+ $this->mFollowPolicy = 'nofollow';
 245+ } else {
 246+ $this->mFollowPolicy = 'follow';
 247+ }
 248+
 249+ if( in_array( 'noindex', $policy ) ) {
 250+ $this->mIndexPolicy = 'noindex';
 251+ } else {
 252+ $this->mIndexPolicy = 'index';
 253+ }
 254+ }
 255+
 256+ /**
 257+ * Set the index policy for the page, but leave the follow policy un-
 258+ * touched.
 259+ *
 260+ * @param $policy string Either 'index' or 'noindex'.
 261+ * @return null
 262+ */
 263+ public function setIndexPolicy( $policy ) {
 264+ $policy = trim( $policy );
 265+ if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
 266+ $this->mIndexPolicy = $policy;
 267+ }
 268+ }
 269+
 270+ /**
 271+ * Set the follow policy for the page, but leave the index policy un-
 272+ * touched.
 273+ *
 274+ * @param $policy string Either 'follow' or 'nofollow'.
 275+ * @return null
 276+ */
 277+ public function setFollowPolicy( $policy ) {
 278+ $policy = trim( $policy );
 279+ if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
 280+ $this->mFollowPolicy = $policy;
 281+ }
 282+ }
 283+
228284 public function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
229285 public function setPageTitle( $name ) {
230286 global $action, $wgContLang;
@@ -879,7 +935,7 @@
880936 global $wgUser, $wgContLang, $wgTitle, $wgLang;
881937
882938 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
883 - $this->setRobotpolicy( 'noindex,nofollow' );
 939+ $this->setRobotPolicy( 'noindex,nofollow' );
884940 $this->setArticleRelated( false );
885941
886942 $name = User::whoIs( $wgUser->blockedBy() );
@@ -945,7 +1001,7 @@
9461002 }
9471003 $this->setPageTitle( wfMsg( $title ) );
9481004 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
949 - $this->setRobotpolicy( 'noindex,nofollow' );
 1005+ $this->setRobotPolicy( 'noindex,nofollow' );
9501006 $this->setArticleRelated( false );
9511007 $this->enableClientCache( false );
9521008 $this->mRedirect = '';
@@ -971,7 +1027,7 @@
9721028 $wgTitle->getPrefixedText() . "\n";
9731029 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
9741030 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
975 - $this->setRobotpolicy( 'noindex,nofollow' );
 1031+ $this->setRobotPolicy( 'noindex,nofollow' );
9761032 $this->setArticleRelated( false );
9771033 $this->enableClientCache( false );
9781034 $this->mRedirect = '';
@@ -994,7 +1050,7 @@
9951051 public function versionRequired( $version ) {
9961052 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
9971053 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
998 - $this->setRobotpolicy( 'noindex,nofollow' );
 1054+ $this->setRobotPolicy( 'noindex,nofollow' );
9991055 $this->setArticleRelated( false );
10001056 $this->mBodytext = '';
10011057
@@ -1012,7 +1068,7 @@
10131069
10141070 $this->setPageTitle( wfMsg( 'badaccess' ) );
10151071 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1016 - $this->setRobotpolicy( 'noindex,nofollow' );
 1072+ $this->setRobotPolicy( 'noindex,nofollow' );
10171073 $this->setArticleRelated( false );
10181074 $this->mBodytext = '';
10191075
@@ -1148,7 +1204,7 @@
11491205 global $wgUser, $wgTitle;
11501206 $skin = $wgUser->getSkin();
11511207
1152 - $this->setRobotpolicy( 'noindex,nofollow' );
 1208+ $this->setRobotPolicy( 'noindex,nofollow' );
11531209 $this->setArticleRelated( false );
11541210
11551211 // If no reason is given, just supply a default "I can't let you do
@@ -1238,7 +1294,7 @@
12391295
12401296 public function showFatalError( $message ) {
12411297 $this->setPageTitle( wfMsg( "internalerror" ) );
1242 - $this->setRobotpolicy( "noindex,nofollow" );
 1298+ $this->setRobotPolicy( "noindex,nofollow" );
12431299 $this->setArticleRelated( false );
12441300 $this->enableClientCache( false );
12451301 $this->mRedirect = '';
@@ -1386,8 +1442,8 @@
13871443 global $wgVersion;
13881444 $this->addMeta( "generator", "MediaWiki $wgVersion" );
13891445
1390 - $p = $this->mRobotpolicy;
1391 - if( $p !== '' && $p != 'index,follow' ) {
 1446+ $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
 1447+ if( $p !== 'index,follow' ) {
13921448 // http://www.robotstxt.org/wc/meta-user.html
13931449 // Only show if it's different from the default robots policy
13941450 $this->addMeta( 'robots', $p );
Index: trunk/phase3/includes/DifferenceEngine.php
@@ -142,7 +142,7 @@
143143 $wgOut->setPageTitle( $oldTitle . ', ' . $newTitle );
144144 }
145145 $wgOut->setSubtitle( wfMsg( 'difference' ) );
146 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 146+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
147147
148148 if ( !( $this->mOldPage->userCanRead() && $this->mNewPage->userCanRead() ) ) {
149149 $wgOut->loginToUse();
@@ -363,7 +363,7 @@
364364 $wgOut->addHTML( $header );
365365
366366 $wgOut->setSubtitle( wfMsg( 'difference' ) );
367 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 367+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
368368
369369 wfProfileOut( __METHOD__ );
370370 }
Index: trunk/phase3/includes/specials/SpecialSpecialpages.php
@@ -12,7 +12,7 @@
1313
1414 $wgMessageCache->loadAllMessages();
1515
16 - $wgOut->setRobotpolicy( 'noindex,nofollow' ); # Is this really needed?
 16+ $wgOut->setRobotPolicy( 'noindex,nofollow' ); # Is this really needed?
1717 $sk = $wgUser->getSkin();
1818
1919 $pages = SpecialPage::getUsablePages();
Index: trunk/phase3/includes/specials/SpecialPreferences.php
@@ -522,7 +522,7 @@
523523
524524 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
525525 $wgOut->setArticleRelated( false );
526 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 526+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
527527 $wgOut->addScriptFile( 'prefs.js' );
528528
529529 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -130,7 +130,7 @@
131131 wfRunHooks( 'AddNewAccount', array( $u, true ) );
132132
133133 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
134 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 134+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
135135 $wgOut->setArticleRelated( false );
136136
137137 if( WikiError::isError( $result ) ) {
@@ -655,7 +655,7 @@
656656 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
657657
658658 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
659 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 659+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
660660 $wgOut->setArticleRelated( false );
661661 $wgOut->addWikiMsgArray( $msg, $params );
662662 $wgOut->addHtml( $injected_html );
@@ -671,7 +671,7 @@
672672 global $wgOut;
673673
674674 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
675 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 675+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
676676 $wgOut->setArticleRelated( false );
677677
678678 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
@@ -694,7 +694,7 @@
695695 # out.
696696
697697 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
698 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 698+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
699699 $wgOut->setArticleRelated( false );
700700
701701 $ip = wfGetIP();
@@ -810,7 +810,7 @@
811811 }
812812
813813 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
814 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 814+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
815815 $wgOut->setArticleRelated( false );
816816 $wgOut->disallowUserJs(); // just in case...
817817 $wgOut->addTemplate( $template );
Index: trunk/phase3/includes/specials/SpecialUserlogout.php
@@ -12,7 +12,7 @@
1313
1414 $oldName = $wgUser->getName();
1515 $wgUser->logout();
16 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 16+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
1717
1818 // Hook.
1919 $injected_html = '';
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -1699,7 +1699,7 @@
17001700 function showError( $description ) {
17011701 global $wgOut;
17021702 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
1703 - $wgOut->setRobotpolicy( "noindex,nofollow" );
 1703+ $wgOut->setRobotPolicy( "noindex,nofollow" );
17041704 $wgOut->setArticleRelated( false );
17051705 $wgOut->enableClientCache( false );
17061706 $wgOut->addWikiText( $description );
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -282,7 +282,7 @@
283283 $subtitlemsg = ( Title::newFromText( $term ) ? 'searchsubtitle' : 'searchsubtitleinvalid' );
284284 $wgOut->setSubtitle( $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ) );
285285 $wgOut->setArticleRelated( false );
286 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 286+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
287287 }
288288
289289 /**
Index: trunk/phase3/includes/Credits.php
@@ -34,7 +34,7 @@
3535 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
3636 $wgOut->setArticleFlag( false );
3737 $wgOut->setArticleRelated( true );
38 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 38+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
3939
4040 if( $article->mTitle->getArticleID() == 0 ) {
4141 $s = wfMsg( 'nocredits' );
Index: trunk/phase3/includes/PageHistory.php
@@ -87,7 +87,7 @@
8888 $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) );
8989 $wgOut->setArticleFlag( false );
9090 $wgOut->setArticleRelated( true );
91 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 91+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
9292 $wgOut->setSyndicated( true );
9393 $wgOut->setFeedAppendQuery( 'action=history' );
9494 $wgOut->addScriptFile( 'history.js' );
Index: trunk/phase3/includes/SpecialPage.php
@@ -484,7 +484,7 @@
485485 if ( !$page ) {
486486 if ( !$including ) {
487487 $wgOut->setArticleRelated( false );
488 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
 488+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
489489 $wgOut->setStatusCode( 404 );
490490 $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
491491 }
Index: trunk/phase3/includes/Exception.php
@@ -137,7 +137,7 @@
138138 global $wgOut;
139139 if ( $this->useOutputPage() ) {
140140 $wgOut->setPageTitle( $this->getPageTitle() );
141 - $wgOut->setRobotpolicy( "noindex,nofollow" );
 141+ $wgOut->setRobotPolicy( "noindex,nofollow" );
142142 $wgOut->setArticleRelated( false );
143143 $wgOut->enableClientCache( false );
144144 $wgOut->redirect( '' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r37969Follow-up to r37968: forgot to commit the change setRobotpolicy -> setRobotPo...simetrical19:25, 23 July 2008
r37971Follow-up to r37968: forgot to commit the change setRobotpolicy -> setRobotPo...simetrical19:33, 23 July 2008
r37973(bug 8068) New __INDEX__ and __NOINDEX__ magic words allow control of search ...simetrical19:49, 23 July 2008
r40356Temporarily reverted SpecialUpload.php to r37968, before Bryan's changes, pen...tstarling03:19, 3 September 2008

Status & tagging log