r73947 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73946‎ | r73947 | r73948 >
Date:14:24, 29 September 2010
Author:thomasv
Status:ok
Tags:
Comment:
simplification using jQuery
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -33,7 +33,7 @@
3434 * Constructor
3535 */
3636 function ProofreadPage() {
37 - global $wgParser, $wgHooks;
 37+ global $wgParser, $wgHooks, $wgScriptPath;
3838 $wgParser->setHook( 'pagelist', array( &$this, 'renderPageList' ) );
3939 $wgParser->setHook( 'pages', array( &$this, 'renderPages' ) );
4040 $wgParser->setHook( 'pagequality', array( &$this, 'pageQuality' ) );
@@ -50,9 +50,25 @@
5151 $wgHooks['EditPage::importFormData'][] = array( &$this, 'importFormData' );
5252 $wgHooks['OutputPageParserOutput'][] = array( &$this, 'OutputPageParserOutput' );
5353 $wgHooks['ResourceLoaderRegisterModules'][] = array( &$this, 'resourceLoaderRegisterModules' );
 54+
5455 wfLoadExtensionMessages( 'ProofreadPage' );
 56+
 57+ /* Namespaces */
5558 $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
5659 $this->index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
 60+
 61+ /* Navigation icons */
 62+ $path = $wgScriptPath . '/extensions/ProofreadPage';
 63+ $this->prev_icon = Html::element( 'img', array( 'src' => $path . '/leftarrow.png',
 64+ 'alt' => wfMsg( 'proofreadpage_prevpage' ),
 65+ 'width' => 15, 'height' => 15 ) );
 66+ $this->next_icon = Html::element( 'img', array( 'src' => $path . '/rightarrow.png',
 67+ 'alt' => wfMsg( 'proofreadpage_nextpage' ),
 68+ 'width' => 15, 'height' => 15 ) );
 69+ $this->up_icon = Html::element( 'img', array( 'src' => $path . '/uparrow.png',
 70+ 'alt' => wfMsg( 'proofreadpage_index' ),
 71+ 'width' => 15, 'height' => 15 ) );
 72+
5773 }
5874
5975 public static function resourceLoaderRegisterModules() {
@@ -62,10 +78,6 @@
6379 array(
6480 'scripts' => 'extensions/ProofreadPage/proofread.js',
6581 'messages' => array(
66 - 'proofreadpage_index',
67 - 'proofreadpage_nextpage',
68 - 'proofreadpage_prevpage',
69 - 'proofreadpage_image',
7082 'proofreadpage_header',
7183 'proofreadpage_body',
7284 'proofreadpage_footer',
@@ -190,18 +202,16 @@
191203 $name = $image->getTitle()->getText();
192204 $prev_name = "$page_namespace:$name/" . ( $pagenr - 1 );
193205 $next_name = "$page_namespace:$name/" . ( $pagenr + 1 );
194 - $prev_url = ( $pagenr == 1 ) ? '' : Title::newFromText( $prev_name )->getFullURL();
195 - $next_url = ( $pagenr == $count ) ? '' : Title::newFromText( $next_name )->getFullURL();
 206+ $prev_title = ( $pagenr == 1 ) ? null : Title::newFromText( $prev_name );
 207+ $next_title = ( $pagenr == $count ) ? null : Title::newFromText( $next_name );
196208
197209 } else {
198 - $prev_url = '';
199 - $next_url = '';
 210+ $prev_title = null;
 211+ $next_title = null;
200212 }
201213
202 - $index_url = $index_title->getFullURL();
203 -
204214 if ( !$index_title->exists() ) {
205 - return array( $index_url, $prev_url, $next_url, $default_header, $default_footer );
 215+ return array( $index_title, $prev_title, $next_title, $default_header, $default_footer );
206216 }
207217
208218 // if the index page exists, find current page number, previous and next pages
@@ -227,12 +237,6 @@
228238 if( ( $i >= 0 ) && ( $i + 1 < count( $links[1] ) ) ) {
229239 $next_title = Title::newFromText( $page_namespace . ':' . $links[1][$i + 1] );
230240 }
231 - if( $prev_title ) {
232 - $prev_url = $prev_title->getFullURL();
233 - }
234 - if( $next_title ) {
235 - $next_url = $next_title->getFullURL();
236 - }
237241 }
238242
239243 // Header and Footer
@@ -246,7 +250,7 @@
247251 $css = $attributes['css'] ? $attributes['css'] : '';
248252 $edit_width = $attributes['width'] ? $attributes['width'] : '';
249253
250 - return array( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width );
 254+ return array( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width );
251255 }
252256
253257 /**
@@ -390,17 +394,28 @@
391395 $thumbURL = '';
392396 }
393397
394 - list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle );
 398+ list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle );
395399
 400+ $sk = $wgUser->getSkin();
 401+ $next_link = $next_title ? $sk->link( $next_title, $this->next_icon,
 402+ array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : '';
 403+ $prev_link = $prev_title ? $sk->link( $prev_title, $this->prev_icon,
 404+ array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): '';
 405+ $index_link = $index_title ? $sk->link( $index_title, $this->up_icon,
 406+ array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : '';
 407+ $scan_link = $sk->link( $imageTitle, wfMsg( 'proofreadpage_image' ),
 408+ array( 'title' => wfMsg( 'proofreadpage_image' ) ) );
 409+
396410 $jsVars = array(
397411 'proofreadPageWidth' => intval( $width ),
398412 'proofreadPageHeight' => intval( $height ),
399413 'proofreadPageEditWidth' => $edit_width,
400414 'proofreadPageThumbURL' => $thumbURL,
401415 'proofreadPageIsEdit' => intval( $isEdit ),
402 - 'proofreadPageIndexURL' => $index_url,
403 - 'proofreadPagePrevURL' => $prev_url,
404 - 'proofreadPageNextURL' => $next_url,
 416+ 'proofreadPageIndexLink' => $index_link,
 417+ 'proofreadPageNextLink' => $next_link,
 418+ 'proofreadPagePrevLink' => $prev_link,
 419+ 'proofreadPageScanLink' => $scan_link,
405420 'proofreadPageHeader' => $header,
406421 'proofreadPageFooter' => $footer,
407422 'proofreadPageAddButtons' => $wgUser->isAllowed( 'pagequality' ),
@@ -978,7 +993,7 @@
979994 $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s";
980995 if( !preg_match( $page_regexp, $text, $m ) ) {
981996 $this->load_index( $wgTitle );
982 - list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle );
 997+ list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle );
983998 $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" />"
984999 ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</noinclude>";
9851000 return array( -1, null, $new_text );
Index: trunk/extensions/ProofreadPage/proofread.js
@@ -1,54 +1,10 @@
22 // Author : ThomasV - License : GPL
33
44 function pr_init_tabs() {
5 - var a = document.getElementById( 'p-namespaces' );
6 - if( !a ) {
7 - a = document.getElementById( 'p-cactions' );
8 - }
9 -
10 - if ( !a ) {
11 - return;
12 - }
13 - var b = a.getElementsByTagName( 'ul' );
14 - if ( !b ) {
15 - return;
16 - }
17 -
18 - if( self.proofreadPageThumbURL ) {
19 - var view_url = self.proofreadPageThumbURL.replace( '##WIDTH##', '' + self.proofreadPageWidth );
20 - b[0].innerHTML = b[0].innerHTML + '<li id="ca-image">' +
21 - '<span><a href="' + escapeQuotesHTML( view_url ) + '">' +
22 - escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_image' ) ) + '</a></span></li>';
23 - }
24 -
25 - if( self.proofreadPageIndexURL ) {
26 - b[0].innerHTML = b[0].innerHTML + '<li id="ca-index">' +
27 - '<span><a href="' + escapeQuotesHTML( proofreadPageIndexURL ) +
28 - '" title="' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_index' ) ) + '">' +
29 - '<img src="' + wgScriptPath + '/extensions/ProofreadPage/uparrow.png" alt="' +
30 - escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_index' ) ) +
31 - '" width="15" height="15" /></a></span></li>';
32 - }
33 -
34 - if( self.proofreadPageNextURL ) {
35 - b[0].innerHTML = '<li id="ca-next">' +
36 - '<span><a href="' + escapeQuotesHTML( self.proofreadPageNextURL ) +
37 - '" title="' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_nextpage' ) ) + '">' +
38 - '<img src="' + wgScriptPath + '/extensions/ProofreadPage/rightarrow.png" alt="' +
39 - escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_nextpage' ) ) +
40 - '" width="15" height="15" /></a></span></li>' +
41 - b[0].innerHTML;
42 - }
43 -
44 - if( self.proofreadPagePrevURL ) {
45 - b[0].innerHTML = '<li id="ca-prev">' +
46 - '<span><a href="' + escapeQuotesHTML( self.proofreadPagePrevURL ) +
47 - '" title="' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_prevpage' ) ) + '">' +
48 - '<img src="' + wgScriptPath + '/extensions/ProofreadPage/leftarrow.png" alt="' +
49 - escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_prevpage' ) ) +
50 - '" width="15" height="15" /></a></span></li>' +
51 - b[0].innerHTML;
52 - }
 5+ $( '#ca-talk' ).prev().before( '<li id="ca-prev"><span>' + self.proofreadPagePrevLink + '</span></li>' );
 6+ $( '#ca-talk' ).prev().before( '<li id="ca-next"><span>' + self.proofreadPageNextLink + '</span></li>' );
 7+ $( '#ca-talk' ).after( '<li id="ca-index"><span>' + self.proofreadPageIndexLink + '</span></li>' );
 8+ $( '#ca-talk' ).after( '<li id="ca-image"><span>' + self.proofreadPageScanLink + '</span></li>' );
539 }
5410
5511 function pr_image_url( requested_width ) {

Status & tagging log