r106297 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106296‎ | r106297 | r106298 >
Date:01:02, 15 December 2011
Author:brion
Status:ok (Comments)
Tags:
Comment:
* (bug 32512) Include 'associated namespace' checkbox on Special:Contributions

patch by MrBlueSky - https://bugzilla.wikimedia.org/attachment.cgi?id=9705&action=diff


This also restructures some pieces of the form in order to better accomodate the extra checkbox (as well as those like 'deleted only' that not everybody sees)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/Namespace.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -105,6 +105,7 @@
106106 * jQuery UI upgraded to 1.8.17
107107 * Extensions can use the 'Language::getMessagesFileName' hook to define new
108108 languages using messages files outside of core.
 109+* (bug 32512) Include 'associated namespace' checkbox on Special:Contributions
109110
110111 === Bug fixes in 1.19 ===
111112 * $wgUploadNavigationUrl should be used for file redlinks if.
Index: trunk/phase3/includes/Namespace.php
@@ -126,7 +126,7 @@
127127 public static function getAssociated( $index ) {
128128 self::isMethodValidFor( $index, __METHOD__ );
129129
130 - if( self::isMain( $index ) ) {
 130+ if( self::isSubject( $index ) ) {
131131 return self::getTalk( $index );
132132 } elseif( self::isTalk( $index ) ) {
133133 return self::getSubject( $index );
@@ -139,7 +139,7 @@
140140 * Returns whether the specified namespace exists
141141 *
142142 * @param $index
143 - *
 143+ *
144144 * @return bool
145145 * @since 1.19
146146 */
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -98,6 +98,8 @@
9999 $this->opts['namespace'] = '';
100100 }
101101
 102+ $this->opts['associated'] = $request->getBool( 'associated' );
 103+
102104 $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' );
103105
104106 $this->opts['tagfilter'] = (string) $request->getVal( 'tagfilter' );
@@ -168,6 +170,7 @@
169171 'deletedOnly' => $this->opts['deletedOnly'],
170172 'topOnly' => $this->opts['topOnly'],
171173 'nsInvert' => $this->opts['nsInvert'],
 174+ 'associated' => $this->opts['associated'],
172175 ) );
173176 if( !$pager->getNumRows() ) {
174177 $out->addWikiMsg( 'nocontribs', $target );
@@ -357,6 +360,10 @@
358361 $this->opts['nsInvert'] = '';
359362 }
360363
 364+ if( !isset( $this->opts['associated'] ) ) {
 365+ $this->opts['associated'] = false;
 366+ }
 367+
361368 if( !isset( $this->opts['contribs'] ) ) {
362369 $this->opts['contribs'] = 'user';
363370 }
@@ -381,49 +388,143 @@
382389 $this->opts['topOnly'] = false;
383390 }
384391
385 - $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
 392+ $form = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'class' => 'mw-contributions-form' ) );
386393
387394 # Add hidden params for tracking except for parameters in $skipParameters
388 - $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly' );
 395+ $skipParameters = array( 'namespace', 'nsInvert', 'deletedOnly', 'target', 'contribs', 'year', 'month', 'topOnly', 'associated' );
