r113358 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113357‎ | r113358 | r113359 >
Date:10:37, 8 March 2012
Author:zaran
Status:reverted
Tags:gerritmigration 
Comment:
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -736,6 +736,9 @@
737737 $index = array_key_exists( 'index', $args ) ? $args['index'] : null;
738738 $from = array_key_exists( 'from', $args ) ? $args['from'] : null;
739739 $to = array_key_exists( 'to', $args ) ? $args['to'] : null;
 740+ $include = array_key_exists( 'include', $args ) ? $args['include'] : null;
 741+ $exclude = array_key_exists( 'exclude', $args ) ? $args['exclude'] : null;
 742+ $step = array_key_exists( 'step', $args ) ? $args['step'] : null;
740743 $header = array_key_exists( 'header', $args ) ? $args['header'] : null;
741744 $tosection = array_key_exists( 'tosection', $args ) ? $args['tosection'] : null;
742745 $fromsection = array_key_exists( 'fromsection', $args ) ? $args['fromsection'] : null;
@@ -762,8 +765,9 @@
763766
764767 list( $links, $params, $attributes ) = self::parse_index( $index_title );
765768
766 - if( $from || $to ) {
 769+ if( $from || $to || $include ) {
767770 $pages = array();
 771+
768772 if( $links == null ) {
769773 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index );
770774 if ( !$imageTitle ) {
@@ -775,36 +779,75 @@
776780 }
777781 $count = $image->pageCount();
778782
779 - if( !$from ) {
780 - $from = 1;
 783+ if( !$step ) {
 784+ $step = 1;
781785 }
782 - if( !$to ) {
783 - $to = $count;
 786+ if( !is_numeric( $step ) || $step < 1 ) {
 787+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
784788 }
785789
786 - if( !is_numeric( $from ) || !is_numeric( $to ) ) {
787 - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
 790+ $pagenums = array();
 791+
 792+ //add page selected with $include in pagenums
 793+ if( $include ) {
 794+ $list = self::parse_num_list( $include );
 795+ if( $list == null ) {
 796+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
 797+ }
 798+ $pagenums = $list;
788799 }
789 - if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) {
790 - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
 800+
 801+ //ad pages selected with form and to in pagenums
 802+ if( $from || $to ) {
 803+ if( !$from ) {
 804+ $from = 1;
 805+ }
 806+ if( !$to ) {
 807+ $to = $count;
 808+ }
 809+ if( !is_numeric( $from ) || !is_numeric( $to ) || !is_numeric( $step ) ) {
 810+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>';
 811+ }
 812+ if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) {
 813+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
 814+ }
 815+
 816+ for( $i = $from; $i <= $to; $i++ ) {
 817+ $pagenums[$i] = $i;
 818+ }
791819 }
792 - if( $to - $from > 1000 ) {
 820+
 821+ //remove excluded pages form $pagenums
 822+ if( $exclude ) {
 823+ $excluded = self::parse_num_list( $exclude );
 824+ if( $excluded == null ) {
 825+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
 826+ }
 827+ $pagenums = array_diff( $pagenums, $excluded );
 828+ }
 829+
 830+ if( count($pagenums)/$step > 1000 ) {
793831 return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>';
794832 }
795833
796 - for( $i = $from; $i <= $to; $i++ ) {
797 - list( $pagenum, $links, $mode ) = self::pageNumber( $i, $params );
798 - $page = str_replace( ' ' , '_', "$index/" . $i );
799 - if( $i == $from ) {
800 - $from_page = $page;
801 - $from_pagenum = $pagenum;
 834+ ksort( $pagenums ); //we must sort the array even if the numerical keys are in a good order.
 835+ if( reset( $pagenums ) > $count ) {
 836+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>';
 837+ }
 838+
 839+ //Create the list of pages to translude. the step system start with the smaller pagenum
 840+ $mod = reset( $pagenums ) % $step;
 841+ foreach( $pagenums as $num ) {
 842+ if( $step == 1 || $num % $step == $mod ) {
 843+ list( $pagenum, $links, $mode ) = self::pageNumber( $num, $params );
 844+ $page = str_replace( ' ' , '_', "$index/" . $num );
 845+ $pages[] = array($page, $pagenum);
802846 }
803 - if( $i == $to ) {
804 - $to_page = $page;
805 - $to_pagenum = $pagenum;
806 - }
807 - $pages[] = array( $page, $pagenum );
808847 }
 848+
 849+ list( $from_page, $from_pagenum ) = end( $pages );
 850+ list( $to_page, $to_pagenum ) = reset( $pages );
 851+
809852 } else {
810853 if( $from ) {
811854 $adding = false;
@@ -971,6 +1014,35 @@
9721015 }
9731016
9741017 /**
 1018+ * Parse a comma-separated list of pages. A dash indicates an interval of pages
 1019+ * example: 1-10,23,38
 1020+ * Return an array of pages, or null if the input does not comply to the syntax
 1021+ */
 1022+ private static function parse_num_list($input) {
 1023+ $input = str_replace(array(' ', '\t', '\n'), '', $input);
 1024+ $list = explode( ',', $input );
 1025+ $nums = array();
 1026+ foreach( $list as $item ) {
 1027+ if( is_numeric( $item ) ) {
 1028+ $nums[$item] = $item;
 1029+ } else {
 1030+ $interval = explode( '-', $item );
 1031+ if( count( $interval ) != 2
 1032+ || !is_numeric( $interval[0] )
 1033+ || !is_numeric( $interval[1] )
 1034+ || $interval[1] < $interval[0]
 1035+ ) {
 1036+ return null;
 1037+ }
 1038+ for( $i = $interval[0]; $i <= $interval[1]; $i += 1 ) {
 1039+ $nums[$i] = $i;
 1040+ }
 1041+ }
 1042+ }
 1043+ return $nums;
 1044+ }
 1045+
 1046+ /**
9751047 * Set is_toc flag (true if page is a table of contents)
9761048 */
9771049 public static function onOutputPageParserOutput( $outputPage, $parserOutput ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r114398Revert r113358, r113461, r114004, r114122. Unreviewed revs in ProofreadPage....catrope19:44, 21 March 2012

Status & tagging log