r88369 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88368‎ | r88369 | r88370 >
Date:14:30, 18 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special:semanticwatchlist
Modified paths:
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/SemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php (modified) (history)
  • /trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticWatchlist/specials/SpecialWatchlistConditions.php
@@ -75,6 +75,15 @@
7676 $wgOut->addModules( 'ext.swl.watchlistconditions' );
7777 }
7878
 79+ /**
 80+ *
 81+ *
 82+ * @since 0.1
 83+ *
 84+ * @param SWLGroup $group
 85+ *
 86+ * @return string
 87+ */
7988 protected function getGroupHtml( SWLGroup $group ) {
8089 return Html::rawElement(
8190 'fieldset',
Index: trunk/extensions/SemanticWatchlist/specials/ext.swl.watchlist.css
@@ -1 +1,13 @@
2 -@CHARSET "UTF-8";
\ No newline at end of file
 2+@CHARSET "UTF-8";
 3+
 4+div .swl-prop-div {
 5+ padding-left: 15px;
 6+}
 7+
 8+.swl-watchlist-insertions {
 9+ display: inline;
 10+}
 11+
 12+.swl-watchlist-deletions {
 13+ display: inline;
 14+}
\ No newline at end of file
Index: trunk/extensions/SemanticWatchlist/specials/SpecialSemanticWatchlist.php
@@ -50,7 +50,7 @@
5151 *
5252 * @param string $arg
5353 */
54 - public function execute( $arg ) {
 54+ public function execute( $subPage ) {
5555 global $wgOut, $wgUser, $wgRequest, $wgLang;
5656
5757 $this->setHeaders();
@@ -74,31 +74,97 @@
7575 $sets[] = SWLChangeSet::newFromArray( $set );
7676 }
7777
78 - $hasContinue = array_key_exists( 'query-continue', $changeSetData );
 78+ $newContinue = false;
7979
80 - if ( $hasContinue ) {
 80+ if ( array_key_exists( 'query-continue', $changeSetData ) ) {
8181 $newContinue = $changeSetData['query-continue']['semanticwatchlist']['swcontinue'];
8282 }
8383
8484 $wgOut->addHTML( '<p>' . wfMsgExt(
85 - 'swl-wacthlist-position',
 85+ 'swl-watchlist-position',
8686 array( 'parseinline' ),
8787 $wgLang->formatNum( count( $sets ) ),
8888 $wgLang->formatNum( $offset + 1 )
8989 ) . '</p>' );
9090
91 - $wgOut->addHTML( wfViewPrevNext(
92 - $offset,
93 - $limit,
94 - $this->getTitle( $arg ),
95 - $hasContinue ? 'continue=' . $newContinue : '',
96 - !$hasContinue
97 - ) );
 91+ $wgOut->addHTML( $this->getPagingControlHTML( $limit, $continue, $subPage, $newContinue, $offset ) );
9892
9993 $this->displayWatchlist( $sets );
10094 }
10195
10296 /**
 97+ * @since 0.1
 98+ *
 99+ * @return string
 100+ */
 101+ protected function getPagingControlHTML( $limit, $currentContinue, $subPage, $newContinue, $offset ) {
 102+ global $wgLang;
 103+
 104+ $nextMsg = wfMsgExt( 'nextn', array( 'parsemag', 'escape' ), $limit );
 105+ $firstMsg = wfMsgExt( 'swl-watchlist-firstn', array( 'parsemag', 'escape' ), $limit );
 106+
 107+ if ( $newContinue === false ) {
 108+ $nextLink = $nextMsg;
 109+ }
 110+ else {
 111+ $nextLink = Html::element(
 112+ 'a',
 113+ array(
 114+ 'href' => $this->getTitle( $subPage )->getLocalURL( wfArrayToCGI( array(
 115+ 'limit' => $limit,
 116+ 'continue' => $newContinue,
 117+ 'offset' => $offset + $limit
 118+ ) ) ),
 119+ 'title' => wfMsgExt( 'nextn-title', array( 'parsemag', 'escape' ), $limit ),
 120+ 'class' => 'mw-nextlink'
 121+ ),
 122+ $nextMsg
 123+ );
 124+ }
 125+
 126+ $limitLinks = array();
 127+ $limitLinkArgs = array();
 128+
 129+ if ( $currentContinue == '' ) {
 130+ $firstLink = $firstMsg;
 131+ }
 132+ else {
 133+ $limitLinkArgs['continue'] = $currentContinue;
 134+
 135+ $firstLink = Html::element(
 136+ 'a',
 137+ array(
 138+ 'href' => $this->getTitle( $subPage )->getLocalURL( wfArrayToCGI( array( 'limit' => $limit ) ) ),
 139+ 'title' => wfMsgExt( 'swl-watchlist-firstn-title', array( 'parsemag', 'escape' ), $limit )
 140+ ),
 141+ $firstMsg
 142+ );
 143+ }
 144+
 145+ foreach ( array( 20, 50, 100, 250, 500 ) as $limitValue ) {
 146+ $limitLinkArgs['limit'] = $limitValue;
 147+ if ( $offset != 0 ) {
 148+ $limitLinkArgs['offset'] = $offset;
 149+ }
 150+
 151+ $limitLinks[] = Html::element(
 152+ 'a',
 153+ array(
 154+ 'href' => $this->getTitle( $subPage )->getLocalURL( wfArrayToCGI( $limitLinkArgs ) ),
 155+ 'title' => wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $limitValue )
 156+ ),
 157+ $wgLang->formatNum( $limitValue )
 158+ );
 159+ }
 160+
 161+ return Html::rawElement(
 162+ 'p',
 163+ array(),
 164+ wfMsgHtml( 'swl-watchlist-pagincontrol', $wgLang->pipeList( array( $firstLink, $nextLink ) ), $wgLang->pipeList( $limitLinks ) )
 165+ );
 166+ }
 167+
 168+ /**
103169 * Displays the watchlist.
104170 *
105171 * @since 0.1
@@ -123,7 +189,7 @@
124190 krsort( $changeSetsHTML );
125191
126192 foreach ( $changeSetsHTML as $dayKey => $daySets ) {
127 - $wgOut->addHTML( HTML::element(
 193+ $wgOut->addHTML( Html::element(
128194 'h4',
129195 array(),
130196 $wgLang->date( str_pad( $dayKey, 14, '0' ) )
@@ -139,6 +205,8 @@
140206 }
141207
142208 SMWOutputs::commitToOutputPage( $wgOut );
 209+
 210+ $wgOut->addModules( 'ext.swl.watchlist' );
143211 }
144212
145213 /**
@@ -185,34 +253,34 @@
186254 $html .=
187255 '<p>' .
188256 $wgLang->time( $changeSet->getTime(), true ) . ' ' .
189 - HTML::element(
 257+ Html::element(
190258 'a',
191259 array( 'href' => $changeSet->getTitle()->getLocalURL() ),
192260 $changeSet->getTitle()->getText()
193261 ) . ' (' .
194 - HTML::element(
 262+ Html::element(
195263 'a',
196264 array( 'href' => $changeSet->getTitle()->getLocalURL( 'action=history' ) ),
197265 wfMsg( 'hist' )
198266 ) . ') . . ' .
199 - HTML::element(
 267+ Html::element(
200268 'a',
201269 array( 'href' => $changeSet->getUser()->getUserPage()->getLocalURL() ),
202270 $changeSet->getUser()->getName()
203271 ) . ' (' .
204 - HTML::element(
 272+ Html::element(
205273 'a',
206274 array( 'href' => $changeSet->getUser()->getTalkPage()->getLocalURL() ),
207275 wfMsg( 'talkpagelinktext' )
208276 ) . ' | ' .
209277 ( $changeSet->getUser()->isAnon() ? '' :
210 - HTML::element(
 278+ Html::element(
211279 'a',
212280 array( 'href' => SpecialPage::getTitleFor( 'Contributions', $changeSet->getUser()->getName() )->getLocalURL() ),
213281 wfMsg( 'contribslink' )
214282 ) . ' | '
215283 ) .
216 - HTML::element(
 284+ Html::element(
217285 'a',
218286 array( 'href' => SpecialPage::getTitleFor( 'Block', $changeSet->getUser()->getName() )->getLocalURL() ),
219287 wfMsg( 'blocklink' )
@@ -242,16 +310,37 @@
243311 * @return string
244312 */
245313 protected function getPropertyHTML( SMWDIProperty $property, array $changes ) {
246 - $html = '';
 314+ $insertions = array();
 315+ $deletions = array();
247316
 317+ // Convert the changes into a list of insertions and a list of deletions.
248318 foreach ( $changes as /* SMWPropertyChange */ $change ) {
249 - $old = $change->getOldValue();
250 - $old = is_null( $old ) ? wfMsg( 'swl-novalue' ) : SMWDataValueFactory::newDataItemValue( $old, $property )->getLongHTMLText();
251 - $new = $change->getNewValue();
252 - $new = is_null( $new ) ? wfMsg( 'swl-novalue' ) : SMWDataValueFactory::newDataItemValue( $new, $property )->getLongHTMLText();
253 - $html .= '* ' . $old . ' -> ' . $new;
 319+ if ( !is_null( $change->getOldValue() ) ) {
 320+ $deletions[] = SMWDataValueFactory::newDataItemValue( $change->getOldValue(), $property )->getLongHTMLText();
 321+ }
 322+ if ( !is_null( $change->getNewValue() ) ) {
 323+ $insertions[] = SMWDataValueFactory::newDataItemValue( $change->getNewValue(), $property )->getLongHTMLText();
 324+ }
254325 }
255326
 327+ $lines = array();
 328+
 329+ if ( count( $insertions ) > 0 ) {
 330+ $lines[] = Html::element( 'div', array( 'class' => 'swl-watchlist-insertions' ), wfMsg( 'swl-watchlist-insertions' ) ) . ' ' . implode( ', ', $insertions );
 331+ }
 332+
 333+ if ( count( $deletions ) > 0 ) {
 334+ $lines[] = Html::element( 'div', array( 'class' => 'swl-watchlist-deletions' ), wfMsg( 'swl-watchlist-deletions' ) ) . ' ' . implode( ', ', $deletions );
 335+ }
 336+
 337+ $html = Html::element( 'b', array(), $property->getLabel() );
 338+
 339+ $html .= Html::rawElement(
 340+ 'div',
 341+ array( 'class' => 'swl-prop-div' ),
 342+ implode( '<br />', $lines )
 343+ );
 344+
256345 return $html;
257346 }
258347
Index: trunk/extensions/SemanticWatchlist/includes/SWL_ChangeSet.php
@@ -1,5 +1,17 @@
22 <?php
33
 4+/**
 5+ * Wrapper around SMWChangeSet that holds extra info such as user and time,
 6+ * and has methods for (un)serialization and database interaction.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file SWL_ChangeSet.php
 11+ * @ingroup SemanticWatchlist
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
416 class SWLChangeSet {
517
618 /**
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.i18n.php
@@ -33,7 +33,12 @@
3434 'swl-group-page-selection' => 'Pages in ',
3535
3636 // Special:SemanticWatchlist
37 - 'swl-wacthlist-position' => "Showing '''$1''' of the last changes starting with '''#$2'''.",
 37+ 'swl-watchlist-position' => "Showing '''$1''' of the last changes starting with '''#$2'''.",
 38+ 'swl-watchlist-insertions' => 'Added:',
 39+ 'swl-watchlist-deletions' => 'Deleted:',
 40+ 'swl-watchlist-pagincontrol' => 'View ($1) ($2)',
 41+ 'swl-watchlist-firstn' => 'First $1',
 42+ 'swl-watchlist-firstn-title' => 'First $1 {{PLURAL:$1|result|results}}',
3843 );
3944
4045 /** German (Deutsch)
Index: trunk/extensions/SemanticWatchlist/SemanticWatchlist.php
@@ -88,6 +88,15 @@
8989 'remoteBasePath' => $egSWLScriptPath
9090 );
9191
 92+$wgResourceModules['ext.swl.watchlist'] = $moduleTemplate + array(
 93+ 'styles' => array( 'specials/ext.swl.watchlist.css' ),
 94+ 'scripts' => array(
 95+ ),
 96+ 'dependencies' => array(),
 97+ 'messages' => array(
 98+ )
 99+);
 100+
92101 $wgResourceModules['ext.swl.watchlistconditions'] = $moduleTemplate + array(
93102 'styles' => array( 'specials/ext.swl.watchlistconditions.css' ),
94103 'scripts' => array(

Status & tagging log