r68289 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68288‎ | r68289 | r68290 >
Date:21:17, 19 June 2010
Author:hartman
Status:resolved (Comments)
Tags:
Comment:
(bug 23621) New Special:ComparePages to compare (diff) two articles.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialComparePages.php (added) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesQqq.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -3207,6 +3207,15 @@
32083208 'ajax-error-dismiss',
32093209 'ajax-remove-category-error',
32103210 ),
 3211+ 'comparepages' => array(
 3212+ 'comparepages'.
 3213+ 'compare-selector',
 3214+ 'compare-page1',
 3215+ 'compare-page2',
 3216+ 'compare-rev1',
 3217+ 'compare-rev2',
 3218+ 'compare-submit',
 3219+ ),
32113220 );
32123221
32133222 /** Comments for each block */
@@ -3417,4 +3426,5 @@
34183427 'db-error-messages' => 'Database error messages',
34193428 'html-forms' => 'HTML forms',
34203429 'ajax-category' => 'Add categories per AJAX',
 3430+ 'comparepages' => 'Special:ComparePages',
34213431 );
Index: trunk/phase3/includes/AutoLoader.php
@@ -577,6 +577,7 @@
578578 'SpecialAllpages' => 'includes/specials/SpecialAllpages.php',
579579 'SpecialBlankpage' => 'includes/specials/SpecialBlankpage.php',
580580 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php',
 581+ 'SpecialComparePages' => 'includes/specials/SpecialComparePages.php',
581582 'SpecialExport' => 'includes/specials/SpecialExport.php',
582583 'SpecialImport' => 'includes/specials/SpecialImport.php',
583584 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4635,6 +4635,7 @@
46364636 'Search' => 'redirects',
46374637 'LinkSearch' => 'redirects',
46384638
 4639+ 'ComparePages' => 'pagetools',
