Merge "Localisation updates from http://translatewiki.net."
[lhc/web/wiklou.git] / includes / job / DoubleRedirectJob.php
index dd63a85..4e02258 100644 (file)
@@ -1,6 +1,21 @@
 <?php
 /**
- * Job to fix double redirects after moving a page
+ * Job to fix double redirects after moving a page.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup JobQueue
@@ -19,19 +34,19 @@ class DoubleRedirectJob extends Job {
         */
        static $user;
 
-       /** 
+       /**
         * Insert jobs into the job queue to fix redirects to the given title
         * @param $reason String: the reason for the fix, see message double-redirect-fixed-<reason>
         * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed
-        * @param $destTitle Not used
+        * @param $destTitle bool Not used
         */
        public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) {
                # Need to use the master to get the redirect table updated in the same transaction
                $dbw = wfGetDB( DB_MASTER );
-               $res = $dbw->select( 
-                       array( 'redirect', 'page' ), 
-                       array( 'page_namespace', 'page_title' ), 
-                       array( 
+               $res = $dbw->select(
+                       array( 'redirect', 'page' ),
+                       array( 'page_namespace', 'page_title' ),
+                       array(
                                'page_id = rd_from',
                                'rd_namespace' => $redirTitle->getNamespace(),
                                'rd_title' => $redirTitle->getDBkey()
@@ -46,7 +61,7 @@ class DoubleRedirectJob extends Job {
                                continue;
                        }
 
-                       $jobs[] = new self( $title, array( 
+                       $jobs[] = new self( $title, array(
                                'reason' => $reason,
                                'redirTitle' => $redirTitle->getPrefixedDBkey() ) );
                        # Avoid excessive memory usage
@@ -65,6 +80,9 @@ class DoubleRedirectJob extends Job {
                $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : '';
        }
 
+       /**
+        * @return bool
+        */
        function run() {
                if ( !$this->redirTitle ) {
                        $this->setLastError( 'Invalid title' );
@@ -103,13 +121,13 @@ class DoubleRedirectJob extends Job {
                }
 
                # Preserve fragment (bug 14904)
-               $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), 
+               $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
                        $currentDest->getFragment() );
 
                # Fix the text
                # Remember that redirect pages can have categories, templates, etc.,
                # so the regex has to be fairly general
-               $newText = preg_replace( '/ \[ \[  [^\]]*  \] \] /x', 
+               $newText = preg_replace( '/ \[ \[  [^\]]*  \] \] /x',
                        '[[' . $newTitle->getFullText() . ']]',
                        $text, 1 );
 
@@ -122,10 +140,10 @@ class DoubleRedirectJob extends Job {
                global $wgUser;
                $oldUser = $wgUser;
                $wgUser = $this->getUser();
-               $article = new Article( $this->title );
-               $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, 
+               $article = WikiPage::factory( $this->title );
+               $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason,
                        $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText() );
-               $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC );
+               $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $this->getUser() );
                $wgUser = $oldUser;
 
                return true;
@@ -133,7 +151,10 @@ class DoubleRedirectJob extends Job {
 
        /**
         * Get the final destination of a redirect
-        * @return false if the specified title is not a redirect, or if it is a circular redirect
+        *
+        * @param $title Title
+        *
+        * @return bool if the specified title is not a redirect, or if it is a circular redirect
         */
        public static function getFinalDestination( $title ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -149,10 +170,10 @@ class DoubleRedirectJob extends Job {
                        }
                        $seenTitles[$titleText] = true;
 
-                       $row = $dbw->selectRow( 
+                       $row = $dbw->selectRow(
                                array( 'redirect', 'page' ),
                                array( 'rd_namespace', 'rd_title' ),
-                               array( 
+                               array(
                                        'rd_from=page_id',
                                        'page_namespace' => $title->getNamespace(),
                                        'page_title' => $title->getDBkey()
@@ -169,10 +190,12 @@ class DoubleRedirectJob extends Job {
 
        /**
         * Get a user object for doing edits, from a request-lifetime cache
+        * @return User
         */
        function getUser() {
                if ( !self::$user ) {
                        self::$user = User::newFromName( wfMsgForContent( 'double-redirect-fixer' ), false );
+                       # FIXME: newFromName could return false on a badly configured wiki.
                        if ( !self::$user->isLoggedIn() ) {
                                self::$user->addToDatabase();
                        }