Page MenuHomePhabricator

Enable SpecialPage::setHeaders() to set a different robot policy besides "noindex,nofollow"
Closed, ResolvedPublic

Description

Sometimes it's desired that a special page be indexed or followed. E.g. some special pages have not just page metadata but actual content, such as a dictionary (e.g. http://childwiki.net/wiki/Special:Dictionary ), that does not exist in that particular format elsewhere on the wiki, and that the wiki owner might wish to have show up in search results.

Therefore, I propose to enable SpecialPage::setHeaders() to set a different robot policy besides "noindex,nofollow". I guess the best way to do this would be to add a $policy argument:

function setHeaders( $policy = "noindex,nofollow" ) {

...
$out->setRobotPolicy( $policy );
...

}


Version: 1.23.0
Severity: enhancement

Details

Reference
bz57764

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:31 AM
bzimport set Reference to bz57764.
bzimport added a subscriber: Unknown Object (MLST).

Another option, of course, would be for the function to override setHeaders(), but that involves more code duplication.

Change 98255 had a related patch set uploaded by Parent5446:
Add $robotPolicy parameter to SpecialPage::setHeaders()

https://gerrit.wikimedia.org/r/98255

Change 98255 merged by jenkins-bot:
Add $robotPolicy parameter to SpecialPage::setHeaders()

https://gerrit.wikimedia.org/r/98255

(In reply to comment #3)

Change 98255 merged by jenkins-bot:
Add $robotPolicy parameter to SpecialPage::setHeaders()

https://gerrit.wikimedia.org/r/98255

Was reverted, caused php warnings. See bug 57883

Question: is there some reason you can't just call $this->getOutput()->setRobotPolicy( $robotPolicy ) after calling $this->setHeaders(), as Brian Wolff mentioned?

If not, this might be a WONTFIX...

(In reply to comment #5)

Question: is there some reason you can't just call
$this->getOutput()->setRobotPolicy( $robotPolicy ) after calling
$this->setHeaders(), as Brian Wolff mentioned?

If not, this might be a WONTFIX...

Alternative fix for this would be to create a new method of SpecialPage, call it getRobotPolicy(), that returns the robot setting, which is called in the default implementation of setHeaders().

That would probably be a cleaner solution anyways than the previous fix.

(In reply to comment #6)

(In reply to comment #5)

Question: is there some reason you can't just call
$this->getOutput()->setRobotPolicy( $robotPolicy ) after calling
$this->setHeaders(), as Brian Wolff mentioned?

If not, this might be a WONTFIX...

Alternative fix for this would be to create a new method of SpecialPage, call
it getRobotPolicy(), that returns the robot setting, which is called in the
default implementation of setHeaders().

That would probably be a cleaner solution anyways than the previous fix.

Comments 5 and 6 both present workable solutions. I take it the latter has an advantage over the former?

So, I guess there should be also created an OutputPage::getIndexPolicy(), OutputPage::getFollowPolicy(), and an OutputPage::getRobotPolicy() that returns an array of the index and follow policies. SpecialPage::setRobotPolicy() then would look like:

public function getRobotPolicy() {

return $this->getOutput()->getRobotPolicy();

}

I was more thinking that SpecialPage::setHeaders() becomes:

function setHeaders() {
        $out = $this->getOutput();
        $out->setArticleRelated( false );
        $out->setRobotPolicy( $this->getRobotPolicy() );
        $out->setPageTitle( $this->getDescription() );
}

and then a new method of SpecialPage

function getRobotPolicy() {
       return "noindex,nofollow";
}

and if people wanted to change what getRobotPolicy was, they would override in a subclass.

Change 117832 had a related patch set uploaded by Siebrand:
Add getRobotPolicy()

https://gerrit.wikimedia.org/r/117832

(In reply to Bawolff (Brian Wolff) from comment #8)

function getRobotPolicy() {

Brian, is there a reason getRobotPolicy() should be public? Addshore says it should be protected. Thanks.

Change 117832 merged by jenkins-bot:
Add getRobotPolicy()

https://gerrit.wikimedia.org/r/117832