389396 foreach ( $this->opts as $name => $value ) {
390397 if( in_array( $name, $skipParameters ) ) {
391398 continue;
392399 }
393 - $f .= "\t" . Html::hidden( $name, $value ) . "\n";
 400+ $form .= "\t" . Html::hidden( $name, $value ) . "\n";
394401 }
395402
396403 $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] );
397404
398 - $f .= Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
399 - Xml::radioLabel( wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
400 - 'contribs', 'newbie' , 'newbie', $this->opts['contribs'] == 'newbie' ) . '<br />' .
401 - Xml::radioLabel( wfMsgExt( 'sp-contributions-username', array( 'parsemag' ) ),
402 - 'contribs' , 'user', 'user', $this->opts['contribs'] == 'user' ) . ' ' .
403 - Html::input( 'target', $this->opts['target'], 'text', array(
404 - 'size' => '20',
405 - 'required' => ''
406 - ) + ( $this->opts['target'] ? array() : array( 'autofocus' ) ) ) . ' '.
 405+ if ($tagFilter) {
 406+ $filterSelection =
 407+ Xml::tags( 'td', array( 'class' => 'mw-label' ), array_shift( $tagFilter ) ) .
 408+ Xml::tags( 'td', array( 'class' => 'mw-input' ), implode( '&#160', $tagFilter ) );
 409+ } else {
 410+ $filterSelection = Xml::tags( 'td', array( 'colspan' => 2 ), '' );
 411+ }
 412+
 413+ $targetSelection = Xml::tags( 'td', array( 'colspan' => 2 ),
 414+ Xml::radioLabel(
 415+ wfMsgExt( 'sp-contributions-newbies', array( 'parsemag' ) ),
 416+ 'contribs',
 417+ 'newbie' ,
 418+ 'newbie',
 419+ $this->opts['contribs'] == 'newbie',
 420+ array( 'class' => 'mw-input' )
 421+ ) . '<br />' .
 422+ Xml::radioLabel(
 423+ wfMsgExt( 'sp-contributions-username', array( 'parsemag' ) ),
 424+ 'contribs',
 425+ 'user',
 426+ 'user',
 427+ $this->opts['contribs'] == 'user',
 428+ array( 'class' => 'mw-input' )
 429+ ) . ' ' .
 430+ Html::input(
 431+ 'target',
 432+ $this->opts['target'],
 433+ 'text',
 434+ array( 'size' => '20', 'required' => '', 'class' => 'mw-input' ) +
 435+ ( $this->opts['target'] ? array() : array( 'autofocus' )
 436+ )
 437+ ) . ' '
 438+ ) ;
 439+
 440+ $namespaceSelection =
 441+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 442+ Xml::label(
 443+ wfMsg( 'namespace' ),
 444+ 'namespace',
 445+ ''
 446+ )
 447+ ) .
 448+ Xml::tags( 'td', null,
 449+ Xml::namespaceSelector( $this->opts['namespace'], '' ) . '&#160;' .
 450+ Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
 451+ Xml::checkLabel(
 452+ wfMsg('invert'),
 453+ 'nsInvert',
 454+ 'nsInvert',
 455+ $this->opts['nsInvert'],
 456+ array( 'title' => wfMsg( 'tooltip-invert' ), 'class' => 'mw-input' )
 457+ ) . '&#160;'
 458+ ) .
 459+ Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
 460+ Xml::checkLabel(
 461+ wfMsg('namespace_association'),
 462+ 'associated',
 463+ 'associated',
 464+ $this->opts['associated'],
 465+ array( 'title' => wfMsg( 'tooltip-namespace_association' ), 'class' => 'mw-input' )
 466+ ) . '&#160;'
 467+ )
 468+ ) ;
 469+
 470+ $extraOptions = Xml::tags( 'td', array( 'colspan' => 2 ),
407471 Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
408 - Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
409 - Xml::namespaceSelector( $this->opts['namespace'], '' )
 472+ Xml::checkLabel(
 473+ wfMsg( 'history-show-deleted' ),
 474+ 'deletedOnly',
 475+ 'mw-show-deleted-only',
 476+ $this->opts['deletedOnly'],
 477+ array( 'class' => 'mw-input' )
 478+ )
410479 ) .
411 - Xml::checkLabel( wfMsg('invert'), 'nsInvert', 'nsInvert', $this->opts['nsInvert'] ) . '&#160;' .
412 - Xml::checkLabel( wfMsg( 'history-show-deleted' ),
413 - 'deletedOnly', 'mw-show-deleted-only', $this->opts['deletedOnly'] ) . '<br />' .
414 - Xml::tags( 'p', null, Xml::checkLabel( wfMsg( 'sp-contributions-toponly' ),
415 - 'topOnly', 'mw-show-top-only', $this->opts['topOnly'] ) ) .
416 - ( $tagFilter ? Xml::tags( 'p', null, implode( '&#160;', $tagFilter ) ) : '' ) .
417 - Html::rawElement( 'p', array( 'style' => 'white-space: nowrap' ),
418 - Xml::dateMenu( $this->opts['year'], $this->opts['month'] ) . ' ' .
419 - Xml::submitButton( wfMsg( 'sp-contributions-submit' ) )
420 - ) . ' ';
 480+ Html::rawElement( 'span', array( 'style' => 'white-space: nowrap' ),
 481+ Xml::checkLabel(
 482+ wfMsg( 'sp-contributions-toponly' ),
 483+ 'topOnly',
 484+ 'mw-show-top-only',
 485+ $this->opts['topOnly'],
 486+ array( 'class' => 'mw-input' )
 487+ )
 488+ )
 489+ ) ;
 490+
 491+ $dateSelectionAndSubmit = Xml::tags( 'td', array( 'colspan' => 2 ),
 492+ Xml::dateMenu(
 493+ $this->opts['year'],
 494+ $this->opts['month']
 495+ ) . ' ' .
 496+ Xml::submitButton(
 497+ wfMsg( 'sp-contributions-submit' ),
 498+ array( 'class' => 'mw-submit' )
 499+ )
 500+ ) ;
 501+
 502+ $form .=
 503+ Xml::fieldset( wfMsg( 'sp-contributions-search' ) ) .
 504+ Xml::openElement( 'table', array( 'class' => 'mw-contributions-table' ) ) .
 505+ Xml::openElement( 'tr' ) .
 506+ $targetSelection .
 507+ Xml::closeElement( 'tr' ) .
 508+ Xml::openElement( 'tr' ) .
 509+ $namespaceSelection .
 510+ Xml::closeElement( 'tr' ) .
 511+ Xml::openElement( 'tr' ) .
 512+ $filterSelection .
 513+ Xml::closeElement( 'tr' ) .
 514+ Xml::openElement( 'tr' ) .
 515+ $extraOptions .
 516+ Xml::closeElement( 'tr' ) .
 517+ Xml::openElement( 'tr' ) .
 518+ $dateSelectionAndSubmit .
 519+ Xml::closeElement( 'tr' ) .
 520+ Xml::closeElement( 'table' );
 521+
