Mass convert NULL -> null. Left strings and comments alone, obviously.
[lhc/web/wiklou.git] / includes / Article.php
index 6de0641..20c01c7 100644 (file)
@@ -60,7 +60,9 @@ class Article {
         */
        public static function newFromID( $id ) {
                $t = Title::newFromID( $id );
-               return $t == null ? null : new Article( $t );
+               # FIXME: doesn't inherit right
+               return $t == null ? null : new self( $t );
+               #return $t == null ? null : new static( $t ); // PHP 5.3
        }
 
        /**
@@ -497,7 +499,7 @@ class Article {
         *
         * @param $x Mixed: FIXME
         */
-       public function forUpdate( $x = NULL ) {
+       public function forUpdate( $x = null ) {
                return wfSetVar( $this->mForUpdate, $x );
        }
 
@@ -612,7 +614,7 @@ class Article {
                } else {
                        $titleObj = Title::newFromRedirect( $text );
                }
-               return $titleObj !== NULL;
+               return $titleObj !== null;
        }
 
        /**
@@ -943,11 +945,10 @@ class Article {
                $rcid = $wgRequest->getVal( 'rcid' );
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
                $purge = $wgRequest->getVal( 'action' ) == 'purge';
-               $htmldiff = $wgRequest->getBool( 'htmldiff' );
                $unhide = $wgRequest->getInt('unhide') == 1;
                $oldid = $this->getOldID();
 
-               $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff, $unhide );
+               $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $unhide );
                // DifferenceEngine directly fetched the revision:
                $this->mRevIdFetched = $de->mNewid;
                $de->showDiffPage( $diffOnly );
@@ -1595,7 +1596,7 @@ class Article {
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
                                'page_is_new'      => ($lastRevision === 0) ? 1 : 0,
-                               'page_is_redirect' => $rt !== NULL ? 1 : 0,
+                               'page_is_redirect' => $rt !== null ? 1 : 0,
                                'page_len'         => strlen( $text ),
                        ),
                        $conditions,
@@ -1687,7 +1688,7 @@ class Article {
         * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
         * @return string Complete article text, or null if error
         */
-       public function replaceSection( $section, $text, $summary = '', $edittime = NULL ) {
+       public function replaceSection( $section, $text, $summary = '', $edittime = null ) {
                wfProfileIn( __METHOD__ );
                if( strval( $section ) == '' ) {
                        // Whole-page edit; let the whole text through
@@ -2255,7 +2256,9 @@ class Article {
         * @return bool true on success
         */
        public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
-               global $wgUser, $wgRestrictionTypes, $wgContLang;
+               global $wgUser, $wgContLang;
+               
+               $restrictionTypes = $this->mTitle->getRestrictionTypes();
 
                $id = $this->mTitle->getArticleID();
                if ( $id <= 0 ) {
@@ -2285,7 +2288,7 @@ class Article {
                $current = array();
                $updated = Article::flattenRestrictions( $limit );
                $changed = false;
-               foreach( $wgRestrictionTypes as $action ) {
+               foreach( $restrictionTypes as $action ) {
                        if( isset( $expiry[$action] ) ) {
                                # Get current restrictions on $action
                                $aLimits = $this->mTitle->getRestrictions( $action );
@@ -2557,7 +2560,13 @@ class Article {
                $conds = $this->mTitle->pageCond();
                $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
                if( $latest === false ) {
-                       $wgOut->showFatalError( wfMsgExt( 'cannotdelete', array( 'parse' ) ) );
+                       $wgOut->showFatalError(
+                               Html::rawElement(
+                                       'div',
+                                       array( 'class' => 'error mw-error-cannotdelete' ),
+                                       wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+                               )
+                       );
                        $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
                        LogEventsList::showLogExtract(
                                $wgOut,
@@ -2578,7 +2587,7 @@ class Article {
 
                if( $confirm ) {
                        $this->doDelete( $reason, $suppress );
-                       if( $wgRequest->getCheck( 'wpWatch' ) ) {
+                       if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
                                $this->doWatch();
                        } elseif( $this->mTitle->userIsWatching() ) {
                                $this->doUnwatch();
@@ -2592,10 +2601,16 @@ class Article {
 
                // If the page has a history, insert a warning
                if( $hasHistory && !$confirm ) {
+                       global $wgLang;
                        $skin = $wgUser->getSkin();
-                       $wgOut->addHTML( '<strong>' . wfMsgExt( 'historywarning', array( 'parseinline' ) ) . ' ' . $skin->historyLink() . '</strong>' );
+                       $revisions = $this->estimateRevisionCount();
+                       $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
+                               wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
+                               wfMsgHtml( 'word-separator' ) . $skin->historyLink() .
+                               '</strong>'
+                       );
                        if( $bigHistory ) {
-                               global $wgLang, $wgDeleteRevisionsLimit;
+                               global $wgDeleteRevisionsLimit;
                                $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
                                        array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
                        }
@@ -2736,14 +2751,19 @@ class Article {
                                        'autofocus'
                                ) ) .
                                "</td>
-                       </tr>
+                       </tr>";
+               # Dissalow watching is user is not logged in
+               if( $wgUser->isLoggedIn() ) {
+                       $form .= "
                        <tr>
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'watchthis' ),
                                                'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
                                "</td>
-                       </tr>
+                       </tr>";
+               }
+               $form .= "
                        $suppress
                        <tr>
                                <td></td>
@@ -2801,7 +2821,13 @@ class Article {
                        }
                } else {
                        if( $error == '' ) {
-                               $wgOut->showFatalError( wfMsgExt( 'cannotdelete', array( 'parse' ) ) );
+                               $wgOut->showFatalError(
+                                       Html::rawElement(
+                                               'div',
+                                               array( 'class' => 'error mw-error-cannotdelete' ),
+                                               wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+                                       )
+                               );
                                $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
                                LogEventsList::showLogExtract(
                                        $wgOut,
@@ -3352,6 +3378,13 @@ class Article {
                        return;
                }
 
+               $unhide = $wgRequest->getInt('unhide') == 1 &&
+                       $wgUser->matchEditToken( $wgRequest->getVal('token'), $oldid );
+               # Cascade unhide param in links for easy deletion browsing
+               $extraParams = array();
+               if( $wgRequest->getVal('unhide') ) {
+                       $extraParams['unhide'] = 1;
+               }
                $revision = Revision::newFromId( $oldid );
 
                $current = ( $oldid == $this->mLatest );
@@ -3365,7 +3398,7 @@ class Article {
                                $this->mTitle,
                                wfMsgHtml( 'currentrevisionlink' ),
                                array(),
-                               array(),
+                               $extraParams,
                                array( 'known', 'noclasses' )
                        );
                $curdiff = $current
@@ -3377,7 +3410,7 @@ class Article {
                                array(
                                        'diff' => 'cur',
                                        'oldid' => $oldid
-                               ),
+                               ) + $extraParams,
                                array( 'known', 'noclasses' )
                        );
                $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
@@ -3389,7 +3422,7 @@ class Article {
                                array(
                                        'direction' => 'prev',
                                        'oldid' => $oldid
-                               ),
+                               ) + $extraParams,
                                array( 'known', 'noclasses' )
                        )
                        : wfMsgHtml( 'previousrevision' );
@@ -3401,7 +3434,7 @@ class Article {
                                array(
                                        'diff' => 'prev',
                                        'oldid' => $oldid
-                               ),
+                               ) + $extraParams,
                                array( 'known', 'noclasses' )
                        )
                        : wfMsgHtml( 'diff' );
@@ -3414,7 +3447,7 @@ class Article {
                                array(
                                        'direction' => 'next',
                                        'oldid' => $oldid
-                               ),
+                               ) + $extraParams,
                                array( 'known', 'noclasses' )
                        );
                $nextdiff = $current
@@ -3426,35 +3459,27 @@ class Article {
                                array(
                                        'diff' => 'next',
                                        'oldid' => $oldid
-                               ),
+                               ) + $extraParams,
                                array( 'known', 'noclasses' )
                        );
 
-               $cdel='';
-               // Don't show useless link to people who cannot hide revisions
-               if( $wgUser->isAllowed('deleterevision') || ($revision->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
+               $cdel = '';
+               // User can delete revisions or view deleted revisions...
+               $canHide = $wgUser->isAllowed( 'deleterevision' );
+               if( $canHide || ($revision->getVisibility() && $wgUser->isAllowed('deletedhistory')) ) {
                        if( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
-                       // If revision was hidden from sysops
-                               $cdel = wfMsgHtml( 'rev-delundel' );
+                               $cdel = $sk->revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
                        } else {
-                               $cdel = $sk->link(
-                                       SpecialPage::getTitleFor( 'Revisiondelete' ),
-                                       wfMsgHtml('rev-delundel'),
-                                       array(),
-                                       array(
-                                               'type' => 'revision',
-                                               'target' => urlencode( $this->mTitle->getPrefixedDbkey() ),
-                                               'ids' => urlencode( $oldid )
-                                       ),
-                                       array( 'known', 'noclasses' )
+                               $query = array(
+                                       'type'   => 'revision',
+                                       'target' => $this->mTitle->getPrefixedDbkey(),
+                                       'ids'    => $oldid
                                );
-                               // Bolden oversighted content
-                               if( $revision->isDeleted( Revision::DELETED_RESTRICTED ) )
-                                       $cdel = "<strong>$cdel</strong>";
+                               $cdel = $sk->revDeleteLink( $query, $revision->isDeleted(File::DELETED_RESTRICTED), $canHide );
                        }
-                       $cdel = "(<small>$cdel</small>) ";
+                       $cdel .= ' ';
                }
-               $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $oldid );
+
                # Show user links if allowed to see them. If hidden, then show them only if requested...
                $userlinks = $sk->revUserTools( $revision, !$unhide );
 
@@ -4074,7 +4099,7 @@ class Article {
                }
                $insertRows = array();
                foreach( $insertCats as $cat ) {
-                       $insertRows[] = array(  'cat_id' => $dbw->nextSequenceValue( 'category_id_seq' ),
+                       $insertRows[] = array(  'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
                                                                                                                        'cat_title' => $cat );
                }
                $dbw->insert( 'category', $insertRows, __METHOD__, 'IGNORE' );