Kill some trailing whitespace
[lhc/web/wiklou.git] / includes / Article.php
index 1b91814..9e12611 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
  * File for articles
- * @package MediaWiki
  */
 
 /**
@@ -11,7 +10,6 @@
  * Note: edit user interface and cache support functions have been
  * moved to separate EditPage and HTMLFileCache classes.
  *
- * @package MediaWiki
  */
 class Article {
        /**@{{
@@ -43,7 +41,7 @@ class Article {
         * @param $title Reference to a Title object.
         * @param $oldId Integer revision ID, null to fetch from request, zero for current
         */
-       function Article( &$title, $oldId = null ) {
+       function __construct( &$title, $oldId = null ) {
                $this->mTitle =& $title;
                $this->mOldId = $oldId;
                $this->clear();
@@ -247,7 +245,7 @@ class Article {
         * @param array    $conditions
         * @private
         */
-       function pageData( &$dbr, $conditions ) {
+       function pageData( $dbr, $conditions ) {
                $fields = array(
                                'page_id',
                                'page_namespace',
@@ -273,7 +271,7 @@ class Article {
         * @param Database $dbr
         * @param Title $title
         */
-       function pageDataFromTitle( &$dbr, $title ) {
+       function pageDataFromTitle( $dbr, $title ) {
                return $this->pageData( $dbr, array(
                        'page_namespace' => $title->getNamespace(),
                        'page_title'     => $title->getDBkey() ) );
@@ -283,7 +281,7 @@ class Article {
         * @param Database $dbr
         * @param int $id
         */
-       function pageDataFromId( &$dbr, $id ) {
+       function pageDataFromId( $dbr, $id ) {
                return $this->pageData( $dbr, array( 'page_id' => $id ) );
        }
 
@@ -296,7 +294,7 @@ class Article {
         */
        function loadPageData( $data = 'fromdb' ) {
                if ( $data === 'fromdb' ) {
-                       $dbr =& $this->getDB();
+                       $dbr = $this->getDB();
                        $data = $this->pageDataFromId( $dbr, $this->getId() );
                }
 
@@ -334,7 +332,7 @@ class Article {
                        return $this->mContent;
                }
 
-               $dbr =& $this->getDB();
+               $dbr = $this->getDB();
 
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
@@ -406,7 +404,7 @@ class Article {
         *
         * @return Database
         */
-       function &getDB() {
+       function getDB() {
                return wfGetDB( DB_MASTER );
        }
 
@@ -455,7 +453,7 @@ class Article {
                        if ( $id == 0 ) {
                                $this->mCounter = 0;
                        } else {
-                               $dbr =& wfGetDB( DB_SLAVE );
+                               $dbr = wfGetDB( DB_SLAVE );
                                $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
                                        'Article::getCount', $this->getSelectOptions() );
                        }
@@ -573,7 +571,7 @@ class Article {
                # XXX: this is expensive; cache this info somewhere.
 
                $contribs = array();
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
                $user = $this->getUser();
@@ -720,9 +718,9 @@ class Article {
                }
 
                $outputDone = false;
+               wfRunHooks( 'ArticleViewHeader', array( &$this ) );
                if ( $pcache ) {
                        if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
-                               wfRunHooks( 'ArticleViewHeader', array( &$this ) );
                                $outputDone = true;
                        }
                }
@@ -769,11 +767,6 @@ class Article {
                        }
                }
                if( !$outputDone ) {
-                       /**
-                        * @fixme: this hook doesn't work most of the time, as it doesn't
-                        * trigger when the parser cache is used.
-                        */
-                       wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
                        $wgOut->setRevisionId( $this->getRevIdFetched() );
                        # wrap user css and user js in pre and don't parse
                        # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
@@ -861,7 +854,7 @@ class Article {
        function addTrackbacks() {
                global $wgOut, $wgUser;
 
-               $dbr =& wfGetDB(DB_SLAVE);
+               $dbr = wfGetDB(DB_SLAVE);
                $tbs = $dbr->select(
                                /* FROM   */ 'trackbacks',
                                /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
@@ -907,7 +900,7 @@ class Article {
                        return;
                }
 
-               $db =& wfGetDB(DB_MASTER);
+               $db = wfGetDB(DB_MASTER);
                $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
                $wgTitle->invalidateCache();
                $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
@@ -973,11 +966,10 @@ class Article {
         * Best if all done inside a transaction.
         *
         * @param Database $dbw
-        * @param string   $restrictions
         * @return int     The newly created page_id key
         * @private
         */
-       function insertOn( &$dbw, $restrictions = '' ) {
+       function insertOn( $dbw ) {
                wfProfileIn( __METHOD__ );
 
                $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
@@ -986,6 +978,7 @@ class Article {
                        'page_namespace'    => $this->mTitle->getNamespace(),
                        'page_title'        => $this->mTitle->getDBkey(),
                        'page_counter'      => 0,
+                       'page_restrictions' => '',
                        'page_is_redirect'  => 0, # Will set this shortly...
                        'page_is_new'       => 1,
                        'page_random'       => wfRandom(),
@@ -1141,7 +1134,7 @@ class Article {
                        if( is_null( $edittime ) ) {
                                $rev = Revision::newFromTitle( $this->mTitle );
                        } else {
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
                        if( is_null( $rev ) ) {
@@ -1184,7 +1177,7 @@ class Article {
 
                $this->doEdit( $text, $summary, $flags );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                if ($watchthis) {
                        if (!$this->mTitle->userIsWatching()) {
                                $dbw->begin();
@@ -1211,7 +1204,7 @@ class Article {
 
                $good = $this->doEdit( $text, $summary, $flags );
                if ( $good ) {
-                       $dbw =& wfGetDB( DB_MASTER );
+                       $dbw = wfGetDB( DB_MASTER );
                        if ($watchthis) {
                                if (!$this->mTitle->userIsWatching()) {
                                        $dbw->begin();
@@ -1303,7 +1296,7 @@ class Article {
                $text = $this->preSaveTransform( $text );
                $newsize = strlen( $text );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $now = wfTimestampNow();
 
                if ( $flags & EDIT_UPDATE ) {
@@ -1636,7 +1629,7 @@ class Article {
         */
        function protect() {
                $form = new ProtectionForm( $this );
-               $form->show();
+               $form->execute();
        }
 
        /**
@@ -1653,7 +1646,7 @@ class Article {
         * @param string $reason
         * @return bool true on success
         */
-       function updateRestrictions( $limit = array(), $reason = '', $cascade = 0 ) {
+       function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = null ) {
                global $wgUser, $wgRestrictionTypes, $wgContLang;
 
                $id = $this->mTitle->getArticleID();
@@ -1665,6 +1658,9 @@ class Article {
                        $cascade = false;
                }
 
+               // Take this opportunity to purge out expired restrictions
+               Title::purgeExpiredRestrictions();
+
                # FIXME: Same limitations as described in ProtectionForm.php (line 37);
                # we expect a single selection, but the schema allows otherwise.
                $current = array();
@@ -1676,29 +1672,43 @@ class Article {
 
                $changed = ( $current != $updated );
                $changed = $changed || ($this->mTitle->areRestrictionsCascading() != $cascade);
+               $changed = $changed || ($this->mTitle->mRestrictionsExpiry != $expiry);
                $protect = ( $updated != '' );
 
                # If nothing's changed, do nothing
                if( $changed ) {
                        if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
 
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
+
+                               $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
+
+                               $expiry_description = '';
+
+                               if ( $encodedExpiry != 'infinity' ) {
+                                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
+                               }
 
                                # Prepare a null revision to be added to the history
                                $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );
+
                                if( $reason )
                                        $comment .= ": $reason";
                                if( $protect )
                                        $comment .= " [$updated]";
+                               if ( $expiry_description && $protect )
+                                       $comment .= "$expiry_description";
+
                                $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
                                $nullRevId = $nullRevision->insertOn( $dbw );
 
                                # Update restrictions table
                                foreach( $limit as $action => $restrictions ) {
                                        if ($restrictions != '' ) {
-                                               $dbw->replace( 'page_restrictions', array( 'pr_pagetype'),
+                                               $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')),
                                                        array( 'pr_page' => $id, 'pr_type' => $action
-                                                               , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0 ), __METHOD__  );
+                                                               , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0
+                                                               , 'pr_expiry' => $encodedExpiry ), __METHOD__  );
                                        } else {
                                                $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
                                                        'pr_type' => $action ), __METHOD__ );
@@ -1727,7 +1737,7 @@ class Article {
                                }
 
                                if( $protect ) {
-                                       $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description" ) );
+                                       $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
                                } else {
                                        $log->addEntry( 'unprotect', $this->mTitle, $reason );
                                }
@@ -1789,7 +1799,7 @@ class Article {
                $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
 
                # Better double-check that it hasn't been deleted yet!
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $conds = $this->mTitle->pageCond();
                $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
                if ( $latest === false ) {
@@ -1891,7 +1901,7 @@ class Article {
                // First try the slave
                // If that doesn't have the latest revision, try the master
                $continue = 2;
-               $db =& wfGetDB( DB_SLAVE );
+               $db = wfGetDB( DB_SLAVE );
                do {
                        $res = $db->select( array( 'page', 'revision' ),
                                array( 'rev_id', 'rev_user_text' ),
@@ -1910,7 +1920,7 @@ class Article {
                        }
                        $row = $db->fetchObject( $res );
                        if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {
-                               $db =& wfGetDB( DB_MASTER );
+                               $db = wfGetDB( DB_MASTER );
                                $continue--;
                        } else {
                                $continue = 0;
@@ -1971,6 +1981,23 @@ class Article {
 </form>\n" );
 
                $wgOut->returnToMain( false );
+
+               $this->showLogExtract( $wgOut );
+       }
+
+
+       /**
+        * Fetch deletion log
+        */
+       function showLogExtract( &$out ) {
+               # Show relevant lines from the deletion log:
+               $out->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
+               $logViewer = new LogViewer(
+                       new LogReader(
+                               new FauxRequest(
+                                       array( 'page' => $this->mTitle->getPrefixedText(),
+                                              'type' => 'delete' ) ) ) );
+               $logViewer->showList( $out );
        }
 
 
@@ -2011,7 +2038,7 @@ class Article {
 
                wfDebug( __METHOD__."\n" );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $ns = $this->mTitle->getNamespace();
                $t = $this->mTitle->getDBkey();
                $id = $this->mTitle->getArticleID();
@@ -2046,6 +2073,7 @@ class Article {
                                'ar_text_id'    => 'rev_text_id',
                                'ar_text'       => '\'\'', // Be explicit to appease
                                'ar_flags'      => '\'\'', // MySQL's "strict mode"...
+                               'ar_len'                => 'rev_len'
                        ), array(
                                'page_id' => $id,
                                'page_id = rev_page'
@@ -2123,7 +2151,7 @@ class Article {
                        $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
                        return;
                }
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
 
                # Enhanced rollback, marks edits rc_bot=1
                $bot = $wgRequest->getBool( 'bot' );
@@ -2148,7 +2176,7 @@ class Article {
                        if( $current->getComment() != '') {
                                $wgOut->addHTML(
                                        wfMsg( 'editcomment',
-                                       htmlspecialchars( $current->getComment() ) ) );
+                                       $wgUser->getSkin()->formatComment( $current->getComment() ) ) );
                        }
                        return;
                }
@@ -2267,7 +2295,7 @@ class Article {
                                # Periodically flush old entries from the recentchanges table.
                                global $wgRCMaxAge;
 
-                               $dbw =& wfGetDB( DB_MASTER );
+                               $dbw = wfGetDB( DB_MASTER );
                                $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
                                $recentchanges = $dbw->tableName( 'recentchanges' );
                                $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
@@ -2320,7 +2348,7 @@ class Article {
         *
         * @param Revision $rev
         *
-        * @fixme This is a shitty interface function. Kill it and replace the
+        * @todo This is a shitty interface function. Kill it and replace the
         * other shitty functions like editUpdates and such so it's not needed
         * anymore.
         */
@@ -2491,7 +2519,7 @@ class Article {
        function quickEdit( $text, $comment = '', $minor = 0 ) {
                wfProfileIn( __METHOD__ );
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $dbw->begin();
                $revision = new Revision( array(
                        'page'       => $this->getId(),
@@ -2516,7 +2544,7 @@ class Article {
                $id = intval( $id );
                global $wgHitcounterUpdateFreq, $wgDBtype;
 
-               $dbw =& wfGetDB( DB_MASTER );
+               $dbw = wfGetDB( DB_MASTER );
                $pageTable = $dbw->tableName( 'page' );
                $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
@@ -2662,7 +2690,7 @@ class Article {
                                $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
                        }
                } else {
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $wl_clause = array(
                                'wl_title'     => $page->getDBkey(),
                                'wl_namespace' => $page->getNamespace() );
@@ -2704,7 +2732,7 @@ class Article {
                        return false;
                }
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
 
                $rev_clause = array( 'rev_page' => $id );
 
@@ -2738,7 +2766,7 @@ class Article {
                        return array();
                }
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( array( 'templatelinks' ),
                        array( 'tl_namespace', 'tl_title' ),
                        array( 'tl_from' => $id ),
@@ -2865,7 +2893,7 @@ class Article {
 
                        $tlTemplates = array();
 
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select( array( 'templatelinks' ),
                                array( 'tl_namespace', 'tl_title' ),
                                array( 'tl_from' => $id ),
@@ -2896,7 +2924,7 @@ class Article {
                                # Whee, link updates time.
                                $u = new LinksUpdate( $this->mTitle, $parserOutput );
 
-                               $dbw =& wfGetDb( DB_MASTER );
+                               $dbw = wfGetDb( DB_MASTER );
                                $dbw->begin();
 
                                $u->doUpdate();