r56730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56729‎ | r56730 | r56731 >
Date:19:21, 21 September 2009
Author:churchofemacs
Status:reverted (Comments)
Tags:
Comment:
New configuration variable $wgShowPageOnRedlink that can be set to show the page instead of an edit interface when visiting a red link. The value can be specified for specific usergroups and namespaces.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -418,12 +418,12 @@
419419 }
420420 }
421421 }
422 -
423 - // If they used redlink=1 and the page exists, redirect to the main article
424 - if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
425 - $wgOut->redirect( $this->mTitle->getFullURL() );
426 - }
427422
 423+ # Evaluate if the edit interface should be shown or
 424+ # if the page should be shown, in case redlink=true
 425+ if ( $wgRequest->getBool( 'redlink' ) )
 426+ $this->showPageOnRedlink();
 427+
428428 wfProfileIn( __METHOD__."-business-end" );
429429
430430 $this->isConflict = false;
@@ -487,7 +487,45 @@
488488 wfProfileOut( __METHOD__."-business-end" );
489489 wfProfileOut( __METHOD__ );
490490 }
491 -
 491+
 492+ /*
 493+ * Evaluate if the edit interface should be shown or the page, in case redlink=true.
 494+ * If the page exists, it is always shown. If it doesn't, it depends on the settings
 495+ * of $wgShowPageOnRedlink (see DefaultSettings for documentation).
 496+ */
 497+ protected function showPageOnRedlink() {
 498+ global $wgShowPageOnRedlink, $wgUser, $wgRequest, $wgOut;
 499+ $redirectToPage = false;
 500+ # If the page exists (it has been created after the link has been emerged),
 501+ # redirect to the page instead of editing the current page
 502+ if ( $this->mTitle->exists() )
 503+ $wgOut->redirect( $this->mTitle->getFullURL() );
 504+ # Check site configuration ($wgShowPageOnRedlink)
 505+ if ( is_array( $wgShowPageOnRedlink ) ) {
 506+ $ns = $this->mTitle->getNamespace();
 507+ $groups = $wgUser->getEffectiveGroups();
 508+ # Gets overwritten if user is member of a group that has been specified:
 509+ $redirectToPage = true;
 510+ foreach ( $groups as $i => $group ) {
 511+ # Test if there is a rule for a specific usergroup and a specific namespace
 512+ if ( isset( $wgShowPageOnRedlink[$group][$ns] ) && $wgShowPageOnRedlink[$group][$ns] == false ) {
 513+ $redirectToPage = false;
 514+ }
 515+ # Test if there is a rule for a specific usergroup in all namespaces
 516+ elseif ( isset( $wgShowPageOnRedlink[$group] ) && !is_array( $wgShowPageOnRedlink[$group] )
 517+ && $wgShowPageOnRedlink[$group] == false ) {
 518+ $redirectToPage = false;
 519+ }
 520+ }
 521+ }
 522+ else {
 523+ $redirectToPage = $wgShowPageOnRedlink;
 524+ }
 525+ if ( $redirectToPage ) {
 526+ $wgOut->redirect( $this->mTitle->getFullURL() );
 527+ }
 528+ }
 529+
