2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
5 # identify if this is a debian based distro
6 isdeb
() { command -v apt
&>/dev
/null
; }
7 # tee unique. append each stdin line if it does not exist in the file
11 for line
in "${MAPFILE[@]}"; do
12 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
16 # get and reset an extension/skin repository, and enable it
19 local original_pwd
="$PWD"
21 local re
='[^/]*/[^/]*$'
23 target
=$mw/${BASH_REMATCH[0]}
24 if [[ ! -e $target/.git
]]; then
25 git clone
$url $target
28 echo "mw-ext error: failed cd $target";
32 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
40 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/extensions
/$ext
41 if [[ -e $mw/ext
/$ext/extension.json
]]; then
42 # new style extension. remove old style declaration
43 sed -i --follow-symlinks '#^require_once( "\\\$IP/extensions/\$ext/\$ext\.php" );#d' $mwc
45 wfLoadExtension( '$ext' );
49 require_once( "\$IP/extensions/$ext/$ext.php" );
53 # --quick is quicker than default flags,
54 # but still add a sleep to make sure everything works right
55 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
59 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/skins
/$skin
60 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
61 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
63 \$wgDefaultSkin = "${skin,,*}";
64 wfLoadSkin( '$skin' );
66 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
69 if command -v apt
&>/dev
/null
; then
76 # <source lang="bash">
77 # From here on out, exit if a command fails.
78 # This will prevent us from not noticing an important failure.
79 # We recommend setting this for the entire installation session.
80 # If you are running commands interactively, it might be best to
81 # put it in your ~/.bashrc temporarily.
83 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
88 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
90 apt-get
install -y imagemagick
91 if apt-get
install -s mediawiki
&>/dev
/null
; then
92 # in debian wheezy time-frame distros, mediawiki was packaged.
93 apt-get
-y install php-apc mediawiki php-mbstring
95 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
96 if apt-get
install -s php7.0
&>/dev
/null
; then
97 # note, 7.0 is untested by the editor here, since it's not
98 # available in debian 8. it's listed as supported
99 # in the mediawiki page.
100 # noninteractive to avoid mysql password prompt.
101 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
102 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
103 php7.0
-apcu php7.0
-mbstring
105 # note: mbstring is recommended, but it's not available for php5 in
107 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
108 php5 php5-mysql libapache2-mod-php5 php5-apcu
111 service apache2 restart
114 # fedora deps are missing a database, so some is translated from debian packages
115 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
117 systemctl restart mariadb.service
118 systemctl
enable mariadb.service
119 systemctl
enable httpd.service
120 systemctl restart httpd.service
124 # slightly different depending on if we already set the root pass
125 if echo exit|mysql
-u root
-p"$dbpass"; then
126 # answer interactive prompts:
127 # mysql root pass, change pass? no, remove anon users? (default, yes)
128 # disallow remote root (default, yes), reload? (default, yes)
129 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
131 # I had 1 less newline at the start when doing ubuntu 14.04,
132 # compared to debian 8, so can't say this is especially portable.
133 # It won't hurt if it fails.
134 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
137 # <source lang="bash">
140 # this will just fail if it already exists which is fine
141 if [[ ! -e .git
]]; then
142 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
144 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
147 git checkout
-f origin
/$mw_branch
149 # Get the php libraries wmf uses. Based on:
150 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
151 if [[ ! -e vendor
/.git
]]; then
152 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
155 git checkout
-f origin
/$mw_branch
158 # Drop any previous database which may have been installed while testing.
159 # If upgrading, we should have a db backup which will get restored.
160 # https://www.mediawiki.org/wiki/Manual:Upgrading
161 mysql
-u root
-p$dbpass <<'EOF' ||:
162 drop database my_wiki;
165 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
166 --dbuser root
--dbpass $dbpass "$mwdescription" "$wikiuser"
168 # lock down the wiki to only the initial owner until anti-spam measures are put in place
169 # limit edits to registered users
170 $wgGroupPermissions['*']['edit'] = false;
171 # don't allow any account creation
172 $wgGroupPermissions['*']['createaccount'] = false;
175 # <source lang="bash">
178 git_site
=https
://iankelling.org
/git
179 git clone
$git_site/acme-tiny-wrapper
183 acme-tiny-wrapper
/acme-tiny-wrapper
-t $mwdomain
185 git clone
$git_site/basic-https-conf
187 ServerAdmin $mw_email
189 # make the site's root url go to our main page
190 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
191 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
192 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
194 find -L $
(readlink
-f $mw) -name .htaccess \
195 |
while read line
; do
196 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
198 } | basic-https-conf
/apache-site
-r ${mw%/*} - $mwdomain
202 # <source lang="bash">
203 dd of
=$mw/..
/robots.txt
<<'EOF'
206 User-agent: ia_archiver
211 # <source lang="bash">
213 \$wgServer = "https://$mwdomain";
214 \$wgDBserver = "localhost";
215 \$wgRightsUrl = "$mw_RightsUrl";
216 \$wgRightsText = "$mw_RightsText";
217 \$wgRightsIcon = "$mw_RightsIcon";
220 # <source lang="bash">
222 \$wgPasswordSender = "$mw_email";
223 \$wgEmergencyContact = "$mw_email";
224 \$wgEnotifUserTalk = true; # UPO
225 \$wgEnotifWatchlist = true; # UPO
226 \$wgMainCacheType = CACHE_ACCEL;
227 \$wgEnableUploads = true;
228 \$wgUseInstantCommons = true;
231 # <source lang="bash">
233 # from https://www.mediawiki.org/wiki/Manual:Short_URL
234 $wgArticlePath = "/wiki/$1";
236 # https://www.mediawiki.org/wiki/Manual:Combating_spam
237 # check that url if our precautions don't work
238 # not using nofollow is good practice, as long as we avoid spam.
239 $wgNoFollowLinks = false;
240 # Allow user customization.
241 $wgAllowUserJs = true;
242 $wgAllowUserCss = true;
244 # use imagemagick over GD
245 $wgUseImageMagick = true;
249 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
250 # Increase from default of 2M to 100M.
251 # This will at least allow high res pics etc.
252 php_ini
=$
(php
-r 'echo(php_ini_loaded_file());')
253 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
255 service apache2 restart
257 systemctl restart httpd.service
260 # if you were to install as a normal user, you would need this for images
261 # sudo usermod -aG $apache_user $USER
263 # this doesn't propogate right away
264 chgrp
-R $apache_user $mw/images
265 chmod -R g
+w
$mw/images
267 # <source lang="bash">
270 #$wgFooterIcons = null;
272 # Make the toolbox go into the drop down.
274 if ! git remote show ian-kelling
&>/dev
/null
; then
275 git remote add ian-kelling https
://iankelling.org
/git
/forks
/Vector
277 git fetch ian-kelling
278 git checkout ian-kelling
/REL1_27-toolbox-in-dropdown
280 # <source lang="bash">
281 mw-ext Cite CiteThisPage CSS Echo Gadgets ImageMap Interwiki News \
282 Nuke ParserFunctions Poem SyntaxHighlight_GeSHi Variables
284 # <source lang="bash">
286 # recommended setup script to account for existing users
287 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
289 # <source lang="bash">
291 sudo
-u $apache_user php
$mw/extensions
/CheckUser
/install.php
; sleep 1
293 # <source lang="bash">
295 apt-get
-y install php-wikidiff2
297 $wgExternalDiffEngine = 'wikidiff2';
299 dir
=$
(dirname $
(php
-r 'echo(php_ini_loaded_file());'))/..
/apache
2/conf.d
300 ln -sf ..
/..
/mods-available
/wikidiff2.ini
$dir
301 service apache2 restart
304 # <source lang="bash">
306 # php5-curl according to Math readme
309 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
312 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
313 ghostscript imagemagick ocaml
$curl_pkg make
315 # todo, php5-curl equivalent on fedora
316 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
318 service apache2 restart
320 cd $mw/extensions
/Math
/math
; make # makes texvc
321 cd $mw/extensions
/Math
/texvccheck
; make
324 # Enable MathJax as rendering option
325 $wgUseMathJax = true;
326 # Enable LaTeXML as rendering option
327 $wgMathValidModes[] = 'latexml';
328 # Set LaTeXML as default rendering option, because it is nicest
329 $wgDefaultUserOptions['math'] = 'latexml';
332 # <source lang="bash">
334 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
336 $wgEnableDnsBlacklist = true;
337 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
339 ini_set( 'pcre.backtrack_limit', '10M' );
340 $wgSpamBlacklistFiles = array(
341 "[[m:Spam blacklist]]",
342 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
347 # <source lang="bash">
348 mw-ext TitleBlacklist
349 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
351 $wgTitleBlacklistSources = array(
354 'src' => 'MediaWiki:Titleblacklist',
358 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
364 # <source lang="bash">
367 # Enable Wikieditor by default
368 $wgDefaultUserOptions['usebetatoolbar'] = 1;
369 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
371 # Display the Preview and Changes tabs
372 $wgDefaultUserOptions['wikieditor-preview'] = 1;
375 # <source lang="bash">
378 # Mediawiki setting dependency for CategoryTree
382 # <source lang="bash">
385 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
386 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
387 $wgGroupPermissions['*']['abusefilter-view'] = true;
388 $wgGroupPermissions['*']['abusefilter-log'] = true;
389 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
390 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
391 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
394 # <source lang="bash">
398 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
399 $wgCaptchaClass = 'QuestyCaptcha';
400 # only captcha on registration
401 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
402 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
404 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
406 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
407 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
412 # <source lang="bash">
413 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
415 # <source lang="bash">
417 if [[ ! -e ~
/pywikibot
/.git
]]; then
418 git clone
--recursive \
419 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
426 # <source lang="bash">
428 dd of
=user-config.py
<<EOF
430 usernames["$mwfamily"]['en'] = u'$wikiuser'
432 console_encoding = 'utf-8'
433 password_file = "secretsfile"
436 dd of
=secretsfile
<<EOF
437 ("$wikiuser", "$wikipass")
440 # it won't overrwrite an existing file. Remove if if one exists
441 rm -f pywikibot
/families
/${mwfamily}_family.py
443 apt-get
install -y python-requests
445 yum
-y install python-requests
448 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
450 # Note, this needed only for ssl site
451 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
452 def protocol(self, code):
456 # <source lang="bash">
459 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
463 site = pywikibot.Site()
465 page = pywikibot.Page(site, p)
467 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
468 page.save(force=True)
470 # Small/medium noncommercial wiki should be fine with no privacy policy
471 # based on https://www.mediawiki.org/wiki/Manual:Footer
472 x("MediaWiki:Privacy")
474 # licenses for uploads. Modified from the mediawiki's wiki
475 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
476 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
478 ** Unknown_copyright|I don't know exactly
479 ** PD|PD: public domain
480 ** CC BY|Creative Commons Attribution
481 ** CC BY-SA|Creative Commons Attribution ShareAlike
482 ** GFDL|GFDL: GNU Free Documentation License
483 ** GPL|GPL: GNU General Public License
484 ** LGPL|LGPL: GNU Lesser General Public License""")
485 x("MediaWiki:Copyright", '$mw_license')
486 x("MediaWiki:Mainpage-description", "$mwdescription")
490 # The rest of the settings are for the site style
492 # Remove various clutter
493 x("MediaWiki:Lastmodifiedat")
494 x("MediaWiki:Disclaimers")
495 x("MediaWiki:Viewcount")
496 x("MediaWiki:Aboutsite")
497 # remove these lines from sidebar
498 # ** recentchanges-url|recentchanges
499 # ** randompage-url|randompage
501 x("MediaWiki:Sidebar", """* navigation
502 ** mainpage|mainpage-description
508 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
509 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
510 /* panel width increased to fit full wiki name. */
511 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
512 div#footer, #mw-head-base, div#content { margin-left: 1em; }
513 #left-navigation { margin-left: 1em; }
516 /* logo, and toolbar hidden */
517 #p-logo, #p-tb.portal {
521 /* make the font size smaller for the misc stuff */
529 div#mw-content-text {
535 # this can spam a warning, so uniq it
536 python pwb.py
${mwfamily}_setup |
& uniq
538 # <source lang="bash">
539 s
=/etc
/cron.daily
/mediawiki_update
544 for dir in extensions/* skins/* $mw; do
545 [[ -d $dir ]] || continue
547 branch=$(git describe --all)
548 branch=${branch#remotes/}
550 new_head=$(git rev-parse $branch)
551 log=$(git log HEAD..$new_head)
556 git checkout -q $new_head
559 php $mw/maintenance/update.php -q