46394640 'Movepage' => 'pagetools',
46404641 'MergeHistory' => 'pagetools',
46414642 'Revisiondelete' => 'pagetools',
Index: trunk/phase3/includes/specials/SpecialComparePages.php
@@ -0,0 +1,150 @@
 2+<?php
 3+
 4+/**
 5+ * implements Special:ComparePages
 6+ * @ingroup SpecialPage
 7+ */
 8+class SpecialComparePages extends SpecialPage {
 9+
 10+ // Stored objects
 11+ protected $opts, $skin;
 12+
 13+ // Some internal settings
 14+ protected $showNavigation = false;
 15+
 16+ public function __construct() {
 17+ parent::__construct( 'ComparePages' );
 18+ $this->includable( false );
 19+ }
 20+
 21+ protected function setup( $par ) {
 22+ global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
 23+
 24+ // Options
 25+ $opts = new FormOptions();
 26+ $this->opts = $opts; // bind
 27+ $opts->add( 'page1', '' );
 28+ $opts->add( 'page2', '' );
 29+ $opts->add( 'rev1', '' );
 30+ $opts->add( 'rev2', '' );
 31+ $opts->add( 'action', '' );
 32+ $opts->add( 'diffonly', '' );
 33+
 34+ // Set values
 35+ $opts->fetchValuesFromRequest( $wgRequest );
 36+
 37+ $title1 = Title::newFromText( $opts->getValue( 'page1' ) );
 38+ $title2 = Title::newFromText( $opts->getValue( 'page2' ) );
 39+
 40+ if( $title1 && $title1->exists() && $opts->getValue( 'rev1' ) == '' ) {
 41+ $pda = new Article( $title1 );
 42+ $pdi = $pda->getID();
 43+ $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
 44+ $opts->setValue('rev1', $pdLastRevision->getId() );
 45+ } elseif ( $opts->getValue( 'rev1' ) != '' ) {
 46+ $pdrev = Revision::newFromId( $opts->getValue( 'rev1' ) );
 47+ if( $pdrev ) $opts->setValue( 'page1', $pdrev->getTitle()->getPrefixedDBkey() );
 48+ }
 49+ if( $title2 && $title2->exists() && $opts->getValue( 'rev2' ) == '' ) {
 50+ $pda = new Article( $title2 );
 51+ $pdi = $pda->getID();
 52+ $pdLastRevision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $pdi );
 53+ $opts->setValue('rev2', $pdLastRevision->getId() );
 54+ } elseif ( $opts->getValue( 'rev2' ) != '' ) {
 55+ $pdrev = Revision::newFromId( $opts->getValue( 'rev2' ) );
 56+ if( $pdrev ) $opts->setValue( 'page2', $pdrev->getTitle()->getPrefixedDBkey() );
 57+ }
 58+
 59+ // Store some objects
 60+ $this->skin = $wgUser->getSkin();
 61+ }
 62+
 63+ /**
 64+ * Show a form for filtering namespace and username
 65+ *
 66+ * @param $par String
 67+ * @return String
 68+ */
 69+ public function execute( $par ) {
 70+ global $wgLang, $wgOut;
 71+
 72+ $this->setHeaders();
 73+ $this->outputHeader();
 74+
 75+ $this->setup( $par );
 76+
 77+ // Settings
 78+ $this->form();
 79+
 80+ if( $this->opts->getValue( 'rev1' ) && $this->opts->getValue( 'rev2' ) ) {
 81+ $de = new DifferenceEngine( null,
 82+ $this->opts->getValue( 'rev1' ),
 83+ $this->opts->getValue( 'rev2' ),
 84+ null, // rcid
 85+ ($this->opts->getValue( 'action') == "purge" ? true : false ),
 86+ false );
 87+ $de->showDiffPage( (bool)$this->opts->getValue( 'diffonly' ) );
 88+ }
 89+ }
 90+
 91+ protected function form() {
 92+ global $wgOut, $wgScript;
 93+
 94+ // Consume values
 95+ $page1 = $this->opts->consumeValue( 'page1' );
 96+ $page2 = $this->opts->consumeValue( 'page2' );
 97+ $rev1 = $this->opts->consumeValue( 'rev1' );
 98+ $rev2 = $this->opts->consumeValue( 'rev2' );
 99+
 100+ // Store query values in hidden fields so that form submission doesn't lose them
 101+ $hidden = array();
 102+ foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
 103+ $hidden[] = Xml::hidden( $key, $value );
 104+ }
 105+ $hidden = implode( "\n", $hidden );
 106+
 107+ $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
 108+ Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
 109+ Xml::fieldset( wfMsg( 'compare-selector') ) .
 110+ Xml::openElement( 'table', array( 'id' => 'mw-diff-table', 'width' => '100%' ) ) .
 111+ "<tr>
 112+ <td class='mw-label' width='10%'>" .
 113+ Xml::label( wfMsg( 'compare-page1' ), 'page1' ) .
 114+ "</td>
 115+ <td class='mw-input' width='40%'>" .
 116+ Xml::input( 'page1', 40, $page1, array( 'type' => 'text' ) ) .
 117+ "</td>
 118+ <td class='mw-label' width='10%'>" .
 119+ Xml::label( wfMsg( 'compare-page2' ), 'page2' ) .
 120+ "</td>
 121+ <td class='mw-input' width='40%'>" .
 122+ Xml::input( 'page2', 40, $page2, array( 'type' => 'text' ) ) .
 123+ "</td>
 124+ </tr>" .
 125+ "<tr>
 126+ <td class='mw-label'>" .
 127+ Xml::label( wfMsg( 'compare-rev1' ), 'rev1' ) .
 128+ "</td>
 129+ <td class='mw-input'>" .
 130+ Xml::input( 'rev1', 8, $rev1, array( 'type' => 'text' ) ) .
 131+ "</td>
 132+ <td class='mw-label'>" .
 133+ Xml::label( wfMsg( 'compare-rev2' ), 'rev2' ) .
 134+ "</td>
 135+ <td class='mw-input'>" .
 136+ Xml::input( 'rev2', 8, $rev2, array( 'type' => 'text' ) ) .
 137+ "</td>
 138+ </tr>" .
 139+ "<tr> <td></td>
 140+ <td class='mw-submit' colspan='3'>" .
 141+ Xml::submitButton( wfMsg( 'compare-submit') ) .
 142+ "</td>
 143+ </tr>" .
 144+ Xml::closeElement( 'table' ) .
 145+ Xml::closeElement( 'fieldset' ) .
 146+ $hidden .
 147+ Xml::closeElement( 'form' );
 148+
 149+ $wgOut->addHTML( $form );
 150+ }
 151+}
