FANDOM


    /**
     * Finds files which have no license template specified and gives them
     * the {{NoLicense}} template as a default.
     */
    public static void addNoLicenseTemplate() throws Exception {

        MediaWikiBot b = new MediaWikiBot(SITE_URL);
        b.login(USERNAME, PASSWORD);
        postStartStatusMessage(b);

        int count = 0;
        AllPageTitles apt = new AllPageTitles(b, FILE_NAMESPACE);
        while (apt.hasNext()) {
            String title = apt.next();
            System.out.println("Checking: " + title);
            try {
                SimpleArticle sa = new SimpleArticle(b.readContent(title));
                String articleText = sa.getText();
                if (!articleText.contains("==Licensing==") && !articleText.contains("{{")) {
                    // this article has no licensing section/content
                    String newText = NO_LICENSE_BLOCK + articleText;
                    sa.setText(newText);
                    b.writeContent(sa);
                    count++;
                    System.out.println(title + " was written");
                }
            } catch (Exception e) {
                System.out.println("An exception occured while processing: " + title);
                System.out.println("Skipping this title");
                //e.printStackTrace();
            }
        }
        postEndStatusMessage(b, count);
    }
Community content is available under CC-BY-SA unless otherwise noted.