Index: trunk/phase3/includes/Article.php |
— | — | @@ -576,7 +576,7 @@ |
577 | 577 | function getCount() { |
578 | 578 | if ( -1 == $this->mCounter ) { |
579 | 579 | $id = $this->getID(); |
580 | | - $dbr =& $this->getDB(); |
| 580 | + $dbr =& wfGetDB( DB_SLAVE ); |
581 | 581 | $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ), |
582 | 582 | 'Article::getCount', $this->getSelectOptions() ); |
583 | 583 | } |
— | — | @@ -690,7 +690,7 @@ |
691 | 691 | |
692 | 692 | $title = $this->mTitle; |
693 | 693 | $contribs = array(); |
694 | | - $dbr =& $this->getDB(); |
| 694 | + $dbr =& wfGetDB( DB_SLAVE ); |
695 | 695 | $revTable = $dbr->tableName( 'revision' ); |
696 | 696 | $userTable = $dbr->tableName( 'user' ); |
697 | 697 | $encDBkey = $dbr->addQuotes( $title->getDBkey() ); |
— | — | @@ -1721,9 +1721,13 @@ |
1722 | 1722 | return; |
1723 | 1723 | } |
1724 | 1724 | |
| 1725 | + $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) ); |
| 1726 | + |
1725 | 1727 | # Better double-check that it hasn't been deleted yet! |
1726 | | - $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) ); |
1727 | | - if( !$this->mTitle->exists() ) { |
| 1728 | + $dbw =& wfGetDB( DB_MASTER ); |
| 1729 | + $conds = $this->mTitle->pageCond(); |
| 1730 | + $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname ); |
| 1731 | + if ( $latest === false ) { |
1728 | 1732 | $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); |
1729 | 1733 | return; |
1730 | 1734 | } |
— | — | @@ -1735,39 +1739,31 @@ |
1736 | 1740 | |
1737 | 1741 | # determine whether this page has earlier revisions |
1738 | 1742 | # and insert a warning if it does |
1739 | | - # we select the text because it might be useful below |
1740 | | - $dbr =& $this->getDB(); |
1741 | | - $ns = $this->mTitle->getNamespace(); |
1742 | | - $title = $this->mTitle->getDBkey(); |
1743 | | - $revisions = $dbr->select( array( 'page', 'revision' ), |
1744 | | - array( 'rev_id', 'rev_user_text' ), |
1745 | | - array( |
1746 | | - 'page_namespace' => $ns, |
1747 | | - 'page_title' => $title, |
1748 | | - 'rev_page = page_id' |
1749 | | - ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'rev_timestamp DESC' ) ) |
1750 | | - ); |
1751 | | - |
1752 | | - if( $dbr->numRows( $revisions ) > 1 && !$confirm ) { |
| 1743 | + $maxRevisions = 20; |
| 1744 | + $authors = $this->getLastNAuthors( $maxRevisions, $latest ); |
| 1745 | + |
| 1746 | + if( count( $authors ) > 1 && !$confirm ) { |
1753 | 1747 | $skin=$wgUser->getSkin(); |
1754 | 1748 | $wgOut->addHTML('<b>'.wfMsg('historywarning')); |
1755 | 1749 | $wgOut->addHTML( $skin->historyLink() .'</b>'); |
1756 | 1750 | } |
1757 | 1751 | |
| 1752 | + # If a single user is responsible for all revisions, find out who they are |
| 1753 | + if ( count( $authors ) == $maxRevisions ) { |
| 1754 | + // Query bailed out, too many revisions to find out if they're all the same |
| 1755 | + $authorOfAll = false; |
| 1756 | + } else { |
| 1757 | + $authorOfAll = reset( $authors ); |
| 1758 | + foreach ( $authors as $author ) { |
| 1759 | + if ( $authorOfAll != $author ) { |
| 1760 | + $authorOfAll = false; |
| 1761 | + break; |
| 1762 | + } |
| 1763 | + } |
| 1764 | + } |
1758 | 1765 | # Fetch article text |
1759 | 1766 | $rev = Revision::newFromTitle( $this->mTitle ); |
1760 | 1767 | |
1761 | | - # Fetch name(s) of contributors |
1762 | | - $rev_name = ''; |
1763 | | - $all_same_user = true; |
1764 | | - while( $row = $dbr->fetchObject( $revisions ) ) { |
1765 | | - if( $rev_name != '' && $rev_name != $row->rev_user_text ) { |
1766 | | - $all_same_user = false; |
1767 | | - } else { |
1768 | | - $rev_name = $row->rev_user_text; |
1769 | | - } |
1770 | | - } |
1771 | | - |
1772 | 1768 | if( !is_null( $rev ) ) { |
1773 | 1769 | # if this is a mini-text, we can paste part of it into the deletion reason |
1774 | 1770 | $text = $rev->getText(); |
— | — | @@ -1800,10 +1796,10 @@ |
1801 | 1797 | $text = preg_replace( "/[\n\r]/", '', $text ); |
1802 | 1798 | |
1803 | 1799 | if( !$blanked ) { |
1804 | | - if( !$all_same_user ) { |
| 1800 | + if( $authorOfAll === false ) { |
1805 | 1801 | $reason = wfMsgForContent( 'excontent', $text ); |
1806 | 1802 | } else { |
1807 | | - $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name ); |
| 1803 | + $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll ); |
1808 | 1804 | } |
1809 | 1805 | } else { |
1810 | 1806 | $reason = wfMsgForContent( 'exbeforeblank', $text ); |
— | — | @@ -1815,6 +1811,53 @@ |
1816 | 1812 | } |
1817 | 1813 | |
1818 | 1814 | /** |
| 1815 | + * Get the last N authors |
| 1816 | + * @param int $num Number of revisions to get |
| 1817 | + * @param string $revLatest The latest rev_id, selected from the master (optional) |
| 1818 | + * @return array Array of authors, duplicates not removed |
| 1819 | + */ |
| 1820 | + function getLastNAuthors( $num, $revLatest = 0 ) { |
| 1821 | + $fname = 'Article::getLastNAuthors'; |
| 1822 | + wfProfileIn( $fname ); |
| 1823 | + |
| 1824 | + // First try the slave |
| 1825 | + // If that doesn't have the latest revision, try the master |
| 1826 | + $continue = 2; |
| 1827 | + $db =& wfGetDB( DB_SLAVE ); |
| 1828 | + do { |
| 1829 | + $res = $db->select( array( 'page', 'revision' ), |
| 1830 | + array( 'rev_id', 'rev_user_text' ), |
| 1831 | + array( |
| 1832 | + 'page_namespace' => $this->mTitle->getNamespace(), |
| 1833 | + 'page_title' => $this->mTitle->getDBkey(), |
| 1834 | + 'rev_page = page_id' |
| 1835 | + ), $fname, $this->getSelectOptions( array( |
| 1836 | + 'ORDER BY' => 'rev_timestamp DESC', |
| 1837 | + 'LIMIT' => $num |
| 1838 | + ) ) |
| 1839 | + ); |
| 1840 | + if ( !$res ) { |
| 1841 | + wfProfileOut( $fname ); |
| 1842 | + return array(); |
| 1843 | + } |
| 1844 | + $row = $db->fetchObject( $res ); |
| 1845 | + if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) { |
| 1846 | + $db =& wfGetDB( DB_MASTER ); |
| 1847 | + $continue--; |
| 1848 | + } else { |
| 1849 | + $continue = 0; |
| 1850 | + } |
| 1851 | + } while ( $continue ); |
| 1852 | + |
| 1853 | + $authors = array( $row->rev_user_text ); |
| 1854 | + while ( $row = $db->fetchObject( $res ) ) { |
| 1855 | + $authors[] = $row->rev_user_text; |
| 1856 | + } |
| 1857 | + wfProfileOut( $fname ); |
| 1858 | + return $authors; |
| 1859 | + } |
| 1860 | + |
| 1861 | + /** |
1819 | 1862 | * Output deletion confirmation dialog |
1820 | 1863 | */ |
1821 | 1864 | function confirmDelete( $par, $reason ) { |
— | — | @@ -2503,7 +2546,7 @@ |
2504 | 2547 | $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) ); |
2505 | 2548 | } |
2506 | 2549 | } else { |
2507 | | - $dbr =& $this->getDB( DB_SLAVE ); |
| 2550 | + $dbr =& wfGetDB( DB_SLAVE ); |
2508 | 2551 | $wl_clause = array( |
2509 | 2552 | 'wl_title' => $page->getDBkey(), |
2510 | 2553 | 'wl_namespace' => $page->getNamespace() ); |
— | — | @@ -2545,7 +2588,7 @@ |
2546 | 2589 | return false; |
2547 | 2590 | } |
2548 | 2591 | |
2549 | | - $dbr =& $this->getDB( DB_SLAVE ); |
| 2592 | + $dbr =& wfGetDB( DB_SLAVE ); |
2550 | 2593 | |
2551 | 2594 | $rev_clause = array( 'rev_page' => $id ); |
2552 | 2595 | $fname = 'Article::pageCountInfo'; |