Property changes on: trunk/phase3/includes/specials/SpecialComparePages.php
___________________________________________________________________
Name: svn:eol-style
1152 + native
Index: trunk/phase3/includes/SpecialPage.php
@@ -169,6 +169,7 @@
170170 'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
171171
172172 # Page tools
 173+ 'ComparePages' => 'SpecialComparePages',
173174 'Export' => 'SpecialExport',
174175 'Import' => 'SpecialImport',
175176 'Undelete' => 'UndeleteForm',
Index: trunk/phase3/languages/messages/MessagesQqq.php
@@ -3613,6 +3613,15 @@
36143614
36153615 * <code>$1</code> is the number of changes marked with the tag',
36163616
 3617+# Special:ComparePages
 3618+'comparepages' => 'The title of [[Special:ComparePages]]',
 3619+'compare-selector' => 'Header of the form on [[Special:ComparePages]]',
 3620+'compare-page1' => 'Label for the field of the 1st page in the comparison for [[Special:ComparePages]]',
 3621+'compare-page2' => 'Label for the field of the 2nd page in the comparison for [[Special:ComparePages]]',
 3622+'compare-rev1' => 'Label for the field of the 1st revision in the comparison for [[Special:ComparePages]]',
 3623+'compare-rev2' => 'Label for the field of the 2nd revision in the comparison for [[Special:ComparePages]]',
 3624+'compare-submit' => 'Submit button on [[Special:ComparePages]]',
 3625+
36173626 # Database error messages
36183627 'dberr-header' => 'This message does not allow any wiki nor html markup.',
36193628 'dberr-problems' => 'This message does not allow any wiki nor html markup.',
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -457,6 +457,7 @@
458458 'Tags' => array( 'Tags' ),
459459 'Activeusers' => array( 'ActiveUsers' ),
460460 'RevisionMove' => array( 'RevisionMove' ),
 461+ 'ComparePages' => array( 'ComparePages' ),
461462 );
462463
463464 /**
@@ -4286,6 +4287,15 @@
42874288 'tags-edit' => 'edit',
42884289 'tags-hitcount' => '$1 {{PLURAL:$1|change|changes}}',
42894290
 4291+# Special:ComparePAges
 4292+'comparepages' => 'Compare pages',
 4293+'compare-selector' => 'Compare page revisions',
 4294+'compare-page1' => 'Page 1',
 4295+'compare-page2' => 'Page 2',
 4296+'compare-rev1' => 'Revision 1',
 4297+'compare-rev2' => 'Revision 2',
 4298+'compare-submit' => 'Compare',
 4299+
42904300 # Database error messages
42914301 'dberr-header' => 'This wiki has a problem',
42924302 'dberr-problems' => 'Sorry!
Index: trunk/phase3/RELEASE-NOTES
@@ -83,6 +83,7 @@
8484 * Show validity period of the login cookie in Special:UserLogin and
8585 Special:Preferences
8686 * Interlanguage links display the page title in their tooltip.
 87+* (bug 23621) New Special:ComparePages to compare (diff) two articles.
8788
8889 === Bug fixes in 1.17 ===
8990 * (bug 17560) Half-broken deletion moved image files to deletion archive

Comments

#Comment by Reedy (talk | contribs)   23:07, 19 June 2010

Really should GPL header the SpecialComparePages.php

#Comment by TheDJ (talk | contribs)   11:42, 21 June 2010

hmm, I copied the framework from another special page. Why do so many special pages seem to lack GPL headers ?

#Comment by 😂 (talk | contribs)   11:53, 21 June 2010

Would be nice if somebody went through the files and added the GPL header where it was missing. The inconsistency is annoying.

#Comment by Reedy (talk | contribs)   12:03, 21 June 2010

I'll have a poke later for procrastination

Status & tagging log