Skip to content

Instantly share code, notes, and snippets.

@rekyuu
Created November 14, 2021 05:38
Show Gist options
  • Save rekyuu/4c90eadec4ad7f63fc13aab3afbda329 to your computer and use it in GitHub Desktop.
Save rekyuu/4c90eadec4ad7f63fc13aab3afbda329 to your computer and use it in GitHub Desktop.
How to upgrade MediaWiki for the forgetful (me)
  1. Backup the wiki

    $ cp -R /srv/http/my-wiki /srv/http/beta-my-wiki
  2. Extract the new MediaWiki over the new site

    $ tar xf mediawiki-1.36.2.tar.gz
    $ sudo cp -TRv mediawiki-1.36.2/ /srv/http/beta-my-wiki/
    $ sudo chown -R http:http /srv/http/beta-my-wiki/
  3. Create new PostgreSQL database

    $ psql -h my-wiki.com -U postgres    
    CREATE DATABASE beta_my_wiki WITH TEMPLATE my_wiki;
    ALTER DATABASE beta_my_wiki OWNER TO wiki_owner;
    GRANT ALL PRIVILEGES ON DATABASE beta_my_wiki TO wiki_owner;
    
    \c beta_my_wiki
    
    GRANT ALL PRIVILEGES ON SCHEMA mediawiki TO wiki_owner;
    GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA mediawiki TO wiki_owner;
    GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA mediawiki TO wiki_owner;
  4. Update LocalSettings.php to reference the new database and domain. Be sure to grab $wgUpgradeKey while you're here!

    $wgServer = "//beta.my-wiki.com";
    
    ...
    
    $wgDBname = "beta_my_wiki";
    $wgDBuser = "wiki_owner";
    $wgDBpassword = "super-secret-password";
    
    ...
    
    $wgUpgradeKey = "s3cr37k3y";
  5. Validate the UPGRADE file in the wiki folder for extra steps. It shouldn't be more complicated than below though.

  6. Navigate to /mw-config/index.php to perform the DB upgrade.

Extra: Coming from 1.32 to 1.36, I had to perform these extra steps on my PostgreSQL database.

-- Grant privileges
GRANT ALL PRIVILEGES ON SCHEMA mediawiki TO wiki_owner;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA mediawiki TO wiki_owner;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA mediawiki TO wiki_owner;

-- Change mediawiki table owners
DO $$
DECLARE row RECORD;
BEGIN
    FOR row IN 
        SELECT schemaname, tablename 
        FROM pg_tables
        WHERE schemaname = 'mediawiki'
        AND tableowner = 'old_owner'
    LOOP
        EXECUTE FORMAT('ALTER TABLE %I.%I OWNER TO wiki_owner;', row.schemaname, row.tablename);
    END LOOP;
END;
$$;

-- Clean redirect
DELETE FROM mediawiki.redirect
WHERE ctid IN
(
    SELECT ctid
    FROM(
        SELECT *, ctid, row_number() OVER (PARTITION BY rd_from ORDER BY ctid)
        FROM mediawiki.redirect
    ) s
    WHERE row_number >= 2
);

-- Clean watchlist
DELETE FROM mediawiki.watchlist
WHERE ctid IN
(
    SELECT ctid
    FROM(
        SELECT *, ctid, row_number() OVER (PARTITION BY wl_title, wl_user ORDER BY ctid)
        FROM mediawiki.watchlist
    ) s
    WHERE row_number >= 2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment