r12492 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12491‎ | r12492 | r12493 >
Date:01:25, 8 January 2006
Author:timstarling
Status:old
Tags:
Comment:
Use wfGetDB(DB_SLAVE) when appropriate. Changed deletion summary autogeneration to make it cheaper and more slave-friendly.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -576,7 +576,7 @@
577577 function getCount() {
578578 if ( -1 == $this->mCounter ) {
579579 $id = $this->getID();
580 - $dbr =& $this->getDB();
 580+ $dbr =& wfGetDB( DB_SLAVE );
581581 $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
582582 'Article::getCount', $this->getSelectOptions() );
583583 }
@@ -690,7 +690,7 @@
691691
692692 $title = $this->mTitle;
693693 $contribs = array();
694 - $dbr =& $this->getDB();
 694+ $dbr =& wfGetDB( DB_SLAVE );
695695 $revTable = $dbr->tableName( 'revision' );
696696 $userTable = $dbr->tableName( 'user' );
697697 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
@@ -1721,9 +1721,13 @@
17221722 return;
17231723 }
17241724
 1725+ $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
 1726+
17251727 # 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 ) {
17281732 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
17291733 return;
17301734 }
@@ -1735,39 +1739,31 @@
17361740
17371741 # determine whether this page has earlier revisions
17381742 # 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 ) {
17531747 $skin=$wgUser->getSkin();
17541748 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
17551749 $wgOut->addHTML( $skin->historyLink() .'</b>');
17561750 }
17571751
 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+ }
17581765 # Fetch article text
17591766 $rev = Revision::newFromTitle( $this->mTitle );
17601767
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 -
17721768 if( !is_null( $rev ) ) {
17731769 # if this is a mini-text, we can paste part of it into the deletion reason
17741770 $text = $rev->getText();
@@ -1800,10 +1796,10 @@
18011797 $text = preg_replace( "/[\n\r]/", '', $text );
18021798
18031799 if( !$blanked ) {
1804 - if( !$all_same_user ) {
 1800+ if( $authorOfAll === false ) {
18051801 $reason = wfMsgForContent( 'excontent', $text );
18061802 } else {
1807 - $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
 1803+ $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
18081804 }
18091805 } else {
18101806 $reason = wfMsgForContent( 'exbeforeblank', $text );
@@ -1815,6 +1811,53 @@
18161812 }
18171813
18181814 /**
 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+ /**
18191862 * Output deletion confirmation dialog
18201863 */
18211864 function confirmDelete( $par, $reason ) {
@@ -2503,7 +2546,7 @@
25042547 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
25052548 }
25062549 } else {
2507 - $dbr =& $this->getDB( DB_SLAVE );
 2550+ $dbr =& wfGetDB( DB_SLAVE );
25082551 $wl_clause = array(
25092552 'wl_title' => $page->getDBkey(),
25102553 'wl_namespace' => $page->getNamespace() );
@@ -2545,7 +2588,7 @@
25462589 return false;
25472590 }
25482591
2549 - $dbr =& $this->getDB( DB_SLAVE );
 2592+ $dbr =& wfGetDB( DB_SLAVE );
25502593
25512594 $rev_clause = array( 'rev_page' => $id );
25522595 $fname = 'Article::pageCountInfo';

Status & tagging log