2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
6 # if we have jessie-backports, we need to use it.
7 if ! apt-get
install -t jessie-backports certbot python-certbot-apache
; then
8 apt-get
install certbot python-certbot-apache
11 # <source lang="bash">
12 # identify if this is a debian based distro
13 isdeb
() { command -v apt
&>/dev
/null
; }
14 # tee unique. append each stdin line if it does not exist in the file
18 for line
in "${MAPFILE[@]}"; do
19 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
23 # get and reset an extension/skin repository, and enable it
26 local original_pwd
="$PWD"
28 local re
='[^/]*/[^/]*$' # last 2 parts of path
30 target
=$mw/${BASH_REMATCH[0]}
31 if [[ ! -e $target/.git
]]; then
32 git clone
$url $target
35 echo "mw-ext error: failed cd $target";
39 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
47 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/extensions
/$ext
48 if [[ -e $mw/extensions
/$ext/extension.json
]]; then
51 wfLoadExtension( '$ext' );
55 require_once( "\$IP/extensions/$ext/$ext.php" );
59 # --quick is quicker than default flags,
60 # but still add a sleep to make sure everything works right
61 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
65 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/skins
/$skin
66 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
67 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
69 \$wgDefaultSkin = "${skin,,*}";
70 wfLoadSkin( '$skin' );
72 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
75 if command -v apt
&>/dev
/null
; then
82 # <source lang="bash">
83 # From here on out, exit if a command fails.
84 # This will prevent us from not noticing an important failure.
85 # We recommend setting this for the entire installation session.
86 # If you are running commands interactively, it might be best to
87 # put it in your ~/.bashrc temporarily.
89 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
94 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
96 DEBIAN_FRONTEND
=noninteractive apt-get
install -y imagemagick curl
97 if apt-get
install -s mediawiki
&>/dev
/null
; then
99 if apt-get
install -s php7.0
-apcu &>/dev
/null
; then
102 # mediawiki is packaged in jessie backports & stretch
103 DEBIAN_FRONTEND
=noninteractive apt-get
-y install $apcu mediawiki
105 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
106 if apt-get
install -s php7.0
&>/dev
/null
; then
107 # note, 7.0 is untested by the editor here, since it's not
108 # available in debian 8. it's listed as supported
109 # in the mediawiki page.
110 # noninteractive to avoid mysql password prompt.
111 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
112 default-mysql-server \
113 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
114 php7.0
-apcu php7.0
-mbstring
116 # note: mbstring is recommended, but it's not available for php5 in
118 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
119 default-mysql-server \
120 php5 php5-mysql libapache2-mod-php5 php5-apcu
123 service apache2 restart
126 # fedora deps are missing a database, so some is translated from debian packages
127 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
129 systemctl restart mariadb.service
130 systemctl
enable mariadb.service
131 systemctl
enable httpd.service
132 systemctl restart httpd.service
136 # skip if we already set the root pass and are on pre-debian 9.
137 if ! echo exit|mysql
-uroot "-p$dbpass"; then
138 # Note: we set a root password here, but in debian 9+, it is ignored;
139 # only the local user root can login, and any password is accepted.
140 # We answer these interactive prompts:
141 # Enter current password for root (enter for none):
142 # Set root password? [Y/n]
144 # Re-enter new password:
145 # Remove anonymous users? [Y/n]
146 # Disallow root login remotely? [Y/n]
147 # Remove test database and access to it? [Y/n]
148 # Reload privilege tables now? [Y/n]
149 # Note, I had 1 less newline at the start when doing ubuntu 14.04,
150 # compared to debian 8, so can't say this is especially portable.
151 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
153 mysql
-uroot "-p$dbpass" <<EOF
154 GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost' IDENTIFIED BY '$dbpass';
157 # <source lang="bash">
160 # this will just fail if it already exists which is fine
161 if [[ ! -e .git
]]; then
162 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
164 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
167 git checkout
-f origin
/$mw_branch
169 # apply librejs patch
170 curl
"https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" |
patch -r - -N -p1
171 # Get the php libraries wmf uses. Based on:
172 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
173 if [[ ! -e vendor
/.git
]]; then
174 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
177 git checkout
-f origin
/$mw_branch
180 # Drop any previous database which may have been installed while testing.
181 # If upgrading, we should have a db backup which will get restored.
182 # https://www.mediawiki.org/wiki/Manual:Upgrading
183 mysql
-uroot "-p$dbpass" <<'EOF' ||:
184 drop database my_wiki;
187 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
188 --dbuser wikiuser
--dbpass $dbpass "$mwdescription" "$wikiuser"
190 # lock down the wiki to only the initial owner until anti-spam measures are put in place
191 # limit edits to registered users
192 $wgGroupPermissions['*']['edit'] = false;
193 # don't allow any account creation
194 $wgGroupPermissions['*']['createaccount'] = false;
197 # <source lang="bash">
202 # for me, this repo is on the same server and apache needs a sec after restarting
204 git clone https
://iankelling.org
/git
/basic-https-conf
206 ServerAdmin $mw_email
208 # make the site's root url go to our main page
209 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
210 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
211 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
213 find -L $
(readlink
-f $mw) -name .htaccess \
214 |
while read line
; do
215 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
217 } | basic-https-conf
/web-conf
-r ${mw%/*} - apache2
$mwdomain
221 # <source lang="bash">
222 dd of
=$mw/..
/robots.txt
<<'EOF'
225 User-agent: ia_archiver
230 # <source lang="bash">
232 \$wgServer = "https://$mwdomain";
233 \$wgDBserver = "localhost";
234 \$wgRightsUrl = "$mw_RightsUrl";
235 \$wgRightsText = "$mw_RightsText";
236 \$wgRightsIcon = "$mw_RightsIcon";
239 # <source lang="bash">
241 \$wgPasswordSender = "$mw_email";
242 \$wgEmergencyContact = "$mw_email";
243 \$wgEnotifUserTalk = true; # UPO
244 \$wgEnotifWatchlist = true; # UPO
245 \$wgMainCacheType = CACHE_ACCEL;
246 \$wgEnableUploads = true;
247 \$wgUseInstantCommons = true;
251 # <source lang="bash">
253 # from https://www.mediawiki.org/wiki/Manual:Short_URL
254 $wgArticlePath = "/wiki/$1";
256 # https://www.mediawiki.org/wiki/Manual:Combating_spam
257 # check that url if our precautions don't work
258 # not using nofollow is good practice, as long as we avoid spam.
259 $wgNoFollowLinks = false;
260 # Allow user customization.
261 $wgAllowUserCss = true;
262 # use imagemagick over GD
263 $wgUseImageMagick = true;
264 # manual says this is not production ready, I think that is mostly
265 # because they are using MobileFrontend extension instead, which gives
266 # an even cleaner more minimal view, I plan to try setting it up
267 # sometime but this seems like a very nice improvement for now.
268 $wgVectorResponsive = true;
272 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
273 # Increase from default of 2M to 100M.
274 # This will at least allow high res pics etc.
275 php_ini
=$
(php
-r 'echo(php_ini_loaded_file());')
276 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
278 service apache2 restart
280 systemctl restart httpd.service
283 # if you were to install as a normal user, you would need this for images
284 # sudo usermod -aG $apache_user $USER
286 # this doesn't propogate right away
287 chgrp
-R $apache_user $mw/images
288 chmod -R g
+w
$mw/images
290 # <source lang="bash">
293 #$wgFooterIcons = null;
295 # Make the toolbox go into the drop down.
297 if ! git remote show ian-kelling
&>/dev
/null
; then
298 git remote add ian-kelling https
://iankelling.org
/git
/mediawiki-sidebar-patch
300 git fetch ian-kelling
301 git checkout ian-kelling
/${mw_branch}-toolbox-in-dropdown
303 # <source lang="bash">
304 mw-ext Cite CiteThisPage CheckUser CSS Echo Gadgets ImageMap Interwiki News \
305 Nuke ParserFunctions Poem Renameuser SyntaxHighlight_GeSHi Variables
307 # <source lang="bash">
309 # recommended setup script to account for existing users
310 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
312 # <source lang="bash">
314 apt-get
-y install php-wikidiff2
316 $wgExternalDiffEngine = 'wikidiff2';
318 dir
=$
(dirname $
(php
-r 'echo(php_ini_loaded_file());'))/..
/apache
2/conf.d
319 ln -sf ..
/..
/mods-available
/wikidiff2.ini
$dir
320 service apache2 restart
323 # <source lang="bash">
325 # php5-curl according to Math readme
328 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
331 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
332 ghostscript imagemagick ocaml
$curl_pkg make
334 # todo, php5-curl equivalent on fedora
335 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
337 service apache2 restart
339 cd $mw/extensions
/Math
/math
; make # makes texvc
340 cd $mw/extensions
/Math
/texvccheck
; make
343 # Enable MathJax as rendering option
344 $wgUseMathJax = true;
345 # Enable LaTeXML as rendering option
346 $wgMathValidModes[] = 'latexml';
347 # Set LaTeXML as default rendering option, because it is nicest
348 $wgDefaultUserOptions['math'] = 'latexml';
351 # <source lang="bash">
353 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
355 $wgEnableDnsBlacklist = true;
356 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
358 ini_set( 'pcre.backtrack_limit', '10M' );
359 $wgSpamBlacklistFiles = array(
360 "[[m:Spam blacklist]]",
361 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
366 # <source lang="bash">
367 mw-ext TitleBlacklist
368 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
370 $wgTitleBlacklistSources = array(
373 'src' => 'MediaWiki:Titleblacklist',
377 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
383 # <source lang="bash">
386 # Enable Wikieditor by default
387 $wgDefaultUserOptions['usebetatoolbar'] = 1;
388 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
390 # Display the Preview and Changes tabs
391 $wgDefaultUserOptions['wikieditor-preview'] = 1;
394 # <source lang="bash">
397 # Mediawiki setting dependency for CategoryTree
401 # <source lang="bash">
404 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
405 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
406 $wgGroupPermissions['*']['abusefilter-view'] = true;
407 $wgGroupPermissions['*']['abusefilter-log'] = true;
408 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
409 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
410 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
413 # <source lang="bash">
417 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
418 $wgCaptchaClass = 'QuestyCaptcha';
419 # only captcha on registration
420 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
421 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
423 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
425 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
426 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
431 # <source lang="bash">
432 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
434 # <source lang="bash">
436 if [[ ! -e ~
/pywikibot
/.git
]]; then
437 git clone
--recursive \
438 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
445 # <source lang="bash">
447 dd of
=user-config.py
<<EOF
449 usernames["$mwfamily"]['en'] = u'$wikiuser'
451 console_encoding = 'utf-8'
452 password_file = "secretsfile"
455 dd of
=secretsfile
<<EOF
456 ("$wikiuser", "$wikipass")
459 # it won't overrwrite an existing file. Remove if if one exists
460 rm -f pywikibot
/families
/${mwfamily}_family.py
462 apt-get
install -y python-requests
464 yum
-y install python-requests
467 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
469 # Note, this needed only for ssl site
470 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
471 def protocol(self, code):
475 # <source lang="bash">
478 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
482 site = pywikibot.Site()
484 page = pywikibot.Page(site, p)
486 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
487 page.save(force=True)
489 # Small/medium noncommercial wiki should be fine with no privacy policy
490 # based on https://www.mediawiki.org/wiki/Manual:Footer
491 x("MediaWiki:Privacy")
493 # licenses for uploads. Modified from the mediawiki's wiki
494 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
495 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
497 ** Unknown_copyright|I don't know exactly
498 ** PD|PD: public domain
499 ** CC BY|Creative Commons Attribution
500 ** CC BY-SA|Creative Commons Attribution ShareAlike
501 ** GFDL|GFDL: GNU Free Documentation License
502 ** GPL|GPL: GNU General Public License
503 ** LGPL|LGPL: GNU Lesser General Public License""")
504 x("MediaWiki:Copyright", '$mw_license')
505 x("MediaWiki:Mainpage-description", "$mwdescription")
509 # The rest of the settings are for the site style
511 # Remove various clutter
512 x("MediaWiki:Lastmodifiedat")
513 x("MediaWiki:Disclaimers")
514 x("MediaWiki:Viewcount")
515 x("MediaWiki:Aboutsite")
516 # remove these lines from sidebar
517 # ** recentchanges-url|recentchanges
518 # ** randompage-url|randompage
520 x("MediaWiki:Sidebar", """* navigation
521 ** mainpage|mainpage-description
527 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
528 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
529 /* adjust sidebar to just be home link and up top */
530 /* panel width increased to fit full wiki name. */
531 /* selectors other than final id are for increasing priority of rule */
532 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
533 div#footer, #mw-head-base, div#content { margin-left: 1em; }
534 #left-navigation { margin-left: 1em; }
537 /* logo, and toolbar hidden */
538 #p-logo, div#mw-navigation div#mw-panel #p-tb {
542 div#mw-content-text {
548 # this can spam a warning, so uniq it
549 python pwb.py
${mwfamily}_setup |
& uniq
551 # <source lang="bash">
552 s
=/etc
/cron.daily
/mediawiki_update
559 [[ -d $dir ]] || return 1
561 branch=$(git describe --all)
562 branch=${branch#remotes/}
564 new_head=$(git rev-parse $branch)
565 log=$(git log HEAD..$new_head)
566 if [[ ! $log ]]; then
571 git checkout -qf $new_head
575 for dir in extensions/* skins/* vendor; do
579 curl "https://iankelling.org/git/?p=mediawiki-librejs-patch;a=blob_plain;f=mediawiki-1.28-librejs.patch;hb=HEAD" | patch -r - -N -p1
581 php $mw/maintenance/update.php -q --quick