421522 $explain = wfMessage( 'sp-contributions-explain' );
422523 if ( $explain->exists() ) {
423 - $f .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
 524+ $form .= "<p id='mw-sp-contributions-explain'>{$explain}</p>";
424525 }
425 - $f .= Xml::closeElement('fieldset' ) .
 526+ $form .= Xml::closeElement('fieldset' ) .
426527 Xml::closeElement( 'form' );
427 - return $f;
 528+ return $form;
428529 }
429530 }
430531
@@ -451,6 +552,7 @@
452553 $this->namespace = isset( $options['namespace'] ) ? $options['namespace'] : '';
453554 $this->tagFilter = isset( $options['tagfilter'] ) ? $options['tagfilter'] : false;
454555 $this->nsInvert = isset( $options['nsInvert'] ) ? $options['nsInvert'] : false;
 556+ $this->associated = isset( $options['associated'] ) ? $options['associated'] : false;
455557
456558 $this->deletedOnly = !empty( $options['deletedOnly'] );
457559 $this->topOnly = !empty( $options['topOnly'] );
@@ -545,11 +647,23 @@
546648
547649 function getNamespaceCond() {
548650 if( $this->namespace !== '' ) {
549 - if ( $this->nsInvert ) {
550 - return array( 'page_namespace != ' . (int)$this->namespace );
 651+ $selectedNS = $this->mDb->addQuotes( $this->namespace );
 652+ $eq_op = $this->nsInvert ? '!=' : '=';
 653+ $bool_op = $this->nsInvert ? 'AND' : 'OR';
 654+
 655+ if( !$this->associated ) {
 656+ return array( "page_namespace $eq_op $selectedNS" );
551657 } else {
552 - return array( 'page_namespace' => (int)$this->namespace );
 658+ $associatedNS = $this->mDb->addQuotes (
 659+ MWNamespace::getAssociated( $this->namespace )
 660+ );
 661+ return array(
 662+ "page_namespace $eq_op $selectedNS " .
 663+ $bool_op .
 664+ " page_namespace $eq_op $associatedNS"
 665+ );
553666 }
 667+
554668 } else {
555669 return array();
556670 }

Comments

#Comment by Duplicatebug (talk | contribs)   18:31, 10 January 2012

Special:RecentChanges is using some javascript to enable/disable the fields, if needed (see r90943). It is possible to get this here, too? Thanks.

Status & tagging log