492530 protected function getEditPermissionErrors() {
493531 global $wgUser;
494532 $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4269,3 +4269,16 @@
42704270 * Use old names for change_tags indices.
42714271 */
42724272 $wgOldChangeTagsIndex = false;
 4273+
 4274+/**
 4275+ * View page instead of edit interface when visiting a red link
 4276+ * There are three ways to define this variable:
 4277+ * 1. Set $wgShowPageOnRedlink to true (false is default)
 4278+ * 2. Set $wgShowPageOnRedlink['usergroup'] to false. If a user is member of at least one usergroup for which the variable
 4279+ * has been set to false, the edit interface will be shown. Otherwise the page is shown.
 4280+ * 3. Set $wgShowPageOnRedlink['usergroup'][NS_XY] to false. Same as 2., but you can specify the namespace. The namespace
 4281+ * is a numerical value (namespace index), you can use constants such as NS_MAIN or NS_USER_TALK.
 4282+ * If you use an array (2. or 3.), the default will be true (for 1. it's false). In 2. and 3. there is no way to overwrite
 4283+ * a value 'false' once it has already been set (this is due to the undefined order of usergroups).
 4284+ */
 4285+$wgShowPageOnRedlink = false;
Index: trunk/phase3/RELEASE-NOTES
@@ -239,6 +239,9 @@
240240 the root permission effectively grants all other permissions on a wiki. Useful
241241 for debugging and administration.
242242 * (bug 16979) Tracking categories for __INDEX__ and __NOINDEX__
 243+* New configuration variable $wgShowPageOnRedlink that can be set to show the page
 244+ instead of an edit interface when visiting a red link. The value can be specified
 245+ for specific usergroups and namespaces.
243246
244247 === Bug fixes in 1.16 ===
245248

Follow-up revisions

RevisionCommit summaryAuthorDate
r57139Pull back r56730 for now: "New configuration variable $wgShowPageOnRedlink th...brion19:12, 30 September 2009

Comments

#Comment by Nikerabbit (talk | contribs)   07:47, 22 September 2009

What's the use case? Could this be made with a hook and an extension instead?

#Comment by Church of emacs (talk | contribs)   10:30, 22 September 2009

Of course this could be made with an extension, but for such a small piece of code, it doesn't seem worth the effort of creating an extension and request activation for each and every wiki where you want to use this feature.

Concerning the use case: I think this could be enabled on big wikis, such as Wikipedia. A large number of articles are created each day, because readers click on red links and then they see the edit box, enter anything and save the page. Normally, if you want to edit, you have to explicitly click the edit button. With red links, normal readers become vandals by accident. They just click a link to read content, and suddenly they are editing a page. They enter anything in the box (like "hello, I was looking for XY") and save the page, not realizing that they are vandalizing. Currently, creating new articles is disallowed for anonymous users on English Wikipedia. One use case would be reallowing IPs to create articles, but enabling the redirect to page for red links. That way, an anonymous user has to explicitly click "Start this page" (it doesn't hurt the usability much, it's just one additional click). Specifically I'm thinking about enabling it for anonymous users in the main namespace on German Wikipedia, where we allow anonymous users to create articles, and where we have large amounts of vandal article-creations by accident. The problem I faced was, that in order to start a RfC on enabling a software feature, the software feature has to exist. So I decided to first include the code and then start a RfC. But I'm almost certain that there will be a consensus to enable this feature on dewiki.

#Comment by Brion VIBBER (talk | contribs)   23:31, 29 September 2009

This config var is pretty inconsistent and confusing. I'd probably recommend replacing the whole thing with a single permission key, and if someone has a need for some bizarre group/namespace combinations they can write an extension to take care of it.

#Comment by Brion VIBBER (talk | contribs)   19:13, 30 September 2009

I've reverted for now in r57139. Tie together with the createpage right maybe?

#Comment by Church of emacs (talk | contribs)   19:52, 30 September 2009

I'm not really sure if using permissions is such a good idea. Although it'd be easy to implement, this is about how the software behaves in certain situations, not what rights groups have. (Beside that, my approach is already implemented, so "using permissions it's easier to implement" is not a good argument). I'm not quite sure what you mean with the inconsistency of the variable, but using permissions to modify the user interface seems inconsistent with normal use cases of permissions. If you think the namespace selection is not needed, I can remove it. IMHO these are the options:

  1. Use permissions (keep group selectivity, ditch namespace selectivity)
  2. Ditch namespace selecitvity, keep $wgShowPageOnRedlink as a variable
  3. Put everything into an extension (Question: could this extension be enabled on WMF wikis if a community wants it?)
  4. Ditch selectivity and pick sane defaults without asking the community :-) (e.g. show page for anonymous users, show edit interface for logged-in users)

About createpage: IIRC, users who are not allowed to create pages, are already shown the normal page instead of the edit interface. So using createpage right wouldn't change anything.

Status & tagging log