Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php |
— | — | @@ -16,6 +16,12 @@ |
17 | 17 | 'proofreadpage_index_expected' => 'Error: index expected', |
18 | 18 | 'proofreadpage_nosuch_index' => 'Error: no such index', |
19 | 19 | 'proofreadpage_nosuch_file' => 'Error: no such file', |
| 20 | + 'proofreadpage_badpage' => 'Wrong Format', |
| 21 | + 'proofreadpage_badpagetext' => 'The format of the page you attempted to save is incorrect.', |
| 22 | + 'proofreadpage_nologin' => 'Not logged in', |
| 23 | + 'proofreadpage_nologintext' => 'You must be [[Special:UserLogin|logged in]] to modify the proofreading status of pages.', |
| 24 | + 'proofreadpage_notallowed' => 'Not Allowed', |
| 25 | + 'proofreadpage_notallowedtext' => 'Not Allowed.', |
20 | 26 | 'proofreadpage_number_expected' => 'Error: numeric value expected', |
21 | 27 | 'proofreadpage_interval_too_large'=> 'Error: interval too large', |
22 | 28 | 'proofreadpage_invalid_interval' => 'Error: invalid interval', |
Index: trunk/extensions/ProofreadPage/ProofreadPage.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | $wgHooks['BeforePageDisplay'][] = 'pr_beforePageDisplay'; |
13 | 13 | $wgHooks['GetLinkColours'][] = 'pr_getLinkColoursHook'; |
14 | 14 | $wgHooks['ImageOpenShowImageInlineBefore'][] = 'pr_imageMessage'; |
| 15 | +$wgHooks['EditPage::attemptSave'][] = 'pr_attemptSave'; |
15 | 16 | $wgHooks['ArticleSaveComplete'][] = 'pr_articleSave'; |
16 | 17 | $wgHooks['EditFormPreloadText'][] = 'pr_preloadText'; |
17 | 18 | |
— | — | @@ -750,16 +751,82 @@ |
751 | 752 | return $out; |
752 | 753 | } |
753 | 754 | |
| 755 | +/* |
| 756 | + * Try to parse a page. |
| 757 | + * Return quality status of the page and username of the proofreader |
| 758 | + * Return -1 if the page cannot be parsed |
| 759 | + */ |
| 760 | +function pr_parse_page( $text ) { |
| 761 | + $page_regexp = "/^<noinclude>\{\{PageQuality\|(0|1|2|3|4)\|(.*?)\}\}(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s"; |
| 762 | + if( !preg_match( $page_regexp, $text, $m ) ) { |
| 763 | + return array( -1, null ); |
| 764 | + } |
| 765 | + return array( intval($m[1]), $m[2] ); |
| 766 | +} |
754 | 767 | |
755 | 768 | |
| 769 | +/* |
| 770 | + * Check the format of pages in "Page" namespace. |
| 771 | + * Todo: check that listed pages are unique for pages in "Index" namespace. |
| 772 | + */ |
756 | 773 | |
| 774 | +function pr_attemptSave( $editpage ) { |
| 775 | + global $wgOut, $wgUser; |
| 776 | + |
| 777 | + wfLoadExtensionMessages( 'ProofreadPage' ); |
| 778 | + $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
| 779 | + $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' ); |
| 780 | + |
| 781 | + $title = $editpage->mTitle; |
| 782 | + if ( ! preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
| 783 | + return true; |
| 784 | + } |
| 785 | + |
| 786 | + //$text = $editpage->mArticle->replaceSection( $editpage->section, $editpage->textbox1, $editpage->summary, $editpage->edittime ); |
| 787 | + $text = $editpage->textbox1; |
| 788 | + |
| 789 | + //parse the page |
| 790 | + list( $q , $username ) = pr_parse_page( $text ); |
| 791 | + if( $q == -1 ) { |
| 792 | + $wgOut->showErrorPage( 'proofreadpage_badpage', 'proofreadpage_badpagetext' ); |
| 793 | + return false; |
| 794 | + } |
| 795 | + //read previous revision, so that I know how much I need to add to pr_index |
| 796 | + $rev = Revision::newFromTitle( $title ); |
| 797 | + if( $rev ) { |
| 798 | + $old_text = $rev->getText(); |
| 799 | + list( $old_q , $old_username ) = pr_parse_page( $old_text ); |
| 800 | + } else { |
| 801 | + $old_q = -1; |
| 802 | + } |
| 803 | + |
| 804 | + //check usernames |
| 805 | + if( $old_q != -1 ) { |
| 806 | + if( ($old_q != $q) && $wgUser->isAnon() ) { |
| 807 | + $wgOut->showErrorPage( 'proofreadpage_nologin', 'proofreadpage_nologintext' ); |
| 808 | + return false; |
| 809 | + } |
| 810 | + if ( $wgUser->getName() != $username ) { |
| 811 | + $wgOut->showErrorPage( 'proofreadpage_notallowed', 'proofreadpage_notallowedtext' ); |
| 812 | + return false; |
| 813 | + } |
| 814 | + if( ( ($q == 4) && ($old_q < 3) ) || ( ($q == 4) && ($old_q == 3) && ($old_username == $username) ) ) { |
| 815 | + $wgOut->showErrorPage( 'proofreadpage_notallowed', 'proofreadpage_notallowedtext' ); |
| 816 | + return false; |
| 817 | + } |
| 818 | + } |
| 819 | + else { |
| 820 | + $old_q = 1; |
| 821 | + } |
| 822 | + return true; |
| 823 | +} |
| 824 | + |
| 825 | + |
757 | 826 | /* update coloured links in index pages */ |
758 | 827 | function pr_articleSave( $article ) { |
759 | 828 | |
760 | 829 | wfLoadExtensionMessages( 'ProofreadPage' ); |
761 | 830 | $page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
762 | | - $index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' ); |
763 | | - |
764 | 831 | $title = $article->mTitle; |
765 | 832 | |
766 | 833 | if ( preg_match( "/^$page_namespace:(.*)$/", $title->getPrefixedText() ) ) { |
— | — | @@ -767,7 +834,7 @@ |
768 | 835 | pr_load_index( $title ); |
769 | 836 | } |
770 | 837 | if ( $title->pr_index_title ) { |
771 | | - $index_title = Title::makeTitleSafe( $index_namespace, $title->pr_index_title ); |
| 838 | + $index_title = Title::newFromText( $title->pr_index_title ); |
772 | 839 | $index_title->invalidateCache(); |
773 | 840 | } |
774 | 841 | } |