Add Special:Diff as an internally-linkable redirect to diff pages
authorJérémie Roquet <jroquet@arkanosis.net>
Sun, 12 May 2013 22:10:47 +0000 (00:10 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 25 Jan 2014 20:41:08 +0000 (21:41 +0100)
This is similar to Special:PermanentLink added in r79036 and has been
asked for several times in different places, including:
- on the English Wikipedia (oldid=539308532)
- on mediawiki.org (lqt_oldid=31691)
- on the French Wikipedia (oldid=93029892)
- on the English Wikipedia again (oldid=588408888)

A notable use-case is linking to diffs in the edit summaries, where
external links are not yet allowed (bug 14892).

All of the following are valid usages:
- [[Special:Diff/12345]] (diff of a revision with the previous one)
- [[Special:Diff/12345/prev]] (diff of a revision with the previous one as well)
- [[Special:Diff/12345/next]] (diff of a revision with the next one)
- [[Special:Diff/12345/cur]] (diff of a revision with the latest one of that page)
- [[Special:Diff/12345/98765]] (diff between arbitrary two revisions)

Co-authored-by: Jérémie Roquet <jroquet@arkanosis.net>
Co-authored-by: Bartosz Dziewoński <matma.rex@gmail.com>
Change-Id: I77fdaf8e04375caa1d67ca4a3ec3bd93920c3309

RELEASE-NOTES-1.23
includes/AutoLoader.php
includes/specialpage/SpecialPageFactory.php
includes/specials/SpecialDiff.php [new file with mode: 0644]
languages/messages/MessagesEn.php

index b80a9a9..7aecdb9 100644 (file)
@@ -75,6 +75,9 @@ production.
 * WikitextContent will now render redirects with the expected "redirect"
   header, rather than as an ordered list. Code calling Article::viewRedirect
   can probably be changed to no longer special-case redirects.
+* [[Special:Diff]] was added, allowing users to create internal links to
+  revision comparison pages using syntax such as [[Special:Diff/12345]],
+  [[Special:Diff/12345/prev]] or [[Special:Diff/12345/98765]].
 
 === Bug fixes in 1.23 ===
 * (bug 41759) The "updated since last visit" markers (on history pages, recent
index 91fa55f..192d071 100644 (file)
@@ -965,6 +965,7 @@ $wgAutoloadLocalClasses = array(
        'SpecialChangePassword' => 'includes/specials/SpecialChangePassword.php',
        'SpecialComparePages' => 'includes/specials/SpecialComparePages.php',
        'SpecialContributions' => 'includes/specials/SpecialContributions.php',
+       'SpecialDiff' => 'includes/specials/SpecialDiff.php',
        'SpecialEditWatchlist' => 'includes/specials/SpecialEditWatchlist.php',
        'SpecialEmailUser' => 'includes/specials/SpecialEmailuser.php',
        'SpecialExpandTemplates' => 'includes/specials/SpecialExpandTemplates.php',
index dcf5f67..792d0a6 100644 (file)
@@ -154,6 +154,7 @@ class SpecialPageFactory {
 
                // Unlisted / redirects
                'Blankpage'                 => 'SpecialBlankpage',
+               'Diff'                      => 'SpecialDiff',
                'Emailuser'                 => 'SpecialEmailUser',
                'Movepage'                  => 'MovePageForm',
                'Mycontributions'           => 'SpecialMycontributions',
diff --git a/includes/specials/SpecialDiff.php b/includes/specials/SpecialDiff.php
new file mode 100644 (file)
index 0000000..bc0d7e3
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Redirect from Special:Diff/### to index.php?diff=### and
+ * from Special:Diff/###/### to index.php?oldid=###&diff=###.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
+
+/**
+ * Redirect from Special:Diff/### to index.php?diff=### and
+ * from Special:Diff/###/### to index.php?oldid=###&diff=###.
+ *
+ * All of the following are valid usages:
+ * - [[Special:Diff/12345]] (diff of a revision with the previous one)
+ * - [[Special:Diff/12345/prev]] (diff of a revision with the previous one as well)
+ * - [[Special:Diff/12345/next]] (diff of a revision with the next one)
+ * - [[Special:Diff/12345/cur]] (diff of a revision with the latest one of that page)
+ * - [[Special:Diff/12345/98765]] (diff between arbitrary two revisions)
+ *
+ * @ingroup SpecialPage
+ * @since 1.23
+ */
+class SpecialDiff extends RedirectSpecialPage {
+       function __construct() {
+               parent::__construct( 'Diff' );
+               $this->mAllowedRedirectParams = array();
+       }
+
+       function getRedirect( $subpage ) {
+               $parts = explode( '/', $subpage );
+
+               // Try to parse the values given, generating somewhat pretty URLs if possible
+               if ( count( $parts ) === 1 ) {
+                       $this->mAddedRedirectParams['diff'] = $parts[0];
+               } elseif ( count( $parts ) === 2 ) {
+                       $this->mAddedRedirectParams['oldid'] = $parts[0];
+                       $this->mAddedRedirectParams['diff'] = $parts[1];
+               } else {
+                       // Wrong number of parameters, bail out
+                       throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
+               }
+
+               return true;
+       }
+}
index a3ff563..89b0fdc 100644 (file)
@@ -404,6 +404,7 @@ $specialPageAliases = array(
        'CreateAccount'             => array( 'CreateAccount' ),
        'Deadendpages'              => array( 'DeadendPages' ),
        'DeletedContributions'      => array( 'DeletedContributions' ),
+       'Diff'                      => array( 'Diff' ),
        'DoubleRedirects'           => array( 'DoubleRedirects' ),
        'EditWatchlist'             => array( 'EditWatchlist' ),
        'Emailuser'                 => array( 'EmailUser' ),