r51789 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51788‎ | r51789 | r51790 >
Date:12:35, 12 June 2009
Author:thomasv
Status:ok
Tags:
Comment:
handle more errors; use from..to params for pages
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -15,6 +15,7 @@
1616 'proofreadpage_index' => 'Index',
1717 'proofreadpage_index_expected' => 'Error: index expected',
1818 'proofreadpage_nosuch_index' => 'Error: no such index',
 19+ 'proofreadpage_nosuch_file' => 'Error: no such file',
1920 'proofreadpage_number_expected' => 'Error: numeric value expected',
2021 'proofreadpage_interval_too_large'=> 'Error: interval too large',
2122 'proofreadpage_invalid_interval' => 'Error: invalid interval',
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -571,91 +571,94 @@
572572 function pr_renderPageList( $input, $args ) {
573573 global $wgUser, $wgTitle;
574574 wfLoadExtensionMessages( 'ProofreadPage' );
 575+
575576 $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
576577 if ( !preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $wgTitle->getPrefixedText(), $m ) ) {
577 - return true;
 578+ return "";
578579 }
579580
580581 $imageTitle = Title::makeTitleSafe( NS_IMAGE, $m[1] );
581582 if ( !$imageTitle ) {
582 - return true;
 583+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>';
583584 }
 585+
584586 $image = wfFindFile( $imageTitle );
 587+ if ( ! ( $image && $image->isMultiPage() && $image->pageCount() ) ) {
 588+ return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_file' ) . '</strong>';
 589+ }
 590+
585591 $return = "";
 592+ $name = $imageTitle->getDBkey();
 593+ $count = $image->pageCount();
 594+ $dbr = wfGetDB( DB_SLAVE );
 595+ $pagetable = $dbr->tableName( 'page' );
586596
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+ }
592602
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;
598607
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>';
603612
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 .= ', ';
618619 }
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__ );
621625
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 );
631635
632 - $sk = $wgUser->getSkin();
 636+ $sk = $wgUser->getSkin();
633637
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 );
637641
638 - if ( $mode == 'highroman' || $mode == 'roman' ) $view = '&nbsp;' . $view;
 642+ if ( $mode == 'highroman' || $mode == 'roman' ) $view = '&nbsp;' . $view;
639643
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';
647649 }
648 - $title = Title::newFromText( $pdbk );
 650+ $view = $txt . '</span>' . $view;
 651+ }
 652+ $title = Title::newFromText( $pdbk );
649653
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 );
652659 } 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 );
659661 }
 662+ $return .= "{$link} ";
660663 }
661664 }
662665 return $return;
@@ -687,14 +690,30 @@
688691 if( ! $index_title || ! $index_title->exists() )
689692 return '<strong class="error">' . wfMsgForContent( 'proofreadpage_nosuch_index' ) . '</strong>';
690693
 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+
691704 $out = '<span id="pr_index" class="hiddenStructure"><a href="'.$index_title->escapeFullUrl().'">'.$index_namespace.'</a> </span>';
692705 list( $links, $params, $attributes ) = pr_parse_index( $index_title );
693706
694707 if( $params ) {
 708+ if( !$from ) $from = 1;
 709+ if( !$to ) $to = $count;
 710+
695711 if(!is_numeric($from) || !is_numeric($to))
696712 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 )
698716 return '<strong class="error">' . wfMsgForContent( 'proofreadpage_interval_too_large' ) . '</strong>';
 717+
699718 for($i=$from; $i<=$to;$i++){
700719 $text = "$page_namespace:$index/" . $i;
701720 list($pagenum, $links, $mode) = pr_pageNumber($i,$params);

Status & tagging log