Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | 'proofreadpage_index' => 'Index', |
17 | 17 | 'proofreadpage_index_expected' => 'Error: index expected', |
18 | 18 | 'proofreadpage_nosuch_index' => 'Error: no such index', |
| 19 | + 'proofreadpage_nosuch_file' => 'Error: no such file', |
19 | 20 | 'proofreadpage_number_expected' => 'Error: numeric value expected', |
20 | 21 | 'proofreadpage_interval_too_large'=> 'Error: interval too large', |
21 | 22 | 'proofreadpage_invalid_interval' => 'Error: invalid interval', |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -571,91 +571,94 @@ |
572 | 572 | function pr_renderPageList( $input, $args ) { |
573 | 573 | global $wgUser, $wgTitle; |
574 | 574 | wfLoadExtensionMessages( 'ProofreadPage' ); |
| 575 | + |
575 | 576 | $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
576 | 577 | if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) { |
577 | | - return true; |
| 578 | + return ""; |
578 | 579 | } |
579 | 580 | |
580 | 581 | $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] ); |
581 | 582 | if ( !$imageTitle ) { |
582 | | - return true; |
| 583 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>'; |
583 | 584 | } |
| 585 | + |
584 | 586 | $image = wfFindFile( $imageTitle ); |
| 587 | + if ( ! ( $image && $image->isMultiPage() && $image->pageCount() ) ) { |
| 588 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>'; |
| 589 | + } |
| 590 | + |
585 | 591 | $return = ""; |
| 592 | + $name = $imageTitle->getDBkey(); |
| 593 | + $count = $image->pageCount(); |
| 594 | + $dbr = wfGetDB( DB_SLAVE ); |
| 595 | + $pagetable = $dbr->tableName( 'page' ); |
586 | 596 | |
587 | | - if ( $image && $image->isMultiPage() && $image->pageCount() ) { |
588 | | - $name = $imageTitle->getDBkey(); |
589 | | - $count = $image->pageCount(); |
590 | | - $dbr = wfGetDB( DB_SLAVE ); |
591 | | - $pagetable = $dbr->tableName( 'page' ); |
| 597 | + $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
| 598 | + $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
| 599 | + if ( $page_ns_index == NULL ) { |
| 600 | + $page_ns_index = NS_MAIN; |
| 601 | + } |
592 | 602 | |
593 | | - $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
594 | | - $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $page_namespace ) ); |
595 | | - if ( $page_ns_index == NULL ) { |
596 | | - $page_ns_index = NS_MAIN; |
597 | | - } |
| 603 | + $from = $args['from']; |
| 604 | + $to = $args['to']; |
| 605 | + if( !$from ) $from = 1; |
| 606 | + if( !$to ) $to = $count; |
598 | 607 | |
599 | | - $from = $args['from']; |
600 | | - $to = $args['to']; |
601 | | - if( !$from ) $from = 1; |
602 | | - if( !$to ) $to = $count; |
| 608 | + if( !is_numeric($from) || !is_numeric($to) ) |
| 609 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
| 610 | + if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) |
| 611 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
603 | 612 | |
604 | | - if( !is_numeric($from) || !is_numeric($to) ) |
605 | | - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
606 | | - if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) |
607 | | - return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
608 | | - |
609 | | - for ( $i = $from - 1; $i < $to; $i++ ) { |
610 | | - if ( !isset( $query ) ) { |
611 | | - $query = "SELECT page_id, page_title, page_namespace"; |
612 | | - $query .= " FROM $pagetable WHERE (page_namespace=" . intval( $page_ns_index ) . " AND page_title IN("; |
613 | | - } else { |
614 | | - $query .= ', '; |
615 | | - } |
616 | | - $link_name = "$name" . '/' . ( $i + 1 ) ; |
617 | | - $query .= $dbr->addQuotes( $link_name ); |
| 613 | + for ( $i = $from - 1; $i < $to; $i++ ) { |
| 614 | + if ( !isset( $query ) ) { |
| 615 | + $query = "SELECT page_id, page_title, page_namespace"; |
| 616 | + $query .= " FROM $pagetable WHERE (page_namespace=" . intval( $page_ns_index ) . " AND page_title IN("; |
| 617 | + } else { |
| 618 | + $query .= ', '; |
618 | 619 | } |
619 | | - $query .= '))'; |
620 | | - $res = $dbr->query( $query, __METHOD__ ); |
| 620 | + $link_name = "$name" . '/' . ( $i + 1 ) ; |
| 621 | + $query .= $dbr->addQuotes( $link_name ); |
| 622 | + } |
| 623 | + $query .= '))'; |
| 624 | + $res = $dbr->query( $query, __METHOD__ ); |
621 | 625 | |
622 | | - $colours = array(); |
623 | | - $linkcolour_ids = array(); |
624 | | - while ( $s = $dbr->fetchObject( $res ) ) { |
625 | | - $title = Title::makeTitle( $s->page_namespace, $s->page_title ); |
626 | | - $pdbk = $title->getPrefixedDBkey(); |
627 | | - $colours[$pdbk] = 'known'; |
628 | | - $linkcolour_ids[$s->page_id] = $pdbk; |
629 | | - } |
630 | | - pr_getLinkColours( $linkcolour_ids, $colours ); |
| 626 | + $colours = array(); |
| 627 | + $linkcolour_ids = array(); |
| 628 | + while ( $s = $dbr->fetchObject( $res ) ) { |
| 629 | + $title = Title::makeTitle( $s->page_namespace, $s->page_title ); |
| 630 | + $pdbk = $title->getPrefixedDBkey(); |
| 631 | + $colours[$pdbk] = 'known'; |
| 632 | + $linkcolour_ids[$s->page_id] = $pdbk; |
| 633 | + } |
| 634 | + pr_getLinkColours( $linkcolour_ids, $colours ); |
631 | 635 | |
632 | | - $sk = $wgUser->getSkin(); |
| 636 | + $sk = $wgUser->getSkin(); |
633 | 637 | |
634 | | - for ( $i = $from; $i < $to + 1; $i++ ) { |
635 | | - $pdbk = "$page_namespace:$name" . '/' . $i ; |
636 | | - list( $view, $links, $mode ) = pr_pageNumber( $i, $args ); |
| 638 | + for ( $i = $from; $i < $to + 1; $i++ ) { |
| 639 | + $pdbk = "$page_namespace:$name" . '/' . $i ; |
| 640 | + list( $view, $links, $mode ) = pr_pageNumber( $i, $args ); |
637 | 641 | |
638 | | - if ( $mode == 'highroman' || $mode == 'roman' ) $view = ' ' . $view; |
| 642 | + if ( $mode == 'highroman' || $mode == 'roman' ) $view = ' ' . $view; |
639 | 643 | |
640 | | - $n = strlen( $count ) - strlen( $view ); |
641 | | - if ( $n && ( $mode == 'normal' || $mode == 'empty' ) ) { |
642 | | - $txt = '<span style="visibility:hidden;">'; |
643 | | - for ( $j = 0; $j < $n; $j++ ) { |
644 | | - $txt = $txt . '0'; |
645 | | - } |
646 | | - $view = $txt . '</span>' . $view; |
| 644 | + $n = strlen( $count ) - strlen( $view ); |
| 645 | + if ( $n && ( $mode == 'normal' || $mode == 'empty' ) ) { |
| 646 | + $txt = '<span style="visibility:hidden;">'; |
| 647 | + for ( $j = 0; $j < $n; $j++ ) { |
| 648 | + $txt = $txt . '0'; |
647 | 649 | } |
648 | | - $title = Title::newFromText( $pdbk ); |
| 650 | + $view = $txt . '</span>' . $view; |
| 651 | + } |
| 652 | + $title = Title::newFromText( $pdbk ); |
649 | 653 | |
650 | | - if ( $links == false ) { |
651 | | - $return .= $view . " "; |
| 654 | + if ( $links == false ) { |
| 655 | + $return .= $view . " "; |
| 656 | + } else { |
| 657 | + if ( !isset( $colours[$pdbk] ) ) { |
| 658 | + $link = $sk->makeBrokenLinkObj( $title, $view ); |
652 | 659 | } else { |
653 | | - if ( !isset( $colours[$pdbk] ) ) { |
654 | | - $link = $sk->makeBrokenLinkObj( $title, $view ); |
655 | | - } else { |
656 | | - $link = $sk->makeColouredLinkObj( $title, $colours[$pdbk], $view ); |
657 | | - } |
658 | | - $return .= "{$link} "; |
| 660 | + $link = $sk->makeColouredLinkObj( $title, $colours[$pdbk], $view ); |
659 | 661 | } |
| 662 | + $return .= "{$link} "; |
660 | 663 | } |
661 | 664 | } |
662 | 665 | return $return; |
— | — | @@ -687,14 +690,30 @@ |
688 | 691 | if( ! $index_title || ! $index_title->exists() ) |
689 | 692 | return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_index' ) . '</strong>'; |
690 | 693 | |
| 694 | + $imageTitle = Title::makeTitleSafe( NS_IMAGE, $index ); |
| 695 | + if ( !$imageTitle ) { |
| 696 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>'; |
| 697 | + } |
| 698 | + $image = wfFindFile( $imageTitle ); |
| 699 | + if ( ! ( $image && $image->isMultiPage() && $image->pageCount() ) ) { |
| 700 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>'; |
| 701 | + } |
| 702 | + $count = $image->pageCount(); |
| 703 | + |
691 | 704 | $out = '<span id="pr_index" class="hiddenStructure"><a href="'.$index_title->escapeFullUrl().'">'.$index_namespace.'</a> </span>'; |
692 | 705 | list( $links, $params, $attributes ) = pr_parse_index( $index_title ); |
693 | 706 | |
694 | 707 | if( $params ) { |
| 708 | + if( !$from ) $from = 1; |
| 709 | + if( !$to ) $to = $count; |
| 710 | + |
695 | 711 | if(!is_numeric($from) || !is_numeric($to)) |
696 | 712 | return '<strong class="error">' . wfMsgForContent( 'proofreadpage_number_expected' ) . '</strong>'; |
697 | | - if( ($from > $to) || ($to - $from > 1000) ) |
| 713 | + if( ($from > $to) || ($from < 1) || ($to < 1 ) || ($to > $count) ) |
| 714 | + return '<strong class="error">' . wfMsgForContent( 'proofreadpage_invalid_interval' ) . '</strong>'; |
| 715 | + if( $to - $from > 1000 ) |
698 | 716 | return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>'; |
| 717 | + |
699 | 718 | for($i=$from; $i<=$to;$i++){ |
700 | 719 | $text = "$page_namespace:$index/" . $i; |
701 | 720 | list($pagenum, $links, $mode) = pr_pageNumber($i,$params); |